@@ -38,10 +38,10 @@ type StaticAuth struct {
38
38
endpoint * string
39
39
accessKey * string
40
40
secretKey * string
41
- sessionToken * string
41
+ sessionToken string
42
42
43
43
assumeRoleARN * string
44
- sessionName * string
44
+ sessionName string
45
45
46
46
session * session.Session
47
47
cfg * aws.Config
@@ -50,15 +50,7 @@ type StaticAuth struct {
50
50
51
51
func newStaticIAM (_ context.Context , opts Options , cfg * aws.Config ) (* StaticAuth , error ) {
52
52
auth := & StaticAuth {
53
- logger : opts .Logger ,
54
- region : & opts .Region ,
55
- endpoint : & opts .Endpoint ,
56
- accessKey : & opts .AccessKey ,
57
- secretKey : & opts .SecretKey ,
58
- sessionToken : & opts .SessionToken ,
59
- assumeRoleARN : & opts .AssumeRoleARN ,
60
- sessionName : & opts .SessionName ,
61
-
53
+ logger : opts .Logger ,
62
54
cfg : func () * aws.Config {
63
55
// if nil is passed or it's just a default cfg,
64
56
// then we use the options to build the aws cfg.
@@ -70,7 +62,29 @@ func newStaticIAM(_ context.Context, opts Options, cfg *aws.Config) (*StaticAuth
70
62
clients : newClients (),
71
63
}
72
64
73
- initialSession , err := auth .getTokenClient ()
65
+ if opts .Region != "" {
66
+ auth .region = & opts .Region
67
+ }
68
+ if opts .Endpoint != "" {
69
+ auth .endpoint = & opts .Endpoint
70
+ }
71
+ if opts .AccessKey != "" {
72
+ auth .accessKey = & opts .AccessKey
73
+ }
74
+ if opts .SecretKey != "" {
75
+ auth .secretKey = & opts .SecretKey
76
+ }
77
+ if opts .SessionToken != "" {
78
+ auth .sessionToken = opts .SessionToken
79
+ }
80
+ if opts .AssumeRoleARN != "" {
81
+ auth .assumeRoleARN = & opts .AssumeRoleARN
82
+ }
83
+ if opts .SessionName != "" {
84
+ auth .sessionName = opts .SessionName
85
+ }
86
+
87
+ initialSession , err := auth .createSession ()
74
88
if err != nil {
75
89
return nil , fmt .Errorf ("failed to get token client: %v" , err )
76
90
}
@@ -231,8 +245,8 @@ func (a *StaticAuth) Kafka(opts KafkaOptions) (*KafkaClients, error) {
231
245
if a .assumeRoleARN != nil {
232
246
tokenProvider .awsIamRoleArn = * a .assumeRoleARN
233
247
}
234
- if a .sessionName != nil {
235
- tokenProvider .awsStsSessionName = * a .sessionName
248
+ if a .sessionName != "" {
249
+ tokenProvider .awsStsSessionName = a .sessionName
236
250
}
237
251
238
252
err := a .clients .kafka .New (a .session , & tokenProvider )
@@ -243,7 +257,7 @@ func (a *StaticAuth) Kafka(opts KafkaOptions) (*KafkaClients, error) {
243
257
return a .clients .kafka , nil
244
258
}
245
259
246
- func (a * StaticAuth ) getTokenClient () (* session.Session , error ) {
260
+ func (a * StaticAuth ) createSession () (* session.Session , error ) {
247
261
var awsConfig * aws.Config
248
262
if a .cfg == nil {
249
263
awsConfig = aws .NewConfig ()
@@ -257,13 +271,15 @@ func (a *StaticAuth) getTokenClient() (*session.Session, error) {
257
271
258
272
if a .accessKey != nil && a .secretKey != nil {
259
273
// session token is an option field
260
- awsConfig = awsConfig .WithCredentials (credentials .NewStaticCredentials (* a .accessKey , * a .secretKey , * a .sessionToken ))
274
+ awsConfig = awsConfig .WithCredentials (credentials .NewStaticCredentials (* a .accessKey , * a .secretKey , a .sessionToken ))
261
275
}
262
276
263
277
if a .endpoint != nil {
264
278
awsConfig = awsConfig .WithEndpoint (* a .endpoint )
265
279
}
266
280
281
+ // TODO support assume role for all aws components
282
+
267
283
awsSession , err := session .NewSessionWithOptions (session.Options {
268
284
Config : * awsConfig ,
269
285
SharedConfigState : session .SharedConfigEnable ,
0 commit comments