-
Notifications
You must be signed in to change notification settings - Fork 38
feat: Add SendUserProvidedResourceTags to third party integrations resource #1388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 27 commits
a3f6d71
4a1b71f
77f3db7
818a572
611d1ea
0cb3c62
08f26be
fb29074
e7ff021
3f7cf7a
f3500d8
820e36c
7594d26
c1e6818
7e75bc7
6391ce0
6aabe73
f1df94b
b60ae36
caa319d
68fc3ac
00204a7
8bb5fc9
d47e43b
2e1f8c7
881a029
6263d62
36e955b
209e1eb
b915df6
8a5a721
153553d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -25,7 +25,7 @@ import ( | |||||
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" | ||||||
"go.mongodb.org/atlas-sdk/v20231115002/admin" | ||||||
"go.mongodb.org/atlas-sdk/v20250312005/admin" | ||||||
) | ||||||
|
||||||
var RequiredFields = []string{constants.IntegrationType, constants.ProjectID} | ||||||
|
@@ -41,7 +41,7 @@ var requiredPerType = map[string][]string{ | |||||
"FLOWDOCK": {"FlowName", "ApiToken", "OrgName"}, | ||||||
"WEBHOOK": {"Url"}, | ||||||
"MICROSOFT_TEAMS": {"MicrosoftTeamsWebhookUrl"}, | ||||||
"PROMETHEUS": {"UserName", "Password", "ServiceDiscovery", "Scheme", "Enabled"}, | ||||||
"PROMETHEUS": {"UserName", "Password", "ServiceDiscovery", "Enabled"}, | ||||||
EspenAlbert marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} | ||||||
|
||||||
func validateModel(fields []string, model *Model) *handler.ProgressEvent { | ||||||
|
@@ -76,18 +76,23 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler | |||||
} | ||||||
|
||||||
requestBody := modelToIntegration(currentModel) | ||||||
integrations, resModel, err := client.Atlas20231115002.ThirdPartyIntegrationsApi.CreateThirdPartyIntegration(context.Background(), *IntegrationType, *ProjectID, requestBody).Execute() | ||||||
integrations, resModel, err := client.AtlasSDK.ThirdPartyIntegrationsApi.CreateThirdPartyIntegration(context.Background(), *IntegrationType, *ProjectID, requestBody).Execute() | ||||||
marcabreracast marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
if err != nil { | ||||||
if apiError, ok := admin.AsError(err); ok && *apiError.Error == http.StatusConflict { | ||||||
if apiError, ok := admin.AsError(err); ok && apiError.Error == http.StatusConflict { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comparison
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
return progressevent.GetFailedEventByCode("INTEGRATION_ALREADY_CONFIGURED.", cloudformation.HandlerErrorCodeAlreadyExists), nil | ||||||
} | ||||||
|
||||||
return progressevent.GetFailedEventByResponse(err.Error(), resModel), nil | ||||||
} | ||||||
|
||||||
if integrations == nil { | ||||||
marcabreracast marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
return progressevent.GetFailedEventByResponse("No integration returned from create", resModel), nil | ||||||
} | ||||||
|
||||||
results := integrations.GetResults() | ||||||
return handler.ProgressEvent{ | ||||||
OperationStatus: handler.Success, | ||||||
ResourceModel: integrationToModel(*currentModel, &integrations.Results[0]), | ||||||
ResourceModel: integrationToModel(*currentModel, &results[0]), | ||||||
}, nil | ||||||
} | ||||||
|
||||||
|
@@ -108,7 +113,7 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P | |||||
ProjectID := currentModel.ProjectId | ||||||
IntegrationType := currentModel.Type | ||||||
|
||||||
integration, res, err := client.Atlas20231115002.ThirdPartyIntegrationsApi.GetThirdPartyIntegration(context.Background(), *ProjectID, *IntegrationType).Execute() | ||||||
integration, res, err := client.AtlasSDK.ThirdPartyIntegrationsApi.GetThirdPartyIntegration(context.Background(), *ProjectID, *IntegrationType).Execute() | ||||||
|
||||||
if err != nil { | ||||||
return progressevent.GetFailedEventByResponse(err.Error(), res), nil | ||||||
|
@@ -139,24 +144,29 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler | |||||
ProjectID := currentModel.ProjectId | ||||||
IntegrationType := currentModel.Type | ||||||
|
||||||
integration, res, err := client.Atlas20231115002.ThirdPartyIntegrationsApi.GetThirdPartyIntegration(context.Background(), *ProjectID, *IntegrationType).Execute() | ||||||
integration, res, err := client.AtlasSDK.ThirdPartyIntegrationsApi.GetThirdPartyIntegration(context.Background(), *ProjectID, *IntegrationType).Execute() | ||||||
if err != nil { | ||||||
return progressevent.GetFailedEventByResponse(err.Error(), res), nil | ||||||
} | ||||||
|
||||||
updateIntegrationFromSchema(currentModel, integration) | ||||||
integrations, res, err := client.Atlas20231115002.ThirdPartyIntegrationsApi.UpdateThirdPartyIntegration(context.Background(), *IntegrationType, *ProjectID, integration).Execute() | ||||||
integrations, res, err := client.AtlasSDK.ThirdPartyIntegrationsApi.UpdateThirdPartyIntegration(context.Background(), *IntegrationType, *ProjectID, integration).Execute() | ||||||
if err != nil { | ||||||
return progressevent.GetFailedEventByResponse(err.Error(), res), nil | ||||||
} | ||||||
|
||||||
if integrations == nil { | ||||||
return progressevent.GetFailedEventByResponse("No integration returned from update", res), nil | ||||||
} | ||||||
|
||||||
results := integrations.GetResults() | ||||||
return handler.ProgressEvent{ | ||||||
OperationStatus: handler.Success, | ||||||
ResourceModel: integrationToModel(*currentModel, &integrations.Results[0]), | ||||||
ResourceModel: integrationToModel(*currentModel, &results[0]), | ||||||
}, nil | ||||||
} | ||||||
|
||||||
func updateIntegrationFromSchema(currentModel *Model, integration *admin.ThridPartyIntegration) { | ||||||
func updateIntegrationFromSchema(currentModel *Model, integration *admin.ThirdPartyIntegration) { | ||||||
marcabreracast marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
if util.IsStringPresent(currentModel.Url) && !util.AreStringPtrEqual(currentModel.Url, integration.Url) { | ||||||
integration.Url = currentModel.Url | ||||||
} | ||||||
|
@@ -196,12 +206,13 @@ func updateIntegrationFromSchema(currentModel *Model, integration *admin.ThridPa | |||||
if util.IsStringPresent(currentModel.ServiceDiscovery) && !util.AreStringPtrEqual(currentModel.ServiceDiscovery, integration.ServiceDiscovery) { | ||||||
integration.ServiceDiscovery = currentModel.ServiceDiscovery | ||||||
} | ||||||
if util.IsStringPresent(currentModel.Scheme) && !util.AreStringPtrEqual(currentModel.Scheme, integration.Scheme) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
integration.Scheme = currentModel.Scheme | ||||||
} | ||||||
if currentModel.Enabled != nil && currentModel.Enabled != integration.Enabled { | ||||||
integration.Enabled = currentModel.Enabled | ||||||
} | ||||||
|
||||||
if currentModel.SendUserProvidedResourceTags != nil { | ||||||
integration.SendUserProvidedResourceTags = currentModel.SendUserProvidedResourceTags | ||||||
} | ||||||
} | ||||||
|
||||||
func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler.ProgressEvent, error) { | ||||||
|
@@ -223,7 +234,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler | |||||
ProjectID := currentModel.ProjectId | ||||||
IntegrationType := currentModel.Type | ||||||
|
||||||
_, res, err = client.Atlas20231115002.ThirdPartyIntegrationsApi.DeleteThirdPartyIntegration(context.Background(), *IntegrationType, *ProjectID).Execute() | ||||||
res, err = client.AtlasSDK.ThirdPartyIntegrationsApi.DeleteThirdPartyIntegration(context.Background(), *IntegrationType, *ProjectID).Execute() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why define vars res and err separated instead of using := here?
|
||||||
|
||||||
if err != nil { | ||||||
return progressevent.GetFailedEventByResponse(err.Error(), res), nil | ||||||
|
@@ -251,15 +262,18 @@ func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.P | |||||
|
||||||
var res *http.Response | ||||||
ProjectID := currentModel.ProjectId | ||||||
integrations, res, err := client.Atlas20231115002.ThirdPartyIntegrationsApi.ListThirdPartyIntegrations(context.Background(), *ProjectID).Execute() | ||||||
integrations, res, err := client.AtlasSDK.ThirdPartyIntegrationsApi.ListThirdPartyIntegrations(context.Background(), *ProjectID).Execute() | ||||||
if err != nil { | ||||||
return progressevent.GetFailedEventByResponse(err.Error(), res), nil | ||||||
} | ||||||
|
||||||
mm := make([]interface{}, 0) | ||||||
for i := range integrations.Results { | ||||||
m := integrationToModel(*currentModel, &integrations.Results[i]) | ||||||
mm = append(mm, m) | ||||||
if integrations == nil { | ||||||
results := integrations.GetResults() | ||||||
for i := range results { | ||||||
m := integrationToModel(*currentModel, &results[i]) | ||||||
mm = append(mm, m) | ||||||
} | ||||||
} | ||||||
|
||||||
// Response | ||||||
|
@@ -270,18 +284,15 @@ func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.P | |||||
}, nil | ||||||
} | ||||||
|
||||||
func modelToIntegration(currentModel *Model) (out *admin.ThridPartyIntegration) { | ||||||
out = &admin.ThridPartyIntegration{} | ||||||
func modelToIntegration(currentModel *Model) (out *admin.ThirdPartyIntegration) { | ||||||
out = &admin.ThirdPartyIntegration{} | ||||||
|
||||||
if util.IsStringPresent(currentModel.Type) { | ||||||
out.Type = currentModel.Type | ||||||
} | ||||||
if currentModel.Enabled != nil { | ||||||
out.Enabled = currentModel.Enabled | ||||||
} | ||||||
if util.IsStringPresent(currentModel.Scheme) { | ||||||
out.Scheme = currentModel.Scheme | ||||||
} | ||||||
if util.IsStringPresent(currentModel.ServiceDiscovery) { | ||||||
out.ServiceDiscovery = currentModel.ServiceDiscovery | ||||||
} | ||||||
|
@@ -321,11 +332,13 @@ func modelToIntegration(currentModel *Model) (out *admin.ThridPartyIntegration) | |||||
if util.IsStringPresent(currentModel.ApiKey) { | ||||||
out.ApiKey = currentModel.ApiKey | ||||||
} | ||||||
|
||||||
if currentModel.SendUserProvidedResourceTags != nil { | ||||||
marcabreracast marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
out.SendUserProvidedResourceTags = currentModel.SendUserProvidedResourceTags | ||||||
} | ||||||
return out | ||||||
} | ||||||
|
||||||
func integrationToModel(currentModel Model, integration *admin.ThridPartyIntegration) Model { | ||||||
func integrationToModel(currentModel Model, integration *admin.ThirdPartyIntegration) Model { | ||||||
// if "Enabled" is not set in the inputs we dont want to return "Enabled" in outputs | ||||||
enabled := currentModel.Enabled != nil | ||||||
|
||||||
|
@@ -341,5 +354,6 @@ func integrationToModel(currentModel Model, integration *admin.ThridPartyIntegra | |||||
if !enabled { | ||||||
out.Enabled = nil | ||||||
} | ||||||
|
||||||
return out | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This update is needed in order to implement
SendUserProvidedResourceTags
field.