Skip to content

Commit 34d12ee

Browse files
CLOUDP-96138: Add serverless to the atlas go client (#236)
1 parent eb731fe commit 34d12ee

File tree

5 files changed

+438
-2
lines changed

5 files changed

+438
-2
lines changed

mongodbatlas/accesslist_api_keys.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func (s *AccessListAPIKeysServiceOp) List(ctx context.Context, orgID, apiKeyID s
9898
return root, resp, nil
9999
}
100100

101-
// Get retrieve information on a single API Key access list entry using the unique identifier for the API Key and desired permitted address.
101+
// Get retrieves information on a single API Key access list entry using the unique identifier for the API Key and desired permitted address.
102102
//
103103
// See more: https://docs.atlas.mongodb.com/reference/api/api-access-list/get-one-api-access-entry/
104104
func (s *AccessListAPIKeysServiceOp) Get(ctx context.Context, orgID, apiKeyID, ipAddress string) (*AccessListAPIKey, *Response, error) {
@@ -128,7 +128,7 @@ func (s *AccessListAPIKeysServiceOp) Get(ctx context.Context, orgID, apiKeyID, i
128128
return root, resp, err
129129
}
130130

131-
// Create one or more new access list entries for the specified API Key.
131+
// Create creates one or more new access list entries for the specified API Key.
132132
//
133133
// See more: https://docs.atlas.mongodb.com/reference/api/api-access-list/create-api-access-entries/
134134
func (s *AccessListAPIKeysServiceOp) Create(ctx context.Context, orgID, apiKeyID string, createRequest []*AccessListAPIKeysReq) (*AccessListAPIKeys, *Response, error) {

mongodbatlas/clusters.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ type Cluster struct {
153153
MongoURIUpdated string `json:"mongoURIUpdated,omitempty"`
154154
MongoURIWithOptions string `json:"mongoURIWithOptions,omitempty"`
155155
Name string `json:"name,omitempty"`
156+
CreateDate string `json:"createDate,omitempty"`
156157
NumShards *int64 `json:"numShards,omitempty"`
157158
Paused *bool `json:"paused,omitempty"`
158159
PitEnabled *bool `json:"pitEnabled,omitempty"`
@@ -164,6 +165,7 @@ type Cluster struct {
164165
SrvAddress string `json:"srvAddress,omitempty"`
165166
StateName string `json:"stateName,omitempty"`
166167
ConnectionStrings *ConnectionStrings `json:"connectionStrings,omitempty"`
168+
Links []*Link `json:"links,omitempty"`
167169
}
168170

169171
// ProcessArgs represents the advanced configuration options for the cluster.

mongodbatlas/mongodbatlas.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ type Client struct {
137137
DefaultMongoDBMajorVersion DefaultMongoDBMajorVersionService
138138
IPInfo IPInfoService
139139
AdvancedClusters AdvancedClustersService
140+
ServerlessInstances ServerlessInstancesService
140141

141142
onRequestCompleted RequestCompletionCallback
142143
}
@@ -167,6 +168,9 @@ type ListOptions struct {
167168

168169
// For paginated result sets, the number of results to include per page.
169170
ItemsPerPage int `url:"itemsPerPage,omitempty"`
171+
172+
// Flag that indicates whether Atlas returns the totalCount parameter in the response body.
173+
IncludeCount bool `url:"includeCount,omitempty"`
170174
}
171175

172176
func (resp *Response) getCurrentPageLink() (*Link, error) {
@@ -270,6 +274,7 @@ func NewClient(httpClient *http.Client) *Client {
270274
c.DefaultMongoDBMajorVersion = &DefaultMongoDBMajorVersionServiceOp{Client: c}
271275
c.IPInfo = &IPInfoServiceOp{Client: c}
272276
c.AdvancedClusters = &AdvancedClustersServiceOp{Client: c}
277+
c.ServerlessInstances = &ServerlessInstancesServiceOp{Client: c}
273278

274279
return c
275280
}
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
// Copyright 2021 MongoDB Inc
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package mongodbatlas
16+
17+
import (
18+
"context"
19+
"fmt"
20+
"net/http"
21+
)
22+
23+
const serverlessInstancesPath = "api/atlas/v1.0/groups/%s/serverless"
24+
25+
// ServerlessInstancesService is an interface for interfacing with the Serverless Instances endpoints of the MongoDB Atlas API.
26+
//
27+
// See more: https://docs.atlas.mongodb.com/reference/api/serverless/return-one-serverless-instance/
28+
type ServerlessInstancesService interface {
29+
List(context.Context, string, *ListOptions) (*ClustersResponse, *Response, error)
30+
Get(context.Context, string, string) (*Cluster, *Response, error)
31+
Create(context.Context, string, *ServerlessCreateRequestParams) (*Cluster, *Response, error)
32+
Delete(context.Context, string, string) (*Response, error)
33+
}
34+
35+
// ServerlessInstancesServiceOp handles communication with the Serverless Instances related methods of the MongoDB Atlas API.
36+
type ServerlessInstancesServiceOp service
37+
38+
var _ ServerlessInstancesService = &ServerlessInstancesServiceOp{}
39+
40+
// ClustersResponse represents the response of ServerlessInstancesService.List.
41+
type ClustersResponse struct {
42+
Links []*Link `json:"links,omitempty"`
43+
Results []*Cluster `json:"results,omitempty"`
44+
TotalCount int `json:"totalCount,omitempty"`
45+
}
46+
47+
// ServerlessCreateRequestParams represents the Request Body Parameters of ServerlessInstancesService.Create.
48+
type ServerlessCreateRequestParams struct {
49+
Name string `json:"name,omitempty"`
50+
ProviderSettings *ServerlessProviderSettings `json:"providerSettings,omitempty"`
51+
}
52+
53+
// ServerlessProviderSettings represents the Provider Settings of serverless instances.
54+
type ServerlessProviderSettings struct {
55+
BackingProviderName string `json:"backingProviderName,omitempty"`
56+
ProviderName string `json:"providerName,omitempty"`
57+
RegionName string `json:"regionName,omitempty"`
58+
}
59+
60+
// List gets all serverless instances in the specified project.
61+
//
62+
// See more: https://docs.atlas.mongodb.com/reference/api/serverless/return-all-serverless-instances/
63+
func (s *ServerlessInstancesServiceOp) List(ctx context.Context, projectID string, listOptions *ListOptions) (*ClustersResponse, *Response, error) {
64+
if projectID == "" {
65+
return nil, nil, NewArgError("projectID", "must be set")
66+
}
67+
68+
path := fmt.Sprintf(serverlessInstancesPath, projectID)
69+
path, err := setListOptions(path, listOptions)
70+
if err != nil {
71+
return nil, nil, err
72+
}
73+
74+
req, err := s.Client.NewRequest(ctx, http.MethodGet, path, nil)
75+
if err != nil {
76+
return nil, nil, err
77+
}
78+
79+
root := new(ClustersResponse)
80+
resp, err := s.Client.Do(ctx, req, root)
81+
if err != nil {
82+
return nil, resp, err
83+
}
84+
85+
return root, resp, nil
86+
}
87+
88+
// Get retrieves one serverless instance in the specified project.
89+
//
90+
// See more: https://docs.atlas.mongodb.com/reference/api/serverless/return-one-serverless-instance/
91+
func (s *ServerlessInstancesServiceOp) Get(ctx context.Context, projectID, instanceName string) (*Cluster, *Response, error) {
92+
if projectID == "" {
93+
return nil, nil, NewArgError("projectID", "must be set")
94+
}
95+
96+
if instanceName == "" {
97+
return nil, nil, NewArgError("instanceName", "must be set")
98+
}
99+
100+
basePath := fmt.Sprintf(serverlessInstancesPath, projectID)
101+
path := fmt.Sprintf("%s/%s", basePath, instanceName)
102+
103+
req, err := s.Client.NewRequest(ctx, http.MethodGet, path, nil)
104+
if err != nil {
105+
return nil, nil, err
106+
}
107+
108+
root := new(Cluster)
109+
resp, err := s.Client.Do(ctx, req, root)
110+
if err != nil {
111+
return nil, resp, err
112+
}
113+
114+
return root, resp, err
115+
}
116+
117+
// Create creates one serverless instance in the specified project.
118+
//
119+
// See more: https://docs.atlas.mongodb.com/reference/api/serverless/create-one-serverless-instance/
120+
func (s *ServerlessInstancesServiceOp) Create(ctx context.Context, projectID string, bodyParams *ServerlessCreateRequestParams) (*Cluster, *Response, error) {
121+
if projectID == "" {
122+
return nil, nil, NewArgError("projectID", "must be set")
123+
}
124+
125+
path := fmt.Sprintf(serverlessInstancesPath, projectID)
126+
127+
req, err := s.Client.NewRequest(ctx, http.MethodPost, path, bodyParams)
128+
if err != nil {
129+
return nil, nil, err
130+
}
131+
132+
root := new(Cluster)
133+
resp, err := s.Client.Do(ctx, req, root)
134+
if err != nil {
135+
return nil, resp, err
136+
}
137+
138+
return root, resp, err
139+
}
140+
141+
// Delete deletes one serverless instance in the specified project.
142+
//
143+
// See more: https://docs.atlas.mongodb.com/reference/api/serverless/remove-one-serverless-instance/
144+
func (s *ServerlessInstancesServiceOp) Delete(ctx context.Context, projectID, instanceName string) (*Response, error) {
145+
if projectID == "" {
146+
return nil, NewArgError("projectID", "must be set")
147+
}
148+
if instanceName == "" {
149+
return nil, NewArgError("instanceName", "must be set")
150+
}
151+
152+
basePath := fmt.Sprintf(serverlessInstancesPath, projectID)
153+
path := fmt.Sprintf("%s/%s", basePath, instanceName)
154+
155+
req, err := s.Client.NewRequest(ctx, http.MethodDelete, path, nil)
156+
if err != nil {
157+
return nil, err
158+
}
159+
resp, err := s.Client.Do(ctx, req, nil)
160+
161+
return resp, err
162+
}

0 commit comments

Comments
 (0)