Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration: Allow empty regions #40984

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/integrations/awsoidc/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ func (req *AWSClientRequest) CheckAndSetDefaults() error {
return trace.BadParameter("role arn is required")
}

if err := awsutils.IsValidRegion(req.Region); err != nil {
return trace.Wrap(err)
if req.Region != "" {
if err := awsutils.IsValidRegion(req.Region); err != nil {
return trace.Wrap(err)
}
}

return nil
Expand Down
10 changes: 10 additions & 0 deletions lib/integrations/awsoidc/clients_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,14 @@ func TestCheckAndSetDefaults(t *testing.T) {
}).CheckAndSetDefaults()
require.NoError(t, err)
})

t.Run("empty region", func(t *testing.T) {
err := (&AWSClientRequest{
IntegrationName: "my-integration",
Token: "token",
RoleARN: "some-arn",
Region: "",
}).CheckAndSetDefaults()
require.NoError(t, err)
})
}
7 changes: 4 additions & 3 deletions lib/integrations/awsoidc/clientsv1.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ type IntegrationTokenGenerator interface {
// NewSessionV1 creates a new AWS Session for the region using the integration as source of credentials.
// This session is usable for AWS SDK Go V1.
func NewSessionV1(ctx context.Context, client IntegrationTokenGenerator, region string, integrationName string) (*session.Session, error) {
if err := utilsaws.IsValidRegion(region); err != nil {
return nil, trace.Wrap(err)
if region != "" {
tigrato marked this conversation as resolved.
Show resolved Hide resolved
if err := utilsaws.IsValidRegion(region); err != nil {
return nil, trace.Wrap(err)
}
}

integration, err := client.GetIntegration(ctx, integrationName)
if err != nil {
return nil, trace.Wrap(err)
Expand Down
9 changes: 9 additions & 0 deletions lib/integrations/awsoidc/clientsv1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ func TestNewSessionV1(t *testing.T) {
require.Equal(t, aws.String("us-dummy-1"), s.Config.Region)
},
},
{
name: "valid with empty region",
region: "",
integration: "myawsintegration",
expectedErr: require.NoError,
sessionValidator: func(t *testing.T, s *session.Session) {
require.Equal(t, aws.String(""), s.Config.Region)
},
},
{
name: "not found error when integration is missing",
region: "us-dummy-1",
Expand Down
Loading