Skip to content

Commit c7fb3d2

Browse files
committed
fix(api): rename *Context functions returning errors to *ContextE
Thirteen exported functions returned (T, error) under names ending in *Context, violating the *ContextE convention used elsewhere. Tagging v1.0 with the convention violation would lock it into the stable API and a later rename would require a major version bump. Renamed in modules/aws/auth.go: NewAuthenticatedSessionContext NewAuthenticatedSessionFromDefaultCredentialsContext NewAuthenticatedSessionFromRoleContext CreateAwsSessionWithCredsContext CreateAwsSessionWithMfaContext ReadPasswordPolicyMinPasswordLengthContext Renamed in modules/azure/client_factory.go: CreateSQLServerClientContext CreateSQLMangedInstanceClientContext CreateSQLMangedDatabasesClientContext CreateDatabaseClientContext CreateActionGroupClientContext Renamed in modules/azure/sql.go: GetSQLServerClientContext GetDatabaseClientContext For each, the original name remains as a // Deprecated: alias delegating to the new *ContextE function so existing callers keep compiling. Internal callers and the existing non-Context deprecated wrappers are repointed at the new names directly. OSS-3451.
1 parent bc047d0 commit c7fb3d2

5 files changed

Lines changed: 154 additions & 63 deletions

File tree

modules/aws/auth.go

Lines changed: 69 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,35 @@ const (
2222
AuthAssumeRoleEnvVar = "TERRATEST_IAM_ROLE"
2323
)
2424

