Skip to content
Draft
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
22 changes: 12 additions & 10 deletions cfn-resources/access-list-api-key/cmd/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@ import (
"net/http"
"strings"

admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin"

"github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go/service/cloudformation"
cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types"

"github.com/mongodb/mongodbatlas-cloudformation-resources/profile"
"github.com/mongodb/mongodbatlas-cloudformation-resources/util"
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants"
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/logger"
progress_events "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent"
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/validator"
admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin"
)

var CreateRequiredFields = []string{constants.OrgID, constants.APIUserID}
Expand Down Expand Up @@ -79,14 +81,14 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler
return handler.ProgressEvent{
OperationStatus: handler.Failed,
Message: EitherOrMessage,
HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest}, nil
HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)}, nil
}

if currentModel.CidrBlock != nil && currentModel.IpAddress != nil {
return handler.ProgressEvent{
OperationStatus: handler.Failed,
Message: MutualExclusiveMessage,
HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest}, nil
HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)}, nil
}

// createReq.ApiService.
Expand Down Expand Up @@ -140,14 +142,14 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P
return handler.ProgressEvent{
OperationStatus: handler.Failed,
Message: EitherOrMessage,
HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest}, nil
HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)}, nil
}

if currentModel.CidrBlock != nil && currentModel.IpAddress != nil {
return handler.ProgressEvent{
OperationStatus: handler.Failed,
Message: MutualExclusiveMessage,
HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest}, nil
HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)}, nil
}

entry := getEntryAddress(currentModel)
Expand Down Expand Up @@ -191,14 +193,14 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler
return handler.ProgressEvent{
OperationStatus: handler.Failed,
Message: EitherOrMessage,
HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest}, nil
HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)}, nil
}

if currentModel.CidrBlock != nil && currentModel.IpAddress != nil {
return handler.ProgressEvent{
OperationStatus: handler.Failed,
Message: MutualExclusiveMessage,
HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest}, nil
HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)}, nil
}

entry := getEntryAddress(currentModel)
Expand Down Expand Up @@ -294,14 +296,14 @@ func handleError(response *http.Response, method string, err error) (handler.Pro
return handler.ProgressEvent{
OperationStatus: handler.Failed,
Message: errMsg,
HandlerErrorCode: cloudformation.HandlerErrorCodeInternalFailure}, nil
HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInternalFailure)}, nil
}

if response.StatusCode == http.StatusConflict {
return handler.ProgressEvent{
OperationStatus: handler.Failed,
Message: errMsg,
HandlerErrorCode: cloudformation.HandlerErrorCodeAlreadyExists}, nil
HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeAlreadyExists)}, nil
}
return progress_events.GetFailedEventByResponse(errMsg, response), nil
}
22 changes: 12 additions & 10 deletions cfn-resources/alert-configuration/cmd/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@ import (
"reflect"
"strings"

admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin"

"github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/cloudformation"
"github.com/aws/aws-sdk-go-v2/aws"
cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types"
"github.com/spf13/cast"

"github.com/mongodb/mongodbatlas-cloudformation-resources/profile"
"github.com/mongodb/mongodbatlas-cloudformation-resources/util"
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants"
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/logger"
progressevents "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent"
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/validator"
"github.com/spf13/cast"
admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin"
)

var CreateRequiredFields = []string{constants.EventTypeName, constants.ProjectID}
Expand Down Expand Up @@ -68,12 +70,12 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler
return handler.ProgressEvent{
OperationStatus: handler.Failed,
Message: "Resource Already Exists",
HandlerErrorCode: cloudformation.HandlerErrorCodeAlreadyExists}, nil
HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeAlreadyExists)}, nil
}

notifications, err := expandAlertConfigurationNotification(currentModel.Notifications)
if err != nil {
return progressevents.GetFailedEventByCode(err.Error(), cloudformation.HandlerErrorCodeInvalidRequest), err
return progressevents.GetFailedEventByCode(err.Error(), string(cloudformationtypes.HandlerErrorCodeInvalidRequest)), err
}

alertConfigRequest := admin20231115014.GroupAlertsConfig{
Expand Down Expand Up @@ -125,7 +127,7 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P
return handler.ProgressEvent{
OperationStatus: handler.Failed,
Message: "Resource Not Found",
HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil
HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)}, nil
}

