Skip to content

Commit 6764345

Browse files
committed
s3 credentials: settle on (Access|Secret)KeyFile and (access|secret)_key_file names
1 parent 7ed8697 commit 6764345

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

backends/s3/credentials.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ type FileSecretsCredentials struct {
1616

1717
// Path to the field containing the access key,
1818
// e.g. /etc/s3-secrets/access-key.
19-
AccessKeyFilename string
19+
AccessKeyFile string
2020

2121
// Path to the field containing the secret key,
2222
// e.g. /etc/s3-secrets/secret-key.
23-
SecretKeyFilename string
23+
SecretKeyFile string
2424
}
2525

2626
// Retrieve implements credentials.Provider.
2727
// It reads files pointed to by p.AccessKeyFilename and p.SecretKeyFilename.
2828
func (c *FileSecretsCredentials) Retrieve() (credentials.Value, error) {
29-
keyId, err := os.ReadFile(c.AccessKeyFilename)
29+
keyId, err := os.ReadFile(c.AccessKeyFile)
3030
if err != nil {
3131
return credentials.Value{}, err
3232
}
33-
secretKey, err := os.ReadFile(c.SecretKeyFilename)
33+
secretKey, err := os.ReadFile(c.SecretKeyFile)
3434
if err != nil {
3535
return credentials.Value{}, err
3636
}

backends/s3/credentials_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ func TestFileSecretsCredentials(t *testing.T) {
1919

2020
// Instanciate provider (what we're testing).
2121
provider := &s3.FileSecretsCredentials{
22-
AccessKeyFilename: filepath.Join(tempDir, "access-key"),
23-
SecretKeyFilename: filepath.Join(tempDir, "secret-key"),
22+
AccessKeyFile: filepath.Join(tempDir, "access-key"),
23+
SecretKeyFile: filepath.Join(tempDir, "secret-key"),
2424
}
2525

2626
// writeFiles creates or overwrites provider files
@@ -40,8 +40,8 @@ func TestFileSecretsCredentials(t *testing.T) {
4040
t.Fatal(err)
4141
}
4242
}
43-
writeContent(provider.AccessKeyFilename)
44-
writeContent(provider.SecretKeyFilename)
43+
writeContent(provider.AccessKeyFile)
44+
writeContent(provider.SecretKeyFile)
4545
}
4646

4747
ctx := context.Background()

backends/s3/s3.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,15 @@ type Options struct {
4545
AccessKey string `yaml:"access_key"`
4646
SecretKey string `yaml:"secret_key"`
4747

48-
// Path to the field containing the access key,
48+
// Path to the file containing the access key
49+
// as an alternative to AccessKey and SecretKey,
4950
// e.g. /etc/s3-secrets/access-key.
50-
AccessKeyFilename string `json:"access_key_filename"`
51+
AccessKeyFile string `yaml:"access_key_file"`
5152

52-
// Path to the field containing the secret key,
53+
// Path to the field containing the secret key
54+
// as an alternative to AccessKey and SecretKey,
5355
// e.g. /etc/s3-secrets/secret-key.
54-
SecretKeyFilename string `json:"secret_key_filename"`
56+
SecretKeyFile string `yaml:"secret_key_file"`
5557

5658
// Region defaults to "us-east-1", which also works for Minio
5759
Region string `yaml:"region"`
@@ -101,7 +103,7 @@ type Options struct {
101103
}
102104

103105
func (o Options) Check() error {
104-
hasSecretsCreds := o.AccessKeyFilename != "" && o.SecretKeyFilename != ""
106+
hasSecretsCreds := o.AccessKeyFile != "" && o.SecretKeyFile != ""
105107
hasStaticCreds := o.AccessKey != "" && o.SecretKey != ""
106108
if !hasSecretsCreds && !hasStaticCreds {
107109
return fmt.Errorf("s3 storage.options: credentials are required, fill either (access_key and secret_key) or (access_key_filename and secret_key_filename)")
@@ -350,10 +352,10 @@ func New(ctx context.Context, opt Options) (*Backend, error) {
350352
}
351353

352354
creds := credentials.NewStaticV4(opt.AccessKey, opt.SecretKey, "")
353-
if opt.AccessKeyFilename != "" {
355+
if opt.AccessKeyFile != "" {
354356
creds = credentials.New(&FileSecretsCredentials{
355-
AccessKeyFilename: opt.AccessKeyFilename,
356-
SecretKeyFilename: opt.SecretKeyFilename,
357+
AccessKeyFile: opt.AccessKeyFile,
358+
SecretKeyFile: opt.SecretKeyFile,
357359
})
358360
}
359361

0 commit comments

Comments
 (0)