25-
// NewAuthenticatedSessionContext creates an AWS Config following to standard AWS authentication workflow.
25+
// NewAuthenticatedSessionContextE creates an AWS Config following to standard AWS authentication workflow.
2626
// If AuthAssumeIamRoleEnvVar environment variable is set, assumes IAM role specified in it.
2727
// The ctx parameter supports cancellation and timeouts.
28-
func NewAuthenticatedSessionContext(ctx context.Context, region string) (*aws.Config, error) {
28+
func NewAuthenticatedSessionContextE(ctx context.Context, region string) (*aws.Config, error) {
2929
if assumeRoleArn, ok := os.LookupEnv(AuthAssumeRoleEnvVar); ok {
30-
return NewAuthenticatedSessionFromRoleContext(ctx, region, assumeRoleArn)
30+
return NewAuthenticatedSessionFromRoleContextE(ctx, region, assumeRoleArn)
3131
}
3232

33-
return NewAuthenticatedSessionFromDefaultCredentialsContext(ctx, region)
33+
return NewAuthenticatedSessionFromDefaultCredentialsContextE(ctx, region)
34+
}
35+
36+
// NewAuthenticatedSessionContext is a backwards-compatible alias for [NewAuthenticatedSessionContextE].
37+
//
38+
// Deprecated: Use [NewAuthenticatedSessionContextE] instead.
39+
func NewAuthenticatedSessionContext(ctx context.Context, region string) (*aws.Config, error) {
40+
return NewAuthenticatedSessionContextE(ctx, region)
3441
}
3542

3643
// NewAuthenticatedSession creates an AWS Config following to standard AWS authentication workflow.
3744
// If AuthAssumeIamRoleEnvVar environment variable is set, assumes IAM role specified in it.
3845
//
39-
// Deprecated: Use [NewAuthenticatedSessionContext] instead.
46+
// Deprecated: Use [NewAuthenticatedSessionContextE] instead.
4047
func NewAuthenticatedSession(region string) (*aws.Config, error) {
41-
return NewAuthenticatedSessionContext(context.Background(), region)
48+
return NewAuthenticatedSessionContextE(context.Background(), region)
4249
}
4350

44-
// NewAuthenticatedSessionFromDefaultCredentialsContext gets an AWS Config, checking that the user has credentials properly configured in their environment.
51+
// NewAuthenticatedSessionFromDefaultCredentialsContextE gets an AWS Config, checking that the user has credentials properly configured in their environment.
4552
// The ctx parameter supports cancellation and timeouts.
46-
func NewAuthenticatedSessionFromDefaultCredentialsContext(ctx context.Context, region string) (*aws.Config, error) {
53+
func NewAuthenticatedSessionFromDefaultCredentialsContextE(ctx context.Context, region string) (*aws.Config, error) {
4754
cfg, err := config.LoadDefaultConfig(ctx, config.WithRegion(region))
4855
if err != nil {
4956
return nil, CredentialsError{UnderlyingErr: err}
@@ -52,19 +59,26 @@ func NewAuthenticatedSessionFromDefaultCredentialsContext(ctx context.Context, r
5259
return &cfg, nil
5360
}
5461

62+
// NewAuthenticatedSessionFromDefaultCredentialsContext is a backwards-compatible alias for [NewAuthenticatedSessionFromDefaultCredentialsContextE].
63+
//
64+
// Deprecated: Use [NewAuthenticatedSessionFromDefaultCredentialsContextE] instead.
65+
func NewAuthenticatedSessionFromDefaultCredentialsContext(ctx context.Context, region string) (*aws.Config, error) {
66+
return NewAuthenticatedSessionFromDefaultCredentialsContextE(ctx, region)
67+
}
68+
5569
// NewAuthenticatedSessionFromDefaultCredentials gets an AWS Config, checking that the user has credentials properly configured in their environment.
5670
//
57-
// Deprecated: Use [NewAuthenticatedSessionFromDefaultCredentialsContext] instead.
71+
// Deprecated: Use [NewAuthenticatedSessionFromDefaultCredentialsContextE] instead.
5872
func NewAuthenticatedSessionFromDefaultCredentials(region string) (*aws.Config, error) {
59-
return NewAuthenticatedSessionFromDefaultCredentialsContext(context.Background(), region)
73+
return NewAuthenticatedSessionFromDefaultCredentialsContextE(context.Background(), region)
6074
}
6175

62-
// NewAuthenticatedSessionFromRoleContext returns a new AWS Config after assuming the
76+
// NewAuthenticatedSessionFromRoleContextE returns a new AWS Config after assuming the
6377
// role whose ARN is provided in roleARN. If the credentials are not properly
6478
// configured in the underlying environment, an error is returned.
6579
// The ctx parameter supports cancellation and timeouts.
66-
func NewAuthenticatedSessionFromRoleContext(ctx context.Context, region string, roleARN string) (*aws.Config, error) {
67-
cfg, err := NewAuthenticatedSessionFromDefaultCredentialsContext(ctx, region)
80+
func NewAuthenticatedSessionFromRoleContextE(ctx context.Context, region string, roleARN string) (*aws.Config, error) {
81+
cfg, err := NewAuthenticatedSessionFromDefaultCredentialsContextE(ctx, region)
6882
if err != nil {
6983
return nil, err
7084
}
@@ -86,36 +100,50 @@ func NewAuthenticatedSessionFromRoleContext(ctx context.Context, region string,
86100
}, nil
87101
}
88102

103+
// NewAuthenticatedSessionFromRoleContext is a backwards-compatible alias for [NewAuthenticatedSessionFromRoleContextE].
104+
//
105+
// Deprecated: Use [NewAuthenticatedSessionFromRoleContextE] instead.
106+
func NewAuthenticatedSessionFromRoleContext(ctx context.Context, region string, roleARN string) (*aws.Config, error) {
107+
return NewAuthenticatedSessionFromRoleContextE(ctx, region, roleARN)
108+
}
109+
89110
// NewAuthenticatedSessionFromRole returns a new AWS Config after assuming the
90111
// role whose ARN is provided in roleARN. If the credentials are not properly
91112
// configured in the underlying environment, an error is returned.
92113
//
93-
// Deprecated: Use [NewAuthenticatedSessionFromRoleContext] instead.
114+
// Deprecated: Use [NewAuthenticatedSessionFromRoleContextE] instead.
94115
func NewAuthenticatedSessionFromRole(region string, roleARN string) (*aws.Config, error) {
95-
return NewAuthenticatedSessionFromRoleContext(context.Background(), region, roleARN)
116+
return NewAuthenticatedSessionFromRoleContextE(context.Background(), region, roleARN)
96117
}
97118

98-
// CreateAwsSessionWithCredsContext creates a new AWS Config using explicit credentials. This is useful if you want to create an IAM User dynamically and
119+
// CreateAwsSessionWithCredsContextE creates a new AWS Config using explicit credentials. This is useful if you want to create an IAM User dynamically and
99120
// create an AWS Config authenticated as the new IAM User.
100121
// The ctx parameter is accepted for API consistency but not currently used.
101-
func CreateAwsSessionWithCredsContext(ctx context.Context, region string, accessKeyID string, secretAccessKey string) (*aws.Config, error) {
122+
func CreateAwsSessionWithCredsContextE(_ context.Context, region string, accessKeyID string, secretAccessKey string) (*aws.Config, error) {
102123
return &aws.Config{
103124
Region: region,
104125
Credentials: aws.NewCredentialsCache(credentials.NewStaticCredentialsProvider(accessKeyID, secretAccessKey, "")),
105126
}, nil
106127
}
107128

129+
// CreateAwsSessionWithCredsContext is a backwards-compatible alias for [CreateAwsSessionWithCredsContextE].
130+
//
131+
// Deprecated: Use [CreateAwsSessionWithCredsContextE] instead.
132+
func CreateAwsSessionWithCredsContext(ctx context.Context, region string, accessKeyID string, secretAccessKey string) (*aws.Config, error) {
133+
return CreateAwsSessionWithCredsContextE(ctx, region, accessKeyID, secretAccessKey)
134+
}
135+
108136
// CreateAwsSessionWithCreds creates a new AWS Config using explicit credentials. This is useful if you want to create an IAM User dynamically and
109137
// create an AWS Config authenticated as the new IAM User.
110138
//
111-
// Deprecated: Use [CreateAwsSessionWithCredsContext] instead.
139+
// Deprecated: Use [CreateAwsSessionWithCredsContextE] instead.
112140
func CreateAwsSessionWithCreds(region string, accessKeyID string, secretAccessKey string) (*aws.Config, error) {
113-
return CreateAwsSessionWithCredsContext(context.Background(), region, accessKeyID, secretAccessKey)
141+
return CreateAwsSessionWithCredsContextE(context.Background(), region, accessKeyID, secretAccessKey)
114142
}
115143

116-
// CreateAwsSessionWithMfaContext creates a new AWS Config authenticated using an MFA token retrieved using the given STS client and MFA Device.
144+
// CreateAwsSessionWithMfaContextE creates a new AWS Config authenticated using an MFA token retrieved using the given STS client and MFA Device.
117145
// The ctx parameter supports cancellation and timeouts.
118-
func CreateAwsSessionWithMfaContext(ctx context.Context, region string, stsClient *sts.Client, mfaDevice *types.VirtualMFADevice) (*aws.Config, error) {
146+
func CreateAwsSessionWithMfaContextE(ctx context.Context, region string, stsClient *sts.Client, mfaDevice *types.VirtualMFADevice) (*aws.Config, error) {
119147
tokenCode, err := GetTimeBasedOneTimePassword(mfaDevice)
120148
if err != nil {
121149
return nil, err
@@ -139,11 +167,18 @@ func CreateAwsSessionWithMfaContext(ctx context.Context, region string, stsClien
139167
}, nil
140168
}
141169

170+
// CreateAwsSessionWithMfaContext is a backwards-compatible alias for [CreateAwsSessionWithMfaContextE].
171+
//
172+
// Deprecated: Use [CreateAwsSessionWithMfaContextE] instead.
173+
func CreateAwsSessionWithMfaContext(ctx context.Context, region string, stsClient *sts.Client, mfaDevice *types.VirtualMFADevice) (*aws.Config, error) {
174+
return CreateAwsSessionWithMfaContextE(ctx, region, stsClient, mfaDevice)
175+
}
176+
142177
// CreateAwsSessionWithMfa creates a new AWS Config authenticated using an MFA token retrieved using the given STS client and MFA Device.
143178
//
144-
// Deprecated: Use [CreateAwsSessionWithMfaContext] instead.
179+
// Deprecated: Use [CreateAwsSessionWithMfaContextE] instead.
145180
func CreateAwsSessionWithMfa(region string, stsClient *sts.Client, mfaDevice *types.VirtualMFADevice) (*aws.Config, error) {
146-
return CreateAwsSessionWithMfaContext(context.Background(), region, stsClient, mfaDevice)
181+
return CreateAwsSessionWithMfaContextE(context.Background(), region, stsClient, mfaDevice)
147182
}
148183

149184
// GetTimeBasedOneTimePassword gets a One-Time Password from the given mfaDevice. Per the RFC 6238 standard, this value will be different every 30 seconds.
@@ -158,9 +193,9 @@ func GetTimeBasedOneTimePassword(mfaDevice *types.VirtualMFADevice) (string, err
158193
return otp, nil
159194
}
160195

161-
// ReadPasswordPolicyMinPasswordLengthContext returns the minimal password length.
196+
// ReadPasswordPolicyMinPasswordLengthContextE returns the minimal password length.
162197
// The ctx parameter supports cancellation and timeouts.
163-
func ReadPasswordPolicyMinPasswordLengthContext(ctx context.Context, iamClient *iam.Client) (int, error) {
198+
func ReadPasswordPolicyMinPasswordLengthContextE(ctx context.Context, iamClient *iam.Client) (int, error) {
164199
output, err := iamClient.GetAccountPasswordPolicy(ctx, &iam.GetAccountPasswordPolicyInput{})
165200
if err != nil {
166201
return -1, err
@@ -169,11 +204,18 @@ func ReadPasswordPolicyMinPasswordLengthContext(ctx context.Context, iamClient *
169204
return int(*output.PasswordPolicy.MinimumPasswordLength), nil
170205
}
171206

207+
// ReadPasswordPolicyMinPasswordLengthContext is a backwards-compatible alias for [ReadPasswordPolicyMinPasswordLengthContextE].
208+
//
209+
// Deprecated: Use [ReadPasswordPolicyMinPasswordLengthContextE] instead.
210+
func ReadPasswordPolicyMinPasswordLengthContext(ctx context.Context, iamClient *iam.Client) (int, error) {
211+
return ReadPasswordPolicyMinPasswordLengthContextE(ctx, iamClient)
212+
}
213+
172214
// ReadPasswordPolicyMinPasswordLength returns the minimal password length.
173215
//
174-
// Deprecated: Use [ReadPasswordPolicyMinPasswordLengthContext] instead.
216+
// Deprecated: Use [ReadPasswordPolicyMinPasswordLengthContextE] instead.
175217
func ReadPasswordPolicyMinPasswordLength(iamClient *iam.Client) (int, error) {
176-
return ReadPasswordPolicyMinPasswordLengthContext(context.Background(), iamClient)
218+
return ReadPasswordPolicyMinPasswordLengthContextE(context.Background(), iamClient)
177219
}
178220

179221
// CredentialsError is an error that occurs because AWS credentials can't be found.

modules/azure/actiongroup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func GetActionGroupResourceContextE(ctx context.Context, ruleName string, resGro
3232
return nil, err
3333
}
3434

35-
client, err := CreateActionGroupClientContext(ctx, subscriptionID)
35+
client, err := CreateActionGroupClientContextE(ctx, subscriptionID)
3636
if err != nil {
3737
return nil, err
3838
}

0 commit comments

Comments
 (0)