Skip to content

Commit acf52ac

Browse files
authored
chore: Updates package aws-sdk-go to aws-sdk-go-v2 (#1467)
1 parent 4a9afaf commit acf52ac

24 files changed

Lines changed: 232 additions & 182 deletions

File tree

cfn-resources/access-list-api-key/cmd/resource/resource.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,18 @@ import (
2121
"net/http"
2222
"strings"
2323

24+
admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin"
25+
2426
"github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler"
2527
"github.com/aws/aws-sdk-go-v2/aws"
26-
"github.com/aws/aws-sdk-go/service/cloudformation"
28+
"github.com/aws/aws-sdk-go-v2/service/cloudformation/types"
29+
2730
"github.com/mongodb/mongodbatlas-cloudformation-resources/profile"
2831
"github.com/mongodb/mongodbatlas-cloudformation-resources/util"
2932
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants"
3033
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/logger"
3134
progress_events "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent"
3235
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/validator"
33-
admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin"
3436
)
3537

3638
var CreateRequiredFields = []string{constants.OrgID, constants.APIUserID}
@@ -79,14 +81,14 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler
7981
return handler.ProgressEvent{
8082
OperationStatus: handler.Failed,
8183
Message: EitherOrMessage,
82-
HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest}, nil
84+
HandlerErrorCode: string(types.HandlerErrorCodeInvalidRequest)}, nil
8385
}
8486

8587
if currentModel.CidrBlock != nil && currentModel.IpAddress != nil {
8688
return handler.ProgressEvent{
8789
OperationStatus: handler.Failed,
8890
Message: MutualExclusiveMessage,
89-
HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest}, nil
91+
HandlerErrorCode: string(types.HandlerErrorCodeInvalidRequest)}, nil
9092
}
9193

9294
// createReq.ApiService.
@@ -140,14 +142,14 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P
140142
return handler.ProgressEvent{
141143
OperationStatus: handler.Failed,
142144
Message: EitherOrMessage,
143-
HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest}, nil
145+
HandlerErrorCode: string(types.HandlerErrorCodeInvalidRequest)}, nil
144146
}
145147

146148
if currentModel.CidrBlock != nil && currentModel.IpAddress != nil {
147149
return handler.ProgressEvent{
148150
OperationStatus: handler.Failed,
149151
Message: MutualExclusiveMessage,
150-
HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest}, nil
152+
HandlerErrorCode: string(types.HandlerErrorCodeInvalidRequest)}, nil
151153
}
152154

153155
entry := getEntryAddress(currentModel)
@@ -191,14 +193,14 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler
191193
return handler.ProgressEvent{
192194
OperationStatus: handler.Failed,
193195
Message: EitherOrMessage,
194-
HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest}, nil
196+
HandlerErrorCode: string(types.HandlerErrorCodeInvalidRequest)}, nil
195197
}
196198

197199
if currentModel.CidrBlock != nil && currentModel.IpAddress != nil {
198200
return handler.ProgressEvent{
199201
OperationStatus: handler.Failed,
200202
Message: MutualExclusiveMessage,
201-
HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest}, nil
203+
HandlerErrorCode: string(types.HandlerErrorCodeInvalidRequest)}, nil
202204
}
203205

204206
entry := getEntryAddress(currentModel)
@@ -294,14 +296,14 @@ func handleError(response *http.Response, method string, err error) (handler.Pro
294296
return handler.ProgressEvent{
295297
OperationStatus: handler.Failed,
296298
Message: errMsg,
297-
HandlerErrorCode: cloudformation.HandlerErrorCodeInternalFailure}, nil
299+
HandlerErrorCode: string(types.HandlerErrorCodeInternalFailure)}, nil
298300
}
299301

300302
if response.StatusCode == http.StatusConflict {
301303
return handler.ProgressEvent{
302304
OperationStatus: handler.Failed,
303305
Message: errMsg,
304-
HandlerErrorCode: cloudformation.HandlerErrorCodeAlreadyExists}, nil
306+
HandlerErrorCode: string(types.HandlerErrorCodeAlreadyExists)}, nil
305307
}
306308
return progress_events.GetFailedEventByResponse(errMsg, response), nil
307309
}

