-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate AWS Redshift services to AWS SDK v2
- Loading branch information
1 parent
2bd71db
commit 8c0f012
Showing
34 changed files
with
823 additions
and
451 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Teleport | ||
* Copyright (C) 2024 Gravitational, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package awstesthelpers | ||
|
||
import ( | ||
"maps" | ||
"slices" | ||
|
||
redshifttypes "github.com/aws/aws-sdk-go-v2/service/redshift/types" | ||
) | ||
|
||
// LabelsToRedshiftTags converts labels into [redshifttypes.Tag] list. | ||
func LabelsToRedshiftTags(labels map[string]string) []redshifttypes.Tag { | ||
keys := slices.Collect(maps.Keys(labels)) | ||
slices.Sort(keys) | ||
|
||
ret := make([]redshifttypes.Tag, 0, len(keys)) | ||
for _, key := range keys { | ||
key := key | ||
value := labels[key] | ||
|
||
ret = append(ret, redshifttypes.Tag{ | ||
Key: &key, | ||
Value: &value, | ||
}) | ||
} | ||
|
||
return ret | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Teleport | ||
* Copyright (C) 2023 Gravitational, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package mocks | ||
|
||
import ( | ||
"context" | ||
"slices" | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/credentials/stscreds" | ||
"github.com/aws/aws-sdk-go-v2/service/sts" | ||
ststypes "github.com/aws/aws-sdk-go-v2/service/sts/types" | ||
|
||
"github.com/gravitational/teleport/lib/cloud/awsconfig" | ||
) | ||
|
||
type FakeAWSConfigProvider struct { | ||
stscreds.AssumeRoleAPIClient | ||
} | ||
|
||
func (f *FakeAWSConfigProvider) GetConfig(ctx context.Context, region string, optFns ...awsconfig.OptionsFn) (aws.Config, error) { | ||
if f.AssumeRoleAPIClient != nil { | ||
optFns = append(optFns, awsconfig.WithAssumeRoleClientProviderFunc(func(_ aws.Config) stscreds.AssumeRoleAPIClient { | ||
return f.AssumeRoleAPIClient | ||
})) | ||
} else { | ||
stsClt := &FakeSTS{} | ||
optFns = append(optFns, awsconfig.WithAssumeRoleClientProviderFunc(func(_ aws.Config) stscreds.AssumeRoleAPIClient { | ||
return stsClt | ||
})) | ||
} | ||
return awsconfig.GetConfig(ctx, region, optFns...) | ||
} | ||
|
||
type stsMock STSMock | ||
|
||
// FakeSTS fakes AWS SDK v2 STS API. | ||
// It also wraps the v1 STS mock client, so callers can use it in tests for both | ||
// the v1 and v2 interfaces. | ||
// This is useful when recording assumed roles and some services use v1 | ||
// while others use a v2 STS client. | ||
// For example: | ||
// | ||
// f := &FakeSTS{} | ||
// a.v1STS = &f.STSMock | ||
// b.v2STS = f | ||
// ... | ||
// gotRoles := f.GetAssumedRoleARNs() // returns roles that were assumed with either v1 or v2 client. | ||
type FakeSTS struct { | ||
STSMock | ||
} | ||
|
||
func (m *FakeSTS) AssumeRole(ctx context.Context, in *sts.AssumeRoleInput, optFns ...func(*sts.Options)) (*sts.AssumeRoleOutput, error) { | ||
m.STSMock.mu.Lock() | ||
defer m.STSMock.mu.Unlock() | ||
if !slices.Contains(m.assumedRoleARNs, aws.ToString(in.RoleArn)) { | ||
m.assumedRoleARNs = append(m.assumedRoleARNs, aws.ToString(in.RoleArn)) | ||
m.assumedRoleExternalIDs = append(m.assumedRoleExternalIDs, aws.ToString(in.ExternalId)) | ||
} | ||
expiry := time.Now().Add(60 * time.Minute) | ||
return &sts.AssumeRoleOutput{ | ||
Credentials: &ststypes.Credentials{ | ||
AccessKeyId: in.RoleArn, | ||
SecretAccessKey: aws.String("secret"), | ||
SessionToken: aws.String("token"), | ||
Expiration: &expiry, | ||
}, | ||
}, nil | ||
} |
Oops, something went wrong.