def Run(self, args): """Run 'service-management operations list'. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: The list of operations for this project. """ messages = services_util.GetMessagesModule() client = services_util.GetClientInstance() service = arg_parsers.GetServiceNameFromArg(args.service) msg_filter = 'serviceName="{0}"'.format(service) if args.filter: msg_filter += ' AND ({0})'.format(args.filter) args.filter = None # We don't want Display() to handle the filter. msg = messages.ServicemanagementOperationsListRequest(filter=msg_filter) return list_pager.YieldFromList( client.operations, msg, limit=args.limit, batch_size_attribute='pageSize', batch_size=args.page_size, field='operations')
def Run(self, args): """Run 'service-management check-access'. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: The response from the access API call. """ messages = services_util.GetMessagesModule() client = services_util.GetClientInstance() all_iam_permissions = services_util.ALL_IAM_PERMISSIONS # Shorten the query request name for better readability query_request = messages.ServicemanagementServicesTestIamPermissionsRequest service = arg_parsers.GetServiceNameFromArg(args.service) request = query_request( servicesId=service, testIamPermissionsRequest=messages.TestIamPermissionsRequest( permissions=all_iam_permissions)) return client.services.TestIamPermissions(request)
def Run(self, args): """Run 'service-management configs list'. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: The response from the List API call. """ messages = services_util.GetMessagesModule() client = services_util.GetClientInstance() service = arg_parsers.GetServiceNameFromArg(args.service) request = messages.ServicemanagementServicesConfigsListRequest( serviceName=service) return list_pager.YieldFromList( client.services_configs, request, limit=args.limit, batch_size_attribute='pageSize', batch_size=args.page_size, field='serviceConfigs')
def Run(self, args): """Run 'service-management remove-iam-policy-binding'. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: The response from the access API call. Raises: ToolException: An error such as specifying a label that doesn't exist or a principal that is already a member of the service or visibility label. """ messages = services_util.GetMessagesModule() client = services_util.GetClientInstance() service = arg_parsers.GetServiceNameFromArg(args.service) request = messages.ServicemanagementServicesGetIamPolicyRequest( servicesId=service) policy = client.services.GetIamPolicy(request) iam_util.RemoveBindingFromIamPolicy(policy, args.member, args.role) # Send updated access policy to backend request = messages.ServicemanagementServicesSetIamPolicyRequest( servicesId=service, setIamPolicyRequest=messages.SetIamPolicyRequest(policy=policy)) return client.services.SetIamPolicy(request)
def Run(self, args): """Run 'service-management delete'. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: The response from the Delete API call (or None if cancelled). """ messages = services_util.GetMessagesModule() client = services_util.GetClientInstance() # Prompt with a warning before continuing. console_io.PromptContinue( message= 'Are you sure? This will set the service configuration to be ' 'deleted, along with all of the associated consumer ' 'information. Note: This does not immediately delete the ' 'service configuration or data and can be undone using the ' 'undelete command for 30 days. Only after 30 days will the ' 'service be purged from the system.', prompt_string='Continue anyway', default=True, throw_if_unattended=True, cancel_on_no=True) service = arg_parsers.GetServiceNameFromArg(args.service) request = messages.ServicemanagementServicesDeleteRequest( serviceName=service, ) operation = client.services.Delete(request) return services_util.ProcessOperationResult(operation, args. async)
def Run(self, args): """Run 'service-management enable'. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: The response from the consumer settings API call. """ project = properties.VALUES.core.project.Get(required=True) service = arg_parsers.GetServiceNameFromArg(args.service) operation = enable_api.EnableServiceApiCall(project, service) return services_util.ProcessOperationResult(operation, args. async)
def Run(self, args): """Run 'service-management describe'. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: The response from the Get API call. """ messages = services_util.GetMessagesModule() client = services_util.GetClientInstance() service = arg_parsers.GetServiceNameFromArg(args.service) request = messages.ServicemanagementServicesGetRequest( serviceName=service, ) return client.services.Get(request)
def Run(self, args): """Run 'service-management add-iam-policy-binding'. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: The response from the access API call. Raises: ToolException: An error such as specifying a label that doesn't exist or a principal that is already a member of the service or visibility label. """ messages = services_util.GetMessagesModule() client = services_util.GetClientInstance() service = arg_parsers.GetServiceNameFromArg(args.service) request = messages.ServicemanagementServicesGetIamPolicyRequest( servicesId=service) try: policy = client.services.GetIamPolicy(request) except apitools_exceptions.HttpError as error: # If the error is a 404, no IAM policy exists, so just create a blank one. exc = exceptions.HttpException(error) if exc.payload.status_code == 404: policy = messages.Policy() else: raise iam_util.AddBindingToIamPolicy(messages.Binding, policy, args.member, args.role) # Send updated access policy to backend request = messages.ServicemanagementServicesSetIamPolicyRequest( servicesId=service, setIamPolicyRequest=(messages.SetIamPolicyRequest(policy=policy))) return client.services.SetIamPolicy(request)
def Run(self, args): """Run 'service-management disable'. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: The response from the consumer settings API call. """ messages = services_util.GetMessagesModule() client = services_util.GetClientInstance() project = properties.VALUES.core.project.Get(required=True) service = arg_parsers.GetServiceNameFromArg(args.service) request = messages.ServicemanagementServicesDisableRequest( serviceName=service, disableServiceRequest=messages.DisableServiceRequest( consumerId='project:' + project)) operation = client.services.Disable(request) return services_util.ProcessOperationResult(operation, args. async)
def Run(self, args): """Run 'service-management configs describe'. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: The response from the Get API call. """ service = arg_parsers.GetServiceNameFromArg(args.service) config_ref = resources.REGISTRY.Parse( args.config_id, params={ 'serviceName': resolvers.FromArgument('--service', service) }, collection='servicemanagement.services.configs') # Check if the user wants the active config or a specific config. return self._GetConfig(config_ref.serviceName, config_ref.configId)
def Run(self, args): """Run 'service-management undelete'. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: The response from the Undelete API call (or None if cancelled). """ messages = services_util.GetMessagesModule() client = services_util.GetClientInstance() service = arg_parsers.GetServiceNameFromArg(args.service) request = messages.ServicemanagementServicesUndeleteRequest( serviceName=service, ) operation = client.services.Undelete(request) return services_util.ProcessOperationResult(operation, args. async)
def Run(self, args): """Run 'service-management get-iam-policy'. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: The response from the access API call. Raises: HttpException: An http error response was received while executing api request. """ messages = services_util.GetMessagesModule() client = services_util.GetClientInstance() service = arg_parsers.GetServiceNameFromArg(args.service) request = messages.ServicemanagementServicesGetIamPolicyRequest( servicesId=service) return client.services.GetIamPolicy(request)
def _GetServiceName(): return arg_parsers.GetServiceNameFromArg( args.MakeGetOrRaise('--service')())