Exemple #1
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)
    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')
Exemple #3
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()))
Exemple #4
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)
Exemple #5
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)