...

Source file src/edge-infra.dev/pkg/lib/gcp/iam/policy.go

Documentation: edge-infra.dev/pkg/lib/gcp/iam

     1  package iam
     2  
     3  import (
     4  	"context"
     5  
     6  	"google.golang.org/api/cloudresourcemanager/v1"
     7  )
     8  
     9  // CreatePolicy returns a new cloudresourcemanager policy.
    10  func CreatePolicy(bindings []*cloudresourcemanager.Binding) *cloudresourcemanager.Policy {
    11  	return &cloudresourcemanager.Policy{
    12  		Bindings: bindings,
    13  	}
    14  }
    15  
    16  // CreatePolicyBinding returns a new cloudresourcemanager binding with the specified role and members.
    17  func CreatePolicyBinding(role string, members []string) *cloudresourcemanager.Binding {
    18  	return &cloudresourcemanager.Binding{
    19  		Role:    role,
    20  		Members: members,
    21  	}
    22  }
    23  
    24  // GetPolicy returns the policy for a specified resource.
    25  func (crmService *CloudResourceManagerService) GetPolicy(ctx context.Context, projectID string) (*cloudresourcemanager.Policy, error) {
    26  	request := new(cloudresourcemanager.GetIamPolicyRequest)
    27  	return crmService.Projects.GetIamPolicy(projectID, request).Context(ctx).Do()
    28  }
    29  
    30  // SetPolicy sets the policy for the specified resources.
    31  func (crmService *CloudResourceManagerService) SetPolicy(ctx context.Context, projectID string, policy *cloudresourcemanager.Policy) (*cloudresourcemanager.Policy, error) {
    32  	request := new(cloudresourcemanager.SetIamPolicyRequest)
    33  	request.Policy = policy
    34  	return crmService.Projects.SetIamPolicy(projectID, request).Context(ctx).Do()
    35  }
    36  

View as plain text