def CreateRequests(self, args): name = args.name if not name: name = gaia_utils.GetDefaultAccountName(self.http) user_ref = self.clouduseraccounts_resources.Parse( name, collection='clouduseraccounts.users') if args.fingerprints: fingerprints = args.fingerprints else: fetcher = users_client.UserResourceFetcher( self.clouduseraccounts, self.project, self.http, self.batch_url) fingerprints = [k.fingerprint for k in fetcher.LookupUser(user_ref.Name()).publicKeys] # Generate warning before deleting. prompt_list = ['[{0}]'.format(fingerprint) for fingerprint in fingerprints] prompt_title = ('The following public keys will be removed from the user ' + user_ref.Name()) utils.PromptForDeletionHelper(None, prompt_list, prompt_title=prompt_title) requests = [] for fingerprint in fingerprints: request = self.messages.ClouduseraccountsUsersRemovePublicKeyRequest( project=self.project, fingerprint=fingerprint, user=user_ref.Name()) requests.append(request) return requests
def Run(self, args): holder = base_classes.ComputeApiHolder(self.ReleaseTrack()) client = holder.client router_ref = self.ROUTER_ARG.ResolveAsResource(args, holder.resources) objects = client.MakeRequests([ (client.apitools_client.routers, 'Get', client.messages.ComputeRoutersGetRequest(**router_ref.AsDict())) ]) router = objects[0] nat_name = args.nat rule_numbers = args.rule_number nat = nats_utils.FindNatOrRaise(router, nat_name) for rule_number in rule_numbers: rule = rules_utils.FindRuleOrRaise(nat, rule_number) nat.rules.remove(rule) utils.PromptForDeletionHelper( 'Rule', ['{} in NAT {}'.format(args.rule_number, nat_name)]) return client.MakeRequests( [self._GetPatchRequest(client, router_ref, router)])
def Run(self, args): holder = base_classes.ComputeUserAccountsApiHolder(self.ReleaseTrack()) client = holder.client name = args.name if not name: name = gaia.GetDefaultAccountName(client.http) user_ref = holder.resources.Parse( name, params={'project': properties.VALUES.core.project.GetOrFail}, collection='clouduseraccounts.users') if args.fingerprints: fingerprints = args.fingerprints else: fetcher = users_client.UserResourceFetcher( client, user_ref.project, client.http, 'https://www.googleapis.com/batch/') fingerprints = [ k.fingerprint for k in fetcher.LookupUser(user_ref.Name()).publicKeys ] # Generate warning before deleting. prompt_list = [ '[{0}]'.format(fingerprint) for fingerprint in fingerprints ] prompt_title = ( 'The following public keys will be removed from the user ' + user_ref.Name()) utils.PromptForDeletionHelper(None, prompt_list, prompt_title=prompt_title) requests = [] for fingerprint in fingerprints: request = (client.MESSAGES_MODULE. ClouduseraccountsUsersRemovePublicKeyRequest( project=user_ref.project, fingerprint=fingerprint, user=user_ref.Name())) requests.append((client.users, 'RemovePublicKey', request)) errors = [] responses = list( request_helper.MakeRequests( requests=requests, http=client.http, batch_url='https://www.googleapis.com/batch/', errors=errors)) if errors: utils.RaiseToolException(errors, error_message='Could not fetch resource:') return responses
def Run(self, args): compute_holder = base_classes.ComputeApiHolder(self.ReleaseTrack()) holder = base_classes.ComputeUserAccountsApiHolder(self.ReleaseTrack()) client = holder.client name = args.name if not name: name = gaia.GetDefaultAccountName(client.http) user_ref = holder.resources.Parse( name, params={'project': properties.VALUES.core.project.GetOrFail}, collection='clouduseraccounts.users') if args.fingerprints: fingerprints = args.fingerprints else: fetcher = users_client.UserResourceFetcher( client, user_ref.project, client.http, compute_holder.client.batch_url) fingerprints = [ k.fingerprint for k in fetcher.LookupUser(user_ref.Name()).publicKeys ] # Generate warning before deleting. prompt_list = [ '[{0}]'.format(fingerprint) for fingerprint in fingerprints ] prompt_title = ( 'The following public keys will be removed from the user ' + user_ref.Name()) utils.PromptForDeletionHelper(None, prompt_list, prompt_title=prompt_title) requests = [] for fingerprint in fingerprints: request = (client.MESSAGES_MODULE. ClouduseraccountsUsersRemovePublicKeyRequest( project=user_ref.project, fingerprint=fingerprint, user=user_ref.Name())) requests.append((client.users, 'RemovePublicKey', request)) return compute_holder.client.MakeRequests(requests)
def Run(self, args): holder = base_classes.ComputeApiHolder(self.ReleaseTrack()) client = holder.client router_ref = self.ROUTER_ARG.ResolveAsResource(args, holder.resources) objects = client.MakeRequests( [(client.apitools_client.routers, 'Get', client.messages.ComputeRoutersGetRequest(**router_ref.AsDict()))]) # Cleared list fields need to be explicitly identified for Patch API. cleared_fields = [] new_object = self.Modify(args, objects[0], cleared_fields) utils.PromptForDeletionHelper( 'NAT', ['{} in router {}'.format(args.name, router_ref.Name())]) with client.apitools_client.IncludeFields(cleared_fields): # There is only one response because one request is made above result = client.MakeRequests( [self._GetPatchRequest(client, router_ref, new_object)]) return result