Skip to content

Commit 9b6e07d

Browse files
authored
feat(account/v3): project api (#1782)
1 parent d13e89c commit 9b6e07d

File tree

1 file changed

+340
-0
lines changed

1 file changed

+340
-0
lines changed

api/account/v3/account_sdk.go

Lines changed: 340 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,340 @@
1+
// This file was automatically generated. DO NOT EDIT.
2+
// If you have any remark or suggestion do not hesitate to open an issue.
3+
4+
// Package account provides methods and message types of the account v3 API.
5+
package account
6+
7+
import (
8+
"bytes"
9+
"encoding/json"
10+
"fmt"
11+
"net"
12+
"net/http"
13+
"net/url"
14+
"strings"
15+
"time"
16+
17+
"github.com/scaleway/scaleway-sdk-go/internal/errors"
18+
"github.com/scaleway/scaleway-sdk-go/internal/marshaler"
19+
"github.com/scaleway/scaleway-sdk-go/internal/parameter"
20+
"github.com/scaleway/scaleway-sdk-go/namegenerator"
21+
"github.com/scaleway/scaleway-sdk-go/scw"
22+
)
23+
24+
// always import dependencies
25+
var (
26+
_ fmt.Stringer
27+
_ json.Unmarshaler
28+
_ url.URL
29+
_ net.IP
30+
_ http.Header
31+
_ bytes.Reader
32+
_ time.Time
33+
_ = strings.Join
34+
35+
_ scw.ScalewayRequest
36+
_ marshaler.Duration
37+
_ scw.File
38+
_ = parameter.AddToQuery
39+
_ = namegenerator.GetRandomName
40+
)
41+
42+
// ProjectAPI: this API allows you to manage projects.
43+
type ProjectAPI struct {
44+
client *scw.Client
45+
}
46+
47+
// NewProjectAPI returns a ProjectAPI object from a Scaleway client.
48+
func NewProjectAPI(client *scw.Client) *ProjectAPI {
49+
return &ProjectAPI{
50+
client: client,
51+
}
52+
}
53+
54+
type ListProjectsRequestOrderBy string
55+
56+
const (
57+
// Creation date ascending
58+
ListProjectsRequestOrderByCreatedAtAsc = ListProjectsRequestOrderBy("created_at_asc")
59+
// Creation date descending
60+
ListProjectsRequestOrderByCreatedAtDesc = ListProjectsRequestOrderBy("created_at_desc")
61+
// Name ascending
62+
ListProjectsRequestOrderByNameAsc = ListProjectsRequestOrderBy("name_asc")
63+
// Name descending
64+
ListProjectsRequestOrderByNameDesc = ListProjectsRequestOrderBy("name_desc")
65+
)
66+
67+
func (enum ListProjectsRequestOrderBy) String() string {
68+
if enum == "" {
69+
// return default value if empty
70+
return "created_at_asc"
71+
}
72+
return string(enum)
73+
}
74+
75+
func (enum ListProjectsRequestOrderBy) MarshalJSON() ([]byte, error) {
76+
return []byte(fmt.Sprintf(`"%s"`, enum)), nil
77+
}
78+
79+
func (enum *ListProjectsRequestOrderBy) UnmarshalJSON(data []byte) error {
80+
tmp := ""
81+
82+
if err := json.Unmarshal(data, &tmp); err != nil {
83+
return err
84+
}
85+
86+
*enum = ListProjectsRequestOrderBy(ListProjectsRequestOrderBy(tmp).String())
87+
return nil
88+
}
89+
90+
// ListProjectsResponse: list projects response.
91+
type ListProjectsResponse struct {
92+
// TotalCount: total number of Projects.
93+
TotalCount uint64 `json:"total_count"`
94+
// Projects: paginated returned Projects.
95+
Projects []*Project `json:"projects"`
96+
}
97+
98+
// Project: project.
99+
type Project struct {
100+
// ID: ID of the Project.
101+
ID string `json:"id"`
102+
// Name: name of the Project.
103+
Name string `json:"name"`
104+
// OrganizationID: organization ID of the Project.
105+
OrganizationID string `json:"organization_id"`
106+
// CreatedAt: creation date of the Project.
107+
CreatedAt *time.Time `json:"created_at"`
108+
// UpdatedAt: update date of the Project.
109+
UpdatedAt *time.Time `json:"updated_at"`
110+
// Description: description of the Project.
111+
Description string `json:"description"`
112+
}
113+
114+
// Service ProjectAPI
115+
116+
type ProjectAPICreateProjectRequest struct {
117+
// Name: name of the Project.
118+
Name string `json:"name"`
119+
// OrganizationID: organization ID of the Project.
120+
OrganizationID string `json:"organization_id"`
121+
// Description: description of the Project.
122+
Description string `json:"description"`
123+
}
124+
125+
// CreateProject: create a new Project for an Organization.
126+
// Generate a new Project for an Organization, specifying its configuration including name and description.
127+
func (s *ProjectAPI) CreateProject(req *ProjectAPICreateProjectRequest, opts ...scw.RequestOption) (*Project, error) {
128+
var err error
129+
130+
if req.OrganizationID == "" {
131+
defaultOrganizationID, _ := s.client.GetDefaultOrganizationID()
132+
req.OrganizationID = defaultOrganizationID
133+
}
134+
135+
if req.Name == "" {
136+
req.Name = namegenerator.GetRandomName("proj")
137+
}
138+
139+
scwReq := &scw.ScalewayRequest{
140+
Method: "POST",
141+
Path: "/account/v3/projects",
142+
Headers: http.Header{},
143+
}
144+
145+
err = scwReq.SetBody(req)
146+
if err != nil {
147+
return nil, err
148+
}
149+
150+
var resp Project
151+
152+
err = s.client.Do(scwReq, &resp, opts...)
153+
if err != nil {
154+
return nil, err
155+
}
156+
return &resp, nil
157+
}
158+
159+
type ProjectAPIListProjectsRequest struct {
160+
// OrganizationID: organization ID of the Project.
161+
OrganizationID string `json:"-"`
162+
// Name: name of the Project.
163+
Name *string `json:"-"`
164+
// Page: page number for the returned Projects.
165+
Page *int32 `json:"-"`
166+
// PageSize: maximum number of Project per page.
167+
PageSize *uint32 `json:"-"`
168+
// OrderBy: sort order of the returned Projects.
169+
// Default value: created_at_asc
170+
OrderBy ListProjectsRequestOrderBy `json:"-"`
171+
// ProjectIDs: project IDs to filter for. The results will be limited to any Projects with an ID in this array.
172+
ProjectIDs []string `json:"-"`
173+
}
174+
175+
// ListProjects: list all Projects of an Organization.
176+
// List all Projects of an Organization. The response will include the total number of Projects as well as their associated Organizations, names, and IDs. Other information includes the creation and update date of the Project.
177+
func (s *ProjectAPI) ListProjects(req *ProjectAPIListProjectsRequest, opts ...scw.RequestOption) (*ListProjectsResponse, error) {
178+
var err error
179+
180+
if req.OrganizationID == "" {
181+
defaultOrganizationID, _ := s.client.GetDefaultOrganizationID()
182+
req.OrganizationID = defaultOrganizationID
183+
}
184+
185+
defaultPageSize, exist := s.client.GetDefaultPageSize()
186+
if (req.PageSize == nil || *req.PageSize == 0) && exist {
187+
req.PageSize = &defaultPageSize
188+
}
189+
190+
query := url.Values{}
191+
parameter.AddToQuery(query, "organization_id", req.OrganizationID)
192+
parameter.AddToQuery(query, "name", req.Name)
193+
parameter.AddToQuery(query, "page", req.Page)
194+
parameter.AddToQuery(query, "page_size", req.PageSize)
195+
parameter.AddToQuery(query, "order_by", req.OrderBy)
196+
parameter.AddToQuery(query, "project_ids", req.ProjectIDs)
197+
198+
scwReq := &scw.ScalewayRequest{
199+
Method: "GET",
200+
Path: "/account/v3/projects",
201+
Query: query,
202+
Headers: http.Header{},
203+
}
204+
205+
var resp ListProjectsResponse
206+
207+
err = s.client.Do(scwReq, &resp, opts...)
208+
if err != nil {
209+
return nil, err
210+
}
211+
return &resp, nil
212+
}
213+
214+
type ProjectAPIGetProjectRequest struct {
215+
// ProjectID: project ID of the Project.
216+
ProjectID string `json:"-"`
217+
}
218+
219+
// GetProject: get an existing Project.
220+
// Retrieve information about an existing Project, specified by its Project ID. Its full details, including ID, name and description, are returned in the response object.
221+
func (s *ProjectAPI) GetProject(req *ProjectAPIGetProjectRequest, opts ...scw.RequestOption) (*Project, error) {
222+
var err error
223+
224+
if req.ProjectID == "" {
225+
defaultProjectID, _ := s.client.GetDefaultProjectID()
226+
req.ProjectID = defaultProjectID
227+
}
228+
229+
if fmt.Sprint(req.ProjectID) == "" {
230+
return nil, errors.New("field ProjectID cannot be empty in request")
231+
}
232+
233+
scwReq := &scw.ScalewayRequest{
234+
Method: "GET",
235+
Path: "/account/v3/projects/" + fmt.Sprint(req.ProjectID) + "",
236+
Headers: http.Header{},
237+
}
238+
239+
var resp Project
240+
241+
err = s.client.Do(scwReq, &resp, opts...)
242+
if err != nil {
243+
return nil, err
244+
}
245+
return &resp, nil
246+
}
247+
248+
type ProjectAPIDeleteProjectRequest struct {
249+
// ProjectID: project ID of the Project.
250+
ProjectID string `json:"-"`
251+
}
252+
253+
// DeleteProject: delete an existing Project.
254+
// Delete an existing Project, specified by its Project ID. The Project needs to be empty (meaning there are no resources left in it) to be deleted effectively. Note that deleting a Project is permanent, and cannot be undone.
255+
func (s *ProjectAPI) DeleteProject(req *ProjectAPIDeleteProjectRequest, opts ...scw.RequestOption) error {
256+
var err error
257+
258+
if req.ProjectID == "" {
259+
defaultProjectID, _ := s.client.GetDefaultProjectID()
260+
req.ProjectID = defaultProjectID
261+
}
262+
263+
if fmt.Sprint(req.ProjectID) == "" {
264+
return errors.New("field ProjectID cannot be empty in request")
265+
}
266+
267+
scwReq := &scw.ScalewayRequest{
268+
Method: "DELETE",
269+
Path: "/account/v3/projects/" + fmt.Sprint(req.ProjectID) + "",
270+
Headers: http.Header{},
271+
}
272+
273+
err = s.client.Do(scwReq, nil, opts...)
274+
if err != nil {
275+
return err
276+
}
277+
return nil
278+
}
279+
280+
type ProjectAPIUpdateProjectRequest struct {
281+
// ProjectID: project ID of the Project.
282+
ProjectID string `json:"-"`
283+
// Name: name of the Project.
284+
Name *string `json:"name"`
285+
// Description: description of the Project.
286+
Description *string `json:"description"`
287+
}
288+
289+
// UpdateProject: update Project.
290+
// Update the parameters of an existing Project, specified by its Project ID. These parameters include the name and description.
291+
func (s *ProjectAPI) UpdateProject(req *ProjectAPIUpdateProjectRequest, opts ...scw.RequestOption) (*Project, error) {
292+
var err error
293+
294+
if req.ProjectID == "" {
295+
defaultProjectID, _ := s.client.GetDefaultProjectID()
296+
req.ProjectID = defaultProjectID
297+
}
298+
299+
if fmt.Sprint(req.ProjectID) == "" {
300+
return nil, errors.New("field ProjectID cannot be empty in request")
301+
}
302+
303+
scwReq := &scw.ScalewayRequest{
304+
Method: "PATCH",
305+
Path: "/account/v3/projects/" + fmt.Sprint(req.ProjectID) + "",
306+
Headers: http.Header{},
307+
}
308+
309+
err = scwReq.SetBody(req)
310+
if err != nil {
311+
return nil, err
312+
}
313+
314+
var resp Project
315+
316+
err = s.client.Do(scwReq, &resp, opts...)
317+
if err != nil {
318+
return nil, err
319+
}
320+
return &resp, nil
321+
}
322+
323+
// UnsafeGetTotalCount should not be used
324+
// Internal usage only
325+
func (r *ListProjectsResponse) UnsafeGetTotalCount() uint64 {
326+
return r.TotalCount
327+
}
328+
329+
// UnsafeAppend should not be used
330+
// Internal usage only
331+
func (r *ListProjectsResponse) UnsafeAppend(res interface{}) (uint64, error) {
332+
results, ok := res.(*ListProjectsResponse)
333+
if !ok {
334+
return 0, errors.New("%T type cannot be appended to type %T", res, r)
335+
}
336+
337+
r.Projects = append(r.Projects, results.Projects...)
338+
r.TotalCount += uint64(len(results.Projects))
339+
return uint64(len(results.Projects)), nil
340+
}

0 commit comments

Comments
 (0)