Skip to content

Commit 832d007

Browse files
committed
requested PR updates
1 parent b51f816 commit 832d007

File tree

6 files changed

+32
-29
lines changed

6 files changed

+32
-29
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ If using Fargate, the credentials URL can be sourced automatically:
189189
```bash
190190
export IMMUDB_S3_STORAGE=true
191191
export IMMUDB_S3_ROLE_ENABLED=true
192-
export IMMUDB_S3_FARGATE_CREDENTIALS=true
192+
export IMMUDB_S3_USE_FARGATE_CREDENTIALS=true
193193
export IMMUDB_S3_BUCKET_NAME=<BUCKET NAME>
194194
export IMMUDB_S3_LOCATION=<AWS S3 REGION>
195195
export IMMUDB_S3_PATH_PREFIX=testing-001

cmd/immudb/command/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (cl *Commandline) setupFlags(cmd *cobra.Command, options *server.Options) {
8989
cmd.Flags().String("s3-path-prefix", "", "s3 path prefix (multiple immudb instances can share the same bucket if they have different prefixes)")
9090
cmd.Flags().Bool("s3-external-identifier", false, "use the remote identifier if there is no local identifier")
9191
cmd.Flags().String("s3-instance-metadata-url", "http://169.254.169.254", "s3 instance metadata url")
92-
cmd.Flags().String("s3-fargate-credentials", "false", "s3 fargate credentials true/false")
92+
cmd.Flags().String("s3-use-fargate-credentials", "false", "use fargate credentials for s3 authentication: true/false")
9393
cmd.Flags().Int("max-sessions", 100, "maximum number of simultaneously opened sessions")
9494
cmd.Flags().Duration("max-session-inactivity-time", 3*time.Minute, "max session inactivity time is a duration after which an active session is declared inactive by the server. A session is kept active if server is still receiving requests from client (keep-alive or other methods)")
9595
cmd.Flags().Duration("max-session-age-time", 0, "the current default value is infinity. max session age time is a duration after which session will be forcibly closed")

cmd/immudb/command/parse_options.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func parseOptions() (options *server.Options, err error) {
106106
s3PathPrefix := viper.GetString("s3-path-prefix")
107107
s3ExternalIdentifier := viper.GetBool("s3-external-identifier")
108108
s3MetadataURL := viper.GetString("s3-instance-metadata-url")
109-
s3FargateCredentials := viper.GetBool("s3-fargate-credentials")
109+
s3UseFargateCredentials := viper.GetBool("s3-use-fargate-credentials")
110110

111111
remoteStorageOptions := server.DefaultRemoteStorageOptions().
112112
WithS3Storage(s3Storage).
@@ -120,7 +120,7 @@ func parseOptions() (options *server.Options, err error) {
120120
WithS3PathPrefix(s3PathPrefix).
121121
WithS3ExternalIdentifier(s3ExternalIdentifier).
122122
WithS3InstanceMetadataURL(s3MetadataURL).
123-
WithS3FargateCredentials(s3FargateCredentials)
123+
WithS3UseFargateCredentials(s3UseFargateCredentials)
124124

125125
sessionOptions := sessions.DefaultOptions().
126126
WithMaxSessions(viper.GetInt("max-sessions")).

embedded/remotestorage/s3/s3.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ type Storage struct {
5757
awsInstanceMetadataURL string
5858
awsCredsRefreshPeriod time.Duration
5959

60-
fargateCredentials bool
60+
useFargateCredentials bool
6161
}
6262

6363
var (
@@ -101,7 +101,7 @@ func Open(
101101
location string,
102102
prefix string,
103103
awsInstanceMetadataURL string,
104-
fargateCredentials bool,
104+
useFargateCredentials bool,
105105
) (remotestorage.Storage, error) {
106106

107107
// Endpoint must always end with '/'
@@ -140,7 +140,7 @@ func Open(
140140
},
141141
awsInstanceMetadataURL: awsInstanceMetadataURL,
142142
awsCredsRefreshPeriod: time.Minute,
143-
fargateCredentials: fargateCredentials,
143+
useFargateCredentials: useFargateCredentials,
144144
}
145145

146146
err := s3storage.getRoleCredentials()
@@ -811,13 +811,16 @@ func (s *Storage) getRoleCredentials() error {
811811
}
812812

813813
func (s *Storage) requestCredentials() (string, string, string, error) {
814-
if s.fargateCredentials {
814+
if s.useFargateCredentials {
815815
// Use Fargate credentials
816+
817+
const fargateMetadataEndpoint = "http://169.254.170.2"
818+
816819
fargateCredentialsRelativeURI := os.Getenv("AWS_CONTAINER_CREDENTIALS_RELATIVE_URI")
817820
if fargateCredentialsRelativeURI == "" {
818-
return "", "", "", errors.New(fmt.Sprintf("environment variable %s is not set or empty", "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI"))
821+
return "", "", "", errors.New("environment variable AWS_CONTAINER_CREDENTIALS_RELATIVE_URI is not set or empty")
819822
}
820-
fargateCredentialsURL := fmt.Sprintf("%s%s", "http://169.254.170.2", fargateCredentialsRelativeURI)
823+
fargateCredentialsURL := fargateMetadataEndpoint + fargateCredentialsRelativeURI
821824

822825
fargateReq, err := http.NewRequest("GET", fargateCredentialsURL, nil)
823826
if err != nil {
@@ -830,7 +833,7 @@ func (s *Storage) requestCredentials() (string, string, string, error) {
830833
}
831834
defer fargateResp.Body.Close()
832835

833-
creds, err := ioutil.ReadAll(fargateResp.Body)
836+
creds, err := io.ReadAll(fargateResp.Body)
834837
if err != nil {
835838
return "", "", "", errors.New("cannot read fargate credentials")
836839
}

pkg/server/options.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,18 @@ type Options struct {
8787
}
8888

8989
type RemoteStorageOptions struct {
90-
S3Storage bool
91-
S3RoleEnabled bool
92-
S3Role string
93-
S3Endpoint string
94-
S3AccessKeyID string
95-
S3SecretKey string `json:"-"`
96-
S3BucketName string
97-
S3Location string
98-
S3PathPrefix string
99-
S3ExternalIdentifier bool
100-
S3InstanceMetadataURL string
101-
FargateCredentials bool
90+
S3Storage bool
91+
S3RoleEnabled bool
92+
S3Role string
93+
S3Endpoint string
94+
S3AccessKeyID string
95+
S3SecretKey string `json:"-"`
96+
S3BucketName string
97+
S3Location string
98+
S3PathPrefix string
99+
S3ExternalIdentifier bool
100+
S3InstanceMetadataURL string
101+
S3UseFargateCredentials bool
102102
}
103103

104104
type ReplicationOptions struct {
@@ -371,8 +371,8 @@ func (o *Options) String() string {
371371
opts = append(opts, "S3 storage")
372372
if o.RemoteStorageOptions.S3RoleEnabled {
373373
opts = append(opts, rightPad(" role auth", o.RemoteStorageOptions.S3RoleEnabled))
374-
if o.RemoteStorageOptions.FargateCredentials {
375-
opts = append(opts, rightPad(" fargate creds", o.RemoteStorageOptions.FargateCredentials))
374+
if o.RemoteStorageOptions.S3UseFargateCredentials {
375+
opts = append(opts, rightPad(" fargate creds", o.RemoteStorageOptions.S3UseFargateCredentials))
376376
} else {
377377
opts = append(opts, rightPad(" role name", o.RemoteStorageOptions.S3Role))
378378
}
@@ -384,7 +384,7 @@ func (o *Options) String() string {
384384
}
385385
opts = append(opts, rightPad(" prefix", o.RemoteStorageOptions.S3PathPrefix))
386386
opts = append(opts, rightPad(" external id", o.RemoteStorageOptions.S3ExternalIdentifier))
387-
if !o.RemoteStorageOptions.FargateCredentials {
387+
if !o.RemoteStorageOptions.S3UseFargateCredentials {
388388
opts = append(opts, rightPad(" metadata url", o.RemoteStorageOptions.S3InstanceMetadataURL))
389389
}
390390
}
@@ -606,8 +606,8 @@ func (opts *RemoteStorageOptions) WithS3InstanceMetadataURL(url string) *RemoteS
606606
return opts
607607
}
608608

609-
func (opts *RemoteStorageOptions) WithS3FargateCredentials(fargateCredentials bool) *RemoteStorageOptions {
610-
opts.FargateCredentials = fargateCredentials
609+
func (opts *RemoteStorageOptions) WithS3UseFargateCredentials(s3UseFargateCredentials bool) *RemoteStorageOptions {
610+
opts.S3UseFargateCredentials = s3UseFargateCredentials
611611
return opts
612612
}
613613

pkg/server/remote_storage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (s *ImmuServer) createRemoteStorageInstance() (remotestorage.Storage, error
6060
s.Options.RemoteStorageOptions.S3Location,
6161
s.Options.RemoteStorageOptions.S3PathPrefix,
6262
s.Options.RemoteStorageOptions.S3InstanceMetadataURL,
63-
s.Options.RemoteStorageOptions.FargateCredentials,
63+
s.Options.RemoteStorageOptions.S3UseFargateCredentials,
6464
)
6565
}
6666

0 commit comments

Comments
 (0)