cfn-resources/alert-configuration/cmd/resource/resource.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,19 @@ import (
2121
"reflect"
2222
"strings"
2323

24+
admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin"
25+
2426
"github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler"
25-
"github.com/aws/aws-sdk-go/aws"
26-
"github.com/aws/aws-sdk-go/service/cloudformation"
27+
"github.com/aws/aws-sdk-go-v2/aws"
28+
"github.com/aws/aws-sdk-go-v2/service/cloudformation/types"
29+
"github.com/spf13/cast"
30+
2731
"github.com/mongodb/mongodbatlas-cloudformation-resources/profile"
2832
"github.com/mongodb/mongodbatlas-cloudformation-resources/util"
2933
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants"
3034
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/logger"
3135
progressevents "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent"
3236
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/validator"
33-
"github.com/spf13/cast"
34-
admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin"
3537
)
3638

3739
var CreateRequiredFields = []string{constants.EventTypeName, constants.ProjectID}
@@ -68,12 +70,12 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler
6870
return handler.ProgressEvent{
6971
OperationStatus: handler.Failed,
7072
Message: "Resource Already Exists",
71-
HandlerErrorCode: cloudformation.HandlerErrorCodeAlreadyExists}, nil
73+
HandlerErrorCode: string(types.HandlerErrorCodeAlreadyExists)}, nil
7274
}
7375

7476
notifications, err := expandAlertConfigurationNotification(currentModel.Notifications)
7577
if err != nil {
76-
return progressevents.GetFailedEventByCode(err.Error(), cloudformation.HandlerErrorCodeInvalidRequest), err
78+
return progressevents.GetFailedEventByCode(err.Error(), string(types.HandlerErrorCodeInvalidRequest)), err
7779
}
7880

7981
alertConfigRequest := admin20231115014.GroupAlertsConfig{
@@ -125,7 +127,7 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P
125127
return handler.ProgressEvent{
126128
OperationStatus: handler.Failed,
127129
Message: "Resource Not Found",
128-
HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil
130+
HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil
129131
}
130132

131133
alertConfig, resp, err := atlasV2.AlertConfigurationsApi.GetAlertConfiguration(context.Background(), *currentModel.ProjectId, *currentModel.Id).Execute()
@@ -165,7 +167,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler
165167
return handler.ProgressEvent{
166168
OperationStatus: handler.Failed,
167169
Message: "Resource Not Found",
168-
HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil
170+
HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil
169171
}
170172

171173
// In order to update an alert config it is necessary to send the original alert configuration request again, if not the
@@ -229,7 +231,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler
229231
return handler.ProgressEvent{
230232
OperationStatus: handler.Failed,
231233
Message: "Resource Not Found",
232-
HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil
234+
HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil
233235
}
234236

235237
res, err := atlasV2.AlertConfigurationsApi.DeleteAlertConfiguration(context.Background(), *currentModel.ProjectId, *currentModel.Id).Execute()
@@ -248,7 +250,7 @@ func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.P
248250
return handler.ProgressEvent{
249251
OperationStatus: handler.Failed,
250252
Message: "List operation is not supported",
251-
HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil
253+
HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil
252254
}
253255

254256
func isExist(currentModel *Model, client *admin20231115014.APIClient) bool {

cfn-resources/api-key/cmd/resource/resource.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,19 @@ import (
2020
"net/http"
2121
"sort"
2222

23+
admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin"
24+
2325
"github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler"
24-
"github.com/aws/aws-sdk-go/aws"
25-
"github.com/aws/aws-sdk-go/service/cloudformation"
26+
"github.com/aws/aws-sdk-go-v2/aws"
27+
"github.com/aws/aws-sdk-go-v2/service/cloudformation/types"
28+
2629
"github.com/mongodb/mongodbatlas-cloudformation-resources/profile"
2730
"github.com/mongodb/mongodbatlas-cloudformation-resources/util"
2831
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants"
2932
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/logger"
3033
progress_events "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent"
3134
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/secrets"
3235
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/validator"
33-
34-
admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin"
3536
)
3637

3738
var CreateRequiredFields = []string{constants.OrgID, constants.Description, constants.AwsSecretName}
@@ -285,13 +286,13 @@ func handleError(response *http.Response, method constants.CfnFunctions, err err
285286
return handler.ProgressEvent{
286287
OperationStatus: handler.Failed,
287288
Message: errMsg,
288-
HandlerErrorCode: cloudformation.HandlerErrorCodeAlreadyExists}, nil
289+
HandlerErrorCode: string(types.HandlerErrorCodeAlreadyExists)}, nil
289290
}
290291
if response.StatusCode == http.StatusBadRequest {
291292
return handler.ProgressEvent{
292293
OperationStatus: handler.Failed,
293294
Message: errMsg,
294-
HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil
295+
HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil
295296
}
296297
return progress_events.GetFailedEventByResponse(errMsg, response), nil
297298
}

cfn-resources/auditing/cmd/resource/resource.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@ import (
1919
"errors"
2020
"net/http"
2121

22+
admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin"
23+
2224
"github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler"
23-
"github.com/aws/aws-sdk-go/aws"
24-
"github.com/aws/aws-sdk-go/service/cloudformation"
25+
"github.com/aws/aws-sdk-go-v2/aws"
26+
"github.com/aws/aws-sdk-go-v2/service/cloudformation/types"
27+
2528
"github.com/mongodb/mongodbatlas-cloudformation-resources/util"
2629
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants"
2730
log "github.com/mongodb/mongodbatlas-cloudformation-resources/util/logger"
2831
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent"
2932
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/validator"
30-
admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin"
3133
)
3234

3335
var RequiredFields = []string{constants.ProjectID}
@@ -58,9 +60,9 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler
5860
return progressevent.GetFailedEventByResponse(err.Error(), res), nil
5961
}
6062

