Skip to content

Commit

Permalink
fix nil session token
Browse files Browse the repository at this point in the history
Signed-off-by: Fabian Martinez <[email protected]>
  • Loading branch information
famarting committed Nov 28, 2024
1 parent c8d900a commit 9b12903
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions common/authentication/aws/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ type StaticAuth struct {
endpoint *string
accessKey *string
secretKey *string
sessionToken *string
sessionToken string

assumeRoleARN *string
sessionName *string
sessionName string

session *session.Session
cfg *aws.Config
Expand Down Expand Up @@ -75,13 +75,13 @@ func newStaticIAM(_ context.Context, opts Options, cfg *aws.Config) (*StaticAuth
auth.secretKey = &opts.SecretKey
}
if opts.SessionToken != "" {
auth.sessionToken = &opts.SessionToken
auth.sessionToken = opts.SessionToken
}
if opts.AssumeRoleARN != "" {
auth.assumeRoleARN = &opts.AssumeRoleARN
}
if opts.SessionName != "" {
auth.sessionName = &opts.SessionName
auth.sessionName = opts.SessionName
}

initialSession, err := auth.createSession()
Expand Down Expand Up @@ -245,8 +245,8 @@ func (a *StaticAuth) Kafka(opts KafkaOptions) (*KafkaClients, error) {
if a.assumeRoleARN != nil {
tokenProvider.awsIamRoleArn = *a.assumeRoleARN
}
if a.sessionName != nil {
tokenProvider.awsStsSessionName = *a.sessionName
if a.sessionName != "" {
tokenProvider.awsStsSessionName = a.sessionName
}

err := a.clients.kafka.New(a.session, &tokenProvider)
Expand All @@ -271,7 +271,7 @@ func (a *StaticAuth) createSession() (*session.Session, error) {

if a.accessKey != nil && a.secretKey != nil {
// session token is an option field
awsConfig = awsConfig.WithCredentials(credentials.NewStaticCredentials(*a.accessKey, *a.secretKey, *a.sessionToken))
awsConfig = awsConfig.WithCredentials(credentials.NewStaticCredentials(*a.accessKey, *a.secretKey, a.sessionToken))
}

if a.endpoint != nil {
Expand Down
2 changes: 1 addition & 1 deletion common/authentication/aws/static_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestGetTokenClient(t *testing.T) {
awsInstance: &StaticAuth{
accessKey: aws.String("testAccessKey"),
secretKey: aws.String("testSecretKey"),
sessionToken: aws.String("testSessionToken"),
sessionToken: "testSessionToken",
region: aws.String("us-west-2"),
endpoint: aws.String("https://test.endpoint.com"),
},
Expand Down

0 comments on commit 9b12903

Please sign in to comment.