Пример #1
0
  def Run(self, args):
    """Run 'service-management api-keys create'.

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

    Returns:
      The response from the keys API call.
    """
    messages = services_util.GetApiKeysMessagesModule()
    client = services_util.GetApiKeysClientInstance()

    # Construct the List API Key request object
    request = messages.ApikeysProjectsApiKeysListRequest(
        projectId=properties.VALUES.core.project.Get(required=True),
        pageSize=args.limit)

    return client.projects_apiKeys.List(request)
Пример #2
0
    def _ConstructApiKeyRequest(self, project, key_type, allowed_entities,
                                display_name):
        messages = services_util.GetApiKeysMessagesModule()

        if key_type == 'browser':
            key_details = messages.BrowserKeyDetails()
            if allowed_entities:
                key_details.allowedReferrers.extend(allowed_entities)
            api_key = messages.ApiKey(browserKeyDetails=key_details)
        elif key_type == 'server':
            key_details = messages.ServerKeyDetails()
            if allowed_entities:
                key_details.allowedIps.extend(allowed_entities)
            api_key = messages.ApiKey(serverKeyDetails=key_details)
        elif key_type == 'ios':
            key_details = messages.IosKeyDetails()
            if allowed_entities:
                key_details.allowedBundleIds.extend(allowed_entities)
            api_key = messages.ApiKey(iosKeyDetails=key_details)
        elif key_type == 'android':

            def _ConstructAndroidApplication(package, fingerprint):
                return messages.AndroidApplication(
                    sha1Fingerprint=services_util.GetByteStringFromFingerprint(
                        fingerprint),
                    packageName=package)

            if allowed_entities:
                apps = [p.split(',') for p in allowed_entities]

            key_details = messages.AndroidKeyDetails()
            key_details.allowedApplications.extend(
                [_ConstructAndroidApplication(p, f) for (p, f) in apps])
            api_key = messages.ApiKey(androidKeyDetails=key_details)

        api_key.displayName = display_name

        return messages.ApikeysProjectsApiKeysCreateRequest(projectId=project,
                                                            apiKey=api_key)
Пример #3
0
  def Run(self, args):
    """Run 'service-management api-keys delete'.

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

    Returns:
      The response from the keys API call.
    """
    messages = services_util.GetApiKeysMessagesModule()
    client = services_util.GetApiKeysClientInstance()

    # Construct the Delete API Key request object
    request = messages.ApikeysProjectsApiKeysDeleteRequest(
        projectId=properties.VALUES.core.project.Get(required=True),
        keyId=args.key)

    result = client.projects_apiKeys.Delete(request)

    # Note that we expect an empty proto as a result (google.protobuf.Empty).
    # If that's what we receive, we can assume success.
    return result or {'key': args.key, 'success': True}
Пример #4
0
 def apikeys_messages(self):
     return services_util.GetApiKeysMessagesModule()