Skip to content

Commit 3367239

Browse files
committed
refactor!: Properly support contexts
The new AWS SDK uses contexts for all API functions and for loading the SDK configuration. When chamber was migrated to the SDK, all of them were set to `context.TODO()`. This commit removes those temporary values and threads contexts properly throughout the codebase, starting from the chamber commands. BREAKING CHANGE: This commit changes the signature of many exported functions to add a context argument.
1 parent e70bb44 commit 3367239

24 files changed

+289
-271
lines changed

cmd/delete.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func delete(cmd *cobra.Command, args []string) error {
5151
Set("backend", backend),
5252
})
5353
}
54-
secretStore, err := getSecretStore()
54+
secretStore, err := getSecretStore(cmd.Context())
5555
if err != nil {
5656
return fmt.Errorf("Failed to get secret store: %w", err)
5757
}
@@ -60,5 +60,5 @@ func delete(cmd *cobra.Command, args []string) error {
6060
Key: key,
6161
}
6262

63-
return secretStore.Delete(secretId)
63+
return secretStore.Delete(cmd.Context(), secretId)
6464
}

cmd/env.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ func exportEnv(cmd *cobra.Command, args []string) ([]string, error) {
6464
return nil, fmt.Errorf("Failed to validate service: %w", err)
6565
}
6666

67-
secretStore, err := getSecretStore()
67+
secretStore, err := getSecretStore(cmd.Context())
6868
if err != nil {
6969
return nil, fmt.Errorf("Failed to get secret store: %w", err)
7070
}
7171

72-
rawSecrets, err := secretStore.ListRaw(service)
72+
rawSecrets, err := secretStore.ListRaw(cmd.Context(), service)
7373
if err != nil {
7474
return nil, fmt.Errorf("Failed to list store contents: %w", err)
7575
}

cmd/exec.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func execRun(cmd *cobra.Command, args []string) error {
9292
}
9393
}
9494

95-
secretStore, err := getSecretStore()
95+
secretStore, err := getSecretStore(cmd.Context())
9696
if err != nil {
9797
return fmt.Errorf("Failed to get secret store: %w", err)
9898
}
@@ -108,7 +108,7 @@ func execRun(cmd *cobra.Command, args []string) error {
108108
}
109109
var err error
110110
env = environ.Environ(os.Environ())
111-
err = env.LoadStrict(secretStore, strictValue, pristine, services...)
111+
err = env.LoadStrict(cmd.Context(), secretStore, strictValue, pristine, services...)
112112
if err != nil {
113113
return err
114114
}
@@ -120,7 +120,7 @@ func execRun(cmd *cobra.Command, args []string) error {
120120
collisions := make([]string, 0)
121121
var err error
122122
// TODO: these interfaces should look the same as Strict*, so move pristine in there
123-
err = env.Load(secretStore, service, &collisions)
123+
err = env.Load(cmd.Context(), secretStore, service, &collisions)
124124
if err != nil {
125125
return fmt.Errorf("Failed to list store contents: %w", err)
126126
}

cmd/export.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func runExport(cmd *cobra.Command, args []string) error {
5353
})
5454
}
5555

56-
secretStore, err := getSecretStore()
56+
secretStore, err := getSecretStore(cmd.Context())
5757
if err != nil {
5858
return err
5959
}
@@ -64,7 +64,7 @@ func runExport(cmd *cobra.Command, args []string) error {
6464
return fmt.Errorf("Failed to validate service %s: %w", service, err)
6565
}
6666

67-
rawSecrets, err := secretStore.ListRaw(service)
67+
rawSecrets, err := secretStore.ListRaw(cmd.Context(), service)
6868
if err != nil {
6969
return fmt.Errorf("Failed to list store contents for service %s: %w", service, err)
7070
}

cmd/find.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@ func find(cmd *cobra.Command, args []string) error {
3939
includeSecrets = true
4040
}
4141

