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)
Esempio n. 2
0
    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_)
Esempio n. 3
0
  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')
Esempio n. 4
0
    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 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)
Esempio n. 6
0
    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)
Esempio n. 8
0
    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)
Esempio n. 9
0
    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)
Esempio n. 10
0
 def _GetServiceName():
     return arg_parsers.GetServiceNameFromArg(
         args.MakeGetOrRaise('--service')())
Esempio n. 11
0
 def testGetServiceNameFromArgNonetypeInput(self):
     expected = None
     actual = arg_parsers.GetServiceNameFromArg(None)
     self.assertEqual(expected, actual)
Esempio n. 12
0
 def testGetServiceNameFromArgSimpleInput(self):
     expected = 'myservice'
     actual = arg_parsers.GetServiceNameFromArg('myservice')
     self.assertEqual(expected, actual)