示例#1
0
 def setup_publisher(self):
     """Set up the pubsub publisher."""
     config.LoadConfig()
     # the publisher we will use the pubsub client in googleapiclient.discovery
     # for more information on using the APIs, see
     # https://cloud.google.com/pubsub/docs/reference/rest
     self.pubsub_api_client = gcp_common.CreateService('pubsub', 'v1')
     self.topic_path = 'projects/{0:s}/topics/{1:s}'.format(
         config.TURBINIA_PROJECT, self.topic_name)
     try:
         log.debug('Trying to create pubsub topic {0:s}'.format(
             self.topic_path))
         topics_client = self.pubsub_api_client.projects().topics()
         # the ExecuteRequest takes API URI, method name as string and parameters
         # as a dict, it executes the API call, handles paging and return response.
         gcp_common.ExecuteRequest(topics_client, 'create',
                                   {'name': self.topic_path})
     except HttpError as exception:
         if exception.resp.status == 409:
             log.debug('PubSub topic {0:s} already exists.'.format(
                 self.topic_path))
         else:
             raise TurbiniaException(
                 'Unknown error occurred when creating Topic:'
                 ' {0!s}'.format(exception), __name__) from exception
     log.debug('Setup PubSub publisher at {0:s}'.format(self.topic_path))
    def GcsApi(self) -> 'googleapiclient.discovery.Resource':
        """Get a Google Cloud Storage service object.

    Returns:
      googleapiclient.discovery.Resource: A Google Cloud Storage service object.
    """

        if self.gcs_api_client:
            return self.gcs_api_client
        self.gcs_api_client = common.CreateService(
            'storage', self.CLOUD_STORAGE_API_VERSION)
        return self.gcs_api_client
示例#3
0
  def GoogleCloudSQLApi(self) -> 'googleapiclient.discovery.Resource':
    """Get a Google CloudSQL service object.

    Returns:
      googleapiclient.discovery.Resource: A Google CloudSQL service object.
    """

    if self.gcsql_api_client:
      return self.gcsql_api_client
    self.gcsql_api_client = common.CreateService(
        'sqladmin', self.SQLADMIN_API_VERSION)
    return self.gcsql_api_client
示例#4
0
    def GcbApi(self) -> 'googleapiclient.discovery.Resource':
        """Get a Google Cloud Build service object.

    Returns:
      googleapiclient.discovery.Resource: A Google Cloud Build service object.
    """

        if self.gcb_api_client:
            return self.gcb_api_client
        self.gcb_api_client = common.CreateService(
            'cloudbuild', self.CLOUD_BUILD_API_VERSION)
        return self.gcb_api_client
示例#5
0
    def GcmApi(self) -> 'googleapiclient.discovery.Resource':
        """Get a Google Cloud Monitoring service object.

    Returns:
      googleapiclient.discovery.Resource: A Google Cloud Monitoring
          service object.
    """
        if self.gcm_api_client:
            return self.gcm_api_client
        self.gcm_api_client = common.CreateService(
            'monitoring', self.CLOUD_MONITORING_API_VERSION)
        return self.gcm_api_client
  def GcfApi(self) -> 'googleapiclient.discovery.Resource':
    """Get a Google Cloud Function service object.

    Returns:
      googleapiclient.discovery.Resource: A Google Cloud Function service
          object.
    """

    if self.gcf_api_client:
      return self.gcf_api_client
    self.gcf_api_client = common.CreateService(
        'cloudfunctions', self.CLOUD_FUNCTIONS_API_VERSION)
    return self.gcf_api_client
示例#7
0
    def GclApi(self) -> 'googleapiclient.discovery.Resource':
        """Get a Google Compute Logging service object.

    Returns:
      googleapiclient.discovery.Resource: A Google Compute Logging service
          object.
    """

        if self.gcl_api_client:
            return self.gcl_api_client
        self.gcl_api_client = common.CreateService('logging',
                                                   self.LOGGING_API_VERSION)
        return self.gcl_api_client
    def GkeApi(self) -> 'googleapiclient.discovery.Resource':
        """Gets a Google Container service object.

    https://container.googleapis.com/$discovery/rest?version=v1

    Returns:
      googleapiclient.discovery.Resource: A Google Container service object.
    """

        if self.gke_api_client:
            return self.gke_api_client
        self.gke_api_client = common.CreateService('container',
                                                   self.GKE_API_VERSION)
        return self.gke_api_client