Skip to content

Commit 117ee36

Browse files
committed
Re-generate snippets...again...
1 parent 81d88af commit 117ee36

33 files changed

Lines changed: 469 additions & 530 deletions

File tree

generated-usage-examples/go/atlas-sdk-go/main.snippet.archive-collections.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"fmt"
77
"log"
8+
"os"
89
"time"
910

1011
"atlas-sdk-go/internal/archive"
@@ -15,20 +16,19 @@ import (
1516
)
1617

1718
func main() {
18-
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
19-
defer cancel()
20-
21-
if err := godotenv.Load(); err != nil {
22-
log.Printf("Warning: could not load .env file: %v", err)
19+
envFile := ".env.production"
20+
if err := godotenv.Load(envFile); err != nil {
21+
log.Printf("Warning: could not load %s file: %v", envFile, err)
2322
}
2423

25-
envName := config.Environment("production")
26-
configPath := "configs/config.production.json"
27-
secrets, cfg, err := config.LoadAll(envName, configPath)
24+
configPath := os.Getenv("CONFIG_FILE")
25+
secrets, cfg, err := config.LoadAll(configPath)
2826
if err != nil {
2927
log.Fatalf("Failed to load configuration %v", err)
3028
}
3129

30+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
31+
defer cancel()
3232
client, err := auth.NewClient(ctx, cfg, secrets)
3333
if err != nil {
3434
log.Fatalf("Failed to initialize authentication client: %v", err)
@@ -41,30 +41,30 @@ func main() {
4141

4242
fmt.Printf("Starting archive analysis for project: %s\n", projectID)
4343

44-
// List all clusters in the project
44+
// Get all clusters in the project
4545
clusters, _, err := client.ClustersApi.ListClusters(ctx, projectID).Execute()
4646
if err != nil {
4747
log.Fatalf("Failed to list clusters: %v", err)
4848
}
4949

5050
fmt.Printf("\nFound %d clusters to analyze\n", len(clusters.GetResults()))
5151

52-
// Process each cluster
52+
// Connect to each cluster and analyze collections for archiving
5353
failedArchives := 0
5454
totalCandidates := 0
5555
for _, cluster := range clusters.GetResults() {
5656
clusterName := cluster.GetName()
5757
fmt.Printf("\n=== Analyzing cluster: %s ===", clusterName)
5858

59-
// Find collections suitable for archiving
60-
// NOTE: This function passes example database/collection names.
61-
// In a real production scenario, you would analyze data patterns and customize the selection logic.
59+
// Find collections suitable for archiving based on specific criteria.
60+
// NOTE: The actual implementation of this function would involve more complex logic
61+
// to determine which collections are eligible for archiving.
6262
candidates := archive.CollectionsForArchiving(ctx, client, projectID, clusterName)
6363
totalCandidates += len(candidates)
6464
fmt.Printf("\nFound %d collections eligible for archiving in cluster %s\n",
65-
totalCandidates, clusterName)
65+
len(candidates), clusterName)
6666

67-
// Step 4: Configure online archive for each candidate collection
67+
// Configure online archive for each candidate collection
6868
for _, candidate := range candidates {
6969
fmt.Printf("- Configuring archive for %s.%s\n",
7070
candidate.DatabaseName, candidate.CollectionName)

generated-usage-examples/go/atlas-sdk-go/main.snippet.get-logs.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"fmt"
77
"log"
8+
"os"
89

910
"atlas-sdk-go/internal/auth"
1011
"atlas-sdk-go/internal/config"
@@ -16,18 +17,18 @@ import (
1617
)
1718

1819
func main() {
19-
if err := godotenv.Load(); err != nil {
20-
log.Printf("Warning: could not load .env file: %v", err)
20+
envFile := ".env.production"
21+
if err := godotenv.Load(envFile); err != nil {
22+
log.Printf("Warning: could not load %s file: %v", envFile, err)
2123
}
2224

23-
ctx := context.Background()
24-
envName := config.Environment("production")
25-
configPath := "configs/config.production.json"
26-
secrets, cfg, err := config.LoadAll(envName, configPath)
25+
configPath := os.Getenv("CONFIG_FILE")
26+
secrets, cfg, err := config.LoadAll(configPath)
2727
if err != nil {
2828
log.Fatalf("Failed to load configuration %v", err)
2929
}
3030

31+
ctx := context.Background()
3132
client, err := auth.NewClient(ctx, cfg, secrets)
3233
if err != nil {
3334
log.Fatalf("Failed to initialize authentication client: %v", err)

generated-usage-examples/go/atlas-sdk-go/main.snippet.get-metrics-dev.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"encoding/json"
77
"fmt"
88
"log"
9+
"os"
910

1011
"atlas-sdk-go/internal/auth"
1112
"atlas-sdk-go/internal/config"
@@ -16,18 +17,18 @@ import (
1617
)
1718

1819
func main() {
19-
if err := godotenv.Load(); err != nil {
20-
log.Printf("Warning: could not load .env file: %v", err)
20+
envFile := ".env.development"
21+
if err := godotenv.Load(envFile); err != nil {
22+
log.Printf("Warning: could not load %s file: %v", envFile, err)
2123
}
2224

23-
ctx := context.Background()
24-
envName := config.Environment("development")
25-
configPath := "configs/config.development.json"
26-
secrets, cfg, err := config.LoadAll(envName, configPath)
25+
configPath := os.Getenv("CONFIG_FILE")
26+
secrets, cfg, err := config.LoadAll(configPath)
2727
if err != nil {
2828
log.Fatalf("Failed to load configuration %v", err)
2929
}
3030

31+
ctx := context.Background()
3132
client, err := auth.NewClient(ctx, cfg, secrets)
3233
if err != nil {
3334
log.Fatalf("Failed to initialize authentication client: %v", err)

generated-usage-examples/go/atlas-sdk-go/main.snippet.get-metrics-prod.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"encoding/json"
77
"fmt"
88
"log"
9+
"os"
910

1011
"atlas-sdk-go/internal/auth"
1112
"atlas-sdk-go/internal/config"
@@ -17,18 +18,18 @@ import (
1718
)
1819

1920
func main() {
20-
if err := godotenv.Load(); err != nil {
21-
log.Printf("Warning: could not load .env file: %v", err)
21+
envFile := ".env.production"
22+
if err := godotenv.Load(envFile); err != nil {
23+
log.Printf("Warning: could not load %s file: %v", envFile, err)
2224
}
2325

24-
ctx := context.Background()
25-
envName := config.Environment("production")
26-
configPath := "configs/config.production.json"
27-
secrets, cfg, err := config.LoadAll(envName, configPath)
26+
configPath := os.Getenv("CONFIG_FILE")
27+
secrets, cfg, err := config.LoadAll(configPath)
2828
if err != nil {
2929
log.Fatalf("Failed to load configuration %v", err)
3030
}
3131

32+
ctx := context.Background()
3233
client, err := auth.NewClient(ctx, cfg, secrets)
3334
if err != nil {
3435
log.Fatalf("Failed to initialize authentication client: %v", err)

generated-usage-examples/go/atlas-sdk-go/main.snippet.historical-billing.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"fmt"
77
"log"
8+
"os"
89
"time"
910

1011
"atlas-sdk-go/internal/auth"
@@ -18,18 +19,17 @@ import (
1819
)
1920

2021
func main() {
21-
if err := godotenv.Load(); err != nil {
22-
log.Printf("Warning: could not load .env file: %v", err)
22+
envFile := ".env.production"
23+
if err := godotenv.Load(envFile); err != nil {
24+
log.Printf("Warning: could not load %s file: %v", envFile, err)
2325
}
24-
25-
ctx := context.Background()
26-
envName := config.Environment("production")
27-
configPath := "configs/config.production.json"
28-
secrets, cfg, err := config.LoadAll(envName, configPath)
26+
configPath := os.Getenv("CONFIG_PATH")
27+
secrets, cfg, err := config.LoadAll(configPath)
2928
if err != nil {
3029
log.Fatalf("Failed to load configuration %v", err)
3130
}
3231

32+
ctx := context.Background()
3333
client, err := auth.NewClient(ctx, cfg, secrets)
3434
if err != nil {
3535
log.Fatalf("Failed to initialize authentication client: %v", err)

generated-usage-examples/go/atlas-sdk-go/main.snippet.line-items.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"fmt"
77
"log"
8+
"os"
89

910
"github.com/joho/godotenv"
1011
"go.mongodb.org/atlas-sdk/v20250219001/admin"
@@ -17,18 +18,18 @@ import (
1718
)
1819

1920
func main() {
20-
if err := godotenv.Load(); err != nil {
21-
log.Printf("Warning: could not load .env file: %v", err)
21+
envFile := ".env.production"
22+
if err := godotenv.Load(envFile); err != nil {
23+
log.Printf("Warning: could not load %s file: %v", envFile, err)
2224
}
2325

24-
ctx := context.Background()
25-
envName := config.Environment("production")
26-
configPath := "configs/config.production.json"
27-
secrets, cfg, err := config.LoadAll(envName, configPath)
26+
configPath := os.Getenv("CONFIG_FILE")
27+
secrets, cfg, err := config.LoadAll(configPath)
2828
if err != nil {
2929
log.Fatalf("Failed to load configuration %v", err)
3030
}
3131

32+
ctx := context.Background()
3233
client, err := auth.NewClient(ctx, cfg, secrets)
3334
if err != nil {
3435
log.Fatalf("Failed to initialize authentication client: %v", err)

generated-usage-examples/go/atlas-sdk-go/main.snippet.linked-billing.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"fmt"
77
"log"
8+
"os"
89

910
"atlas-sdk-go/internal/auth"
1011
"atlas-sdk-go/internal/billing"
@@ -15,18 +16,18 @@ import (
1516
)
1617

1718
func main() {
18-
if err := godotenv.Load(); err != nil {
19-
log.Printf("Warning: could not load .env file: %v", err)
19+
envFile := ".env.production"
20+
if err := godotenv.Load(envFile); err != nil {
21+
log.Printf("Warning: could not load %s file: %v", envFile, err)
2022
}
2123

22-
ctx := context.Background()
23-
envName := config.Environment("production")
24-
configPath := "configs/config.production.json"
25-
secrets, cfg, err := config.LoadAll(envName, configPath)
24+
configPath := os.Getenv("CONFIG_FILE")
25+
secrets, cfg, err := config.LoadAll(configPath)
2626
if err != nil {
2727
log.Fatalf("Failed to load configuration %v", err)
2828
}
2929

30+
ctx := context.Background()
3031
client, err := auth.NewClient(ctx, cfg, secrets)
3132
if err != nil {
3233
log.Fatalf("Failed to initialize authentication client: %v", err)
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
MONGODB_ATLAS_SERVICE_ACCOUNT_ID=your_mdb_service_account_id
2-
MONGODB_ATLAS_SERVICE_ACCOUNT_SECRET=your_mdb_service_account_secret
3-
ATLAS_DOWNLOADS_DIR="tmp/atlas_downloads" # optional directory for downloads
1+
MONGODB_ATLAS_SERVICE_ACCOUNT_ID=<your_mdb_service_account_id>
2+
MONGODB_ATLAS_SERVICE_ACCOUNT_SECRET=<your_mdb_service_account_secret>
3+
ATLAS_DOWNLOADS_DIR=tmp/atlas_downloads # optional directory for downloads
4+
CONFIG_PATH=./configs/config.<env>.json # path to corresponding config file

generated-usage-examples/go/atlas-sdk-go/project-copy/.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Secrets (keep example)
2-
.env
2+
tmp/.env
33
!.env.example
4-
.env.development
4+
tmp/.env.development
55
.env.production
6-
.env.test
6+
tmp/.env.test
77

88
# config files (keep example)
99
configs

generated-usage-examples/go/atlas-sdk-go/project-copy/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ and improvements to existing code.
6161

6262
1. Create a `.env.<environment>` file in the root directory with your MongoDB Atlas service account credentials. For example, create a `.env.development` file for your dev environment:
6363
```dotenv
64-
MONGODB_ATLAS_SERVICE_ACCOUNT_ID=your_service_account_id
65-
MONGODB_ATLAS_SERVICE_ACCOUNT_SECRET=your_service_account_secret
64+
MONGODB_ATLAS_SERVICE_ACCOUNT_ID=<your_service_account_id>
65+
MONGODB_ATLAS_SERVICE_ACCOUNT_SECRET=<your_service_account_secret>
6666
ATLAS_DOWNLOADS_DIR="tmp/atlas_downloads" # optional download directory
67+
CONFIG_PATH="configs/config.development.json"
6768
```
6869
> **NOTE:** For production, use a secrets manager (e.g. HashiCorp Vault, AWS Secrets Manager)
6970
> instead of environment variables.

0 commit comments

Comments
 (0)