def Run(self, args):
        release_track = args.calliope_command.ReleaseTrack()
        client = apis.GetClientInstance(release_track)
        messages = apis.GetMessagesModule(release_track)

        attachment_point = args.attachment_point.replace('/', '%2F')

        # If etag is not present, get using GetPolicy API.
        etag = args.etag
        if not etag:
            get_result = client.policies.Get(
                messages.IamPoliciesGetRequest(name='policies/{}/{}/{}'.format(
                    attachment_point, args.kind, args.policy_id)))
            if release_track == base.ReleaseTrack.ALPHA and isinstance(
                    get_result, messages.GoogleIamV2alphaPolicy):
                etag = get_result.etag
            elif isinstance(get_result, messages.GoogleIamV2betaPolicy):
                etag = get_result.etag
            else:
                raise Exception('Unexpected response from policies client.')

        if release_track == base.ReleaseTrack.ALPHA:
            policy = apis.ParseYamlOrJsonPolicyFile(
                args.policy_file, messages.GoogleIamV2alphaPolicy)
        else:
            policy = apis.ParseYamlOrJsonPolicyFile(
                args.policy_file, messages.GoogleIamV2betaPolicy)

        policy.name = 'policies/{}/{}/{}'.format(attachment_point, args.kind,
                                                 args.policy_id)
        policy.etag = etag

        result = client.policies.Update(policy)
        log.UpdatedResource(result.name, 'denyPolicy', is_async=True)
        return result
예제 #2
0
  def Run(self, args):
    client = apis.GetClientInstance()
    messages = apis.GetMessagesModule()

    attachment_point = args.attachment_point.replace('/', '%2F')

    # If etag is not present, get using GetPolicy API.
    etag = args.etag
    if not etag:
      get_result = client.policies.Get(
          messages.IamPoliciesGetRequest(name='policies/{}/{}/{}'.format(
              attachment_point, args.kind, args.policy_id)))
      if isinstance(get_result, messages.GoogleIamV2alpha1Policy):
        etag = get_result.etag
      else:
        raise Exception('Unexpected response from policies client.')

    policy = apis.ParseYamlOrJsonPolicyFile(args.policy_file,
                                            messages.GoogleIamV2alpha1Policy)
    policy.name = 'policies/{}/{}/{}'.format(attachment_point, args.kind,
                                             args.policy_id)
    policy.etag = etag

    result = client.policies.ReplacePolicy(policy)
    return result
예제 #3
0
    def Run(self, args):
        client = apis.GetClientInstance()
        messages = apis.GetMessagesModule()

        attachment_point = args.attachment_point.replace('/', '%2F')

        result = client.policies.Get(
            messages.IamPoliciesGetRequest(name='policies/{}/{}/{}'.format(
                attachment_point, args.kind, args.policy_id)))
        return result
예제 #4
0
    def Run(self, args):
        client = apis.GetClientInstance(args.calliope_command.ReleaseTrack())
        messages = apis.GetMessagesModule(args.calliope_command.ReleaseTrack())

        attachment_point = args.attachment_point.replace('/', '%2F')

        result = client.policies.ListPolicies(
            messages.IamPoliciesListPoliciesRequest(
                parent='policies/{}/{}'.format(attachment_point, args.kind),
                pageSize=args.page_size,
                pageToken=args.page_token))
        return result
예제 #5
0
    def Run(self, args):
        client = apis.GetClientInstance()
        messages = apis.GetMessagesModule()

        attachment_point = args.attachment_point.replace('/', '%2F')

        result = client.policies.CreatePolicy(
            messages.IamPoliciesCreatePolicyRequest(
                parent='policies/{}/{}'.format(attachment_point, args.kind),
                policyId=args.policy_id,
                googleIamV2alpha1Policy=apis.ParseYamlOrJsonPolicyFile(
                    args.policy_file, messages.GoogleIamV2alpha1Policy)))
        return result
  def Run(self, args):
    release_track = args.calliope_command.ReleaseTrack()
    client = apis.GetClientInstance(release_track)
    messages = apis.GetMessagesModule(release_track)

    attachment_point = args.attachment_point.replace('/', '%2F')

    if release_track == base.ReleaseTrack.ALPHA:
      result = client.policies.CreatePolicy(
          messages.IamPoliciesCreatePolicyRequest(
              parent='policies/{}/{}'.format(attachment_point, args.kind),
              policyId=args.policy_id,
              googleIamV2alphaPolicy=apis.ParseYamlOrJsonPolicyFile(
                  args.policy_file, messages.GoogleIamV2alphaPolicy)))
    else:
      result = client.policies.CreatePolicy(
          messages.IamPoliciesCreatePolicyRequest(
              parent='policies/{}/{}'.format(attachment_point, args.kind),
              policyId=args.policy_id,
              googleIamV2betaPolicy=apis.ParseYamlOrJsonPolicyFile(
                  args.policy_file, messages.GoogleIamV2betaPolicy)))
    log.CreatedResource(result.name, 'denyPolicy', is_async=True)
    return result