...

Source file src/cloud.google.com/go/iam/admin/apiv1/policy_methods.go

Documentation: cloud.google.com/go/iam/admin/apiv1

     1  // Copyright 2016 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // This is handwritten code. These methods are implemented by hand so they can use
    16  // the iam.Policy type.
    17  
    18  package admin
    19  
    20  import (
    21  	"context"
    22  
    23  	"cloud.google.com/go/iam"
    24  	"cloud.google.com/go/iam/apiv1/iampb"
    25  )
    26  
    27  // GetIamPolicy returns the IAM access control policy for a ServiceAccount.
    28  func (c *IamClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest) (*iam.Policy, error) {
    29  	policy, err := c.getIamPolicy(ctx, req)
    30  	if err != nil {
    31  		return nil, err
    32  	}
    33  	return &iam.Policy{InternalProto: policy}, nil
    34  }
    35  
    36  // SetIamPolicyRequest is the request type for the SetIamPolicy method.
    37  type SetIamPolicyRequest struct {
    38  	Resource string
    39  	Policy   *iam.Policy
    40  }
    41  
    42  // SetIamPolicy sets the IAM access control policy for a ServiceAccount.
    43  func (c *IamClient) SetIamPolicy(ctx context.Context, req *SetIamPolicyRequest) (*iam.Policy, error) {
    44  	preq := &iampb.SetIamPolicyRequest{
    45  		Resource: req.Resource,
    46  		Policy:   req.Policy.InternalProto,
    47  	}
    48  	policy, err := c.setIamPolicy(ctx, preq)
    49  	if err != nil {
    50  		return nil, err
    51  	}
    52  	return &iam.Policy{InternalProto: policy}, nil
    53  }
    54  

View as plain text