stackdriver_service.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:spinnaker-monitoring 作者: spinnaker 项目源码 文件源码
def make_stub(options):
  """Helper function for making a stub to talk to service."""
  if not stackdriver_available:
      raise ImportError(
          'You must "pip install google-api-python-client oauth2client" to get the stackdriver client library.')

  stackdriver_config = options.get('stackdriver', {})
  credentials_path = options.get('credentials_path', None)
  if credentials_path is None:
    credentials_path = stackdriver_config.get('credentials_path')
  if credentials_path:
    credentials_path = os.path.expandvars(credentials_path)

  http = httplib2.Http()
  http = apiclient.http.set_user_agent(
      http, 'SpinnakerStackdriverAgent/0.001')
  if credentials_path:
    logging.info('Using Stackdriver Credentials from "%s"', credentials_path)
    credentials = ServiceAccountCredentials.from_json_keyfile_name(
        credentials_path, scopes=StackdriverMetricsService.WRITE_SCOPE)
  else:
    logging.info('Using Stackdriver Credentials from application default.')
    credentials = GoogleCredentials.get_application_default()

  http = credentials.authorize(http)
  developer_key = os.environ.get('STACKDRIVER_API_KEY',
                                 options.get('stackdriver', {}).get('api_key'))
  if developer_key:
    url = 'https://monitoring.googleapis.com/$discovery/rest?labels=DASHBOARD_TRUSTED_TESTER&key=' + developer_key
    return apiclient.discovery.build(
        'monitoring', 'v3', http=http,
        discoveryServiceUrl=url)
  else:
    return apiclient.discovery.build('monitoring', 'v3', http=http)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号