42-
secretStore, err := getSecretStore()
42+
secretStore, err := getSecretStore(cmd.Context())
4343
if err != nil {
4444
return fmt.Errorf("Failed to get secret store: %w", err)
4545
}
46-
services, err := secretStore.ListServices(blankService, includeSecrets)
46+
services, err := secretStore.ListServices(cmd.Context(), blankService, includeSecrets)
4747
if err != nil {
4848
return fmt.Errorf("Failed to list store contents: %w", err)
4949
}
5050

5151
if byValue {
5252
for _, service := range services {
53-
allSecrets, err := secretStore.List(service, true)
53+
allSecrets, err := secretStore.List(cmd.Context(), service, true)
5454
if err == nil {
5555
matches = append(matches, findValueMatch(allSecrets, findSecret)...)
5656
}

cmd/history.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func history(cmd *cobra.Command, args []string) error {
4747
})
4848
}
4949

50-
secretStore, err := getSecretStore()
50+
secretStore, err := getSecretStore(cmd.Context())
5151
if err != nil {
5252
return fmt.Errorf("Failed to get secret store: %w", err)
5353
}
@@ -56,7 +56,7 @@ func history(cmd *cobra.Command, args []string) error {
5656
Key: key,
5757
}
5858

59-
events, err := secretStore.History(secretId)
59+
events, err := secretStore.History(cmd.Context(), secretId)
6060
if err != nil {
6161
return fmt.Errorf("Failed to get history: %w", err)
6262
}

cmd/import.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func importRun(cmd *cobra.Command, args []string) error {
6565
})
6666
}
6767

68-
secretStore, err := getSecretStore()
68+
secretStore, err := getSecretStore(cmd.Context())
6969
if err != nil {
7070
return fmt.Errorf("Failed to get secret store: %w", err)
7171
}
@@ -78,7 +78,7 @@ func importRun(cmd *cobra.Command, args []string) error {
7878
Service: service,
7979
Key: key,
8080
}
81-
if err := secretStore.Write(secretId, value); err != nil {
81+
if err := secretStore.Write(cmd.Context(), secretId, value); err != nil {
8282
return fmt.Errorf("Failed to write secret: %w", err)
8383
}
8484
}

cmd/list-services.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ func listServices(cmd *cobra.Command, args []string) error {
3434
service = utils.NormalizeService(args[0])
3535

3636
}
37-
secretStore, err := getSecretStore()
37+
secretStore, err := getSecretStore(cmd.Context())
3838
if err != nil {
3939
return fmt.Errorf("Failed to get secret store: %w", err)
4040
}
41-
secrets, err := secretStore.ListServices(service, includeSecretName)
41+
secrets, err := secretStore.ListServices(cmd.Context(), service, includeSecretName)
4242
if err != nil {
4343
return fmt.Errorf("Failed to list store contents: %w", err)
4444
}

cmd/list.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ func list(cmd *cobra.Command, args []string) error {
5454
})
5555
}
5656

57-
secretStore, err := getSecretStore()
57+
secretStore, err := getSecretStore(cmd.Context())
5858
if err != nil {
5959
return fmt.Errorf("Failed to get secret store: %w", err)
6060
}
61-
secrets, err := secretStore.List(service, withValues)
61+
secrets, err := secretStore.List(cmd.Context(), service, withValues)
6262
if err != nil {
6363
return fmt.Errorf("Failed to list store contents: %w", err)
6464
}

cmd/read.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func read(cmd *cobra.Command, args []string) error {
5454
})
5555
}
5656

57-
secretStore, err := getSecretStore()
57+
secretStore, err := getSecretStore(cmd.Context())
5858
if err != nil {
5959
return fmt.Errorf("Failed to get secret store: %w", err)
6060
}
@@ -64,7 +64,7 @@ func read(cmd *cobra.Command, args []string) error {
6464
Key: key,
6565
}
6666

67-
secret, err := secretStore.Read(secretId, version)
67+
secret, err := secretStore.Read(cmd.Context(), secretId, version)
6868
if err != nil {
6969
return fmt.Errorf("Failed to read: %w", err)
7070
}

0 commit comments

Comments
 (0)