Пример #1
0
    def Run(self, args):

        policy = iam_util.ParseJsonPolicyFile(args.policy_file,
                                              self.messages.Policy)

        ref = self.CreateReference(args)
        request_class = self.service.GetRequestType(self.method)
        request = request_class(project=self.project)
        self.ScopeRequest(ref, request)
        self.SetResourceName(ref, request)
        request.policy = policy

        set_policy_request = (self.service, self.method, request)
        errors = []
        objects = request_helper.MakeRequests(requests=[set_policy_request],
                                              http=self.http,
                                              batch_url=self.batch_url,
                                              errors=errors,
                                              custom_get_requests=None)

        # Converting the objects genrator to a list triggers the
        # logic that actually populates the errors list.
        resources = list(objects)
        if errors:
            utils.RaiseToolException(errors,
                                     error_message='Could not fetch resource:')

        # TODO(user): determine how this output should look when empty.

        # SetIamPolicy always returns either an error or the newly set policy.
        # If the policy was just set to the empty policy it returns a valid empty
        # policy (just an etag.)
        # It is not possible to have multiple policies for one resource.
        return resources[0]
    def Run(self, args):
        self.SetAddress(args.account)
        policy = iam_util.ParseJsonPolicyFile(args.policy_file,
                                              self.messages.Policy)

        return self.iam_client.projects_serviceAccounts.SetIamPolicy(
            self.messages.IamProjectsServiceAccountsSetIamPolicyRequest(
                resource=utils.EmailToAccountResourceName(args.account),
                setIamPolicyRequest=self.messages.SetIamPolicyRequest(
                    policy=policy)))
Пример #3
0
    def Run(self, args):
        projects = self.context['projects_client']
        messages = self.context['projects_messages']

        project_ref = self.GetProject(args.id)

        policy = iam_util.ParseJsonPolicyFile(args.policy_file,
                                              messages.Policy)

        policy_request = messages.CloudresourcemanagerProjectsSetIamPolicyRequest(
            resource=project_ref.Name(),
            setIamPolicyRequest=messages.SetIamPolicyRequest(policy=policy))
        return projects.projects.SetIamPolicy(policy_request)
  def Run(self, args):
    apitools_client = self.context[lib.GENOMICS_APITOOLS_CLIENT_KEY]
    messages = self.context[lib.GENOMICS_MESSAGES_MODULE_KEY]
    resources = self.context[lib.GENOMICS_RESOURCES_KEY]

    dataset_resource = resources.Parse(args.id, collection='genomics.datasets')

    policy = iam_util.ParseJsonPolicyFile(args.policy_file, messages.Policy)

    policy_request = messages.GenomicsDatasetsSetIamPolicyRequest(
        resource='datasets/{0}'.format(dataset_resource.Name()),
        setIamPolicyRequest=messages.SetIamPolicyRequest(policy=policy),
    )
    return apitools_client.datasets.SetIamPolicy(policy_request)