Example #1
0
    def Run(self, args):
        """Run command.

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

    Returns:
      The response from the Undelete API call.
    """

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

        key_ref = args.CONCEPTS.key.Parse()
        request = messages.ApikeysProjectsKeysUndeleteRequest(
            name=key_ref.RelativeName())
        op = client.projects_keys.Undelete(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)
        log.status.Print('Operation [{0}] complete. Result: {1}'.format(
            op.name,
            json.dumps(encoding.MessageToDict(op.response),
                       sort_keys=True,
                       indent=4,
                       separators=(',', ':'))))
  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
Example #4
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)
Example #5
0
  def Run(self, args):
    """Run command.

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

    Returns:
      Resource name and its parent name.
    """

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

    request = messages.ApikeysGetKeyStringNameRequest(keyString=args.key_string)
    return client.v2alpha1.GetKeyStringName(request)
    def Run(self, args):
        """Run command.

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

    Returns:
      Key string.
    """

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

        key_ref = args.CONCEPTS.key.Parse()
        request = messages.ApikeysProjectsLocationsKeysGetKeyStringRequest(
            name=key_ref.RelativeName())
        return client.projects_locations_keys.GetKeyString(request)