alertConfig, resp, err := atlasV2.AlertConfigurationsApi.GetAlertConfiguration(context.Background(), *currentModel.ProjectId, *currentModel.Id).Execute()
Expand Down Expand Up @@ -165,7 +167,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler
return handler.ProgressEvent{
OperationStatus: handler.Failed,
Message: "Resource Not Found",
HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil
HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)}, nil
}

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

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

func isExist(currentModel *Model, client *admin20231115014.APIClient) bool {
Expand Down
13 changes: 7 additions & 6 deletions cfn-resources/api-key/cmd/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@ import (
"net/http"
"sort"

admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin"

"github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/cloudformation"
"github.com/aws/aws-sdk-go-v2/aws"
cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types"

"github.com/mongodb/mongodbatlas-cloudformation-resources/profile"
"github.com/mongodb/mongodbatlas-cloudformation-resources/util"
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants"
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/logger"
progress_events "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent"
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/secrets"
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/validator"

admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin"
)

var CreateRequiredFields = []string{constants.OrgID, constants.Description, constants.AwsSecretName}
Expand Down Expand Up @@ -285,13 +286,13 @@ func handleError(response *http.Response, method constants.CfnFunctions, err err
return handler.ProgressEvent{
OperationStatus: handler.Failed,
Message: errMsg,
HandlerErrorCode: cloudformation.HandlerErrorCodeAlreadyExists}, nil
HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeAlreadyExists)}, nil
}
if response.StatusCode == http.StatusBadRequest {
return handler.ProgressEvent{
OperationStatus: handler.Failed,
Message: errMsg,
HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil
HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)}, nil
}
return progress_events.GetFailedEventByResponse(errMsg, response), nil
}
Expand Down
22 changes: 12 additions & 10 deletions cfn-resources/auditing/cmd/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ import (
"errors"
"net/http"

admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin"

"github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/cloudformation"
"github.com/aws/aws-sdk-go-v2/aws"
cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types"

"github.com/mongodb/mongodbatlas-cloudformation-resources/util"
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants"
log "github.com/mongodb/mongodbatlas-cloudformation-resources/util/logger"
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent"
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/validator"
admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin"
)

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

if aws.BoolValue(atlasAuditing.Enabled) {
if aws.ToBool(atlasAuditing.Enabled) {
return handler.ProgressEvent{
HandlerErrorCode: cloudformation.HandlerErrorCodeAlreadyExists,
HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeAlreadyExists),
OperationStatus: handler.Failed,
}, nil
}
Expand Down Expand Up @@ -116,9 +118,9 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P
return progressevent.GetFailedEventByResponse(err.Error(), res), nil
}

if !aws.BoolValue(atlasAuditing.Enabled) {
if !aws.ToBool(atlasAuditing.Enabled) {
return handler.ProgressEvent{
HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound,
HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound),
OperationStatus: handler.Failed,
}, nil
}
Expand Down Expand Up @@ -156,7 +158,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler
}
if !resourceEnabled {
return handler.ProgressEvent{
HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound,
HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound),
OperationStatus: handler.Failed,
Message: "resource not found",
}, nil
Expand Down Expand Up @@ -222,7 +224,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler

if !resourceEnabled {
return handler.ProgressEvent{
HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound,
HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound),
OperationStatus: handler.Failed,
}, nil
}
Expand Down Expand Up @@ -254,7 +256,7 @@ func isEnabled(client admin20231115014.APIClient, currentModel Model) (bool, *ha
return false, &er
}

return aws.BoolValue(atlasAuditing.Enabled), nil
return aws.ToBool(atlasAuditing.Enabled), nil
}

func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.ProgressEvent, error) {
Expand Down
34 changes: 18 additions & 16 deletions cfn-resources/cloud-backup-restore-jobs/cmd/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ import (
"fmt"
"time"

admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin"

"github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/cloudformation"
"github.com/aws/aws-sdk-go-v2/aws"
cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types"

"github.com/mongodb/mongodbatlas-cloudformation-resources/util"
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants"
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent"
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/validator"
admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin"
)

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

if *model.InstanceType != clusterInstanceType && *model.InstanceType != serverlessInstanceType {
pe := progressevent.GetFailedEventByCode(fmt.Sprintf("InstanceType must be %s or %s", clusterInstanceType, serverlessInstanceType),
cloudformation.HandlerErrorCodeInvalidRequest)
string(cloudformationtypes.HandlerErrorCodeInvalidRequest))
return &pe
}

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