61-
if aws.BoolValue(atlasAuditing.Enabled) {
63+
if aws.ToBool(atlasAuditing.Enabled) {
6264
return handler.ProgressEvent{
63-
HandlerErrorCode: cloudformation.HandlerErrorCodeAlreadyExists,
65+
HandlerErrorCode: string(types.HandlerErrorCodeAlreadyExists),
6466
OperationStatus: handler.Failed,
6567
}, nil
6668
}
@@ -116,9 +118,9 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P
116118
return progressevent.GetFailedEventByResponse(err.Error(), res), nil
117119
}
118120

119-
if !aws.BoolValue(atlasAuditing.Enabled) {
121+
if !aws.ToBool(atlasAuditing.Enabled) {
120122
return handler.ProgressEvent{
121-
HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound,
123+
HandlerErrorCode: string(types.HandlerErrorCodeNotFound),
122124
OperationStatus: handler.Failed,
123125
}, nil
124126
}
@@ -156,7 +158,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler
156158
}
157159
if !resourceEnabled {
158160
return handler.ProgressEvent{
159-
HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound,
161+
HandlerErrorCode: string(types.HandlerErrorCodeNotFound),
160162
OperationStatus: handler.Failed,
161163
Message: "resource not found",
162164
}, nil
@@ -222,7 +224,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler
222224

223225
if !resourceEnabled {
224226
return handler.ProgressEvent{
225-
HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound,
227+
HandlerErrorCode: string(types.HandlerErrorCodeNotFound),
226228
OperationStatus: handler.Failed,
227229
}, nil
228230
}
@@ -254,7 +256,7 @@ func isEnabled(client admin20231115014.APIClient, currentModel Model) (bool, *ha
254256
return false, &er
255257
}
256258

257-
return aws.BoolValue(atlasAuditing.Enabled), nil
259+
return aws.ToBool(atlasAuditing.Enabled), nil
258260
}
259261

