From 70dfc4d668a3579f34e56c236a12361d85d03d4a Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Tue, 27 Sep 2022 20:11:52 -0500 Subject: [PATCH 01/12] Add serverless private endpoints --- mongodbatlas/private_endpoints.go | 175 +++++++++++++++++++++++++++++- 1 file changed, 173 insertions(+), 2 deletions(-) diff --git a/mongodbatlas/private_endpoints.go b/mongodbatlas/private_endpoints.go index a7133512b..4e4030217 100644 --- a/mongodbatlas/private_endpoints.go +++ b/mongodbatlas/private_endpoints.go @@ -22,8 +22,9 @@ import ( ) const ( - privateEndpointsPath = "api/atlas/v1.0/groups/%s/privateEndpoint" - regionalModePath = privateEndpointsPath + "/regionalMode" + privateEndpointsPath = "api/atlas/v1.0/groups/%s/privateEndpoint" + serverlessPrivateEndpointsPath = "api/atlas/v1.0/groups/%s/privateEndpoint/serverless/instance/%s/endpoint" + regionalModePath = privateEndpointsPath + "/regionalMode" ) // PrivateEndpointsService is an interface for interfacing with the Private Endpoints @@ -40,6 +41,11 @@ type PrivateEndpointsService interface { DeleteOnePrivateEndpoint(context.Context, string, string, string, string) (*Response, error) UpdateRegionalizedPrivateEndpointSetting(context.Context, string, bool) (*RegionalizedPrivateEndpointSetting, *Response, error) GetRegionalizedPrivateEndpointSetting(context.Context, string) (*RegionalizedPrivateEndpointSetting, *Response, error) + ListPrivateServerlessEndpoint(context.Context, string, string, *ListOptions) ([]PrivateServerlessEndpointConnection, *Response, error) + AddOnePrivateServerlessEndpoint(context.Context, string, string, string, *PrivateServerlessEndpointConnection) (*PrivateServerlessEndpointConnection, *Response, error) + GetOnePrivateServerlessEndpoint(context.Context, string, string, string) (*PrivateServerlessEndpointConnection, *Response, error) + DeleteOnePrivateServerlessEndpoint(context.Context, string, string, string) (*Response, error) + UpdateOnePrivateServerlessEndpoint(context.Context, string, string, string) (*PrivateServerlessEndpointConnection, *Response, error) } // PrivateEndpointsServiceOp handles communication with the PrivateEndpoints related methods @@ -94,6 +100,17 @@ type GCPEndpoint struct { ServiceAttachmentName string `json:"serviceAttachmentName,omitempty"` // Unique alphanumeric and special character strings that identify the service attachment associated with the endpoint. } +// PrivateEndpointServerlessConnection represents MongoDB Private Endpoint Connection. + +type PrivateServerlessEndpointConnection struct { + ID string `json:"id,omitempty"` // Unique identifier of the AWS PrivateLink connection or Azure Private Link Service. + CloudProviderEndpointID string `json:"cloudProviderEndpointId,omitempty"` + Comment string `json:"comment,omitempty"` + EndpointServiceName string `json:"endpointServiceName,omitempty"` // Name of the PrivateLink endpoint service in AWS. Returns null while the endpoint service is being created. + ErrorMessage interface{} `json:"errorMessage,omitempty"` // Error message pertaining to the AWS PrivateLink connection or Azure Private Link Service or GCP Private Service Connect. Returns null if there are no errors. + Status string `json:"status,omitempty"` // Status of the AWS, Azure OR GCP PrivateLink connection: INITIATING, WAITING_FOR_USER, FAILED, DELETING, AVAILABLE. +} + // Create one private endpoint service for AWS or Azure in an Atlas project. // // See more: https://docs.atlas.mongodb.com/reference/api/private-endpoints-service-create-one/ @@ -353,3 +370,157 @@ func (s *PrivateEndpointsServiceOp) GetRegionalizedPrivateEndpointSetting(ctx co return root, resp, err } + +// List retrieve details for all private Serverless endpoint services in one Atlas project. +// +// See more: https://www.mongodb.com/docs/atlas/reference/api/serverless-private-endpoints-get-all/ +func (s *PrivateEndpointsServiceOp) ListPrivateServerlessEndpoint(ctx context.Context, groupID, instanceID string, listOptions *ListOptions) ([]PrivateServerlessEndpointConnection, *Response, error) { + if groupID == "" { + return nil, nil, NewArgError("groupID", "must be set") + } + if instanceID == "" { + return nil, nil, NewArgError("instanceID", "must be set") + } + + path := fmt.Sprintf(serverlessPrivateEndpointsPath, groupID, instanceID) + + // Add query params from listOptions + path, err := setListOptions(path, listOptions) + if err != nil { + return nil, nil, err + } + + req, err := s.Client.NewRequest(ctx, http.MethodGet, path, nil) + if err != nil { + return nil, nil, err + } + + root := new([]PrivateServerlessEndpointConnection) + resp, err := s.Client.Do(ctx, req, root) + if err != nil { + return nil, resp, err + } + + return *root, resp, nil +} + +// DeleteOnePrivateServerlessEndpoint one private serverless endpoint service in an Atlas project. +// +// See more https://docs.atlas.mongodb.com/reference/api/private-endpoints-service-delete-one/ +func (s *PrivateEndpointsServiceOp) DeleteOnePrivateServerlessEndpoint(ctx context.Context, groupID, instanceID, privateEndpointID string) (*Response, error) { + if groupID == "" { + return nil, NewArgError("groupID", "must be set") + } + if privateEndpointID == "" { + return nil, NewArgError("PrivateEndpointID", "must be set") + } + if instanceID == "" { + return nil, NewArgError("instanceID", "must be set") + } + + basePath := fmt.Sprintf(serverlessPrivateEndpointsPath, groupID, instanceID) + path := fmt.Sprintf("%s/%s", basePath, url.PathEscape(privateEndpointID)) + + req, err := s.Client.NewRequest(ctx, http.MethodDelete, path, nil) + if err != nil { + return nil, err + } + + return s.Client.Do(ctx, req, nil) +} + +// AddOnePrivateServerlessEndpoint Adds one serverless private endpoint in an Atlas project. +// +// See more: https://www.mongodb.com/docs/atlas/reference/api/serverless-private-endpoints-get-one/ +func (s *PrivateEndpointsServiceOp) AddOnePrivateServerlessEndpoint(ctx context.Context, groupID, instanceID, privateEndpointID string, createRequest *PrivateServerlessEndpointConnection) (*PrivateServerlessEndpointConnection, *Response, error) { + if groupID == "" { + return nil, nil, NewArgError("groupID", "must be set") + } + if privateEndpointID == "" { + return nil, nil, NewArgError("PrivateEndpointID", "must be set") + } + if instanceID == "" { + return nil, nil, NewArgError("instanceID", "must be set") + } + if createRequest == nil { + return nil, nil, NewArgError("createRequest", "cannot be nil") + } + + basePath := fmt.Sprintf(serverlessPrivateEndpointsPath, groupID, instanceID) + path := fmt.Sprintf("%s/%s", basePath, url.PathEscape(privateEndpointID)) + + req, err := s.Client.NewRequest(ctx, http.MethodPost, path, createRequest) + if err != nil { + return nil, nil, err + } + + root := new(PrivateServerlessEndpointConnection) + resp, err := s.Client.Do(ctx, req, root) + if err != nil { + return nil, resp, err + } + + return root, resp, err +} + +// GetOnePrivateServerlessEndpoint retrieve details for one private serverless endpoint in an Atlas project. +// +// See more: https://www.mongodb.com/docs/atlas/reference/api/serverless-private-endpoints-get-one/ +func (s *PrivateEndpointsServiceOp) GetOnePrivateServerlessEndpoint(ctx context.Context, groupID, instanceID, privateEndpointID string) (*PrivateServerlessEndpointConnection, *Response, error) { + if groupID == "" { + return nil, nil, NewArgError("groupID", "must be set") + } + + if instanceID == "" { + return nil, nil, NewArgError("instanceID", "must be set") + } + if privateEndpointID == "" { + return nil, nil, NewArgError("privateEndpointID", "must be set") + } + + basePath := fmt.Sprintf(serverlessPrivateEndpointsPath, groupID, instanceID) + path := fmt.Sprintf("%s/%s", basePath, url.PathEscape(privateEndpointID)) + + req, err := s.Client.NewRequest(ctx, http.MethodGet, path, nil) + if err != nil { + return nil, nil, err + } + + root := new(PrivateServerlessEndpointConnection) + resp, err := s.Client.Do(ctx, req, root) + if err != nil { + return nil, resp, err + } + + return root, resp, err +} + +// UpdateOnePrivateServerlessEndpoint updates the private serverless endpoint setting for one Atlas project. +// +// See more: https://docs.atlas.mongodb.com/reference/api/private-endpoints-update-regional-mode +func (s *PrivateEndpointsServiceOp) UpdateOnePrivateServerlessEndpoint(ctx context.Context, groupID, instanceID, privateEndpointID string) (*PrivateServerlessEndpointConnection, *Response, error) { + if groupID == "" { + return nil, nil, NewArgError("groupID", "must be set") + } + if instanceID == "" { + return nil, nil, NewArgError("instanceID", "must be set") + } + if privateEndpointID == "" { + return nil, nil, NewArgError("privateEndpointID", "must be set") + } + + basePath := fmt.Sprintf(serverlessPrivateEndpointsPath, groupID, instanceID) + path := fmt.Sprintf("%s/%s", basePath, url.PathEscape(privateEndpointID)) + req, err := s.Client.NewRequest(ctx, http.MethodPatch, path, nil) + if err != nil { + return nil, nil, err + } + + root := new(PrivateServerlessEndpointConnection) + resp, err := s.Client.Do(ctx, req, root) + if err != nil { + return nil, resp, err + } + + return root, resp, err +} From c9da1fbd5253c3db25fac37ba3683d20a66c7e52 Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Tue, 27 Sep 2022 20:48:47 -0500 Subject: [PATCH 02/12] Add update payload --- mongodbatlas/private_endpoints.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mongodbatlas/private_endpoints.go b/mongodbatlas/private_endpoints.go index 4e4030217..e4bf04d84 100644 --- a/mongodbatlas/private_endpoints.go +++ b/mongodbatlas/private_endpoints.go @@ -45,7 +45,7 @@ type PrivateEndpointsService interface { AddOnePrivateServerlessEndpoint(context.Context, string, string, string, *PrivateServerlessEndpointConnection) (*PrivateServerlessEndpointConnection, *Response, error) GetOnePrivateServerlessEndpoint(context.Context, string, string, string) (*PrivateServerlessEndpointConnection, *Response, error) DeleteOnePrivateServerlessEndpoint(context.Context, string, string, string) (*Response, error) - UpdateOnePrivateServerlessEndpoint(context.Context, string, string, string) (*PrivateServerlessEndpointConnection, *Response, error) + UpdateOnePrivateServerlessEndpoint(context.Context, string, string, string, *PrivateServerlessEndpointConnection) (*PrivateServerlessEndpointConnection, *Response, error) } // PrivateEndpointsServiceOp handles communication with the PrivateEndpoints related methods @@ -498,7 +498,7 @@ func (s *PrivateEndpointsServiceOp) GetOnePrivateServerlessEndpoint(ctx context. // UpdateOnePrivateServerlessEndpoint updates the private serverless endpoint setting for one Atlas project. // // See more: https://docs.atlas.mongodb.com/reference/api/private-endpoints-update-regional-mode -func (s *PrivateEndpointsServiceOp) UpdateOnePrivateServerlessEndpoint(ctx context.Context, groupID, instanceID, privateEndpointID string) (*PrivateServerlessEndpointConnection, *Response, error) { +func (s *PrivateEndpointsServiceOp) UpdateOnePrivateServerlessEndpoint(ctx context.Context, groupID, instanceID, privateEndpointID string, updateRequest *PrivateServerlessEndpointConnection) (*PrivateServerlessEndpointConnection, *Response, error) { if groupID == "" { return nil, nil, NewArgError("groupID", "must be set") } From a1aa71449c6bbd3e207c014dcdcbbd4edaaedc69 Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Tue, 27 Sep 2022 20:59:30 -0500 Subject: [PATCH 03/12] Remove extra parameter --- mongodbatlas/private_endpoints.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/mongodbatlas/private_endpoints.go b/mongodbatlas/private_endpoints.go index e4bf04d84..8ced0d1c8 100644 --- a/mongodbatlas/private_endpoints.go +++ b/mongodbatlas/private_endpoints.go @@ -42,7 +42,7 @@ type PrivateEndpointsService interface { UpdateRegionalizedPrivateEndpointSetting(context.Context, string, bool) (*RegionalizedPrivateEndpointSetting, *Response, error) GetRegionalizedPrivateEndpointSetting(context.Context, string) (*RegionalizedPrivateEndpointSetting, *Response, error) ListPrivateServerlessEndpoint(context.Context, string, string, *ListOptions) ([]PrivateServerlessEndpointConnection, *Response, error) - AddOnePrivateServerlessEndpoint(context.Context, string, string, string, *PrivateServerlessEndpointConnection) (*PrivateServerlessEndpointConnection, *Response, error) + AddOnePrivateServerlessEndpoint(context.Context, string, string, *PrivateServerlessEndpointConnection) (*PrivateServerlessEndpointConnection, *Response, error) GetOnePrivateServerlessEndpoint(context.Context, string, string, string) (*PrivateServerlessEndpointConnection, *Response, error) DeleteOnePrivateServerlessEndpoint(context.Context, string, string, string) (*Response, error) UpdateOnePrivateServerlessEndpoint(context.Context, string, string, string, *PrivateServerlessEndpointConnection) (*PrivateServerlessEndpointConnection, *Response, error) @@ -432,13 +432,11 @@ func (s *PrivateEndpointsServiceOp) DeleteOnePrivateServerlessEndpoint(ctx conte // AddOnePrivateServerlessEndpoint Adds one serverless private endpoint in an Atlas project. // // See more: https://www.mongodb.com/docs/atlas/reference/api/serverless-private-endpoints-get-one/ -func (s *PrivateEndpointsServiceOp) AddOnePrivateServerlessEndpoint(ctx context.Context, groupID, instanceID, privateEndpointID string, createRequest *PrivateServerlessEndpointConnection) (*PrivateServerlessEndpointConnection, *Response, error) { +func (s *PrivateEndpointsServiceOp) AddOnePrivateServerlessEndpoint(ctx context.Context, groupID, instanceID string, createRequest *PrivateServerlessEndpointConnection) (*PrivateServerlessEndpointConnection, *Response, error) { if groupID == "" { return nil, nil, NewArgError("groupID", "must be set") } - if privateEndpointID == "" { - return nil, nil, NewArgError("PrivateEndpointID", "must be set") - } + if instanceID == "" { return nil, nil, NewArgError("instanceID", "must be set") } @@ -447,7 +445,7 @@ func (s *PrivateEndpointsServiceOp) AddOnePrivateServerlessEndpoint(ctx context. } basePath := fmt.Sprintf(serverlessPrivateEndpointsPath, groupID, instanceID) - path := fmt.Sprintf("%s/%s", basePath, url.PathEscape(privateEndpointID)) + path := fmt.Sprintf("%s/%s", basePath, url.PathEscape(instanceID)) req, err := s.Client.NewRequest(ctx, http.MethodPost, path, createRequest) if err != nil { From b406fc2a45f9a477d0148286fba2f8e1be8c882d Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Tue, 27 Sep 2022 21:50:19 -0500 Subject: [PATCH 04/12] Remove extra parameter --- mongodbatlas/private_endpoints.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mongodbatlas/private_endpoints.go b/mongodbatlas/private_endpoints.go index 8ced0d1c8..44277173f 100644 --- a/mongodbatlas/private_endpoints.go +++ b/mongodbatlas/private_endpoints.go @@ -444,8 +444,7 @@ func (s *PrivateEndpointsServiceOp) AddOnePrivateServerlessEndpoint(ctx context. return nil, nil, NewArgError("createRequest", "cannot be nil") } - basePath := fmt.Sprintf(serverlessPrivateEndpointsPath, groupID, instanceID) - path := fmt.Sprintf("%s/%s", basePath, url.PathEscape(instanceID)) + path := fmt.Sprintf(serverlessPrivateEndpointsPath, groupID, instanceID) req, err := s.Client.NewRequest(ctx, http.MethodPost, path, createRequest) if err != nil { From c3e387b38974ab904af0adf820d3413d78af7b12 Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Wed, 28 Sep 2022 18:00:10 -0500 Subject: [PATCH 05/12] Edit struct for id --- mongodbatlas/private_endpoints.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mongodbatlas/private_endpoints.go b/mongodbatlas/private_endpoints.go index 44277173f..75028ddc2 100644 --- a/mongodbatlas/private_endpoints.go +++ b/mongodbatlas/private_endpoints.go @@ -103,12 +103,12 @@ type GCPEndpoint struct { // PrivateEndpointServerlessConnection represents MongoDB Private Endpoint Connection. type PrivateServerlessEndpointConnection struct { - ID string `json:"id,omitempty"` // Unique identifier of the AWS PrivateLink connection or Azure Private Link Service. + ID string `json:"_id,omitempty"` // Unique identifier of the Serverless PrivateLink Service. CloudProviderEndpointID string `json:"cloudProviderEndpointId,omitempty"` Comment string `json:"comment,omitempty"` EndpointServiceName string `json:"endpointServiceName,omitempty"` // Name of the PrivateLink endpoint service in AWS. Returns null while the endpoint service is being created. - ErrorMessage interface{} `json:"errorMessage,omitempty"` // Error message pertaining to the AWS PrivateLink connection or Azure Private Link Service or GCP Private Service Connect. Returns null if there are no errors. - Status string `json:"status,omitempty"` // Status of the AWS, Azure OR GCP PrivateLink connection: INITIATING, WAITING_FOR_USER, FAILED, DELETING, AVAILABLE. + ErrorMessage interface{} `json:"errorMessage,omitempty"` // Error message pertaining to the AWS Service Connect. Returns null if there are no errors. + Status string `json:"status,omitempty"` // Status of the AWS Servxerless PrivateLink connection: INITIATING, WAITING_FOR_USER, FAILED, DELETING, AVAILABLE. } // Create one private endpoint service for AWS or Azure in an Atlas project. From e66b9f9b941e6bcb90f7a987f11caf4ce72a00df Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Wed, 28 Sep 2022 18:16:40 -0500 Subject: [PATCH 06/12] Add serverless update payload --- mongodbatlas/private_endpoints.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mongodbatlas/private_endpoints.go b/mongodbatlas/private_endpoints.go index 75028ddc2..92a0693c0 100644 --- a/mongodbatlas/private_endpoints.go +++ b/mongodbatlas/private_endpoints.go @@ -508,7 +508,7 @@ func (s *PrivateEndpointsServiceOp) UpdateOnePrivateServerlessEndpoint(ctx conte basePath := fmt.Sprintf(serverlessPrivateEndpointsPath, groupID, instanceID) path := fmt.Sprintf("%s/%s", basePath, url.PathEscape(privateEndpointID)) - req, err := s.Client.NewRequest(ctx, http.MethodPatch, path, nil) + req, err := s.Client.NewRequest(ctx, http.MethodPatch, path, updateRequest) if err != nil { return nil, nil, err } From 1cc1360dc96582cfc23a236d3906b021001f9dec Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Thu, 29 Sep 2022 08:21:57 -0500 Subject: [PATCH 07/12] Add ProviderName to serverless endpoint --- mongodbatlas/private_endpoints.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mongodbatlas/private_endpoints.go b/mongodbatlas/private_endpoints.go index 92a0693c0..bbea701c4 100644 --- a/mongodbatlas/private_endpoints.go +++ b/mongodbatlas/private_endpoints.go @@ -108,7 +108,8 @@ type PrivateServerlessEndpointConnection struct { Comment string `json:"comment,omitempty"` EndpointServiceName string `json:"endpointServiceName,omitempty"` // Name of the PrivateLink endpoint service in AWS. Returns null while the endpoint service is being created. ErrorMessage interface{} `json:"errorMessage,omitempty"` // Error message pertaining to the AWS Service Connect. Returns null if there are no errors. - Status string `json:"status,omitempty"` // Status of the AWS Servxerless PrivateLink connection: INITIATING, WAITING_FOR_USER, FAILED, DELETING, AVAILABLE. + Status string `json:"status,omitempty"` // Status of the AWS Serverless PrivateLink connection: INITIATING, WAITING_FOR_USER, FAILED, DELETING, AVAILABLE. + ProviderName string `json:"providerName,omitempty"` //Human-readable label that identifies the cloud provider. Values include AWS or AZURE. Atlas currently supports only AWS. } // Create one private endpoint service for AWS or Azure in an Atlas project. From 3a63487dc732601e220f402f88502deaf63a69eb Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Mon, 3 Oct 2022 12:56:33 -0500 Subject: [PATCH 08/12] Add test for serverless endpoints --- mongodbatlas/private_endpoints.go | 5 +- mongodbatlas/private_endpoints_test.go | 69 ++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 4 deletions(-) diff --git a/mongodbatlas/private_endpoints.go b/mongodbatlas/private_endpoints.go index bbea701c4..92e2f3ca3 100644 --- a/mongodbatlas/private_endpoints.go +++ b/mongodbatlas/private_endpoints.go @@ -101,7 +101,6 @@ type GCPEndpoint struct { } // PrivateEndpointServerlessConnection represents MongoDB Private Endpoint Connection. - type PrivateServerlessEndpointConnection struct { ID string `json:"_id,omitempty"` // Unique identifier of the Serverless PrivateLink Service. CloudProviderEndpointID string `json:"cloudProviderEndpointId,omitempty"` @@ -383,9 +382,7 @@ func (s *PrivateEndpointsServiceOp) ListPrivateServerlessEndpoint(ctx context.Co return nil, nil, NewArgError("instanceID", "must be set") } - path := fmt.Sprintf(serverlessPrivateEndpointsPath, groupID, instanceID) - - // Add query params from listOptions + path := fmt.Sprintf(serverlessPrivateEndpointsPath, groupID, instanceID) // Add query params from listOptions path, err := setListOptions(path, listOptions) if err != nil { return nil, nil, err diff --git a/mongodbatlas/private_endpoints_test.go b/mongodbatlas/private_endpoints_test.go index accdcf358..d2458296a 100644 --- a/mongodbatlas/private_endpoints_test.go +++ b/mongodbatlas/private_endpoints_test.go @@ -1003,3 +1003,72 @@ func TestPrivateEndpoints_GetRegionalizedPrivateEndpointSetting(t *testing.T) { t.Errorf("PrivateEndpoints.UpdateRegionalizedPrivateEndpointSetting\n got=%#v\nwant=%#v", interfaceEndpoint, expected) } } + +func TestPrivateEndpoints_GetOnePrivateServerlessEndpoint(t *testing.T) { + client, mux, teardown := setup() + defer teardown() + + groupID := "1" + instanceName := "serverless" + endpointID := "3658569708087079" + + mux.HandleFunc(fmt.Sprintf("/api/atlas/v1.0/groups/%s/privateEndpoint/serverless/instance/%s/endpoint/%s", groupID, instanceName, endpointID), func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, http.MethodGet) + fmt.Fprint(w, `{ + "ID":"", "CloudProviderEndpointID":"vpce-12356", "Comment":"Test Serverless", "EndpointServiceName":"", "Status":"AVAILABLE", "ProviderName":"AWS" + }`) + }) + + interfaceEndpoint, _, err := client.PrivateEndpoints.GetOnePrivateServerlessEndpoint(ctx, groupID, instanceName, endpointID) + if err != nil { + t.Errorf("PrivateEndpoints.GetOnePrivateServerlessEndpoint returned error: %v", err) + } + + expected := &PrivateServerlessEndpointConnection{ + Comment: "Test Serverless", + ProviderName: "AWS", + Status: "AVAILABLE", + CloudProviderEndpointID: "vpce-12356", + } + + if !reflect.DeepEqual(interfaceEndpoint, expected) { + t.Errorf("PrivateEndpoints.GetOnePrivateServerlessEndpoint\n got=%#v\nwant=%#v", interfaceEndpoint, expected) + } +} + +func TestPrivateEndpoints_UpdateOnePrivateServerlessEndpoint(t *testing.T) { + client, mux, teardown := setup() + defer teardown() + + groupID := "1" + instanceName := "serverless" + endpointID := "3658569708087079" + + mux.HandleFunc(fmt.Sprintf("/api/atlas/v1.0/groups/%s/privateEndpoint/serverless/instance/%s/endpoint/%s", groupID, instanceName, endpointID), func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, http.MethodPatch) + fmt.Fprint(w, `{ + "ID":"", "CloudProviderEndpointID":"vpce1234567", "Comment":"Test Serverless", "EndpointServiceName":"", "Status":"AVAILABLE", "ProviderName":"AWS" + }`) + }) + + update := &PrivateServerlessEndpointConnection{ + CloudProviderEndpointID: "vpce1234567", + ProviderName: "AWS", + } + + interfaceEndpoint, _, err := client.PrivateEndpoints.UpdateOnePrivateServerlessEndpoint(ctx, groupID, instanceName, endpointID, update) + if err != nil { + t.Errorf("PrivateEndpoints.UpdateOnePrivateServerlessEndpoint returned error: %v", err) + } + + expected := &PrivateServerlessEndpointConnection{ + Comment: "Test Serverless", + ProviderName: "AWS", + Status: "AVAILABLE", + CloudProviderEndpointID: "vpce1234567", + } + + if !reflect.DeepEqual(interfaceEndpoint, expected) { + t.Errorf("PrivateEndpoints.UpdateOnePrivateServerlessEndpoint\n got=%#v\nwant=%#v", interfaceEndpoint, expected) + } +} From ca808f3499690393fc563e2120732b8b3ad61cd9 Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Mon, 3 Oct 2022 13:30:55 -0500 Subject: [PATCH 09/12] Fix lint --- mongodbatlas/private_endpoints.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mongodbatlas/private_endpoints.go b/mongodbatlas/private_endpoints.go index 92e2f3ca3..b3224ba7a 100644 --- a/mongodbatlas/private_endpoints.go +++ b/mongodbatlas/private_endpoints.go @@ -108,7 +108,7 @@ type PrivateServerlessEndpointConnection struct { EndpointServiceName string `json:"endpointServiceName,omitempty"` // Name of the PrivateLink endpoint service in AWS. Returns null while the endpoint service is being created. ErrorMessage interface{} `json:"errorMessage,omitempty"` // Error message pertaining to the AWS Service Connect. Returns null if there are no errors. Status string `json:"status,omitempty"` // Status of the AWS Serverless PrivateLink connection: INITIATING, WAITING_FOR_USER, FAILED, DELETING, AVAILABLE. - ProviderName string `json:"providerName,omitempty"` //Human-readable label that identifies the cloud provider. Values include AWS or AZURE. Atlas currently supports only AWS. + ProviderName string `json:"providerName,omitempty"` // Human-readable label that identifies the cloud provider. Values include AWS or AZURE. Atlas currently supports only AWS. } // Create one private endpoint service for AWS or Azure in an Atlas project. From fa92f510a28270152f539ab9c06b9970676dafe4 Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Wed, 5 Oct 2022 08:46:02 -0500 Subject: [PATCH 10/12] Update links for API references --- mongodbatlas/private_endpoints.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mongodbatlas/private_endpoints.go b/mongodbatlas/private_endpoints.go index b3224ba7a..82fbdaa16 100644 --- a/mongodbatlas/private_endpoints.go +++ b/mongodbatlas/private_endpoints.go @@ -373,7 +373,7 @@ func (s *PrivateEndpointsServiceOp) GetRegionalizedPrivateEndpointSetting(ctx co // List retrieve details for all private Serverless endpoint services in one Atlas project. // -// See more: https://www.mongodb.com/docs/atlas/reference/api/serverless-private-endpoints-get-all/ +// See more: https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#operation/returnAllPrivateEndpointsForOneServerlessInstance func (s *PrivateEndpointsServiceOp) ListPrivateServerlessEndpoint(ctx context.Context, groupID, instanceID string, listOptions *ListOptions) ([]PrivateServerlessEndpointConnection, *Response, error) { if groupID == "" { return nil, nil, NewArgError("groupID", "must be set") @@ -404,7 +404,7 @@ func (s *PrivateEndpointsServiceOp) ListPrivateServerlessEndpoint(ctx context.Co // DeleteOnePrivateServerlessEndpoint one private serverless endpoint service in an Atlas project. // -// See more https://docs.atlas.mongodb.com/reference/api/private-endpoints-service-delete-one/ +// See more https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#operation/removeOnePrivateEndpointFromOneServerlessInstance func (s *PrivateEndpointsServiceOp) DeleteOnePrivateServerlessEndpoint(ctx context.Context, groupID, instanceID, privateEndpointID string) (*Response, error) { if groupID == "" { return nil, NewArgError("groupID", "must be set") @@ -429,7 +429,7 @@ func (s *PrivateEndpointsServiceOp) DeleteOnePrivateServerlessEndpoint(ctx conte // AddOnePrivateServerlessEndpoint Adds one serverless private endpoint in an Atlas project. // -// See more: https://www.mongodb.com/docs/atlas/reference/api/serverless-private-endpoints-get-one/ +// See more: https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#operation/createOnePrivateEndpointForOneServerlessInstance func (s *PrivateEndpointsServiceOp) AddOnePrivateServerlessEndpoint(ctx context.Context, groupID, instanceID string, createRequest *PrivateServerlessEndpointConnection) (*PrivateServerlessEndpointConnection, *Response, error) { if groupID == "" { return nil, nil, NewArgError("groupID", "must be set") @@ -460,7 +460,7 @@ func (s *PrivateEndpointsServiceOp) AddOnePrivateServerlessEndpoint(ctx context. // GetOnePrivateServerlessEndpoint retrieve details for one private serverless endpoint in an Atlas project. // -// See more: https://www.mongodb.com/docs/atlas/reference/api/serverless-private-endpoints-get-one/ +// See more: https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#operation/returnOnePrivateEndpointForOneServerlessInstance func (s *PrivateEndpointsServiceOp) GetOnePrivateServerlessEndpoint(ctx context.Context, groupID, instanceID, privateEndpointID string) (*PrivateServerlessEndpointConnection, *Response, error) { if groupID == "" { return nil, nil, NewArgError("groupID", "must be set") @@ -492,7 +492,7 @@ func (s *PrivateEndpointsServiceOp) GetOnePrivateServerlessEndpoint(ctx context. // UpdateOnePrivateServerlessEndpoint updates the private serverless endpoint setting for one Atlas project. // -// See more: https://docs.atlas.mongodb.com/reference/api/private-endpoints-update-regional-mode +// See more: https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#operation/updateOnePrivateEndpointForOneServerlessInstance func (s *PrivateEndpointsServiceOp) UpdateOnePrivateServerlessEndpoint(ctx context.Context, groupID, instanceID, privateEndpointID string, updateRequest *PrivateServerlessEndpointConnection) (*PrivateServerlessEndpointConnection, *Response, error) { if groupID == "" { return nil, nil, NewArgError("groupID", "must be set") From 9997c59cd605de5acb714e5a0e7abee05877e851 Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Mon, 10 Oct 2022 12:31:44 -0500 Subject: [PATCH 11/12] Split out serverless endpoints to separate service --- mongodbatlas/mongodbatlas.go | 2 + mongodbatlas/private_endpoints.go | 170 +-------------- mongodbatlas/private_endpoints_test.go | 69 ------ mongodbatlas/private_serverless_endpoints.go | 204 ++++++++++++++++++ .../private_serverless_endpoints_test.go | 91 ++++++++ 5 files changed, 299 insertions(+), 237 deletions(-) create mode 100644 mongodbatlas/private_serverless_endpoints.go create mode 100644 mongodbatlas/private_serverless_endpoints_test.go diff --git a/mongodbatlas/mongodbatlas.go b/mongodbatlas/mongodbatlas.go index 602ab6db0..edf083ad7 100644 --- a/mongodbatlas/mongodbatlas.go +++ b/mongodbatlas/mongodbatlas.go @@ -116,6 +116,7 @@ type Client struct { Auditing AuditingsService AlertConfigurations AlertConfigurationsService PrivateEndpoints PrivateEndpointsService + PrivateServerlessEndpoints PrivateServerlessEndpointsService PrivateEndpointsDeprecated PrivateEndpointsServiceDeprecated X509AuthDBUsers X509AuthDBUsersService ContinuousSnapshots ContinuousSnapshotsService @@ -263,6 +264,7 @@ func NewClient(httpClient *http.Client) *Client { c.Auditing = &AuditingsServiceOp{Client: c} c.AlertConfigurations = &AlertConfigurationsServiceOp{Client: c} c.PrivateEndpoints = &PrivateEndpointsServiceOp{Client: c} + c.PrivateServerlessEndpoints = &PrivateServerlessEndpointsServiceOp{Client: c} c.PrivateEndpointsDeprecated = &PrivateEndpointsServiceOpDeprecated{Client: c} c.X509AuthDBUsers = &X509AuthDBUsersServiceOp{Client: c} c.ContinuousRestoreJobs = &ContinuousRestoreJobsServiceOp{Client: c} diff --git a/mongodbatlas/private_endpoints.go b/mongodbatlas/private_endpoints.go index 82fbdaa16..a7133512b 100644 --- a/mongodbatlas/private_endpoints.go +++ b/mongodbatlas/private_endpoints.go @@ -22,9 +22,8 @@ import ( ) const ( - privateEndpointsPath = "api/atlas/v1.0/groups/%s/privateEndpoint" - serverlessPrivateEndpointsPath = "api/atlas/v1.0/groups/%s/privateEndpoint/serverless/instance/%s/endpoint" - regionalModePath = privateEndpointsPath + "/regionalMode" + privateEndpointsPath = "api/atlas/v1.0/groups/%s/privateEndpoint" + regionalModePath = privateEndpointsPath + "/regionalMode" ) // PrivateEndpointsService is an interface for interfacing with the Private Endpoints @@ -41,11 +40,6 @@ type PrivateEndpointsService interface { DeleteOnePrivateEndpoint(context.Context, string, string, string, string) (*Response, error) UpdateRegionalizedPrivateEndpointSetting(context.Context, string, bool) (*RegionalizedPrivateEndpointSetting, *Response, error) GetRegionalizedPrivateEndpointSetting(context.Context, string) (*RegionalizedPrivateEndpointSetting, *Response, error) - ListPrivateServerlessEndpoint(context.Context, string, string, *ListOptions) ([]PrivateServerlessEndpointConnection, *Response, error) - AddOnePrivateServerlessEndpoint(context.Context, string, string, *PrivateServerlessEndpointConnection) (*PrivateServerlessEndpointConnection, *Response, error) - GetOnePrivateServerlessEndpoint(context.Context, string, string, string) (*PrivateServerlessEndpointConnection, *Response, error) - DeleteOnePrivateServerlessEndpoint(context.Context, string, string, string) (*Response, error) - UpdateOnePrivateServerlessEndpoint(context.Context, string, string, string, *PrivateServerlessEndpointConnection) (*PrivateServerlessEndpointConnection, *Response, error) } // PrivateEndpointsServiceOp handles communication with the PrivateEndpoints related methods @@ -100,17 +94,6 @@ type GCPEndpoint struct { ServiceAttachmentName string `json:"serviceAttachmentName,omitempty"` // Unique alphanumeric and special character strings that identify the service attachment associated with the endpoint. } -// PrivateEndpointServerlessConnection represents MongoDB Private Endpoint Connection. -type PrivateServerlessEndpointConnection struct { - ID string `json:"_id,omitempty"` // Unique identifier of the Serverless PrivateLink Service. - CloudProviderEndpointID string `json:"cloudProviderEndpointId,omitempty"` - Comment string `json:"comment,omitempty"` - EndpointServiceName string `json:"endpointServiceName,omitempty"` // Name of the PrivateLink endpoint service in AWS. Returns null while the endpoint service is being created. - ErrorMessage interface{} `json:"errorMessage,omitempty"` // Error message pertaining to the AWS Service Connect. Returns null if there are no errors. - Status string `json:"status,omitempty"` // Status of the AWS Serverless PrivateLink connection: INITIATING, WAITING_FOR_USER, FAILED, DELETING, AVAILABLE. - ProviderName string `json:"providerName,omitempty"` // Human-readable label that identifies the cloud provider. Values include AWS or AZURE. Atlas currently supports only AWS. -} - // Create one private endpoint service for AWS or Azure in an Atlas project. // // See more: https://docs.atlas.mongodb.com/reference/api/private-endpoints-service-create-one/ @@ -370,152 +353,3 @@ func (s *PrivateEndpointsServiceOp) GetRegionalizedPrivateEndpointSetting(ctx co return root, resp, err } - -// List retrieve details for all private Serverless endpoint services in one Atlas project. -// -// See more: https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#operation/returnAllPrivateEndpointsForOneServerlessInstance -func (s *PrivateEndpointsServiceOp) ListPrivateServerlessEndpoint(ctx context.Context, groupID, instanceID string, listOptions *ListOptions) ([]PrivateServerlessEndpointConnection, *Response, error) { - if groupID == "" { - return nil, nil, NewArgError("groupID", "must be set") - } - if instanceID == "" { - return nil, nil, NewArgError("instanceID", "must be set") - } - - path := fmt.Sprintf(serverlessPrivateEndpointsPath, groupID, instanceID) // Add query params from listOptions - path, err := setListOptions(path, listOptions) - if err != nil { - return nil, nil, err - } - - req, err := s.Client.NewRequest(ctx, http.MethodGet, path, nil) - if err != nil { - return nil, nil, err - } - - root := new([]PrivateServerlessEndpointConnection) - resp, err := s.Client.Do(ctx, req, root) - if err != nil { - return nil, resp, err - } - - return *root, resp, nil -} - -// DeleteOnePrivateServerlessEndpoint one private serverless endpoint service in an Atlas project. -// -// See more https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#operation/removeOnePrivateEndpointFromOneServerlessInstance -func (s *PrivateEndpointsServiceOp) DeleteOnePrivateServerlessEndpoint(ctx context.Context, groupID, instanceID, privateEndpointID string) (*Response, error) { - if groupID == "" { - return nil, NewArgError("groupID", "must be set") - } - if privateEndpointID == "" { - return nil, NewArgError("PrivateEndpointID", "must be set") - } - if instanceID == "" { - return nil, NewArgError("instanceID", "must be set") - } - - basePath := fmt.Sprintf(serverlessPrivateEndpointsPath, groupID, instanceID) - path := fmt.Sprintf("%s/%s", basePath, url.PathEscape(privateEndpointID)) - - req, err := s.Client.NewRequest(ctx, http.MethodDelete, path, nil) - if err != nil { - return nil, err - } - - return s.Client.Do(ctx, req, nil) -} - -// AddOnePrivateServerlessEndpoint Adds one serverless private endpoint in an Atlas project. -// -// See more: https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#operation/createOnePrivateEndpointForOneServerlessInstance -func (s *PrivateEndpointsServiceOp) AddOnePrivateServerlessEndpoint(ctx context.Context, groupID, instanceID string, createRequest *PrivateServerlessEndpointConnection) (*PrivateServerlessEndpointConnection, *Response, error) { - if groupID == "" { - return nil, nil, NewArgError("groupID", "must be set") - } - - if instanceID == "" { - return nil, nil, NewArgError("instanceID", "must be set") - } - if createRequest == nil { - return nil, nil, NewArgError("createRequest", "cannot be nil") - } - - path := fmt.Sprintf(serverlessPrivateEndpointsPath, groupID, instanceID) - - req, err := s.Client.NewRequest(ctx, http.MethodPost, path, createRequest) - if err != nil { - return nil, nil, err - } - - root := new(PrivateServerlessEndpointConnection) - resp, err := s.Client.Do(ctx, req, root) - if err != nil { - return nil, resp, err - } - - return root, resp, err -} - -// GetOnePrivateServerlessEndpoint retrieve details for one private serverless endpoint in an Atlas project. -// -// See more: https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#operation/returnOnePrivateEndpointForOneServerlessInstance -func (s *PrivateEndpointsServiceOp) GetOnePrivateServerlessEndpoint(ctx context.Context, groupID, instanceID, privateEndpointID string) (*PrivateServerlessEndpointConnection, *Response, error) { - if groupID == "" { - return nil, nil, NewArgError("groupID", "must be set") - } - - if instanceID == "" { - return nil, nil, NewArgError("instanceID", "must be set") - } - if privateEndpointID == "" { - return nil, nil, NewArgError("privateEndpointID", "must be set") - } - - basePath := fmt.Sprintf(serverlessPrivateEndpointsPath, groupID, instanceID) - path := fmt.Sprintf("%s/%s", basePath, url.PathEscape(privateEndpointID)) - - req, err := s.Client.NewRequest(ctx, http.MethodGet, path, nil) - if err != nil { - return nil, nil, err - } - - root := new(PrivateServerlessEndpointConnection) - resp, err := s.Client.Do(ctx, req, root) - if err != nil { - return nil, resp, err - } - - return root, resp, err -} - -// UpdateOnePrivateServerlessEndpoint updates the private serverless endpoint setting for one Atlas project. -// -// See more: https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#operation/updateOnePrivateEndpointForOneServerlessInstance -func (s *PrivateEndpointsServiceOp) UpdateOnePrivateServerlessEndpoint(ctx context.Context, groupID, instanceID, privateEndpointID string, updateRequest *PrivateServerlessEndpointConnection) (*PrivateServerlessEndpointConnection, *Response, error) { - if groupID == "" { - return nil, nil, NewArgError("groupID", "must be set") - } - if instanceID == "" { - return nil, nil, NewArgError("instanceID", "must be set") - } - if privateEndpointID == "" { - return nil, nil, NewArgError("privateEndpointID", "must be set") - } - - basePath := fmt.Sprintf(serverlessPrivateEndpointsPath, groupID, instanceID) - path := fmt.Sprintf("%s/%s", basePath, url.PathEscape(privateEndpointID)) - req, err := s.Client.NewRequest(ctx, http.MethodPatch, path, updateRequest) - if err != nil { - return nil, nil, err - } - - root := new(PrivateServerlessEndpointConnection) - resp, err := s.Client.Do(ctx, req, root) - if err != nil { - return nil, resp, err - } - - return root, resp, err -} diff --git a/mongodbatlas/private_endpoints_test.go b/mongodbatlas/private_endpoints_test.go index d2458296a..accdcf358 100644 --- a/mongodbatlas/private_endpoints_test.go +++ b/mongodbatlas/private_endpoints_test.go @@ -1003,72 +1003,3 @@ func TestPrivateEndpoints_GetRegionalizedPrivateEndpointSetting(t *testing.T) { t.Errorf("PrivateEndpoints.UpdateRegionalizedPrivateEndpointSetting\n got=%#v\nwant=%#v", interfaceEndpoint, expected) } } - -func TestPrivateEndpoints_GetOnePrivateServerlessEndpoint(t *testing.T) { - client, mux, teardown := setup() - defer teardown() - - groupID := "1" - instanceName := "serverless" - endpointID := "3658569708087079" - - mux.HandleFunc(fmt.Sprintf("/api/atlas/v1.0/groups/%s/privateEndpoint/serverless/instance/%s/endpoint/%s", groupID, instanceName, endpointID), func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, http.MethodGet) - fmt.Fprint(w, `{ - "ID":"", "CloudProviderEndpointID":"vpce-12356", "Comment":"Test Serverless", "EndpointServiceName":"", "Status":"AVAILABLE", "ProviderName":"AWS" - }`) - }) - - interfaceEndpoint, _, err := client.PrivateEndpoints.GetOnePrivateServerlessEndpoint(ctx, groupID, instanceName, endpointID) - if err != nil { - t.Errorf("PrivateEndpoints.GetOnePrivateServerlessEndpoint returned error: %v", err) - } - - expected := &PrivateServerlessEndpointConnection{ - Comment: "Test Serverless", - ProviderName: "AWS", - Status: "AVAILABLE", - CloudProviderEndpointID: "vpce-12356", - } - - if !reflect.DeepEqual(interfaceEndpoint, expected) { - t.Errorf("PrivateEndpoints.GetOnePrivateServerlessEndpoint\n got=%#v\nwant=%#v", interfaceEndpoint, expected) - } -} - -func TestPrivateEndpoints_UpdateOnePrivateServerlessEndpoint(t *testing.T) { - client, mux, teardown := setup() - defer teardown() - - groupID := "1" - instanceName := "serverless" - endpointID := "3658569708087079" - - mux.HandleFunc(fmt.Sprintf("/api/atlas/v1.0/groups/%s/privateEndpoint/serverless/instance/%s/endpoint/%s", groupID, instanceName, endpointID), func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, http.MethodPatch) - fmt.Fprint(w, `{ - "ID":"", "CloudProviderEndpointID":"vpce1234567", "Comment":"Test Serverless", "EndpointServiceName":"", "Status":"AVAILABLE", "ProviderName":"AWS" - }`) - }) - - update := &PrivateServerlessEndpointConnection{ - CloudProviderEndpointID: "vpce1234567", - ProviderName: "AWS", - } - - interfaceEndpoint, _, err := client.PrivateEndpoints.UpdateOnePrivateServerlessEndpoint(ctx, groupID, instanceName, endpointID, update) - if err != nil { - t.Errorf("PrivateEndpoints.UpdateOnePrivateServerlessEndpoint returned error: %v", err) - } - - expected := &PrivateServerlessEndpointConnection{ - Comment: "Test Serverless", - ProviderName: "AWS", - Status: "AVAILABLE", - CloudProviderEndpointID: "vpce1234567", - } - - if !reflect.DeepEqual(interfaceEndpoint, expected) { - t.Errorf("PrivateEndpoints.UpdateOnePrivateServerlessEndpoint\n got=%#v\nwant=%#v", interfaceEndpoint, expected) - } -} diff --git a/mongodbatlas/private_serverless_endpoints.go b/mongodbatlas/private_serverless_endpoints.go new file mode 100644 index 000000000..9c48371dc --- /dev/null +++ b/mongodbatlas/private_serverless_endpoints.go @@ -0,0 +1,204 @@ +// Copyright 2021 MongoDB Inc +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package mongodbatlas + +import ( + "context" + "fmt" + "net/http" + "net/url" +) + +const ( + serverlessPrivateEndpointsPath = "api/atlas/v1.0/groups/%s/privateEndpoint/serverless/instance/%s/endpoint" +) + +// PrivateEndpointsService is an interface for interfacing with the Private Endpoints +// of the MongoDB Atlas API. +// +// See more: https://docs.atlas.mongodb.com/reference/api/private-endpoints/ +type PrivateServerlessEndpointsService interface { + ListPrivateServerlessEndpoint(context.Context, string, string, *ListOptions) ([]PrivateServerlessEndpointConnection, *Response, error) + AddOnePrivateServerlessEndpoint(context.Context, string, string, *PrivateServerlessEndpointConnection) (*PrivateServerlessEndpointConnection, *Response, error) + GetOnePrivateServerlessEndpoint(context.Context, string, string, string) (*PrivateServerlessEndpointConnection, *Response, error) + DeleteOnePrivateServerlessEndpoint(context.Context, string, string, string) (*Response, error) + UpdateOnePrivateServerlessEndpoint(context.Context, string, string, string, *PrivateServerlessEndpointConnection) (*PrivateServerlessEndpointConnection, *Response, error) +} + +// PrivateServerlessEndpointsServiceOp handles communication with the PrivateServerlessEndpoints related methods +// of the MongoDB Atlas API. +type PrivateServerlessEndpointsServiceOp service + +var _ PrivateServerlessEndpointsService = &PrivateServerlessEndpointsServiceOp{} + +// PrivateEndpointServerlessConnection represents MongoDB Private Endpoint Connection. +type PrivateServerlessEndpointConnection struct { + ID string `json:"_id,omitempty"` // Unique identifier of the Serverless PrivateLink Service. + CloudProviderEndpointID string `json:"cloudProviderEndpointId,omitempty"` + Comment string `json:"comment,omitempty"` + EndpointServiceName string `json:"endpointServiceName,omitempty"` // Name of the PrivateLink endpoint service in AWS. Returns null while the endpoint service is being created. + ErrorMessage string `json:"errorMessage,omitempty"` // Error message pertaining to the AWS Service Connect. Returns null if there are no errors. + Status string `json:"status,omitempty"` // Status of the AWS Serverless PrivateLink connection: INITIATING, WAITING_FOR_USER, FAILED, DELETING, AVAILABLE. + ProviderName string `json:"providerName,omitempty"` // Human-readable label that identifies the cloud provider. Values include AWS or AZURE. Atlas currently supports only AWS. +} + +// List retrieve details for all private Serverless endpoint services in one Atlas project. +// +// See more: https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#operation/returnAllPrivateEndpointsForOneServerlessInstance +func (s *PrivateServerlessEndpointsServiceOp) ListPrivateServerlessEndpoint(ctx context.Context, groupID, instanceID string, listOptions *ListOptions) ([]PrivateServerlessEndpointConnection, *Response, error) { + if groupID == "" { + return nil, nil, NewArgError("groupID", "must be set") + } + if instanceID == "" { + return nil, nil, NewArgError("instanceID", "must be set") + } + + path := fmt.Sprintf(serverlessPrivateEndpointsPath, groupID, instanceID) // Add query params from listOptions + path, err := setListOptions(path, listOptions) + if err != nil { + return nil, nil, err + } + + req, err := s.Client.NewRequest(ctx, http.MethodGet, path, nil) + if err != nil { + return nil, nil, err + } + + root := new([]PrivateServerlessEndpointConnection) + resp, err := s.Client.Do(ctx, req, root) + if err != nil { + return nil, resp, err + } + + return *root, resp, nil +} + +// DeleteOnePrivateServerlessEndpoint one private serverless endpoint service in an Atlas project. +// +// See more https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#operation/removeOnePrivateEndpointFromOneServerlessInstance +func (s *PrivateServerlessEndpointsServiceOp) DeleteOnePrivateServerlessEndpoint(ctx context.Context, groupID, instanceID, privateEndpointID string) (*Response, error) { + if groupID == "" { + return nil, NewArgError("groupID", "must be set") + } + if privateEndpointID == "" { + return nil, NewArgError("PrivateEndpointID", "must be set") + } + if instanceID == "" { + return nil, NewArgError("instanceID", "must be set") + } + + basePath := fmt.Sprintf(serverlessPrivateEndpointsPath, groupID, instanceID) + path := fmt.Sprintf("%s/%s", basePath, url.PathEscape(privateEndpointID)) + + req, err := s.Client.NewRequest(ctx, http.MethodDelete, path, nil) + if err != nil { + return nil, err + } + + return s.Client.Do(ctx, req, nil) +} + +// AddOnePrivateServerlessEndpoint Adds one serverless private endpoint in an Atlas project. +// +// See more: https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#operation/createOnePrivateEndpointForOneServerlessInstance +func (s *PrivateServerlessEndpointsServiceOp) AddOnePrivateServerlessEndpoint(ctx context.Context, groupID, instanceID string, createRequest *PrivateServerlessEndpointConnection) (*PrivateServerlessEndpointConnection, *Response, error) { + if groupID == "" { + return nil, nil, NewArgError("groupID", "must be set") + } + + if instanceID == "" { + return nil, nil, NewArgError("instanceID", "must be set") + } + if createRequest == nil { + return nil, nil, NewArgError("createRequest", "cannot be nil") + } + + path := fmt.Sprintf(serverlessPrivateEndpointsPath, groupID, instanceID) + + req, err := s.Client.NewRequest(ctx, http.MethodPost, path, createRequest) + if err != nil { + return nil, nil, err + } + + root := new(PrivateServerlessEndpointConnection) + resp, err := s.Client.Do(ctx, req, root) + if err != nil { + return nil, resp, err + } + + return root, resp, err +} + +// GetOnePrivateServerlessEndpoint retrieve details for one private serverless endpoint in an Atlas project. +// +// See more: https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#operation/returnOnePrivateEndpointForOneServerlessInstance +func (s *PrivateServerlessEndpointsServiceOp) GetOnePrivateServerlessEndpoint(ctx context.Context, groupID, instanceID, privateEndpointID string) (*PrivateServerlessEndpointConnection, *Response, error) { + if groupID == "" { + return nil, nil, NewArgError("groupID", "must be set") + } + + if instanceID == "" { + return nil, nil, NewArgError("instanceID", "must be set") + } + if privateEndpointID == "" { + return nil, nil, NewArgError("privateEndpointID", "must be set") + } + + basePath := fmt.Sprintf(serverlessPrivateEndpointsPath, groupID, instanceID) + path := fmt.Sprintf("%s/%s", basePath, url.PathEscape(privateEndpointID)) + + req, err := s.Client.NewRequest(ctx, http.MethodGet, path, nil) + if err != nil { + return nil, nil, err + } + + root := new(PrivateServerlessEndpointConnection) + resp, err := s.Client.Do(ctx, req, root) + if err != nil { + return nil, resp, err + } + + return root, resp, err +} + +// UpdateOnePrivateServerlessEndpoint updates the private serverless endpoint setting for one Atlas project. +// +// See more: https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#operation/updateOnePrivateEndpointForOneServerlessInstance +func (s *PrivateServerlessEndpointsServiceOp) UpdateOnePrivateServerlessEndpoint(ctx context.Context, groupID, instanceID, privateEndpointID string, updateRequest *PrivateServerlessEndpointConnection) (*PrivateServerlessEndpointConnection, *Response, error) { + if groupID == "" { + return nil, nil, NewArgError("groupID", "must be set") + } + if instanceID == "" { + return nil, nil, NewArgError("instanceID", "must be set") + } + if privateEndpointID == "" { + return nil, nil, NewArgError("privateEndpointID", "must be set") + } + + basePath := fmt.Sprintf(serverlessPrivateEndpointsPath, groupID, instanceID) + path := fmt.Sprintf("%s/%s", basePath, url.PathEscape(privateEndpointID)) + req, err := s.Client.NewRequest(ctx, http.MethodPatch, path, updateRequest) + if err != nil { + return nil, nil, err + } + + root := new(PrivateServerlessEndpointConnection) + resp, err := s.Client.Do(ctx, req, root) + if err != nil { + return nil, resp, err + } + + return root, resp, err +} diff --git a/mongodbatlas/private_serverless_endpoints_test.go b/mongodbatlas/private_serverless_endpoints_test.go new file mode 100644 index 000000000..88a089821 --- /dev/null +++ b/mongodbatlas/private_serverless_endpoints_test.go @@ -0,0 +1,91 @@ +// Copyright 2021 MongoDB Inc +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package mongodbatlas + +import ( + "fmt" + "net/http" + "reflect" + "testing" +) + +func TestPrivateEndpoints_GetOnePrivateServerlessEndpoint(t *testing.T) { + client, mux, teardown := setup() + defer teardown() + + groupID := "1" + instanceName := "serverless" + endpointID := "3658569708087079" + + mux.HandleFunc(fmt.Sprintf("/api/atlas/v1.0/groups/%s/privateEndpoint/serverless/instance/%s/endpoint/%s", groupID, instanceName, endpointID), func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, http.MethodGet) + fmt.Fprint(w, `{ + "ID":"", "CloudProviderEndpointID":"vpce-12356", "Comment":"Test Serverless", "EndpointServiceName":"", "Status":"AVAILABLE", "ProviderName":"AWS" + }`) + }) + + interfaceEndpoint, _, err := client.PrivateServerlessEndpoints.GetOnePrivateServerlessEndpoint(ctx, groupID, instanceName, endpointID) + if err != nil { + t.Errorf("PrivateEndpoints.GetOnePrivateServerlessEndpoint returned error: %v", err) + } + + expected := &PrivateServerlessEndpointConnection{ + Comment: "Test Serverless", + ProviderName: "AWS", + Status: "AVAILABLE", + CloudProviderEndpointID: "vpce-12356", + } + + if !reflect.DeepEqual(interfaceEndpoint, expected) { + t.Errorf("PrivateEndpoints.GetOnePrivateServerlessEndpoint\n got=%#v\nwant=%#v", interfaceEndpoint, expected) + } +} + +func TestPrivateEndpoints_UpdateOnePrivateServerlessEndpoint(t *testing.T) { + client, mux, teardown := setup() + defer teardown() + + groupID := "1" + instanceName := "serverless" + endpointID := "3658569708087079" + + mux.HandleFunc(fmt.Sprintf("/api/atlas/v1.0/groups/%s/privateEndpoint/serverless/instance/%s/endpoint/%s", groupID, instanceName, endpointID), func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, http.MethodPatch) + fmt.Fprint(w, `{ + "ID":"", "CloudProviderEndpointID":"vpce1234567", "Comment":"Test Serverless", "EndpointServiceName":"", "Status":"AVAILABLE", "ProviderName":"AWS" + }`) + }) + + update := &PrivateServerlessEndpointConnection{ + CloudProviderEndpointID: "vpce1234567", + ProviderName: "AWS", + } + + interfaceEndpoint, _, err := client.PrivateServerlessEndpoints.UpdateOnePrivateServerlessEndpoint(ctx, groupID, instanceName, endpointID, update) + if err != nil { + t.Errorf("PrivateEndpoints.UpdateOnePrivateServerlessEndpoint returned error: %v", err) + } + + expected := &PrivateServerlessEndpointConnection{ + Comment: "Test Serverless", + ProviderName: "AWS", + Status: "AVAILABLE", + CloudProviderEndpointID: "vpce1234567", + } + + if !reflect.DeepEqual(interfaceEndpoint, expected) { + t.Errorf("PrivateEndpoints.UpdateOnePrivateServerlessEndpoint\n got=%#v\nwant=%#v", interfaceEndpoint, expected) + } +} From 786c00762719bbf43ae780b395c465cd956e1cc5 Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Tue, 11 Oct 2022 23:14:13 -0500 Subject: [PATCH 12/12] Refactor Serverless endpoint naming convention --- mongodbatlas/mongodbatlas.go | 4 +- ...nts.go => serverless_private_endpoints.go} | 92 ++++++++++--------- ...o => serverless_private_endpoints_test.go} | 18 ++-- 3 files changed, 58 insertions(+), 56 deletions(-) rename mongodbatlas/{private_serverless_endpoints.go => serverless_private_endpoints.go} (50%) rename mongodbatlas/{private_serverless_endpoints_test.go => serverless_private_endpoints_test.go} (74%) diff --git a/mongodbatlas/mongodbatlas.go b/mongodbatlas/mongodbatlas.go index edf083ad7..af4c61f04 100644 --- a/mongodbatlas/mongodbatlas.go +++ b/mongodbatlas/mongodbatlas.go @@ -116,7 +116,7 @@ type Client struct { Auditing AuditingsService AlertConfigurations AlertConfigurationsService PrivateEndpoints PrivateEndpointsService - PrivateServerlessEndpoints PrivateServerlessEndpointsService + ServerlessPrivateEndpoints ServerlessPrivateEndpointsService PrivateEndpointsDeprecated PrivateEndpointsServiceDeprecated X509AuthDBUsers X509AuthDBUsersService ContinuousSnapshots ContinuousSnapshotsService @@ -264,7 +264,7 @@ func NewClient(httpClient *http.Client) *Client { c.Auditing = &AuditingsServiceOp{Client: c} c.AlertConfigurations = &AlertConfigurationsServiceOp{Client: c} c.PrivateEndpoints = &PrivateEndpointsServiceOp{Client: c} - c.PrivateServerlessEndpoints = &PrivateServerlessEndpointsServiceOp{Client: c} + c.ServerlessPrivateEndpoints = &ServerlessPrivateEndpointsServiceOp{Client: c} c.PrivateEndpointsDeprecated = &PrivateEndpointsServiceOpDeprecated{Client: c} c.X509AuthDBUsers = &X509AuthDBUsersServiceOp{Client: c} c.ContinuousRestoreJobs = &ContinuousRestoreJobsServiceOp{Client: c} diff --git a/mongodbatlas/private_serverless_endpoints.go b/mongodbatlas/serverless_private_endpoints.go similarity index 50% rename from mongodbatlas/private_serverless_endpoints.go rename to mongodbatlas/serverless_private_endpoints.go index 9c48371dc..0ae07b680 100644 --- a/mongodbatlas/private_serverless_endpoints.go +++ b/mongodbatlas/serverless_private_endpoints.go @@ -25,47 +25,49 @@ const ( serverlessPrivateEndpointsPath = "api/atlas/v1.0/groups/%s/privateEndpoint/serverless/instance/%s/endpoint" ) -// PrivateEndpointsService is an interface for interfacing with the Private Endpoints +// ServerlessPrivateEndpointsService is an interface for interfacing with the Private Endpoints // of the MongoDB Atlas API. // -// See more: https://docs.atlas.mongodb.com/reference/api/private-endpoints/ -type PrivateServerlessEndpointsService interface { - ListPrivateServerlessEndpoint(context.Context, string, string, *ListOptions) ([]PrivateServerlessEndpointConnection, *Response, error) - AddOnePrivateServerlessEndpoint(context.Context, string, string, *PrivateServerlessEndpointConnection) (*PrivateServerlessEndpointConnection, *Response, error) - GetOnePrivateServerlessEndpoint(context.Context, string, string, string) (*PrivateServerlessEndpointConnection, *Response, error) - DeleteOnePrivateServerlessEndpoint(context.Context, string, string, string) (*Response, error) - UpdateOnePrivateServerlessEndpoint(context.Context, string, string, string, *PrivateServerlessEndpointConnection) (*PrivateServerlessEndpointConnection, *Response, error) +// See more: See more: https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Serverless-Private-Endpoints +type ServerlessPrivateEndpointsService interface { + List(context.Context, string, string, *ListOptions) ([]ServerlessPrivateEndpointConnection, *Response, error) + Create(context.Context, string, string, *ServerlessPrivateEndpointConnection) (*ServerlessPrivateEndpointConnection, *Response, error) + Get(context.Context, string, string, string) (*ServerlessPrivateEndpointConnection, *Response, error) + Delete(context.Context, string, string, string) (*Response, error) + Update(context.Context, string, string, string, *ServerlessPrivateEndpointConnection) (*ServerlessPrivateEndpointConnection, *Response, error) } // PrivateServerlessEndpointsServiceOp handles communication with the PrivateServerlessEndpoints related methods // of the MongoDB Atlas API. -type PrivateServerlessEndpointsServiceOp service +type ServerlessPrivateEndpointsServiceOp service -var _ PrivateServerlessEndpointsService = &PrivateServerlessEndpointsServiceOp{} +var _ ServerlessPrivateEndpointsService = &ServerlessPrivateEndpointsServiceOp{} // PrivateEndpointServerlessConnection represents MongoDB Private Endpoint Connection. -type PrivateServerlessEndpointConnection struct { - ID string `json:"_id,omitempty"` // Unique identifier of the Serverless PrivateLink Service. - CloudProviderEndpointID string `json:"cloudProviderEndpointId,omitempty"` - Comment string `json:"comment,omitempty"` - EndpointServiceName string `json:"endpointServiceName,omitempty"` // Name of the PrivateLink endpoint service in AWS. Returns null while the endpoint service is being created. - ErrorMessage string `json:"errorMessage,omitempty"` // Error message pertaining to the AWS Service Connect. Returns null if there are no errors. - Status string `json:"status,omitempty"` // Status of the AWS Serverless PrivateLink connection: INITIATING, WAITING_FOR_USER, FAILED, DELETING, AVAILABLE. - ProviderName string `json:"providerName,omitempty"` // Human-readable label that identifies the cloud provider. Values include AWS or AZURE. Atlas currently supports only AWS. +type ServerlessPrivateEndpointConnection struct { + ID string `json:"_id,omitempty"` // Unique identifier of the Serverless PrivateLink Service. + CloudProviderEndpointID string `json:"cloudProviderEndpointId,omitempty"` + Comment string `json:"comment,omitempty"` + EndpointServiceName string `json:"endpointServiceName,omitempty"` // Name of the PrivateLink endpoint service in AWS. Returns null while the endpoint service is being created. + ErrorMessage string `json:"errorMessage,omitempty"` // Error message pertaining to the AWS Service Connect. Returns null if there are no errors. + Status string `json:"status,omitempty"` // Status of the AWS Serverless PrivateLink connection: INITIATING, WAITING_FOR_USER, FAILED, DELETING, AVAILABLE. + ProviderName string `json:"providerName,omitempty"` // Human-readable label that identifies the cloud provider. Values include AWS or AZURE. + PrivateEndpointIPAddress string `json:"privateEndpointIpAddress,omitempty"` // IPv4 address of the private endpoint in your Azure VNet that someone added to this private endpoint service. + PrivateLinkServiceResourceID string `json:"privateLinkServiceResourceId,omitempty"` // Root-relative path that identifies the Azure Private Link Service that MongoDB Cloud manages. MongoDB Cloud returns null while it creates the endpoint service. } // List retrieve details for all private Serverless endpoint services in one Atlas project. // // See more: https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#operation/returnAllPrivateEndpointsForOneServerlessInstance -func (s *PrivateServerlessEndpointsServiceOp) ListPrivateServerlessEndpoint(ctx context.Context, groupID, instanceID string, listOptions *ListOptions) ([]PrivateServerlessEndpointConnection, *Response, error) { +func (s *ServerlessPrivateEndpointsServiceOp) List(ctx context.Context, groupID, instanceName string, listOptions *ListOptions) ([]ServerlessPrivateEndpointConnection, *Response, error) { if groupID == "" { return nil, nil, NewArgError("groupID", "must be set") } - if instanceID == "" { + if instanceName == "" { return nil, nil, NewArgError("instanceID", "must be set") } - path := fmt.Sprintf(serverlessPrivateEndpointsPath, groupID, instanceID) // Add query params from listOptions + path := fmt.Sprintf(serverlessPrivateEndpointsPath, groupID, instanceName) // Add query params from listOptions path, err := setListOptions(path, listOptions) if err != nil { return nil, nil, err @@ -76,7 +78,7 @@ func (s *PrivateServerlessEndpointsServiceOp) ListPrivateServerlessEndpoint(ctx return nil, nil, err } - root := new([]PrivateServerlessEndpointConnection) + root := new([]ServerlessPrivateEndpointConnection) resp, err := s.Client.Do(ctx, req, root) if err != nil { return nil, resp, err @@ -85,21 +87,21 @@ func (s *PrivateServerlessEndpointsServiceOp) ListPrivateServerlessEndpoint(ctx return *root, resp, nil } -// DeleteOnePrivateServerlessEndpoint one private serverless endpoint service in an Atlas project. +// Delete one private serverless endpoint service in an Atlas project. // // See more https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#operation/removeOnePrivateEndpointFromOneServerlessInstance -func (s *PrivateServerlessEndpointsServiceOp) DeleteOnePrivateServerlessEndpoint(ctx context.Context, groupID, instanceID, privateEndpointID string) (*Response, error) { +func (s *ServerlessPrivateEndpointsServiceOp) Delete(ctx context.Context, groupID, instanceName, privateEndpointID string) (*Response, error) { if groupID == "" { return nil, NewArgError("groupID", "must be set") } if privateEndpointID == "" { return nil, NewArgError("PrivateEndpointID", "must be set") } - if instanceID == "" { - return nil, NewArgError("instanceID", "must be set") + if instanceName == "" { + return nil, NewArgError("instanceName", "must be set") } - basePath := fmt.Sprintf(serverlessPrivateEndpointsPath, groupID, instanceID) + basePath := fmt.Sprintf(serverlessPrivateEndpointsPath, groupID, instanceName) path := fmt.Sprintf("%s/%s", basePath, url.PathEscape(privateEndpointID)) req, err := s.Client.NewRequest(ctx, http.MethodDelete, path, nil) @@ -110,29 +112,29 @@ func (s *PrivateServerlessEndpointsServiceOp) DeleteOnePrivateServerlessEndpoint return s.Client.Do(ctx, req, nil) } -// AddOnePrivateServerlessEndpoint Adds one serverless private endpoint in an Atlas project. +// Create Adds one serverless private endpoint in an Atlas project. // // See more: https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#operation/createOnePrivateEndpointForOneServerlessInstance -func (s *PrivateServerlessEndpointsServiceOp) AddOnePrivateServerlessEndpoint(ctx context.Context, groupID, instanceID string, createRequest *PrivateServerlessEndpointConnection) (*PrivateServerlessEndpointConnection, *Response, error) { +func (s *ServerlessPrivateEndpointsServiceOp) Create(ctx context.Context, groupID, instanceName string, createRequest *ServerlessPrivateEndpointConnection) (*ServerlessPrivateEndpointConnection, *Response, error) { if groupID == "" { return nil, nil, NewArgError("groupID", "must be set") } - if instanceID == "" { - return nil, nil, NewArgError("instanceID", "must be set") + if instanceName == "" { + return nil, nil, NewArgError("instanceName", "must be set") } if createRequest == nil { return nil, nil, NewArgError("createRequest", "cannot be nil") } - path := fmt.Sprintf(serverlessPrivateEndpointsPath, groupID, instanceID) + path := fmt.Sprintf(serverlessPrivateEndpointsPath, groupID, instanceName) req, err := s.Client.NewRequest(ctx, http.MethodPost, path, createRequest) if err != nil { return nil, nil, err } - root := new(PrivateServerlessEndpointConnection) + root := new(ServerlessPrivateEndpointConnection) resp, err := s.Client.Do(ctx, req, root) if err != nil { return nil, resp, err @@ -141,22 +143,22 @@ func (s *PrivateServerlessEndpointsServiceOp) AddOnePrivateServerlessEndpoint(ct return root, resp, err } -// GetOnePrivateServerlessEndpoint retrieve details for one private serverless endpoint in an Atlas project. +// Get retrieve details for one private serverless endpoint in an Atlas project. // // See more: https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#operation/returnOnePrivateEndpointForOneServerlessInstance -func (s *PrivateServerlessEndpointsServiceOp) GetOnePrivateServerlessEndpoint(ctx context.Context, groupID, instanceID, privateEndpointID string) (*PrivateServerlessEndpointConnection, *Response, error) { +func (s *ServerlessPrivateEndpointsServiceOp) Get(ctx context.Context, groupID, instanceName, privateEndpointID string) (*ServerlessPrivateEndpointConnection, *Response, error) { if groupID == "" { return nil, nil, NewArgError("groupID", "must be set") } - if instanceID == "" { - return nil, nil, NewArgError("instanceID", "must be set") + if instanceName == "" { + return nil, nil, NewArgError("instanceName", "must be set") } if privateEndpointID == "" { return nil, nil, NewArgError("privateEndpointID", "must be set") } - basePath := fmt.Sprintf(serverlessPrivateEndpointsPath, groupID, instanceID) + basePath := fmt.Sprintf(serverlessPrivateEndpointsPath, groupID, instanceName) path := fmt.Sprintf("%s/%s", basePath, url.PathEscape(privateEndpointID)) req, err := s.Client.NewRequest(ctx, http.MethodGet, path, nil) @@ -164,7 +166,7 @@ func (s *PrivateServerlessEndpointsServiceOp) GetOnePrivateServerlessEndpoint(ct return nil, nil, err } - root := new(PrivateServerlessEndpointConnection) + root := new(ServerlessPrivateEndpointConnection) resp, err := s.Client.Do(ctx, req, root) if err != nil { return nil, resp, err @@ -173,28 +175,28 @@ func (s *PrivateServerlessEndpointsServiceOp) GetOnePrivateServerlessEndpoint(ct return root, resp, err } -// UpdateOnePrivateServerlessEndpoint updates the private serverless endpoint setting for one Atlas project. +// Update updates the private serverless endpoint setting for one Atlas project. // // See more: https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#operation/updateOnePrivateEndpointForOneServerlessInstance -func (s *PrivateServerlessEndpointsServiceOp) UpdateOnePrivateServerlessEndpoint(ctx context.Context, groupID, instanceID, privateEndpointID string, updateRequest *PrivateServerlessEndpointConnection) (*PrivateServerlessEndpointConnection, *Response, error) { +func (s *ServerlessPrivateEndpointsServiceOp) Update(ctx context.Context, groupID, instanceName, privateEndpointID string, updateRequest *ServerlessPrivateEndpointConnection) (*ServerlessPrivateEndpointConnection, *Response, error) { if groupID == "" { return nil, nil, NewArgError("groupID", "must be set") } - if instanceID == "" { - return nil, nil, NewArgError("instanceID", "must be set") + if instanceName == "" { + return nil, nil, NewArgError("instanceName", "must be set") } if privateEndpointID == "" { return nil, nil, NewArgError("privateEndpointID", "must be set") } - basePath := fmt.Sprintf(serverlessPrivateEndpointsPath, groupID, instanceID) + basePath := fmt.Sprintf(serverlessPrivateEndpointsPath, groupID, instanceName) path := fmt.Sprintf("%s/%s", basePath, url.PathEscape(privateEndpointID)) req, err := s.Client.NewRequest(ctx, http.MethodPatch, path, updateRequest) if err != nil { return nil, nil, err } - root := new(PrivateServerlessEndpointConnection) + root := new(ServerlessPrivateEndpointConnection) resp, err := s.Client.Do(ctx, req, root) if err != nil { return nil, resp, err diff --git a/mongodbatlas/private_serverless_endpoints_test.go b/mongodbatlas/serverless_private_endpoints_test.go similarity index 74% rename from mongodbatlas/private_serverless_endpoints_test.go rename to mongodbatlas/serverless_private_endpoints_test.go index 88a089821..90cb3c5e9 100644 --- a/mongodbatlas/private_serverless_endpoints_test.go +++ b/mongodbatlas/serverless_private_endpoints_test.go @@ -36,12 +36,12 @@ func TestPrivateEndpoints_GetOnePrivateServerlessEndpoint(t *testing.T) { }`) }) - interfaceEndpoint, _, err := client.PrivateServerlessEndpoints.GetOnePrivateServerlessEndpoint(ctx, groupID, instanceName, endpointID) + interfaceEndpoint, _, err := client.ServerlessPrivateEndpoints.Get(ctx, groupID, instanceName, endpointID) if err != nil { - t.Errorf("PrivateEndpoints.GetOnePrivateServerlessEndpoint returned error: %v", err) + t.Errorf("PrivateEndpoints.Get returned error: %v", err) } - expected := &PrivateServerlessEndpointConnection{ + expected := &ServerlessPrivateEndpointConnection{ Comment: "Test Serverless", ProviderName: "AWS", Status: "AVAILABLE", @@ -49,7 +49,7 @@ func TestPrivateEndpoints_GetOnePrivateServerlessEndpoint(t *testing.T) { } if !reflect.DeepEqual(interfaceEndpoint, expected) { - t.Errorf("PrivateEndpoints.GetOnePrivateServerlessEndpoint\n got=%#v\nwant=%#v", interfaceEndpoint, expected) + t.Errorf("PrivateEndpoints.Get \n got=%#v\nwant=%#v", interfaceEndpoint, expected) } } @@ -68,17 +68,17 @@ func TestPrivateEndpoints_UpdateOnePrivateServerlessEndpoint(t *testing.T) { }`) }) - update := &PrivateServerlessEndpointConnection{ + update := &ServerlessPrivateEndpointConnection{ CloudProviderEndpointID: "vpce1234567", ProviderName: "AWS", } - interfaceEndpoint, _, err := client.PrivateServerlessEndpoints.UpdateOnePrivateServerlessEndpoint(ctx, groupID, instanceName, endpointID, update) + interfaceEndpoint, _, err := client.ServerlessPrivateEndpoints.Update(ctx, groupID, instanceName, endpointID, update) if err != nil { - t.Errorf("PrivateEndpoints.UpdateOnePrivateServerlessEndpoint returned error: %v", err) + t.Errorf("PrivateEndpoints.Update returned error: %v", err) } - expected := &PrivateServerlessEndpointConnection{ + expected := &ServerlessPrivateEndpointConnection{ Comment: "Test Serverless", ProviderName: "AWS", Status: "AVAILABLE", @@ -86,6 +86,6 @@ func TestPrivateEndpoints_UpdateOnePrivateServerlessEndpoint(t *testing.T) { } if !reflect.DeepEqual(interfaceEndpoint, expected) { - t.Errorf("PrivateEndpoints.UpdateOnePrivateServerlessEndpoint\n got=%#v\nwant=%#v", interfaceEndpoint, expected) + t.Errorf("PrivateEndpoints.Update\n got=%#v\nwant=%#v", interfaceEndpoint, expected) } }