Skip to content

Commit

Permalink
Automated DCL import.
Browse files Browse the repository at this point in the history
  - f0da38f869555597d32d9988379cdd83f14c863d Automatic import from cloud_mmv2_dcl_20220914_1231_RC00 by DCL Team <[email protected]>

GitOrigin-RevId: f0da38f869555597d32d9988379cdd83f14c863d
  • Loading branch information
DCL Team authored and copybara-github committed Sep 14, 2022
1 parent 3126eec commit a621913
Show file tree
Hide file tree
Showing 32 changed files with 274 additions and 105 deletions.
1 change: 1 addition & 0 deletions python/proto/cloudresourcemanager/alpha/project.proto
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ message DeleteCloudresourcemanagerAlphaProjectRequest {

message ListCloudresourcemanagerAlphaProjectRequest {
string service_account_file = 1;
string Parent = 2;
}

message ListCloudresourcemanagerAlphaProjectResponse {
Expand Down
1 change: 1 addition & 0 deletions python/proto/cloudresourcemanager/beta/project.proto
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ message DeleteCloudresourcemanagerBetaProjectRequest {

message ListCloudresourcemanagerBetaProjectRequest {
string service_account_file = 1;
string Parent = 2;
}

message ListCloudresourcemanagerBetaProjectResponse {
Expand Down
1 change: 1 addition & 0 deletions python/proto/cloudresourcemanager/project.proto
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ message DeleteCloudresourcemanagerProjectRequest {

message ListCloudresourcemanagerProjectRequest {
string service_account_file = 1;
string Parent = 2;
}

message ListCloudresourcemanagerProjectResponse {
Expand Down
4 changes: 3 additions & 1 deletion python/services/cloudresourcemanager/alpha/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion python/services/cloudresourcemanager/beta/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion python/services/cloudresourcemanager/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion python/services/cloudresourcemanager/project_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
14 changes: 8 additions & 6 deletions services/google/cloudresourcemanager/alpha/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
13 changes: 11 additions & 2 deletions services/google/cloudresourcemanager/alpha/project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/<org_id> and folders/<folder_id>. 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/<org_id> and folders/<folder_id>. 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
16 changes: 5 additions & 11 deletions services/google/cloudresourcemanager/alpha/project_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{}
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
}

Expand Down Expand Up @@ -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
}
Expand Down
27 changes: 23 additions & 4 deletions services/google/cloudresourcemanager/alpha/project_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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/<org_id> and folders/<folder_id>. 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/<org_id> and folders/<folder_id>. 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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{
Expand Down Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit a621913

Please sign in to comment.