@@ -38,10 +38,10 @@ type StaticAuth struct {
3838 endpoint * string
3939 accessKey * string
4040 secretKey * string
41- sessionToken * string
41+ sessionToken string
4242
4343 assumeRoleARN * string
44- sessionName * string
44+ sessionName string
4545
4646 session * session.Session
4747 cfg * aws.Config
@@ -50,15 +50,7 @@ type StaticAuth struct {
5050
5151func newStaticIAM (_ context.Context , opts Options , cfg * aws.Config ) (* StaticAuth , error ) {
5252 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 ,
6254 cfg : func () * aws.Config {
6355 // if nil is passed or it's just a default cfg,
6456 // then we use the options to build the aws cfg.
@@ -70,7 +62,29 @@ func newStaticIAM(_ context.Context, opts Options, cfg *aws.Config) (*StaticAuth
7062 clients : newClients (),
7163 }
7264
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 ()
7488 if err != nil {
7589 return nil , fmt .Errorf ("failed to get token client: %v" , err )
7690 }
@@ -231,8 +245,8 @@ func (a *StaticAuth) Kafka(opts KafkaOptions) (*KafkaClients, error) {
231245 if a .assumeRoleARN != nil {
232246 tokenProvider .awsIamRoleArn = * a .assumeRoleARN
233247 }
234- if a .sessionName != nil {
235- tokenProvider .awsStsSessionName = * a .sessionName
248+ if a .sessionName != "" {
249+ tokenProvider .awsStsSessionName = a .sessionName
236250 }
237251
238252 err := a .clients .kafka .New (a .session , & tokenProvider )
@@ -243,7 +257,7 @@ func (a *StaticAuth) Kafka(opts KafkaOptions) (*KafkaClients, error) {
243257 return a .clients .kafka , nil
244258}
245259
246- func (a * StaticAuth ) getTokenClient () (* session.Session , error ) {
260+ func (a * StaticAuth ) createSession () (* session.Session , error ) {
247261 var awsConfig * aws.Config
248262 if a .cfg == nil {
249263 awsConfig = aws .NewConfig ()
@@ -257,13 +271,15 @@ func (a *StaticAuth) getTokenClient() (*session.Session, error) {
257271
258272 if a .accessKey != nil && a .secretKey != nil {
259273 // 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 ))
261275 }
262276
263277 if a .endpoint != nil {
264278 awsConfig = awsConfig .WithEndpoint (* a .endpoint )
265279 }
266280
281+ // TODO support assume role for all aws components
282+
267283 awsSession , err := session .NewSessionWithOptions (session.Options {
268284 Config : * awsConfig ,
269285 SharedConfigState : session .SharedConfigEnable ,
0 commit comments