260262
func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.ProgressEvent, error) {

cfn-resources/cloud-backup-restore-jobs/cmd/resource/resource.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@ import (
2020
"fmt"
2121
"time"
2222

23+
admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin"
24+
2325
"github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler"
24-
"github.com/aws/aws-sdk-go/aws"
25-
"github.com/aws/aws-sdk-go/service/cloudformation"
26+
"github.com/aws/aws-sdk-go-v2/aws"
27+
"github.com/aws/aws-sdk-go-v2/service/cloudformation/types"
28+
2629
"github.com/mongodb/mongodbatlas-cloudformation-resources/util"
2730
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants"
2831
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent"
2932
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/validator"
30-
admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin"
3133
)
3234

3335
var CreateRequiredFields = []string{constants.SnapshotID, constants.DeliveryType, constants.InstanceType, constants.InstanceName}
@@ -53,7 +55,7 @@ func validateModel(fields []string, model *Model) *handler.ProgressEvent {
5355

5456
if *model.InstanceType != clusterInstanceType && *model.InstanceType != serverlessInstanceType {
5557
pe := progressevent.GetFailedEventByCode(fmt.Sprintf("InstanceType must be %s or %s", clusterInstanceType, serverlessInstanceType),
56-
cloudformation.HandlerErrorCodeInvalidRequest)
58+
string(types.HandlerErrorCodeInvalidRequest))
5759
return &pe
5860
}
5961

@@ -74,7 +76,7 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler
7476

7577
err := currentModel.validateAsynchronousProperties()
7678
if err != nil {
77-
return progressevent.GetFailedEventByCode(err.Error(), cloudformation.HandlerErrorCodeInvalidRequest), err
79+
return progressevent.GetFailedEventByCode(err.Error(), string(types.HandlerErrorCodeInvalidRequest)), err
7880
}
7981

8082
if _, idExists := req.CallbackContext[constants.StateName]; idExists {
@@ -110,7 +112,7 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler
110112
currentModel.Id = server.Id
111113
}
112114

113-
if aws.BoolValue(currentModel.EnableSynchronousCreation) {
115+
if aws.ToBool(currentModel.EnableSynchronousCreation) {
114116
return progressevent.GetInProgressProgressEvent(
115117
"Create in progress",
116118
map[string]interface{}{
@@ -146,11 +148,11 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P
146148
return *err, nil
147149
}
148150

149-
if aws.BoolValue(currentModel.Cancelled) {
151+
if aws.ToBool(currentModel.Cancelled) {
150152
return handler.ProgressEvent{
151153
OperationStatus: handler.Failed,
152154
Message: "The job is in status cancelled, Cannot read a cancelled job",
153-
HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil
155+
HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil
154156
}
155157

156158
return handler.ProgressEvent{
@@ -180,14 +182,14 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler
180182
return *err, nil
181183
}
182184

183-
if aws.BoolValue(currentModel.Cancelled) {
185+
if aws.ToBool(currentModel.Cancelled) {
184186
return handler.ProgressEvent{
185187
OperationStatus: handler.Failed,
186188
Message: "The job is in status cancelled, Cannot delete a cancelled job",
187-
HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil
189+
HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil
188190
}
189191

190-
if util.IsStringPresent(currentModel.FinishedAt) || aws.BoolValue(currentModel.Failed) || aws.BoolValue(currentModel.Expired) {
192+
if util.IsStringPresent(currentModel.FinishedAt) || aws.ToBool(currentModel.Failed) || aws.ToBool(currentModel.Expired) {
191193
return handler.ProgressEvent{
192194
OperationStatus: handler.Success,
193195
Message: "The resource is finished, failed, or expired",
@@ -242,7 +244,7 @@ func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.P
242244
InstanceName: currentModel.InstanceName,
243245
Profile: currentModel.Profile,
244246
}
245-
if !aws.BoolValue(job.Cancelled) && !aws.BoolValue(job.Expired) {
247+
if !aws.ToBool(job.Cancelled) && !aws.ToBool(job.Expired) {
246248
updateModelServerless(model, job)
247249
models = append(models, model)
248250
}
@@ -262,7 +264,7 @@ func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.P
262264
InstanceName: currentModel.InstanceName,
263265
Profile: currentModel.Profile,
264266
}
265-
if !aws.BoolValue(job.Cancelled) && !aws.BoolValue(job.Expired) {
267+
if !aws.ToBool(job.Cancelled) && !aws.ToBool(job.Expired) {
266268
updateModelServer(model, job)
267269
models = append(models, model)
268270
}
@@ -283,11 +285,11 @@ func (model *Model) validateAsynchronousProperties() error {
283285
}
284286

285287
if model.SynchronousCreationOptions.CallbackDelaySeconds == nil {
286-
model.SynchronousCreationOptions.CallbackDelaySeconds = aws.Int(defaultBackSeconds)
288+
model.SynchronousCreationOptions.CallbackDelaySeconds = util.IntPtr(defaultBackSeconds)
287289
}
288290

289291
if model.SynchronousCreationOptions.TimeOutInSeconds == nil {
290-
model.SynchronousCreationOptions.TimeOutInSeconds = aws.Int(defaultTimeOutInSeconds)
292+
model.SynchronousCreationOptions.TimeOutInSeconds = util.IntPtr(defaultTimeOutInSeconds)
291293
}
292294

293295
if model.SynchronousCreationOptions.ReturnSuccessIfTimeOut == nil {
@@ -321,7 +323,7 @@ func createCallback(client *util.MongoDBClient, currentModel *Model, jobID, star
321323
}
322324
}
323325

324-
return progressevent.GetFailedEventByCode("Create failed with Timout", cloudformation.HandlerErrorCodeInternalFailure)
326+
return progressevent.GetFailedEventByCode("Create failed with Timout", string(types.HandlerErrorCodeInternalFailure))
325327
}
326328

327329
return progressevent.GetInProgressProgressEvent(

0 commit comments

Comments
 (0)