err := currentModel.validateAsynchronousProperties()
if err != nil {
return progressevent.GetFailedEventByCode(err.Error(), cloudformation.HandlerErrorCodeInvalidRequest), err
return progressevent.GetFailedEventByCode(err.Error(), string(cloudformationtypes.HandlerErrorCodeInvalidRequest)), err
}

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

if aws.BoolValue(currentModel.EnableSynchronousCreation) {
if aws.ToBool(currentModel.EnableSynchronousCreation) {
return progressevent.GetInProgressProgressEvent(
"Create in progress",
map[string]interface{}{
Expand Down Expand Up @@ -146,11 +148,11 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P
return *err, nil
}

if aws.BoolValue(currentModel.Cancelled) {
if aws.ToBool(currentModel.Cancelled) {
return handler.ProgressEvent{
OperationStatus: handler.Failed,
Message: "The job is in status cancelled, Cannot read a cancelled job",
HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil
HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)}, nil
}

return handler.ProgressEvent{
Expand Down Expand Up @@ -180,14 +182,14 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler
return *err, nil
}

if aws.BoolValue(currentModel.Cancelled) {
if aws.ToBool(currentModel.Cancelled) {
return handler.ProgressEvent{
OperationStatus: handler.Failed,
Message: "The job is in status cancelled, Cannot delete a cancelled job",
HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil
HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)}, nil
}

if util.IsStringPresent(currentModel.FinishedAt) || aws.BoolValue(currentModel.Failed) || aws.BoolValue(currentModel.Expired) {
if util.IsStringPresent(currentModel.FinishedAt) || aws.ToBool(currentModel.Failed) || aws.ToBool(currentModel.Expired) {
return handler.ProgressEvent{
OperationStatus: handler.Success,
Message: "The resource is finished, failed, or expired",
Expand Down Expand Up @@ -242,7 +244,7 @@ func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.P
InstanceName: currentModel.InstanceName,
Profile: currentModel.Profile,
}
if !aws.BoolValue(job.Cancelled) && !aws.BoolValue(job.Expired) {
if !aws.ToBool(job.Cancelled) && !aws.ToBool(job.Expired) {
updateModelServerless(model, job)
models = append(models, model)
}
Expand All @@ -262,7 +264,7 @@ func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.P
InstanceName: currentModel.InstanceName,
Profile: currentModel.Profile,
}
if !aws.BoolValue(job.Cancelled) && !aws.BoolValue(job.Expired) {
if !aws.ToBool(job.Cancelled) && !aws.ToBool(job.Expired) {
updateModelServer(model, job)
models = append(models, model)
}
Expand All @@ -283,11 +285,11 @@ func (model *Model) validateAsynchronousProperties() error {
}

if model.SynchronousCreationOptions.CallbackDelaySeconds == nil {
model.SynchronousCreationOptions.CallbackDelaySeconds = aws.Int(defaultBackSeconds)
model.SynchronousCreationOptions.CallbackDelaySeconds = util.IntPtr(defaultBackSeconds)
}

if model.SynchronousCreationOptions.TimeOutInSeconds == nil {
model.SynchronousCreationOptions.TimeOutInSeconds = aws.Int(defaultTimeOutInSeconds)
model.SynchronousCreationOptions.TimeOutInSeconds = util.IntPtr(defaultTimeOutInSeconds)
}

if model.SynchronousCreationOptions.ReturnSuccessIfTimeOut == nil {
Expand Down Expand Up @@ -321,7 +323,7 @@ func createCallback(client *util.MongoDBClient, currentModel *Model, jobID, star
}
}

return progressevent.GetFailedEventByCode("Create failed with Timout", cloudformation.HandlerErrorCodeInternalFailure)
return progressevent.GetFailedEventByCode("Create failed with Timout", string(cloudformationtypes.HandlerErrorCodeInternalFailure))
}

return progressevent.GetInProgressProgressEvent(
Expand Down
Loading
Loading