Esempio n. 1
0
    def Run(self, args):
        """Run 'api-gateway gateways delete'.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
          with.

    Raises:
      OperationCancelledError
    Returns:
      The response from the Delete API call.
    """

        gateway_ref = args.CONCEPTS.gateway.Parse()

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

        resp = gateways.GatewayClient().Delete(gateway_ref)

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

        return operations_util.PrintOperationResult(
            resp.name,
            operations.OperationsClient(),
            wait_string=wait,
            is_async=args.async_)
Esempio n. 2
0
    def Run(self, args):
        parent_ref = args.CONCEPTS.location.Parse()

        return operations.OperationsClient().List(parent_ref.RelativeName(),
                                                  filters=args.filter,
                                                  limit=args.limit,
                                                  page_size=args.page_size)
  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_)
Esempio n. 4
0
    def Run(self, args):
        """Run 'api-gateway api-configs 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_config_ref = args.CONCEPTS.api_config.Parse()

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

        client = api_configs.ApiConfigClient()

        resp = client.Delete(api_config_ref)

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

        return operations_util.PrintOperationResult(
            resp.name,
            operations.OperationsClient(),
            wait_string=wait,
            is_async=args.async_)
Esempio n. 5
0
    def Run(self, args):
        gateway_ref = args.CONCEPTS.gateway.Parse()
        api_config_ref = args.CONCEPTS.api_config.Parse()

        gateways_client = gateways.GatewayClient()
        resp = gateways_client.Create(gateway_ref,
                                      api_config_ref,
                                      display_name=args.display_name,
                                      labels=args.labels)
        operation_ref = resources.REGISTRY.Parse(
            resp.name, collection='apigateway.projects.locations.operations')

        # If async operation, simply log and return the result on passed in object
        if args.async_:
            operations_util.PrintOperationResultWithWaitEpilogue(
                operation_ref, 'Asynchronous operation is in progress')
            return resp

        op_client = operations.OperationsClient()

        return op_client.WaitForOperation(
            operation_ref,
            'Waiting for API Gateway [{}] to be created with [{}] config'.
            format(gateway_ref.Name(), api_config_ref.RelativeName()),
            gateways_client.client.projects_locations_gateways)
Esempio n. 6
0
    def Run(self, args):
        gateway_ref = args.CONCEPTS.gateway.Parse()

        gateways_client = gateways.GatewayClient()
        gateway, mask = self.ProcessUpdates(gateways_client.Get(gateway_ref),
                                            args)

        resp = gateways_client.Update(gateway, update_mask=mask)

        op_client = operations.OperationsClient()
        return op_client.GetOperationResult(resp, is_async=args.async_)
Esempio n. 7
0
    def Run(self, args):
        gateway_ref = args.CONCEPTS.gateway.Parse()
        api_config_ref = args.CONCEPTS.api_config.Parse()

        gateways_client = gateways.GatewayClient()
        resp = gateways_client.Create(gateway_ref,
                                      api_config_ref,
                                      display_name=args.display_name,
                                      labels=args.labels)

        op_client = operations.OperationsClient()

        return op_client.GetOperationResult(resp, is_async=args.async_)
Esempio n. 8
0
  def Run(self, args):
    api_ref = args.CONCEPTS.api.Parse()

    api_client = apis.ApiClient()
    api, mask = self.ProcessUpdates(api_client.Get(api_ref), args)

    resp = api_client.Update(api, update_mask=mask)

    return operations_util.PrintOperationResult(
        resp.name,
        operations.OperationsClient(),
        service=api_client.service,
        wait_string='Waiting for API [{}] to be updated'.format(api_ref.Name()),
        is_async=args.async_)
    def Run(self, args):
        client = operations.OperationsClient()
        operation_ref = args.CONCEPTS.operation.Parse()

        console_io.PromptContinue(
            message='The operation [{}] will be cancelled.'.format(
                operation_ref.RelativeName()),
            throw_if_unattended=True,
            cancel_on_no=True)

        client.Cancel(operation_ref)

        operations_util.PrintOperationResultWithWaitEpilogue(
            operation_ref, 'Operation cancellation requested')
Esempio n. 10
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()

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

        open_api_docs = []
        svc_configs = []
        grpc_svc_defs = []
        # When we add gRPC support back, we can remove the 'hasattr' call.
        if hasattr(args, 'grpc_files') and args.grpc_files:
            args.grpc_files = [f.strip() for f in args.grpc_files]
            svc_configs, grpc_svc_defs = self.__GrpcMessages(args.grpc_files)
        else:
            args.openapi_spec = [f.strip() for f in args.openapi_spec]
            open_api_docs = self.__OpenApiMessage(args.openapi_spec)

        # Create ApiConfig object.
        # Only piece affected by async right now
        resp = api_configs.Create(
            api_config_ref,
            labels=args.labels,
            display_name=args.display_name,
            backend_auth=args.backend_auth_service_account,
            managed_service_configs=svc_configs,
            grpc_service_defs=grpc_svc_defs,
            open_api_docs=open_api_docs)

        wait = 'Waiting for API Config [{0}] to be created for API [{1}]'.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_)
Esempio n. 11
0
    def Run(self, args):
        api_ref = args.CONCEPTS.api.Parse()
        api_client = apis.ApiClient()

        resp = api_client.Create(api_ref,
                                 managed_service=args.managed_service,
                                 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_)
Esempio n. 12
0
  def Run(self, args):
    gateway_ref = args.CONCEPTS.gateway.Parse()

    gateways_client = gateways.GatewayClient()
    gateway, mask = self.ProcessUpdates(gateways_client.Get(gateway_ref), args)

    resp = gateways_client.Update(gateway, update_mask=mask)

    wait = 'Waiting for API Gateway [{}] to be updated'.format(
        gateway_ref.Name())

    return operations_util.PrintOperationResult(
        resp.name,
        operations.OperationsClient(),
        service=gateways_client.service,
        wait_string=wait,
        is_async=args.async_)
Esempio n. 13
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 = '{}.apigateway.{}.cloud.goog'.format(
            api_ref.Name(), api_ref.projectsId)

        # 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)
            ops.GetOperationResult(res)

        # Create OP ServiceConfig and Rollout
        if args.openapi_spec:
            service_config_id = self.__PushOpenApiServiceFile(
                args.openapi_spec,
                service_name,
                api_config_ref.projectsId,
                config_id=api_config_ref.Name())
        else:
            service_config_id = self.__PushGrpcConfigFiles(
                args.grpc_files,
                service_name,
                api_config_ref.projectsId,
                config_id=api_config_ref.Name())
        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)

        return ops.GetOperationResult(resp, is_async=args.async_)
Esempio n. 14
0
  def Run(self, args):
    gateway_ref = args.CONCEPTS.gateway.Parse()
    api_config_ref = args.CONCEPTS.api_config.Parse()

    gateways_client = gateways.GatewayClient()
    resp = gateways_client.Create(gateway_ref,
                                  api_config_ref,
                                  display_name=args.display_name,
                                  labels=args.labels)

    wait = 'Waiting for API Gateway [{}] to be created with [{}] config'.format(
        gateway_ref.Name(), api_config_ref.RelativeName())

    return operations_util.PrintOperationResult(
        resp.name,
        operations.OperationsClient(),
        service=gateways_client.service,
        wait_string=wait,
        is_async=args.async_)
Esempio n. 15
0
    def Run(self, args):
        client = operations.OperationsClient()
        operation_ref = args.CONCEPTS.operation.Parse()

        # To give a better message for already-completed operations, get the
        # operation here and check if it's already completed.
        operation = client.Get(operation_ref)

        if operation.done:
            msg_prefix = 'Operation has already completed.'
        else:
            # No need to check for the result, errors and timeouts are handled already
            client.WaitForOperation(operation_ref)

            msg_prefix = 'Operation completed successfully.'

        log.status.Print('{} Use the following command for more details:\n\n'
                         'gcloud api-gateway operations describe {}\n'.format(
                             msg_prefix, operation_ref.RelativeName()))
Esempio n. 16
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_)
Esempio n. 17
0
    def Run(self, args):
        """Run 'api-gateway gateways delete'.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
          with.

    Raises:
      OperationCancelledError
    Returns:
      The response from the Delete API call.
    """

        gateway_ref = args.CONCEPTS.gateway.Parse()

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

        resp = gateways.GatewayClient().Delete(gateway_ref.RelativeName())
        operation_ref = resources.REGISTRY.Parse(
            resp.name, collection='apigateway.projects.locations.operations')

        # If async operation, simply log and return the result on passed in object
        if args.async_:
            operations_util.PrintOperationResultWithWaitEpilogue(
                operation_ref, 'Asynchronous operation is in progress')
            return resp

        op_client = operations.OperationsClient()

        return op_client.WaitForOperation(
            operation_ref, 'Waiting for API Gateway [{}] to be deleted'.format(
                gateway_ref.Name()))
Esempio n. 18
0
    def Run(self, args):
        gateway_ref = args.CONCEPTS.gateway.Parse()

        gateways_client = gateways.GatewayClient()
        gateway, mask = self.ProcessUpdates(gateways_client.Get(gateway_ref),
                                            args)

        resp = gateways_client.Update(gateway, update_mask=mask)
        operation_ref = resources.REGISTRY.Parse(
            resp.name, collection='apigateway.projects.locations.operations')

        # If async operation, simply log and return the result on passed in object
        if args.async_:
            operations_util.PrintOperationResultWithWaitEpilogue(
                operation_ref, 'Asynchronous operation is in progress')
            return resp

        op_client = operations.OperationsClient()

        return op_client.WaitForOperation(
            operation_ref, 'Waiting for API Gateway [{}] to be updated'.format(
                gateway_ref.Name()),
            gateways_client.client.projects_locations_gateways)
    def Run(self, args):
        client = operations.OperationsClient()
        operation_ref = args.CONCEPTS.operation.Parse()

        return client.Get(operation_ref)
Esempio n. 20
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 = '{}.apigateway.{}.cloud.goog'.format(
            api_ref.Name(), api_ref.projectsId)

        # 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)
            operation_ref = resources.REGISTRY.Parse(
                res.name,
                collection='apigateway.projects.locations.operations')

            ops.WaitForOperation(
                operation_ref,
                'Waiting for API [{}] to be created'.format(api_ref.Name()))

        # Create OP ServiceConfig and Rollout
        if args.openapi_spec:
            service_config_id = self.__PushOpenApiServiceFile(
                args.openapi_spec,
                service_name,
                api_config_ref.projectsId,
                config_id=api_config_ref.Name())
        else:
            service_config_id = self.__PushGrpcConfigFiles(
                args.grpc_files,
                service_name,
                api_config_ref.projectsId,
                config_id=api_config_ref.Name())
        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)
        operation_ref = resources.REGISTRY.Parse(
            resp.name, collection='apigateway.projects.locations.operations')

        # If async operation, simply log and return the result on passed in object
        if args.async_:
            operations_util.PrintOperationResultWithWaitEpilogue(
                operation_ref, 'Asynchronous operation is in progress')
            return resp

        return ops.WaitForOperation(
            operation_ref,
            'Waiting for API Config [{}] to be created for API [{}]'.format(
                api_config_ref.Name(), api_ref.Name()),
            api_configs.client.projects_locations_apis_configs)