Esempio n. 1
0
  def Run(self, args):
    """Run command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      None
    """

    client = apikeys.GetClientInstance()
    messages = client.MESSAGES_MODULE

    key_ref = args.CONCEPTS.key.Parse()
    request = messages.ApikeysProjectsKeysCloneRequest(
        name=key_ref.RelativeName())
    op = client.projects_keys.Clone(request)
    if not op.done:
      if args.async_:
        cmd = OP_WAIT_CMD.format(op.name)
        log.status.Print('Asynchronous operation is in progress... '
                         'Use the following command to wait for its '
                         'completion:\n {0}'.format(cmd))
        return op
      op = services_util.WaitOperation(op.name, apikeys.GetOperation)
    services_util.PrintOperationWithResponse(op)
    def Run(self, args):
        """Run command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      None
    """

        client = apikeys.GetClientInstance()
        messages = client.MESSAGES_MODULE

        key_ref = args.CONCEPTS.key.Parse()
        update_mask = []
        key_proto = messages.V2Key(name=key_ref.RelativeName(),
                                   restrictions=messages.V2Restrictions())
        if args.IsSpecified('display_name'):
            update_mask.append('display_name')
            key_proto.displayName = args.display_name
        if args.IsSpecified('clear_restrictions'):
            update_mask.append('restrictions')
        else:
            if args.IsSpecified('allowed_referrers'):
                update_mask.append('restrictions.browser_key_restrictions')
                key_proto.restrictions.browserKeyRestrictions = messages.V2BrowserKeyRestrictions(
                    allowedReferrers=args.allowed_referrers)
            elif args.IsSpecified('allowed_ips'):
                update_mask.append('restrictions.server_key_restrictions')
                key_proto.restrictions.serverKeyRestrictions = messages.V2ServerKeyRestrictions(
                    allowedIps=args.allowed_ips)
            elif args.IsSpecified('allowed_bundle_ids'):
                update_mask.append('restrictions.ios_key_restrictions')
                key_proto.restrictions.iosKeyRestrictions = messages.V2IosKeyRestrictions(
                    allowedBundleIds=args.allowed_bundle_ids)
            elif args.IsSpecified('allowed_application'):
                update_mask.append('restrictions.android_key_restrictions')
                key_proto.restrictions.androidKeyRestrictions = messages.V2AndroidKeyRestrictions(
                    allowedApplications=apikeys.GetAllowedAndroidApplications(
                        args, messages))
            if args.IsSpecified('api_target'):
                update_mask.append('restrictions.api_targets')
                key_proto.restrictions.apiTargets = apikeys.GetApiTargets(
                    args, messages)
        request = messages.ApikeysProjectsLocationsKeysPatchRequest(
            name=key_ref.RelativeName(),
            updateMask=','.join(update_mask),
            v2Key=key_proto)
        op = client.projects_locations_keys.Patch(request)
        if not op.done:
            if args.async_:
                cmd = OP_WAIT_CMD.format(op.name)
                log.status.Print('Asynchronous operation is in progress... '
                                 'Use the following command to wait for its '
                                 'completion:\n {0}'.format(cmd))
                return op
            op = services_util.WaitOperation(op.name, apikeys.GetOperation)
        services_util.PrintOperationWithResponse(op)
        return op
Esempio n. 3
0
    def Run(self, args):
        """Run command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      None
    """
        project_id = properties.VALUES.core.project.GetOrFail()

        client = apikeys.GetClientInstance()
        messages = client.MESSAGES_MODULE

        key_proto = messages.V2alpha1ApiKey(
            restrictions=messages.V2alpha1Restrictions())
        if args.IsSpecified('display_name'):
            key_proto.displayName = args.display_name
        if args.IsSpecified('allowed_referrers'):
            key_proto.restrictions.browserKeyRestrictions = messages.V2alpha1BrowserKeyRestrictions(
                allowedReferrers=args.allowed_referrers)
        elif args.IsSpecified('allowed_ips'):
            key_proto.restrictions.serverKeyRestrictions = messages.V2alpha1ServerKeyRestrictions(
                allowedIps=args.allowed_ips)
        elif args.IsSpecified('allowed_bundle_ids'):
            key_proto.restrictions.iosKeyRestrictions = messages.V2alpha1IosKeyRestrictions(
                allowedBundleIds=args.allowed_bundle_ids)
        elif args.IsSpecified('allowed_application'):
            key_proto.restrictions.androidKeyRestrictions = messages.V2alpha1AndroidKeyRestrictions(
                allowedApplications=apikeys.GetAllowedAndroidApplications(
                    args, messages))
        if args.IsSpecified('api_target'):
            key_proto.restrictions.apiTargets = apikeys.GetApiTargets(
                args, messages)
        request = messages.ApikeysProjectsKeysCreateRequest(
            parent=apikeys.GetParentResourceName(project_id),
            v2alpha1ApiKey=key_proto)
        op = client.projects_keys.Create(request)
        if not op.done:
            if args.async_:
                cmd = OP_WAIT_CMD.format(op.name)
                log.status.Print('Asynchronous operation is in progress... '
                                 'Use the following command to wait for its '
                                 'completion:\n {0}'.format(cmd))
                return op
            op = services_util.WaitOperation(op.name, apikeys.GetOperation)
        services_util.PrintOperationWithResponse(op)
Esempio n. 4
0
    def Run(self, args):
        """Run 'services operations describe'.

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

    Returns:
      The response from the operations.Get API call.
    """
        namespace = common_flags.get_operation_namespace(args.operation)
        get_op_func = _GET_OP_FUNC_MAP.get(namespace,
                                           serviceusage.GetOperation)

        op = get_op_func(args.operation)
        services_util.PrintOperationWithResponse(op)