Skip to content

Commit 6e95d88

Browse files
authored
feat(rdb): add project_id to resources (#571)
1 parent ed5be7b commit 6e95d88

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

api/rdb/v1/rdb_sdk.go

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,8 @@ type Instance struct {
821821
Name string `json:"name"`
822822
// OrganizationID: organization ID the instance belongs to
823823
OrganizationID string `json:"organization_id"`
824+
// ProjectID: project ID the instance belongs to
825+
ProjectID string `json:"project_id"`
824826
// Status: status of the instance
825827
//
826828
// Default value: unknown
@@ -917,9 +919,9 @@ type ListInstanceLogsResponse struct {
917919

918920
// ListInstancesResponse: list instances response
919921
type ListInstancesResponse struct {
920-
// Instances: list all instances available in a given organization
922+
// Instances: list all instances available in a given organization/project
921923
Instances []*Instance `json:"instances"`
922-
// TotalCount: total count of instances available in a given organization
924+
// TotalCount: total count of instances available in a given organization/project
923925
TotalCount uint32 `json:"total_count"`
924926
}
925927

@@ -1069,6 +1071,8 @@ type ListDatabaseBackupsRequest struct {
10691071
InstanceID *string `json:"-"`
10701072
// OrganizationID: organization ID the database backups belongs to
10711073
OrganizationID *string `json:"-"`
1074+
// ProjectID: project ID the database backups belongs to
1075+
ProjectID *string `json:"-"`
10721076

10731077
Page *int32 `json:"-"`
10741078

@@ -1094,6 +1098,7 @@ func (s *API) ListDatabaseBackups(req *ListDatabaseBackupsRequest, opts ...scw.R
10941098
parameter.AddToQuery(query, "order_by", req.OrderBy)
10951099
parameter.AddToQuery(query, "instance_id", req.InstanceID)
10961100
parameter.AddToQuery(query, "organization_id", req.OrganizationID)
1101+
parameter.AddToQuery(query, "project_id", req.ProjectID)
10971102
parameter.AddToQuery(query, "page", req.Page)
10981103
parameter.AddToQuery(query, "page_size", req.PageSize)
10991104

@@ -1571,8 +1576,10 @@ type ListInstancesRequest struct {
15711576
//
15721577
// Default value: created_at_asc
15731578
OrderBy ListInstancesRequestOrderBy `json:"-"`
1574-
// OrganizationID: organization ID to list the instance of
1579+
// OrganizationID: please use `project_id` instead
15751580
OrganizationID *string `json:"-"`
1581+
// ProjectID: project ID to list the instance of
1582+
ProjectID *string `json:"-"`
15761583

15771584
Page *int32 `json:"-"`
15781585

@@ -1598,6 +1605,7 @@ func (s *API) ListInstances(req *ListInstancesRequest, opts ...scw.RequestOption
15981605
parameter.AddToQuery(query, "name", req.Name)
15991606
parameter.AddToQuery(query, "order_by", req.OrderBy)
16001607
parameter.AddToQuery(query, "organization_id", req.OrganizationID)
1608+
parameter.AddToQuery(query, "project_id", req.ProjectID)
16011609
parameter.AddToQuery(query, "page", req.Page)
16021610
parameter.AddToQuery(query, "page_size", req.PageSize)
16031611

@@ -1680,8 +1688,12 @@ func (s *API) GetInstance(req *GetInstanceRequest, opts ...scw.RequestOption) (*
16801688

16811689
type CreateInstanceRequest struct {
16821690
Region scw.Region `json:"-"`
1683-
// OrganizationID: the organization ID on which to create the instance
1684-
OrganizationID string `json:"organization_id"`
1691+
// Deprecated: OrganizationID: please use `project_id` instead
1692+
// Precisely one of OrganizationID, ProjectID must be set.
1693+
OrganizationID *string `json:"organization_id,omitempty"`
1694+
// ProjectID: the project ID on which to create the instance
1695+
// Precisely one of OrganizationID, ProjectID must be set.
1696+
ProjectID *string `json:"project_id,omitempty"`
16851697
// Name: name of the instance
16861698
Name string `json:"name"`
16871699
// Engine: database engine of the database (PostgreSQL, MySQL, ...)
@@ -1706,9 +1718,14 @@ type CreateInstanceRequest struct {
17061718
func (s *API) CreateInstance(req *CreateInstanceRequest, opts ...scw.RequestOption) (*Instance, error) {
17071719
var err error
17081720

1709-
if req.OrganizationID == "" {
1710-
defaultOrganizationID, _ := s.client.GetDefaultOrganizationID()
1711-
req.OrganizationID = defaultOrganizationID
1721+
defaultProjectID, exist := s.client.GetDefaultProjectID()
1722+
if exist && req.OrganizationID == nil && req.ProjectID == nil {
1723+
req.ProjectID = &defaultProjectID
1724+
}
1725+
1726+
defaultOrganizationID, exist := s.client.GetDefaultOrganizationID()
1727+
if exist && req.OrganizationID == nil && req.ProjectID == nil {
1728+
req.OrganizationID = &defaultOrganizationID
17121729
}
17131730

17141731
if req.Region == "" {

0 commit comments

Comments
 (0)