예제 #1
0
  def Run(self, args):
    apis = apis_client.ApiClient()
    api_configs = api_configs_client.ApiConfigClient()
    ops = operations_client.OperationsClient()

    api_config_ref = args.CONCEPTS.api_config.Parse()
    api_ref = api_config_ref.Parent()

    service_name = common_flags.ProcessApiRefToEndpointsService(api_ref)

    # Check if OP service exists with Api name, create if not, activate it
    if not endpoints.DoesServiceExist(service_name):
      endpoints.CreateService(service_name, api_ref.projectsId)

    # Check to see if Api exists, create if not
    if not apis.DoesExist(api_ref):
      res = apis.Create(api_ref, service_name)
      operations_util.PrintOperationResult(
          res.name, ops,
          wait_string='Waiting for API [{}] to be created'.format(
              api_ref.Name()))

    # Create OP ServiceConfig and Rollout

    # Creating a suffix to avoid name collisions on ServiceConfig IDs.
    suffix = '-' + str(int(time.time()))
    length = MAX_SERVICE_CONFIG_ID_LENGTH - len(suffix)
    config_id = api_config_ref.Name()[:length] + suffix

    if args.openapi_spec:
      service_config_id = self.__PushOpenApiServiceFile(
          args.openapi_spec,
          service_name,
          api_config_ref.projectsId,
          config_id=config_id)
    else:
      service_config_id = self.__PushGrpcConfigFiles(
          args.grpc_files,
          service_name,
          api_config_ref.projectsId,
          config_id=config_id)
    rollout = endpoints.CreateRollout(service_config_id, service_name)

    # Create ApiConfig object using the service config and rollout
    # Only piece affected by async right now
    resp = api_configs.Create(api_config_ref,
                              rollout['rolloutId'],
                              labels=args.labels,
                              display_name=args.display_name,
                              backend_auth=args.backend_auth_service_account)

    wait = 'Waiting for API Config [{}] to be created for API [{}]'.format(
        api_config_ref.Name(), api_ref.Name())

    return operations_util.PrintOperationResult(
        resp.name,
        ops,
        service=api_configs.service,
        wait_string=wait,
        is_async=args.async_)
예제 #2
0
    def Run(self, args):
        """Run 'api-gateway apis 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).
    """

        api_ref = args.CONCEPTS.api.Parse()
        service_name = common_flags.ProcessApiRefToEndpointsService(api_ref)

        # Prompt with a warning before continuing.
        console_io.PromptContinue(
            message='Are you sure? This will delete the API \'{}\', '
            'along with all of the associated consumer '
            'information.'.format(api_ref.RelativeName()),
            prompt_string='Continue anyway',
            default=True,
            throw_if_unattended=True,
            cancel_on_no=True)

        self.__DeleteEndpointsService(service_name)
        resp = apis.ApiClient().Delete(api_ref)

        wait = 'Waiting for API [{}] to be deleted'.format(api_ref.Name())

        return operations_util.PrintOperationResult(
            resp.name,
            operations.OperationsClient(),
            wait_string=wait,
            is_async=args.async_)
예제 #3
0
  def Run(self, args):
    api_ref = args.CONCEPTS.api.Parse()
    service_name = common_flags.ProcessApiRefToEndpointsService(api_ref)
    api_client = apis.ApiClient()

    # Check if OP service exists with Api name, create if not, activate it
    if not endpoints.DoesServiceExist(service_name):
      endpoints.CreateService(service_name, api_ref.projectsId)

    resp = api_client.Create(api_ref,
                             service_name,
                             labels=args.labels,
                             display_name=args.display_name)

    return operations_util.PrintOperationResult(
        resp.name,
        ops.OperationsClient(),
        service=api_client.service,
        wait_string='Waiting for API [{}] to be created'.format(api_ref.Name()),
        is_async=args.async_)