From a6219133ec91ba55fc556658c971b10698fc422d Mon Sep 17 00:00:00 2001 From: DCL Team Date: Wed, 14 Sep 2022 12:48:46 -0700 Subject: [PATCH] Automated DCL import. - f0da38f869555597d32d9988379cdd83f14c863d Automatic import from cloud_mmv2_dcl_20220914_1231_RC00 by DCL Team GitOrigin-RevId: f0da38f869555597d32d9988379cdd83f14c863d --- .../cloudresourcemanager/alpha/project.proto | 1 + .../cloudresourcemanager/beta/project.proto | 1 + .../proto/cloudresourcemanager/project.proto | 1 + .../cloudresourcemanager/alpha/project.py | 4 ++- .../alpha/project_server.go | 2 +- .../cloudresourcemanager/beta/project.py | 4 ++- .../beta/project_server.go | 2 +- .../services/cloudresourcemanager/project.py | 4 ++- .../cloudresourcemanager/project_server.go | 2 +- .../cloudresourcemanager/alpha/project.go | 14 +++++---- .../cloudresourcemanager/alpha/project.yaml | 13 ++++++-- .../alpha/project_alpha_yaml_embed.go | 6 ++-- .../alpha/project_internal.go | 16 ++++------ .../alpha/project_schema.go | 27 ++++++++++++++--- .../alpha/resourcemanager_utils.go | 28 +++++++++++++---- .../cloudresourcemanager/beta/project.go | 14 +++++---- .../cloudresourcemanager/beta/project.yaml | 13 ++++++-- .../beta/project_beta_yaml_embed.go | 6 ++-- .../beta/project_internal.go | 16 ++++------ .../beta/project_schema.go | 27 ++++++++++++++--- .../beta/resourcemanager_utils.go | 28 +++++++++++++---- .../google/cloudresourcemanager/project.go | 14 +++++---- .../google/cloudresourcemanager/project.yaml | 13 ++++++-- .../cloudresourcemanager/project_internal.go | 16 ++++------ .../cloudresourcemanager/project_schema.go | 27 ++++++++++++++--- .../project_yaml_embed.go | 6 ++-- .../resourcemanager_utils.go | 28 +++++++++++++---- .../samples/folder.project.json | 4 +++ .../samples/folder_project.yaml | 30 +++++++++++++++++++ .../cloudresourcemanager/alpha/project.go | 4 +-- .../cloudresourcemanager/beta/project.go | 4 +-- .../google/cloudresourcemanager/project.go | 4 +-- 32 files changed, 274 insertions(+), 105 deletions(-) create mode 100755 services/google/cloudresourcemanager/samples/folder.project.json create mode 100755 services/google/cloudresourcemanager/samples/folder_project.yaml diff --git a/python/proto/cloudresourcemanager/alpha/project.proto b/python/proto/cloudresourcemanager/alpha/project.proto index 3029d326c..6a560b8d3 100755 --- a/python/proto/cloudresourcemanager/alpha/project.proto +++ b/python/proto/cloudresourcemanager/alpha/project.proto @@ -51,6 +51,7 @@ message DeleteCloudresourcemanagerAlphaProjectRequest { message ListCloudresourcemanagerAlphaProjectRequest { string service_account_file = 1; + string Parent = 2; } message ListCloudresourcemanagerAlphaProjectResponse { diff --git a/python/proto/cloudresourcemanager/beta/project.proto b/python/proto/cloudresourcemanager/beta/project.proto index bbefcf3cc..b3e2b1234 100755 --- a/python/proto/cloudresourcemanager/beta/project.proto +++ b/python/proto/cloudresourcemanager/beta/project.proto @@ -51,6 +51,7 @@ message DeleteCloudresourcemanagerBetaProjectRequest { message ListCloudresourcemanagerBetaProjectRequest { string service_account_file = 1; + string Parent = 2; } message ListCloudresourcemanagerBetaProjectResponse { diff --git a/python/proto/cloudresourcemanager/project.proto b/python/proto/cloudresourcemanager/project.proto index 941edf6a4..8fb49660f 100755 --- a/python/proto/cloudresourcemanager/project.proto +++ b/python/proto/cloudresourcemanager/project.proto @@ -51,6 +51,7 @@ message DeleteCloudresourcemanagerProjectRequest { message ListCloudresourcemanagerProjectRequest { string service_account_file = 1; + string Parent = 2; } message ListCloudresourcemanagerProjectResponse { diff --git a/python/services/cloudresourcemanager/alpha/project.py b/python/services/cloudresourcemanager/alpha/project.py index 18f49c2c9..73a31cf30 100755 --- a/python/services/cloudresourcemanager/alpha/project.py +++ b/python/services/cloudresourcemanager/alpha/project.py @@ -91,12 +91,14 @@ def delete(self): response = stub.DeleteCloudresourcemanagerAlphaProject(request) @classmethod - def list(self, service_account_file=""): + def list(self, parent, service_account_file=""): stub = project_pb2_grpc.CloudresourcemanagerAlphaProjectServiceStub( channel.Channel() ) request = project_pb2.ListCloudresourcemanagerAlphaProjectRequest() request.service_account_file = service_account_file + request.Parent = parent + return stub.ListCloudresourcemanagerAlphaProject(request).items def to_proto(self): diff --git a/python/services/cloudresourcemanager/alpha/project_server.go b/python/services/cloudresourcemanager/alpha/project_server.go index a5f8a5e49..715f9b57e 100755 --- a/python/services/cloudresourcemanager/alpha/project_server.go +++ b/python/services/cloudresourcemanager/alpha/project_server.go @@ -114,7 +114,7 @@ func (s *ProjectServer) ListCloudresourcemanagerAlphaProject(ctx context.Context return nil, err } - resources, err := cl.ListProject(ctx) + resources, err := cl.ListProject(ctx, request.GetParent()) if err != nil { return nil, err } diff --git a/python/services/cloudresourcemanager/beta/project.py b/python/services/cloudresourcemanager/beta/project.py index 22858d862..6f5cc9ca1 100755 --- a/python/services/cloudresourcemanager/beta/project.py +++ b/python/services/cloudresourcemanager/beta/project.py @@ -91,12 +91,14 @@ def delete(self): response = stub.DeleteCloudresourcemanagerBetaProject(request) @classmethod - def list(self, service_account_file=""): + def list(self, parent, service_account_file=""): stub = project_pb2_grpc.CloudresourcemanagerBetaProjectServiceStub( channel.Channel() ) request = project_pb2.ListCloudresourcemanagerBetaProjectRequest() request.service_account_file = service_account_file + request.Parent = parent + return stub.ListCloudresourcemanagerBetaProject(request).items def to_proto(self): diff --git a/python/services/cloudresourcemanager/beta/project_server.go b/python/services/cloudresourcemanager/beta/project_server.go index 4f33685c1..66ed910ce 100755 --- a/python/services/cloudresourcemanager/beta/project_server.go +++ b/python/services/cloudresourcemanager/beta/project_server.go @@ -114,7 +114,7 @@ func (s *ProjectServer) ListCloudresourcemanagerBetaProject(ctx context.Context, return nil, err } - resources, err := cl.ListProject(ctx) + resources, err := cl.ListProject(ctx, request.GetParent()) if err != nil { return nil, err } diff --git a/python/services/cloudresourcemanager/project.py b/python/services/cloudresourcemanager/project.py index 41a65e09a..6db633744 100755 --- a/python/services/cloudresourcemanager/project.py +++ b/python/services/cloudresourcemanager/project.py @@ -91,12 +91,14 @@ def delete(self): response = stub.DeleteCloudresourcemanagerProject(request) @classmethod - def list(self, service_account_file=""): + def list(self, parent, service_account_file=""): stub = project_pb2_grpc.CloudresourcemanagerProjectServiceStub( channel.Channel() ) request = project_pb2.ListCloudresourcemanagerProjectRequest() request.service_account_file = service_account_file + request.Parent = parent + return stub.ListCloudresourcemanagerProject(request).items def to_proto(self): diff --git a/python/services/cloudresourcemanager/project_server.go b/python/services/cloudresourcemanager/project_server.go index 51d85c916..0cfe2af8c 100755 --- a/python/services/cloudresourcemanager/project_server.go +++ b/python/services/cloudresourcemanager/project_server.go @@ -114,7 +114,7 @@ func (s *ProjectServer) ListCloudresourcemanagerProject(ctx context.Context, req return nil, err } - resources, err := cl.ListProject(ctx) + resources, err := cl.ListProject(ctx, request.GetParent()) if err != nil { return nil, err } diff --git a/services/google/cloudresourcemanager/alpha/project.go b/services/google/cloudresourcemanager/alpha/project.go index 03f9fd6a4..f54e2dd99 100755 --- a/services/google/cloudresourcemanager/alpha/project.go +++ b/services/google/cloudresourcemanager/alpha/project.go @@ -121,21 +121,23 @@ func (l *ProjectList) Next(ctx context.Context, c *Client) error { return err } -func (c *Client) ListProject(ctx context.Context) (*ProjectList, error) { +func (c *Client) ListProject(ctx context.Context, parent string) (*ProjectList, error) { ctx = dcl.ContextWithRequestID(ctx) ctx, cancel := context.WithTimeout(ctx, c.Config.TimeoutOr(0*time.Second)) defer cancel() - return c.ListProjectWithMaxResults(ctx, ProjectMaxPage) + return c.ListProjectWithMaxResults(ctx, parent, ProjectMaxPage) } -func (c *Client) ListProjectWithMaxResults(ctx context.Context, pageSize int32) (*ProjectList, error) { +func (c *Client) ListProjectWithMaxResults(ctx context.Context, parent string, pageSize int32) (*ProjectList, error) { ctx, cancel := context.WithTimeout(ctx, c.Config.TimeoutOr(0*time.Second)) defer cancel() // Create a resource object so that we can use proper url normalization methods. - r := &Project{} + r := &Project{ + Parent: &parent, + } items, token, err := c.listProject(ctx, r, "", pageSize) if err != nil { return nil, err @@ -202,8 +204,8 @@ func (c *Client) DeleteProject(ctx context.Context, r *Project) error { } // DeleteAllProject deletes all resources that the filter functions returns true on. -func (c *Client) DeleteAllProject(ctx context.Context, filter func(*Project) bool) error { - listObj, err := c.ListProject(ctx) +func (c *Client) DeleteAllProject(ctx context.Context, parent string, filter func(*Project) bool) error { + listObj, err := c.ListProject(ctx, parent) if err != nil { return err } diff --git a/services/google/cloudresourcemanager/alpha/project.yaml b/services/google/cloudresourcemanager/alpha/project.yaml index a591d461e..6ac4158d3 100755 --- a/services/google/cloudresourcemanager/alpha/project.yaml +++ b/services/google/cloudresourcemanager/alpha/project.yaml @@ -37,10 +37,18 @@ paths: description: A full instance of a Project deleteAll: description: The function used to delete all Project - parameters: [] + parameters: + - name: parent + required: true + schema: + type: string list: description: The function used to list information about many Project - parameters: [] + parameters: + - name: parent + required: true + schema: + type: string components: schemas: Project: @@ -98,6 +106,7 @@ components: the `UpdateProject` method; the end user must have the `resourcemanager.projects.create` permission on the parent. Read-write. ' x-kubernetes-immutable: true + x-dcl-forward-slash-allowed: true projectNumber: type: integer format: int64 diff --git a/services/google/cloudresourcemanager/alpha/project_alpha_yaml_embed.go b/services/google/cloudresourcemanager/alpha/project_alpha_yaml_embed.go index 05a19d052..4935024d8 100755 --- a/services/google/cloudresourcemanager/alpha/project_alpha_yaml_embed.go +++ b/services/google/cloudresourcemanager/alpha/project_alpha_yaml_embed.go @@ -17,7 +17,7 @@ package alpha // blaze-out/k8-fastbuild/genfiles/cloud/graphite/mmv2/services/google/cloudresourcemanager/alpha/project.yaml -var YAML_project = []byte("info:\n title: CloudResourceManager/Project\n description: The CloudResourceManager Project resource\n x-dcl-struct-name: Project\n x-dcl-has-iam: true\npaths:\n get:\n description: The function used to get information about a Project\n parameters:\n - name: project\n required: true\n description: A full instance of a Project\n apply:\n description: The function used to apply information about a Project\n parameters:\n - name: project\n required: true\n description: A full instance of a Project\n delete:\n description: The function used to delete a Project\n parameters:\n - name: project\n required: true\n description: A full instance of a Project\n deleteAll:\n description: The function used to delete all Project\n parameters: []\n list:\n description: The function used to list information about many Project\n parameters: []\ncomponents:\n schemas:\n Project:\n title: Project\n x-dcl-id: projects/{{name}}\n x-dcl-labels: labels\n x-dcl-has-create: true\n x-dcl-has-iam: true\n x-dcl-read-timeout: 0\n x-dcl-apply-timeout: 0\n x-dcl-delete-timeout: 0\n type: object\n properties:\n displayname:\n type: string\n x-dcl-go-name: DisplayName\n description: 'The optional user-assigned display name of the Project. When\n present it must be between 4 to 30 characters. Allowed characters are:\n lowercase and uppercase letters, numbers, hyphen, single-quote, double-quote,\n space, and exclamation point. Example: `My Project` Read-write.'\n x-kubernetes-immutable: true\n labels:\n type: object\n additionalProperties:\n type: string\n x-dcl-go-name: Labels\n description: User-specified labels.\n lifecycleState:\n type: string\n x-dcl-go-name: LifecycleState\n x-dcl-go-type: ProjectLifecycleStateEnum\n readOnly: true\n description: 'The Project lifecycle state. Read-only. Possible values: LIFECYCLE_STATE_UNSPECIFIED,\n ACTIVE, DELETE_REQUESTED, DELETE_IN_PROGRESS'\n x-kubernetes-immutable: true\n enum:\n - LIFECYCLE_STATE_UNSPECIFIED\n - ACTIVE\n - DELETE_REQUESTED\n - DELETE_IN_PROGRESS\n name:\n type: string\n x-dcl-go-name: Name\n description: 'The unique, user-assigned ID of the Project. It must be 6\n to 30 lowercase letters, digits, or hyphens. It must start with a letter.\n Trailing hyphens are prohibited. Example: `tokyo-rain-123` Read-only after\n creation.'\n x-kubernetes-immutable: true\n parent:\n type: string\n x-dcl-go-name: Parent\n description: 'An optional reference to a parent Resource. Supported values\n include organizations/ and folders/. Once set, the\n parent cannot be cleared. The `parent` can be set on creation or using\n the `UpdateProject` method; the end user must have the `resourcemanager.projects.create`\n permission on the parent. Read-write. '\n x-kubernetes-immutable: true\n projectNumber:\n type: integer\n format: int64\n x-dcl-go-name: ProjectNumber\n readOnly: true\n description: 'The number uniquely identifying the project. Example: `415104041262`\n Read-only. '\n x-kubernetes-immutable: true\n") +var YAML_project = []byte("info:\n title: CloudResourceManager/Project\n description: The CloudResourceManager Project resource\n x-dcl-struct-name: Project\n x-dcl-has-iam: true\npaths:\n get:\n description: The function used to get information about a Project\n parameters:\n - name: project\n required: true\n description: A full instance of a Project\n apply:\n description: The function used to apply information about a Project\n parameters:\n - name: project\n required: true\n description: A full instance of a Project\n delete:\n description: The function used to delete a Project\n parameters:\n - name: project\n required: true\n description: A full instance of a Project\n deleteAll:\n description: The function used to delete all Project\n parameters:\n - name: parent\n required: true\n schema:\n type: string\n list:\n description: The function used to list information about many Project\n parameters:\n - name: parent\n required: true\n schema:\n type: string\ncomponents:\n schemas:\n Project:\n title: Project\n x-dcl-id: projects/{{name}}\n x-dcl-labels: labels\n x-dcl-has-create: true\n x-dcl-has-iam: true\n x-dcl-read-timeout: 0\n x-dcl-apply-timeout: 0\n x-dcl-delete-timeout: 0\n type: object\n properties:\n displayname:\n type: string\n x-dcl-go-name: DisplayName\n description: 'The optional user-assigned display name of the Project. When\n present it must be between 4 to 30 characters. Allowed characters are:\n lowercase and uppercase letters, numbers, hyphen, single-quote, double-quote,\n space, and exclamation point. Example: `My Project` Read-write.'\n x-kubernetes-immutable: true\n labels:\n type: object\n additionalProperties:\n type: string\n x-dcl-go-name: Labels\n description: User-specified labels.\n lifecycleState:\n type: string\n x-dcl-go-name: LifecycleState\n x-dcl-go-type: ProjectLifecycleStateEnum\n readOnly: true\n description: 'The Project lifecycle state. Read-only. Possible values: LIFECYCLE_STATE_UNSPECIFIED,\n ACTIVE, DELETE_REQUESTED, DELETE_IN_PROGRESS'\n x-kubernetes-immutable: true\n enum:\n - LIFECYCLE_STATE_UNSPECIFIED\n - ACTIVE\n - DELETE_REQUESTED\n - DELETE_IN_PROGRESS\n name:\n type: string\n x-dcl-go-name: Name\n description: 'The unique, user-assigned ID of the Project. It must be 6\n to 30 lowercase letters, digits, or hyphens. It must start with a letter.\n Trailing hyphens are prohibited. Example: `tokyo-rain-123` Read-only after\n creation.'\n x-kubernetes-immutable: true\n parent:\n type: string\n x-dcl-go-name: Parent\n description: 'An optional reference to a parent Resource. Supported values\n include organizations/ and folders/. Once set, the\n parent cannot be cleared. The `parent` can be set on creation or using\n the `UpdateProject` method; the end user must have the `resourcemanager.projects.create`\n permission on the parent. Read-write. '\n x-kubernetes-immutable: true\n x-dcl-forward-slash-allowed: true\n projectNumber:\n type: integer\n format: int64\n x-dcl-go-name: ProjectNumber\n readOnly: true\n description: 'The number uniquely identifying the project. Example: `415104041262`\n Read-only. '\n x-kubernetes-immutable: true\n") -// 3507 bytes -// MD5: 1e9983843d63b2021ebfe346052682aa +// 3695 bytes +// MD5: 004070936d1301457692aac722300969 diff --git a/services/google/cloudresourcemanager/alpha/project_internal.go b/services/google/cloudresourcemanager/alpha/project_internal.go index 3e11c9fdd..d1de195fc 100755 --- a/services/google/cloudresourcemanager/alpha/project_internal.go +++ b/services/google/cloudresourcemanager/alpha/project_internal.go @@ -42,13 +42,6 @@ func (r *Project) getURL(userBasePath string) (string, error) { return dcl.URL("v1/projects/{{name}}", nr.basePath(), userBasePath, params), nil } -func (r *Project) listURL(userBasePath string) (string, error) { - nr := r.urlNormalized() - params := map[string]interface{}{} - return dcl.URL("v1/projects", nr.basePath(), userBasePath, params), nil - -} - func (r *Project) createURL(userBasePath string) (string, error) { nr := r.urlNormalized() params := map[string]interface{}{} @@ -194,8 +187,8 @@ func (c *Client) listProjectRaw(ctx context.Context, r *Project, pageToken strin } type listProjectOperation struct { - Items []map[string]interface{} `json:"items"` - Token string `json:"nextPageToken"` + Projects []map[string]interface{} `json:"projects"` + Token string `json:"nextPageToken"` } func (c *Client) listProject(ctx context.Context, r *Project, pageToken string, pageSize int32) ([]*Project, string, error) { @@ -210,11 +203,12 @@ func (c *Client) listProject(ctx context.Context, r *Project, pageToken string, } var l []*Project - for _, v := range m.Items { + for _, v := range m.Projects { res, err := unmarshalMapProject(v, c, r) if err != nil { return nil, m.Token, err } + res.Parent = r.Parent l = append(l, res) } @@ -548,7 +542,7 @@ func diffProject(c *Client, desired, actual *Project, opts ...dcl.ApplyOption) ( func (r *Project) urlNormalized() *Project { normalized := dcl.Copy(*r).(Project) normalized.DisplayName = dcl.SelfLinkToName(r.DisplayName) - normalized.Parent = dcl.SelfLinkToName(r.Parent) + normalized.Parent = r.Parent normalized.Name = dcl.SelfLinkToName(r.Name) return &normalized } diff --git a/services/google/cloudresourcemanager/alpha/project_schema.go b/services/google/cloudresourcemanager/alpha/project_schema.go index 5863c1406..4ad6ecdb8 100755 --- a/services/google/cloudresourcemanager/alpha/project_schema.go +++ b/services/google/cloudresourcemanager/alpha/project_schema.go @@ -58,9 +58,27 @@ func DCLProjectSchema() *dcl.Schema { }, DeleteAll: &dcl.Path{ Description: "The function used to delete all Project", + Parameters: []dcl.PathParameters{ + dcl.PathParameters{ + Name: "parent", + Required: true, + Schema: &dcl.PathParametersSchema{ + Type: "string", + }, + }, + }, }, List: &dcl.Path{ Description: "The function used to list information about many Project", + Parameters: []dcl.PathParameters{ + dcl.PathParameters{ + Name: "parent", + Required: true, + Schema: &dcl.PathParametersSchema{ + Type: "string", + }, + }, + }, }, }, Components: &dcl.Components{ @@ -109,10 +127,11 @@ func DCLProjectSchema() *dcl.Schema { Immutable: true, }, "parent": &dcl.Property{ - Type: "string", - GoName: "Parent", - Description: "An optional reference to a parent Resource. Supported values include organizations/ and folders/. Once set, the parent cannot be cleared. The `parent` can be set on creation or using the `UpdateProject` method; the end user must have the `resourcemanager.projects.create` permission on the parent. Read-write. ", - Immutable: true, + Type: "string", + GoName: "Parent", + Description: "An optional reference to a parent Resource. Supported values include organizations/ and folders/. Once set, the parent cannot be cleared. The `parent` can be set on creation or using the `UpdateProject` method; the end user must have the `resourcemanager.projects.create` permission on the parent. Read-write. ", + Immutable: true, + ForwardSlashAllowed: true, }, "projectNumber": &dcl.Property{ Type: "integer", diff --git a/services/google/cloudresourcemanager/alpha/resourcemanager_utils.go b/services/google/cloudresourcemanager/alpha/resourcemanager_utils.go index 53e37dc27..3afdaa98c 100755 --- a/services/google/cloudresourcemanager/alpha/resourcemanager_utils.go +++ b/services/google/cloudresourcemanager/alpha/resourcemanager_utils.go @@ -24,11 +24,6 @@ import ( "github.com/GoogleCloudPlatform/declarative-resource-client-library/dcl/operations" ) -// The project is already effectively deleted if it's in DELETE_REQUESTED state. -func projectDeletePrecondition(r *Project) bool { - return *r.LifecycleState == *ProjectLifecycleStateEnumRef("DELETE_REQUESTED") -} - func (r *Folder) createURL(userBasePath string) (string, error) { nr := r.urlNormalized() params := map[string]interface{}{ @@ -125,6 +120,29 @@ func (op *updateFolderMoveFolderOperation) do(ctx context.Context, r *Folder, c return nil } +// The project is already effectively deleted if it's in DELETE_REQUESTED state. +func projectDeletePrecondition(r *Project) bool { + return *r.LifecycleState == *ProjectLifecycleStateEnumRef("DELETE_REQUESTED") +} + +// Project's list endpoint has a custom url method to use the filter query parameters. +func (r *Project) listURL(userBasePath string) (string, error) { + parentParts := strings.Split(dcl.ValueOrEmptyString(r.Parent), "/") + var parentType, parentID string + if len(parentParts) == 2 { + parentType = strings.TrimSuffix(parentParts[0], "s") + parentID = parentParts[1] + u, err := dcl.AddQueryParams("https://cloudresourcemanager.googleapis.com/v1/projects", map[string]string{ + "filter": fmt.Sprintf("parent.type=%s parent.id=%s", parentType, parentID), + }) + if err != nil { + return "", err + } + return u, nil + } + return "https://cloudresourcemanager.googleapis.com/v1/projects", nil +} + // expandProjectParent expands an instance of ProjectParent into a JSON // request object. func expandProjectParent(_ *Client, fval *string, _ *Project) (map[string]interface{}, error) { diff --git a/services/google/cloudresourcemanager/beta/project.go b/services/google/cloudresourcemanager/beta/project.go index eee2a1c84..47909bad9 100755 --- a/services/google/cloudresourcemanager/beta/project.go +++ b/services/google/cloudresourcemanager/beta/project.go @@ -121,21 +121,23 @@ func (l *ProjectList) Next(ctx context.Context, c *Client) error { return err } -func (c *Client) ListProject(ctx context.Context) (*ProjectList, error) { +func (c *Client) ListProject(ctx context.Context, parent string) (*ProjectList, error) { ctx = dcl.ContextWithRequestID(ctx) ctx, cancel := context.WithTimeout(ctx, c.Config.TimeoutOr(0*time.Second)) defer cancel() - return c.ListProjectWithMaxResults(ctx, ProjectMaxPage) + return c.ListProjectWithMaxResults(ctx, parent, ProjectMaxPage) } -func (c *Client) ListProjectWithMaxResults(ctx context.Context, pageSize int32) (*ProjectList, error) { +func (c *Client) ListProjectWithMaxResults(ctx context.Context, parent string, pageSize int32) (*ProjectList, error) { ctx, cancel := context.WithTimeout(ctx, c.Config.TimeoutOr(0*time.Second)) defer cancel() // Create a resource object so that we can use proper url normalization methods. - r := &Project{} + r := &Project{ + Parent: &parent, + } items, token, err := c.listProject(ctx, r, "", pageSize) if err != nil { return nil, err @@ -202,8 +204,8 @@ func (c *Client) DeleteProject(ctx context.Context, r *Project) error { } // DeleteAllProject deletes all resources that the filter functions returns true on. -func (c *Client) DeleteAllProject(ctx context.Context, filter func(*Project) bool) error { - listObj, err := c.ListProject(ctx) +func (c *Client) DeleteAllProject(ctx context.Context, parent string, filter func(*Project) bool) error { + listObj, err := c.ListProject(ctx, parent) if err != nil { return err } diff --git a/services/google/cloudresourcemanager/beta/project.yaml b/services/google/cloudresourcemanager/beta/project.yaml index a591d461e..6ac4158d3 100755 --- a/services/google/cloudresourcemanager/beta/project.yaml +++ b/services/google/cloudresourcemanager/beta/project.yaml @@ -37,10 +37,18 @@ paths: description: A full instance of a Project deleteAll: description: The function used to delete all Project - parameters: [] + parameters: + - name: parent + required: true + schema: + type: string list: description: The function used to list information about many Project - parameters: [] + parameters: + - name: parent + required: true + schema: + type: string components: schemas: Project: @@ -98,6 +106,7 @@ components: the `UpdateProject` method; the end user must have the `resourcemanager.projects.create` permission on the parent. Read-write. ' x-kubernetes-immutable: true + x-dcl-forward-slash-allowed: true projectNumber: type: integer format: int64 diff --git a/services/google/cloudresourcemanager/beta/project_beta_yaml_embed.go b/services/google/cloudresourcemanager/beta/project_beta_yaml_embed.go index a9288ea6c..aa7c89e84 100755 --- a/services/google/cloudresourcemanager/beta/project_beta_yaml_embed.go +++ b/services/google/cloudresourcemanager/beta/project_beta_yaml_embed.go @@ -17,7 +17,7 @@ package beta // blaze-out/k8-fastbuild/genfiles/cloud/graphite/mmv2/services/google/cloudresourcemanager/beta/project.yaml -var YAML_project = []byte("info:\n title: CloudResourceManager/Project\n description: The CloudResourceManager Project resource\n x-dcl-struct-name: Project\n x-dcl-has-iam: true\npaths:\n get:\n description: The function used to get information about a Project\n parameters:\n - name: project\n required: true\n description: A full instance of a Project\n apply:\n description: The function used to apply information about a Project\n parameters:\n - name: project\n required: true\n description: A full instance of a Project\n delete:\n description: The function used to delete a Project\n parameters:\n - name: project\n required: true\n description: A full instance of a Project\n deleteAll:\n description: The function used to delete all Project\n parameters: []\n list:\n description: The function used to list information about many Project\n parameters: []\ncomponents:\n schemas:\n Project:\n title: Project\n x-dcl-id: projects/{{name}}\n x-dcl-labels: labels\n x-dcl-has-create: true\n x-dcl-has-iam: true\n x-dcl-read-timeout: 0\n x-dcl-apply-timeout: 0\n x-dcl-delete-timeout: 0\n type: object\n properties:\n displayname:\n type: string\n x-dcl-go-name: DisplayName\n description: 'The optional user-assigned display name of the Project. When\n present it must be between 4 to 30 characters. Allowed characters are:\n lowercase and uppercase letters, numbers, hyphen, single-quote, double-quote,\n space, and exclamation point. Example: `My Project` Read-write.'\n x-kubernetes-immutable: true\n labels:\n type: object\n additionalProperties:\n type: string\n x-dcl-go-name: Labels\n description: User-specified labels.\n lifecycleState:\n type: string\n x-dcl-go-name: LifecycleState\n x-dcl-go-type: ProjectLifecycleStateEnum\n readOnly: true\n description: 'The Project lifecycle state. Read-only. Possible values: LIFECYCLE_STATE_UNSPECIFIED,\n ACTIVE, DELETE_REQUESTED, DELETE_IN_PROGRESS'\n x-kubernetes-immutable: true\n enum:\n - LIFECYCLE_STATE_UNSPECIFIED\n - ACTIVE\n - DELETE_REQUESTED\n - DELETE_IN_PROGRESS\n name:\n type: string\n x-dcl-go-name: Name\n description: 'The unique, user-assigned ID of the Project. It must be 6\n to 30 lowercase letters, digits, or hyphens. It must start with a letter.\n Trailing hyphens are prohibited. Example: `tokyo-rain-123` Read-only after\n creation.'\n x-kubernetes-immutable: true\n parent:\n type: string\n x-dcl-go-name: Parent\n description: 'An optional reference to a parent Resource. Supported values\n include organizations/ and folders/. Once set, the\n parent cannot be cleared. The `parent` can be set on creation or using\n the `UpdateProject` method; the end user must have the `resourcemanager.projects.create`\n permission on the parent. Read-write. '\n x-kubernetes-immutable: true\n projectNumber:\n type: integer\n format: int64\n x-dcl-go-name: ProjectNumber\n readOnly: true\n description: 'The number uniquely identifying the project. Example: `415104041262`\n Read-only. '\n x-kubernetes-immutable: true\n") +var YAML_project = []byte("info:\n title: CloudResourceManager/Project\n description: The CloudResourceManager Project resource\n x-dcl-struct-name: Project\n x-dcl-has-iam: true\npaths:\n get:\n description: The function used to get information about a Project\n parameters:\n - name: project\n required: true\n description: A full instance of a Project\n apply:\n description: The function used to apply information about a Project\n parameters:\n - name: project\n required: true\n description: A full instance of a Project\n delete:\n description: The function used to delete a Project\n parameters:\n - name: project\n required: true\n description: A full instance of a Project\n deleteAll:\n description: The function used to delete all Project\n parameters:\n - name: parent\n required: true\n schema:\n type: string\n list:\n description: The function used to list information about many Project\n parameters:\n - name: parent\n required: true\n schema:\n type: string\ncomponents:\n schemas:\n Project:\n title: Project\n x-dcl-id: projects/{{name}}\n x-dcl-labels: labels\n x-dcl-has-create: true\n x-dcl-has-iam: true\n x-dcl-read-timeout: 0\n x-dcl-apply-timeout: 0\n x-dcl-delete-timeout: 0\n type: object\n properties:\n displayname:\n type: string\n x-dcl-go-name: DisplayName\n description: 'The optional user-assigned display name of the Project. When\n present it must be between 4 to 30 characters. Allowed characters are:\n lowercase and uppercase letters, numbers, hyphen, single-quote, double-quote,\n space, and exclamation point. Example: `My Project` Read-write.'\n x-kubernetes-immutable: true\n labels:\n type: object\n additionalProperties:\n type: string\n x-dcl-go-name: Labels\n description: User-specified labels.\n lifecycleState:\n type: string\n x-dcl-go-name: LifecycleState\n x-dcl-go-type: ProjectLifecycleStateEnum\n readOnly: true\n description: 'The Project lifecycle state. Read-only. Possible values: LIFECYCLE_STATE_UNSPECIFIED,\n ACTIVE, DELETE_REQUESTED, DELETE_IN_PROGRESS'\n x-kubernetes-immutable: true\n enum:\n - LIFECYCLE_STATE_UNSPECIFIED\n - ACTIVE\n - DELETE_REQUESTED\n - DELETE_IN_PROGRESS\n name:\n type: string\n x-dcl-go-name: Name\n description: 'The unique, user-assigned ID of the Project. It must be 6\n to 30 lowercase letters, digits, or hyphens. It must start with a letter.\n Trailing hyphens are prohibited. Example: `tokyo-rain-123` Read-only after\n creation.'\n x-kubernetes-immutable: true\n parent:\n type: string\n x-dcl-go-name: Parent\n description: 'An optional reference to a parent Resource. Supported values\n include organizations/ and folders/. Once set, the\n parent cannot be cleared. The `parent` can be set on creation or using\n the `UpdateProject` method; the end user must have the `resourcemanager.projects.create`\n permission on the parent. Read-write. '\n x-kubernetes-immutable: true\n x-dcl-forward-slash-allowed: true\n projectNumber:\n type: integer\n format: int64\n x-dcl-go-name: ProjectNumber\n readOnly: true\n description: 'The number uniquely identifying the project. Example: `415104041262`\n Read-only. '\n x-kubernetes-immutable: true\n") -// 3507 bytes -// MD5: 1e9983843d63b2021ebfe346052682aa +// 3695 bytes +// MD5: 004070936d1301457692aac722300969 diff --git a/services/google/cloudresourcemanager/beta/project_internal.go b/services/google/cloudresourcemanager/beta/project_internal.go index 5a91abe31..092d0a864 100755 --- a/services/google/cloudresourcemanager/beta/project_internal.go +++ b/services/google/cloudresourcemanager/beta/project_internal.go @@ -42,13 +42,6 @@ func (r *Project) getURL(userBasePath string) (string, error) { return dcl.URL("v1/projects/{{name}}", nr.basePath(), userBasePath, params), nil } -func (r *Project) listURL(userBasePath string) (string, error) { - nr := r.urlNormalized() - params := map[string]interface{}{} - return dcl.URL("v1/projects", nr.basePath(), userBasePath, params), nil - -} - func (r *Project) createURL(userBasePath string) (string, error) { nr := r.urlNormalized() params := map[string]interface{}{} @@ -194,8 +187,8 @@ func (c *Client) listProjectRaw(ctx context.Context, r *Project, pageToken strin } type listProjectOperation struct { - Items []map[string]interface{} `json:"items"` - Token string `json:"nextPageToken"` + Projects []map[string]interface{} `json:"projects"` + Token string `json:"nextPageToken"` } func (c *Client) listProject(ctx context.Context, r *Project, pageToken string, pageSize int32) ([]*Project, string, error) { @@ -210,11 +203,12 @@ func (c *Client) listProject(ctx context.Context, r *Project, pageToken string, } var l []*Project - for _, v := range m.Items { + for _, v := range m.Projects { res, err := unmarshalMapProject(v, c, r) if err != nil { return nil, m.Token, err } + res.Parent = r.Parent l = append(l, res) } @@ -548,7 +542,7 @@ func diffProject(c *Client, desired, actual *Project, opts ...dcl.ApplyOption) ( func (r *Project) urlNormalized() *Project { normalized := dcl.Copy(*r).(Project) normalized.DisplayName = dcl.SelfLinkToName(r.DisplayName) - normalized.Parent = dcl.SelfLinkToName(r.Parent) + normalized.Parent = r.Parent normalized.Name = dcl.SelfLinkToName(r.Name) return &normalized } diff --git a/services/google/cloudresourcemanager/beta/project_schema.go b/services/google/cloudresourcemanager/beta/project_schema.go index 8444f1c18..c04325f8e 100755 --- a/services/google/cloudresourcemanager/beta/project_schema.go +++ b/services/google/cloudresourcemanager/beta/project_schema.go @@ -58,9 +58,27 @@ func DCLProjectSchema() *dcl.Schema { }, DeleteAll: &dcl.Path{ Description: "The function used to delete all Project", + Parameters: []dcl.PathParameters{ + dcl.PathParameters{ + Name: "parent", + Required: true, + Schema: &dcl.PathParametersSchema{ + Type: "string", + }, + }, + }, }, List: &dcl.Path{ Description: "The function used to list information about many Project", + Parameters: []dcl.PathParameters{ + dcl.PathParameters{ + Name: "parent", + Required: true, + Schema: &dcl.PathParametersSchema{ + Type: "string", + }, + }, + }, }, }, Components: &dcl.Components{ @@ -109,10 +127,11 @@ func DCLProjectSchema() *dcl.Schema { Immutable: true, }, "parent": &dcl.Property{ - Type: "string", - GoName: "Parent", - Description: "An optional reference to a parent Resource. Supported values include organizations/ and folders/. Once set, the parent cannot be cleared. The `parent` can be set on creation or using the `UpdateProject` method; the end user must have the `resourcemanager.projects.create` permission on the parent. Read-write. ", - Immutable: true, + Type: "string", + GoName: "Parent", + Description: "An optional reference to a parent Resource. Supported values include organizations/ and folders/. Once set, the parent cannot be cleared. The `parent` can be set on creation or using the `UpdateProject` method; the end user must have the `resourcemanager.projects.create` permission on the parent. Read-write. ", + Immutable: true, + ForwardSlashAllowed: true, }, "projectNumber": &dcl.Property{ Type: "integer", diff --git a/services/google/cloudresourcemanager/beta/resourcemanager_utils.go b/services/google/cloudresourcemanager/beta/resourcemanager_utils.go index 234f3443b..115c38921 100755 --- a/services/google/cloudresourcemanager/beta/resourcemanager_utils.go +++ b/services/google/cloudresourcemanager/beta/resourcemanager_utils.go @@ -24,11 +24,6 @@ import ( "github.com/GoogleCloudPlatform/declarative-resource-client-library/dcl/operations" ) -// The project is already effectively deleted if it's in DELETE_REQUESTED state. -func projectDeletePrecondition(r *Project) bool { - return *r.LifecycleState == *ProjectLifecycleStateEnumRef("DELETE_REQUESTED") -} - func (r *Folder) createURL(userBasePath string) (string, error) { nr := r.urlNormalized() params := map[string]interface{}{ @@ -125,6 +120,29 @@ func (op *updateFolderMoveFolderOperation) do(ctx context.Context, r *Folder, c return nil } +// The project is already effectively deleted if it's in DELETE_REQUESTED state. +func projectDeletePrecondition(r *Project) bool { + return *r.LifecycleState == *ProjectLifecycleStateEnumRef("DELETE_REQUESTED") +} + +// Project's list endpoint has a custom url method to use the filter query parameters. +func (r *Project) listURL(userBasePath string) (string, error) { + parentParts := strings.Split(dcl.ValueOrEmptyString(r.Parent), "/") + var parentType, parentID string + if len(parentParts) == 2 { + parentType = strings.TrimSuffix(parentParts[0], "s") + parentID = parentParts[1] + u, err := dcl.AddQueryParams("https://cloudresourcemanager.googleapis.com/v1/projects", map[string]string{ + "filter": fmt.Sprintf("parent.type=%s parent.id=%s", parentType, parentID), + }) + if err != nil { + return "", err + } + return u, nil + } + return "https://cloudresourcemanager.googleapis.com/v1/projects", nil +} + // expandProjectParent expands an instance of ProjectParent into a JSON // request object. func expandProjectParent(_ *Client, fval *string, _ *Project) (map[string]interface{}, error) { diff --git a/services/google/cloudresourcemanager/project.go b/services/google/cloudresourcemanager/project.go index b99af4558..f4b117bb7 100755 --- a/services/google/cloudresourcemanager/project.go +++ b/services/google/cloudresourcemanager/project.go @@ -121,21 +121,23 @@ func (l *ProjectList) Next(ctx context.Context, c *Client) error { return err } -func (c *Client) ListProject(ctx context.Context) (*ProjectList, error) { +func (c *Client) ListProject(ctx context.Context, parent string) (*ProjectList, error) { ctx = dcl.ContextWithRequestID(ctx) ctx, cancel := context.WithTimeout(ctx, c.Config.TimeoutOr(0*time.Second)) defer cancel() - return c.ListProjectWithMaxResults(ctx, ProjectMaxPage) + return c.ListProjectWithMaxResults(ctx, parent, ProjectMaxPage) } -func (c *Client) ListProjectWithMaxResults(ctx context.Context, pageSize int32) (*ProjectList, error) { +func (c *Client) ListProjectWithMaxResults(ctx context.Context, parent string, pageSize int32) (*ProjectList, error) { ctx, cancel := context.WithTimeout(ctx, c.Config.TimeoutOr(0*time.Second)) defer cancel() // Create a resource object so that we can use proper url normalization methods. - r := &Project{} + r := &Project{ + Parent: &parent, + } items, token, err := c.listProject(ctx, r, "", pageSize) if err != nil { return nil, err @@ -202,8 +204,8 @@ func (c *Client) DeleteProject(ctx context.Context, r *Project) error { } // DeleteAllProject deletes all resources that the filter functions returns true on. -func (c *Client) DeleteAllProject(ctx context.Context, filter func(*Project) bool) error { - listObj, err := c.ListProject(ctx) +func (c *Client) DeleteAllProject(ctx context.Context, parent string, filter func(*Project) bool) error { + listObj, err := c.ListProject(ctx, parent) if err != nil { return err } diff --git a/services/google/cloudresourcemanager/project.yaml b/services/google/cloudresourcemanager/project.yaml index a591d461e..6ac4158d3 100755 --- a/services/google/cloudresourcemanager/project.yaml +++ b/services/google/cloudresourcemanager/project.yaml @@ -37,10 +37,18 @@ paths: description: A full instance of a Project deleteAll: description: The function used to delete all Project - parameters: [] + parameters: + - name: parent + required: true + schema: + type: string list: description: The function used to list information about many Project - parameters: [] + parameters: + - name: parent + required: true + schema: + type: string components: schemas: Project: @@ -98,6 +106,7 @@ components: the `UpdateProject` method; the end user must have the `resourcemanager.projects.create` permission on the parent. Read-write. ' x-kubernetes-immutable: true + x-dcl-forward-slash-allowed: true projectNumber: type: integer format: int64 diff --git a/services/google/cloudresourcemanager/project_internal.go b/services/google/cloudresourcemanager/project_internal.go index 3e5d9b3dc..8aafc5c3b 100755 --- a/services/google/cloudresourcemanager/project_internal.go +++ b/services/google/cloudresourcemanager/project_internal.go @@ -42,13 +42,6 @@ func (r *Project) getURL(userBasePath string) (string, error) { return dcl.URL("v1/projects/{{name}}", nr.basePath(), userBasePath, params), nil } -func (r *Project) listURL(userBasePath string) (string, error) { - nr := r.urlNormalized() - params := map[string]interface{}{} - return dcl.URL("v1/projects", nr.basePath(), userBasePath, params), nil - -} - func (r *Project) createURL(userBasePath string) (string, error) { nr := r.urlNormalized() params := map[string]interface{}{} @@ -194,8 +187,8 @@ func (c *Client) listProjectRaw(ctx context.Context, r *Project, pageToken strin } type listProjectOperation struct { - Items []map[string]interface{} `json:"items"` - Token string `json:"nextPageToken"` + Projects []map[string]interface{} `json:"projects"` + Token string `json:"nextPageToken"` } func (c *Client) listProject(ctx context.Context, r *Project, pageToken string, pageSize int32) ([]*Project, string, error) { @@ -210,11 +203,12 @@ func (c *Client) listProject(ctx context.Context, r *Project, pageToken string, } var l []*Project - for _, v := range m.Items { + for _, v := range m.Projects { res, err := unmarshalMapProject(v, c, r) if err != nil { return nil, m.Token, err } + res.Parent = r.Parent l = append(l, res) } @@ -548,7 +542,7 @@ func diffProject(c *Client, desired, actual *Project, opts ...dcl.ApplyOption) ( func (r *Project) urlNormalized() *Project { normalized := dcl.Copy(*r).(Project) normalized.DisplayName = dcl.SelfLinkToName(r.DisplayName) - normalized.Parent = dcl.SelfLinkToName(r.Parent) + normalized.Parent = r.Parent normalized.Name = dcl.SelfLinkToName(r.Name) return &normalized } diff --git a/services/google/cloudresourcemanager/project_schema.go b/services/google/cloudresourcemanager/project_schema.go index 81e5c54aa..50d5416a4 100755 --- a/services/google/cloudresourcemanager/project_schema.go +++ b/services/google/cloudresourcemanager/project_schema.go @@ -58,9 +58,27 @@ func DCLProjectSchema() *dcl.Schema { }, DeleteAll: &dcl.Path{ Description: "The function used to delete all Project", + Parameters: []dcl.PathParameters{ + dcl.PathParameters{ + Name: "parent", + Required: true, + Schema: &dcl.PathParametersSchema{ + Type: "string", + }, + }, + }, }, List: &dcl.Path{ Description: "The function used to list information about many Project", + Parameters: []dcl.PathParameters{ + dcl.PathParameters{ + Name: "parent", + Required: true, + Schema: &dcl.PathParametersSchema{ + Type: "string", + }, + }, + }, }, }, Components: &dcl.Components{ @@ -109,10 +127,11 @@ func DCLProjectSchema() *dcl.Schema { Immutable: true, }, "parent": &dcl.Property{ - Type: "string", - GoName: "Parent", - Description: "An optional reference to a parent Resource. Supported values include organizations/ and folders/. Once set, the parent cannot be cleared. The `parent` can be set on creation or using the `UpdateProject` method; the end user must have the `resourcemanager.projects.create` permission on the parent. Read-write. ", - Immutable: true, + Type: "string", + GoName: "Parent", + Description: "An optional reference to a parent Resource. Supported values include organizations/ and folders/. Once set, the parent cannot be cleared. The `parent` can be set on creation or using the `UpdateProject` method; the end user must have the `resourcemanager.projects.create` permission on the parent. Read-write. ", + Immutable: true, + ForwardSlashAllowed: true, }, "projectNumber": &dcl.Property{ Type: "integer", diff --git a/services/google/cloudresourcemanager/project_yaml_embed.go b/services/google/cloudresourcemanager/project_yaml_embed.go index 507d79340..b178ea0c3 100755 --- a/services/google/cloudresourcemanager/project_yaml_embed.go +++ b/services/google/cloudresourcemanager/project_yaml_embed.go @@ -17,7 +17,7 @@ package cloudresourcemanager // blaze-out/k8-fastbuild/genfiles/cloud/graphite/mmv2/services/google/cloudresourcemanager/project.yaml -var YAML_project = []byte("info:\n title: CloudResourceManager/Project\n description: The CloudResourceManager Project resource\n x-dcl-struct-name: Project\n x-dcl-has-iam: true\npaths:\n get:\n description: The function used to get information about a Project\n parameters:\n - name: project\n required: true\n description: A full instance of a Project\n apply:\n description: The function used to apply information about a Project\n parameters:\n - name: project\n required: true\n description: A full instance of a Project\n delete:\n description: The function used to delete a Project\n parameters:\n - name: project\n required: true\n description: A full instance of a Project\n deleteAll:\n description: The function used to delete all Project\n parameters: []\n list:\n description: The function used to list information about many Project\n parameters: []\ncomponents:\n schemas:\n Project:\n title: Project\n x-dcl-id: projects/{{name}}\n x-dcl-labels: labels\n x-dcl-has-create: true\n x-dcl-has-iam: true\n x-dcl-read-timeout: 0\n x-dcl-apply-timeout: 0\n x-dcl-delete-timeout: 0\n type: object\n properties:\n displayname:\n type: string\n x-dcl-go-name: DisplayName\n description: 'The optional user-assigned display name of the Project. When\n present it must be between 4 to 30 characters. Allowed characters are:\n lowercase and uppercase letters, numbers, hyphen, single-quote, double-quote,\n space, and exclamation point. Example: `My Project` Read-write.'\n x-kubernetes-immutable: true\n labels:\n type: object\n additionalProperties:\n type: string\n x-dcl-go-name: Labels\n description: User-specified labels.\n lifecycleState:\n type: string\n x-dcl-go-name: LifecycleState\n x-dcl-go-type: ProjectLifecycleStateEnum\n readOnly: true\n description: 'The Project lifecycle state. Read-only. Possible values: LIFECYCLE_STATE_UNSPECIFIED,\n ACTIVE, DELETE_REQUESTED, DELETE_IN_PROGRESS'\n x-kubernetes-immutable: true\n enum:\n - LIFECYCLE_STATE_UNSPECIFIED\n - ACTIVE\n - DELETE_REQUESTED\n - DELETE_IN_PROGRESS\n name:\n type: string\n x-dcl-go-name: Name\n description: 'The unique, user-assigned ID of the Project. It must be 6\n to 30 lowercase letters, digits, or hyphens. It must start with a letter.\n Trailing hyphens are prohibited. Example: `tokyo-rain-123` Read-only after\n creation.'\n x-kubernetes-immutable: true\n parent:\n type: string\n x-dcl-go-name: Parent\n description: 'An optional reference to a parent Resource. Supported values\n include organizations/ and folders/. Once set, the\n parent cannot be cleared. The `parent` can be set on creation or using\n the `UpdateProject` method; the end user must have the `resourcemanager.projects.create`\n permission on the parent. Read-write. '\n x-kubernetes-immutable: true\n projectNumber:\n type: integer\n format: int64\n x-dcl-go-name: ProjectNumber\n readOnly: true\n description: 'The number uniquely identifying the project. Example: `415104041262`\n Read-only. '\n x-kubernetes-immutable: true\n") +var YAML_project = []byte("info:\n title: CloudResourceManager/Project\n description: The CloudResourceManager Project resource\n x-dcl-struct-name: Project\n x-dcl-has-iam: true\npaths:\n get:\n description: The function used to get information about a Project\n parameters:\n - name: project\n required: true\n description: A full instance of a Project\n apply:\n description: The function used to apply information about a Project\n parameters:\n - name: project\n required: true\n description: A full instance of a Project\n delete:\n description: The function used to delete a Project\n parameters:\n - name: project\n required: true\n description: A full instance of a Project\n deleteAll:\n description: The function used to delete all Project\n parameters:\n - name: parent\n required: true\n schema:\n type: string\n list:\n description: The function used to list information about many Project\n parameters:\n - name: parent\n required: true\n schema:\n type: string\ncomponents:\n schemas:\n Project:\n title: Project\n x-dcl-id: projects/{{name}}\n x-dcl-labels: labels\n x-dcl-has-create: true\n x-dcl-has-iam: true\n x-dcl-read-timeout: 0\n x-dcl-apply-timeout: 0\n x-dcl-delete-timeout: 0\n type: object\n properties:\n displayname:\n type: string\n x-dcl-go-name: DisplayName\n description: 'The optional user-assigned display name of the Project. When\n present it must be between 4 to 30 characters. Allowed characters are:\n lowercase and uppercase letters, numbers, hyphen, single-quote, double-quote,\n space, and exclamation point. Example: `My Project` Read-write.'\n x-kubernetes-immutable: true\n labels:\n type: object\n additionalProperties:\n type: string\n x-dcl-go-name: Labels\n description: User-specified labels.\n lifecycleState:\n type: string\n x-dcl-go-name: LifecycleState\n x-dcl-go-type: ProjectLifecycleStateEnum\n readOnly: true\n description: 'The Project lifecycle state. Read-only. Possible values: LIFECYCLE_STATE_UNSPECIFIED,\n ACTIVE, DELETE_REQUESTED, DELETE_IN_PROGRESS'\n x-kubernetes-immutable: true\n enum:\n - LIFECYCLE_STATE_UNSPECIFIED\n - ACTIVE\n - DELETE_REQUESTED\n - DELETE_IN_PROGRESS\n name:\n type: string\n x-dcl-go-name: Name\n description: 'The unique, user-assigned ID of the Project. It must be 6\n to 30 lowercase letters, digits, or hyphens. It must start with a letter.\n Trailing hyphens are prohibited. Example: `tokyo-rain-123` Read-only after\n creation.'\n x-kubernetes-immutable: true\n parent:\n type: string\n x-dcl-go-name: Parent\n description: 'An optional reference to a parent Resource. Supported values\n include organizations/ and folders/. Once set, the\n parent cannot be cleared. The `parent` can be set on creation or using\n the `UpdateProject` method; the end user must have the `resourcemanager.projects.create`\n permission on the parent. Read-write. '\n x-kubernetes-immutable: true\n x-dcl-forward-slash-allowed: true\n projectNumber:\n type: integer\n format: int64\n x-dcl-go-name: ProjectNumber\n readOnly: true\n description: 'The number uniquely identifying the project. Example: `415104041262`\n Read-only. '\n x-kubernetes-immutable: true\n") -// 3507 bytes -// MD5: 1e9983843d63b2021ebfe346052682aa +// 3695 bytes +// MD5: 004070936d1301457692aac722300969 diff --git a/services/google/cloudresourcemanager/resourcemanager_utils.go b/services/google/cloudresourcemanager/resourcemanager_utils.go index d7641b0b1..2f56ab649 100755 --- a/services/google/cloudresourcemanager/resourcemanager_utils.go +++ b/services/google/cloudresourcemanager/resourcemanager_utils.go @@ -24,11 +24,6 @@ import ( "github.com/GoogleCloudPlatform/declarative-resource-client-library/dcl/operations" ) -// The project is already effectively deleted if it's in DELETE_REQUESTED state. -func projectDeletePrecondition(r *Project) bool { - return *r.LifecycleState == *ProjectLifecycleStateEnumRef("DELETE_REQUESTED") -} - func (r *Folder) createURL(userBasePath string) (string, error) { nr := r.urlNormalized() params := map[string]interface{}{ @@ -125,6 +120,29 @@ func (op *updateFolderMoveFolderOperation) do(ctx context.Context, r *Folder, c return nil } +// The project is already effectively deleted if it's in DELETE_REQUESTED state. +func projectDeletePrecondition(r *Project) bool { + return *r.LifecycleState == *ProjectLifecycleStateEnumRef("DELETE_REQUESTED") +} + +// Project's list endpoint has a custom url method to use the filter query parameters. +func (r *Project) listURL(userBasePath string) (string, error) { + parentParts := strings.Split(dcl.ValueOrEmptyString(r.Parent), "/") + var parentType, parentID string + if len(parentParts) == 2 { + parentType = strings.TrimSuffix(parentParts[0], "s") + parentID = parentParts[1] + u, err := dcl.AddQueryParams("https://cloudresourcemanager.googleapis.com/v1/projects", map[string]string{ + "filter": fmt.Sprintf("parent.type=%s parent.id=%s", parentType, parentID), + }) + if err != nil { + return "", err + } + return u, nil + } + return "https://cloudresourcemanager.googleapis.com/v1/projects", nil +} + // expandProjectParent expands an instance of ProjectParent into a JSON // request object. func expandProjectParent(_ *Client, fval *string, _ *Project) (map[string]interface{}, error) { diff --git a/services/google/cloudresourcemanager/samples/folder.project.json b/services/google/cloudresourcemanager/samples/folder.project.json new file mode 100755 index 000000000..54a715e55 --- /dev/null +++ b/services/google/cloudresourcemanager/samples/folder.project.json @@ -0,0 +1,4 @@ +{ + "name": "{{id}}", + "parent": "folders/{{ref:organization.folder.json:name}}" +} diff --git a/services/google/cloudresourcemanager/samples/folder_project.yaml b/services/google/cloudresourcemanager/samples/folder_project.yaml new file mode 100755 index 000000000..f87fc7df0 --- /dev/null +++ b/services/google/cloudresourcemanager/samples/folder_project.yaml @@ -0,0 +1,30 @@ +# Copyright 2022 Google LLC. All Rights Reserved. +# +# 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. +name: folder_project +description: A basic example for a project in a folder +type: project +versions: +- ga +- beta +- alpha +resource: samples/folder.project.json +dependencies: +- samples/organization.folder.json +variables: +- name: folder + type: resource_name +- name: id + type: resource_name +- name: org_id + type: org_id diff --git a/unstructured/google/cloudresourcemanager/alpha/project.go b/unstructured/google/cloudresourcemanager/alpha/project.go index 3339da90b..061e6d298 100755 --- a/unstructured/google/cloudresourcemanager/alpha/project.go +++ b/unstructured/google/cloudresourcemanager/alpha/project.go @@ -125,9 +125,9 @@ func GetProject(ctx context.Context, config *dcl.Config, u *unstructured.Resourc return ProjectToUnstructured(r), nil } -func ListProject(ctx context.Context, config *dcl.Config) ([]*unstructured.Resource, error) { +func ListProject(ctx context.Context, config *dcl.Config, parent string) ([]*unstructured.Resource, error) { c := dclService.NewClient(config) - l, err := c.ListProject(ctx) + l, err := c.ListProject(ctx, parent) if err != nil { return nil, err } diff --git a/unstructured/google/cloudresourcemanager/beta/project.go b/unstructured/google/cloudresourcemanager/beta/project.go index 0a409d810..3d168d773 100755 --- a/unstructured/google/cloudresourcemanager/beta/project.go +++ b/unstructured/google/cloudresourcemanager/beta/project.go @@ -125,9 +125,9 @@ func GetProject(ctx context.Context, config *dcl.Config, u *unstructured.Resourc return ProjectToUnstructured(r), nil } -func ListProject(ctx context.Context, config *dcl.Config) ([]*unstructured.Resource, error) { +func ListProject(ctx context.Context, config *dcl.Config, parent string) ([]*unstructured.Resource, error) { c := dclService.NewClient(config) - l, err := c.ListProject(ctx) + l, err := c.ListProject(ctx, parent) if err != nil { return nil, err } diff --git a/unstructured/google/cloudresourcemanager/project.go b/unstructured/google/cloudresourcemanager/project.go index 27a899fbf..d46bf5fc5 100755 --- a/unstructured/google/cloudresourcemanager/project.go +++ b/unstructured/google/cloudresourcemanager/project.go @@ -125,9 +125,9 @@ func GetProject(ctx context.Context, config *dcl.Config, u *unstructured.Resourc return ProjectToUnstructured(r), nil } -func ListProject(ctx context.Context, config *dcl.Config) ([]*unstructured.Resource, error) { +func ListProject(ctx context.Context, config *dcl.Config, parent string) ([]*unstructured.Resource, error) { c := dclService.NewClient(config) - l, err := c.ListProject(ctx) + l, err := c.ListProject(ctx, parent) if err != nil { return nil, err }