Skip to content

Commit 3c5b0fe

Browse files
committed
add new attrs
1 parent 9ccfdae commit 3c5b0fe

File tree

10 files changed

+61
-34
lines changed

10 files changed

+61
-34
lines changed

cfn-resources/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ require (
4343
github.com/josharian/intern v1.0.0 // indirect
4444
github.com/mailru/easyjson v0.7.7 // indirect
4545
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
46+
github.com/mongodb-labs/go-client-mongodb-atlas-app-services v1.0.0-pre // indirect
4647
github.com/oasdiff/yaml v0.0.0-20241210131133-6b86fb107d80 // indirect
4748
github.com/oasdiff/yaml3 v0.0.0-20241210130736-a94c01f36349 // indirect
4849
github.com/openlyinc/pointy v1.2.0 // indirect

cfn-resources/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9
7474
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
7575
github.com/mongodb-forks/digest v1.1.0 h1:7eUdsR1BtqLv0mdNm4OXs6ddWvR4X2/OsLwdKksrOoc=
7676
github.com/mongodb-forks/digest v1.1.0/go.mod h1:rb+EX8zotClD5Dj4NdgxnJXG9nwrlx3NWKJ8xttz1Dg=
77+
github.com/mongodb-labs/go-client-mongodb-atlas-app-services v1.0.0-pre h1:ikBZOTvFcpgKPcheKKqn1xnBc0REvkmlTbR+grJjcb8=
78+
github.com/mongodb-labs/go-client-mongodb-atlas-app-services v1.0.0-pre/go.mod h1:AJpBaQM0zT9fIFib9E0GPKS0HHjS2Qm6Ti/cPJDgsJw=
7779
github.com/oasdiff/yaml v0.0.0-20241210131133-6b86fb107d80 h1:nZspmSkneBbtxU9TopEAE0CY+SBJLxO8LPUlw2vG4pU=
7880
github.com/oasdiff/yaml v0.0.0-20241210131133-6b86fb107d80/go.mod h1:7tFDb+Y51LcDpn26GccuUgQXUk6t0CXZsivKjyimYX8=
7981
github.com/oasdiff/yaml3 v0.0.0-20241210130736-a94c01f36349 h1:t05Ww3DxZutOqbMN+7OIuqDwXbhl32HiZGpLy26BAPc=

cfn-resources/trigger/cmd/resource/model.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ import (
2424
"github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler"
2525
"github.com/aws/aws-sdk-go/aws"
2626
"github.com/aws/aws-sdk-go/service/cloudformation"
27+
"github.com/mongodb-labs/go-client-mongodb-atlas-app-services/appservices"
28+
2729
"github.com/mongodb/mongodbatlas-cloudformation-resources/profile"
2830
"github.com/mongodb/mongodbatlas-cloudformation-resources/util"
2931
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants"
3032
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/logger"
3133
progressevents "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent"
3234
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/validator"
33-
"go.mongodb.org/realm/realm"
3435
)
3536

3637
type TriggerType string
@@ -63,9 +64,9 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler
6364
setProfileIfAbsent(currentModel)
6465

6566
ctx := context.Background()
66-
client, err := util.GetRealmClient(ctx, req, currentModel.Profile)
67+
client, err := util.GetAppServicesClient(ctx, req, currentModel.Profile)
6768
if err != nil {
68-
return progressevents.GetFailedEventByCode(fmt.Sprintf("Error creating realm client : %s", err.Error()),
69+
return progressevents.GetFailedEventByCode(fmt.Sprintf("Error creating App Services client : %s", err.Error()),
6970
cloudformation.HandlerErrorCodeInvalidRequest), nil
7071
}
7172

@@ -99,9 +100,9 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P
99100
setProfileIfAbsent(currentModel)
100101

101102
ctx := context.Background()
102-
client, err := util.GetRealmClient(ctx, req, currentModel.Profile)
103+
client, err := util.GetAppServicesClient(ctx, req, currentModel.Profile)
103104
if err != nil {
104-
return progressevents.GetFailedEventByCode(fmt.Sprintf("Error creating realm client : %s", err.Error()),
105+
return progressevents.GetFailedEventByCode(fmt.Sprintf("Error creating App Services client : %s", err.Error()),
105106
cloudformation.HandlerErrorCodeInvalidRequest), nil
106107
}
107108

@@ -130,9 +131,9 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler
130131
setProfileIfAbsent(currentModel)
131132

132133
ctx := context.Background()
133-
client, err := util.GetRealmClient(ctx, req, currentModel.Profile)
134+
client, err := util.GetAppServicesClient(ctx, req, currentModel.Profile)
134135
if err != nil {
135-
return progressevents.GetFailedEventByCode(fmt.Sprintf("Error creating realm client : %s", err.Error()),
136+
return progressevents.GetFailedEventByCode(fmt.Sprintf("Error creating App Services client : %s", err.Error()),
136137
cloudformation.HandlerErrorCodeInvalidRequest), nil
137138
}
138139

@@ -165,9 +166,9 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler
165166
setProfileIfAbsent(currentModel)
166167

167168
ctx := context.Background()
168-
client, err := util.GetRealmClient(ctx, req, currentModel.Profile)
169+
client, err := util.GetAppServicesClient(ctx, req, currentModel.Profile)
169170
if err != nil {
170-
return progressevents.GetFailedEventByCode(fmt.Sprintf("Error creating realm client : %s", err.Error()),
171+
return progressevents.GetFailedEventByCode(fmt.Sprintf("Error creating App Services client : %s", err.Error()),
171172
cloudformation.HandlerErrorCodeInvalidRequest), nil
172173
}
173174

@@ -189,9 +190,9 @@ func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.P
189190
setProfileIfAbsent(currentModel)
190191

191192
ctx := context.Background()
192-
client, err := util.GetRealmClient(ctx, req, currentModel.Profile)
193+
client, err := util.GetAppServicesClient(ctx, req, currentModel.Profile)
193194
if err != nil {
194-
return progressevents.GetFailedEventByCode(fmt.Sprintf("Error creating realm client : %s", err.Error()),
195+
return progressevents.GetFailedEventByCode(fmt.Sprintf("Error creating App Services client : %s", err.Error()),
195196
cloudformation.HandlerErrorCodeInvalidRequest), nil
196197
}
197198

@@ -213,8 +214,8 @@ func setProfileIfAbsent(model *Model) {
213214
}
214215
}
215216

216-
func newEventTrigger(model *Model) (*realm.EventTriggerRequest, error) {
217-
et := realm.EventTriggerRequest{Disabled: model.Disabled}
217+
func newEventTrigger(model *Model) (*appservices.EventTriggerRequest, error) {
218+
et := appservices.EventTriggerRequest{Disabled: model.Disabled}
218219
if model.Name != nil {
219220
et.Name = *model.Name
220221
}
@@ -224,7 +225,7 @@ func newEventTrigger(model *Model) (*realm.EventTriggerRequest, error) {
224225
if model.FunctionId != nil {
225226
et.FunctionID = *model.FunctionId
226227
}
227-
conf := realm.EventTriggerConfig{}
228+
conf := appservices.EventTriggerConfig{}
228229
if model.DatabaseTrigger != nil {
229230
conf.Database = *model.DatabaseTrigger.Database
230231
}
@@ -257,6 +258,9 @@ func newEventTrigger(model *Model) (*realm.EventTriggerRequest, error) {
257258
conf.FullDocument = dTrigger.FullDocument
258259
conf.FullDocumentBeforeChange = dTrigger.FullDocumentBeforeChange
259260
conf.Unordered = dTrigger.Unordered
261+
conf.TolerateResumeErrors = dTrigger.TolerateResumeErrors
262+
conf.SkipCatchupEvents = dTrigger.SkipCatchupEvents
263+
conf.MaximumThroughput = dTrigger.MaximumThroughput
260264
}
261265

262266
if model.ScheduleTrigger != nil &&
@@ -298,7 +302,7 @@ func newEventTrigger(model *Model) (*realm.EventTriggerRequest, error) {
298302
return &et, nil
299303
}
300304

301-
func newEventProcessor(model *Model, et realm.EventTriggerRequest) (realm.EventTriggerRequest, error) {
305+
func newEventProcessor(model *Model, et appservices.EventTriggerRequest) (appservices.EventTriggerRequest, error) {
302306
ep := EventProcess{}
303307
if model.EventProcessors.FUNCTION != nil && model.EventProcessors.FUNCTION.FuncConfig != nil {
304308
ep.FUNCTION = new(FUNC)

cfn-resources/trigger/docs/databaseconfig.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ To declare this entity in your AWS CloudFormation template, use the following sy
1818
"<a href="#fulldocumentbeforechange" title="FullDocumentBeforeChange">FullDocumentBeforeChange</a>" : <i>Boolean</i>,
1919
"<a href="#skipcatchupevents" title="SkipCatchupEvents">SkipCatchupEvents</a>" : <i>Boolean</i>,
2020
"<a href="#tolerateresumeerrors" title="TolerateResumeErrors">TolerateResumeErrors</a>" : <i>Boolean</i>,
21+
"<a href="#maximumthroughput" title="MaximumThroughput">MaximumThroughput</a>" : <i>Boolean</i>,
2122
"<a href="#unordered" title="Unordered">Unordered</a>" : <i>Boolean</i>
2223
}
2324
</pre>
@@ -36,6 +37,7 @@ To declare this entity in your AWS CloudFormation template, use the following sy
3637
<a href="#fulldocumentbeforechange" title="FullDocumentBeforeChange">FullDocumentBeforeChange</a>: <i>Boolean</i>
3738
<a href="#skipcatchupevents" title="SkipCatchupEvents">SkipCatchupEvents</a>: <i>Boolean</i>
3839
<a href="#tolerateresumeerrors" title="TolerateResumeErrors">TolerateResumeErrors</a>: <i>Boolean</i>
40+
<a href="#maximumthroughput" title="MaximumThroughput">MaximumThroughput</a>: <i>Boolean</i>
3941
<a href="#unordered" title="Unordered">Unordered</a>: <i>Boolean</i>
4042
</pre>
4143

@@ -161,6 +163,16 @@ _Type_: Boolean
161163

162164
_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)
163165

166+
#### MaximumThroughput
167+
168+
If `true`, the trigger will use the maximize throughput option (https://www.mongodb.com/docs/atlas/app-services/triggers/database-triggers/#std-label-triggers-maximum-throughput).
169+
170+
_Required_: No
171+
172+
_Type_: Boolean
173+
174+
_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)
175+
164176
#### Unordered
165177

166178
If `true`, event ordering is disabled and this Trigger

cfn-resources/trigger/mongodb-atlas-trigger.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@
146146
"default": false,
147147
"description": "If `true`, when this Trigger's resume token\ncannot be found in the cluster's oplog, the Trigger automatically resumes\nprocessing events at the next relevant change stream event.\nAll change stream events from when the Trigger was suspended until the Trigger\nresumes execution do not have the Trigger fire for them."
148148
},
149+
"MaximumThroughput": {
150+
"type": "boolean",
151+
"default": false,
152+
"description": "If `true`, the trigger will use the maximize throughput option (https://www.mongodb.com/docs/atlas/app-services/triggers/database-triggers/#std-label-triggers-maximum-throughput)."
153+
},
149154
"Unordered": {
150155
"type": "boolean",
151156
"description": "If `true`, event ordering is disabled and this Trigger\ncan process events in parallel. If `false`, event\nordering is enabled and the Trigger executes events\nserially."

cfn-resources/trigger/test/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ The following components use this resource and are potentially impacted by any c
1212
All these resources need to be manually provided. Follow the steps below.
1313
- Atlas project (PROJECT_ID)
1414
- Atlas Cluster loaded with database and a collection (DB_NAME,COLLECTION_NAME)
15-
- Realm App (APP_ID)
16-
- Realm Service (SERVICE_ID)
15+
- App Services App (APP_ID)
16+
- App Services Service (SERVICE_ID)
1717
- Atlas Function (FUNC_NAME,FUNC_ID)
1818

1919

cfn-resources/trigger/test/inputs_1_create.template.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
"FullDocument": "true",
1313
"FullDocumentBeforeChange": "false",
1414
"Unordered": "false",
15-
"SkipCatchupEvents": "false",
16-
"Match" : "{\"$and\":[{\"fullDocument.availability.value\":\"AVAILABLE\"},{\"$ne\":[\"fullDocument.retailPrice\",\"fullDocumentBeforeChange.retailPrice\"]}]}"
15+
"SkipCatchupEvents": "true",
16+
"TolerateResumeErrors": "true",
17+
"Match": "{\"$and\":[{\"fullDocument.availability.value\":\"AVAILABLE\"},{\"$ne\":[\"fullDocument.retailPrice\",\"fullDocumentBeforeChange.retailPrice\"]}]}"
1718
},
1819
"Disabled": "false",
1920
"EventProcessors": {

cfn-resources/trigger/test/inputs_1_update.template.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"FullDocumentBeforeChange": "false",
1414
"Unordered": "false",
1515
"SkipCatchupEvents": "false",
16-
"Match" : "{\"$and\":[{\"fullDocument.availability.value\":\"AVAILABLE\"},{\"$ne\":[\"fullDocument.retailPrice\",\"fullDocumentBeforeChange.retailPrice\"]}]}"
16+
"MaximumThroughput": "true",
17+
"Match": "{\"$and\":[{\"fullDocument.availability.value\":\"AVAILABLE\"},{\"$ne\":[\"fullDocument.retailPrice\",\"fullDocumentBeforeChange.retailPrice\"]}]}"
1718
},
1819
"Disabled": "false",
1920
"EventProcessors": {

cfn-resources/util/util.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ import (
2929
admin20231115002 "go.mongodb.org/atlas-sdk/v20231115002/admin"
3030
admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin"
3131
"go.mongodb.org/atlas-sdk/v20241113004/admin"
32-
realmAuth "go.mongodb.org/realm/auth"
33-
"go.mongodb.org/realm/realm"
3432

3533
"github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler"
3634
"github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/logging"
@@ -39,6 +37,8 @@ import (
3937
"github.com/aws/aws-sdk-go/service/cloudformation"
4038
"github.com/aws/aws-sdk-go/service/ssm"
4139
"github.com/mongodb-forks/digest"
40+
"github.com/mongodb-labs/go-client-mongodb-atlas-app-services/appservices"
41+
appServicesAuth "github.com/mongodb-labs/go-client-mongodb-atlas-app-services/auth"
4242

4343
"github.com/mongodb/mongodbatlas-cloudformation-resources/profile"
4444
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/logger"
@@ -59,12 +59,12 @@ type MongoDBClient struct {
5959
}
6060

6161
type Config struct {
62-
AssumeRole *AssumeRole
63-
PublicKey string
64-
PrivateKey string
65-
BaseURL string
66-
RealmBaseURL string
67-
DebugClient bool
62+
AssumeRole *AssumeRole
63+
PublicKey string
64+
PrivateKey string
65+
BaseURL string
66+
AppServicesBaseURL string
67+
DebugClient bool
6868
}
6969

7070
type AssumeRole struct {
@@ -101,26 +101,26 @@ func EnsureAWSRegion(region string) string {
101101
return r
102102
}
103103

104-
func GetRealmClient(ctx context.Context, req handler.Request, profileName *string) (*realm.Client, error) {
104+
func GetAppServicesClient(ctx context.Context, req handler.Request, profileName *string) (*appservices.Client, error) {
105105
p, err := profile.NewProfile(&req, profileName, true)
106106
if err != nil {
107107
return nil, err
108108
}
109109

110-
optsRealm := []realm.ClientOpt{realm.SetUserAgent(userAgent)}
111-
authConfig := realmAuth.NewConfig(nil)
110+
optsAppServices := []appservices.ClientOpt{appservices.SetUserAgent(userAgent)}
111+
authConfig := appServicesAuth.NewConfig(nil)
112112
token, err := authConfig.NewTokenFromCredentials(ctx, p.PublicKey, p.PrivateKey)
113113
if err != nil {
114114
return nil, err
115115
}
116116

117-
clientRealm := realmAuth.NewClient(realmAuth.BasicTokenSource(token))
118-
realmClient, err := realm.New(clientRealm, optsRealm...)
117+
clientAppServices := appServicesAuth.NewClient(appServicesAuth.BasicTokenSource(token))
118+
appServicesClient, err := appservices.New(clientAppServices, optsAppServices...)
119119
if err != nil {
120120
return nil, err
121121
}
122122

123-
return realmClient, nil
123+
return appServicesClient, nil
124124
}
125125

126126
func NewAtlasClient(req *handler.Request, profileName *string) (*MongoDBClient, *handler.ProgressEvent) {

0 commit comments

Comments
 (0)