utils/audio_upload.py [288:358]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def _GetClientCredentials(impersonated_service_account):
  """Gets client credentials for GCP requests.

  If an account to impersonate is provided, then it will be used rather than the
  default. Otherwise, default gcloud credentials will be used.

  Args:
      impersonated_service_account: The service account to impersonate.

  Returns:
      A credential for requests to GCP.
  """
  creds, _ = google.auth.default(
      scopes=['https://www.googleapis.com/auth/cloud-platform']
  )
  if not impersonated_service_account:
    return creds
  target_scopes = ['https://www.googleapis.com/auth/cloud-platform']
  target_credentials = impersonated_credentials.Credentials(
      source_credentials=creds,
      target_principal=impersonated_service_account,
      target_scopes=target_scopes,
      lifetime=3600,
  )
  # Override the source credentials so refresh will work.
  # See https://github.com/googleapis/google-auth-library-python/issues/416.
  # pylint: disable=protected-access
  target_credentials._source_credentials._scopes = creds.scopes
  return target_credentials


def _GetOauthToken(impersonated_service_account):
  """Gets an oauth token to use for HTTP requests to GCP.

  Assumes usage of Gcloud credentials.

  Args:
      impersonated_service_account: The service account to impersonate.

  Returns:
      The oauth token.
  """
  creds = _GetClientCredentials(impersonated_service_account)
  auth_req = google.auth.transport.requests.Request()
  creds.refresh(auth_req)
  return creds.token


# Needs modification based on customer's XML structure/fields
def _GetMetaData(file):
  """Parse XML file to get metadata.

  Args:
    file: XML file name

  Returns:
    data: Dictionary consisting of metadata
  """
  tree = ET.parse(file)
  root = tree.getroot()

  data = {}
  data['duration'] = str(root[0][1].text)
  data['agent_id'] = str(root[0][6].text)
  data['channel'] = str(root[0][8].text)
  data['sid'] = str(root[0][10].text)
  data['dbs'] = str(root[0][11].text)
  data['no_of_holds'] = str(root[0][13].text)
  data['hold_time'] = str(root[0][16].text)

  return data
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



utils/import_conversations_v2.py [601:671]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def _GetClientCredentials(impersonated_service_account):
  """Gets client credentials for GCP requests.

  If an account to impersonate is provided, then it will be used rather than the
  default. Otherwise, default gcloud credentials will be used.

  Args:
      impersonated_service_account: The service account to impersonate.

  Returns:
      A credential for requests to GCP.
  """
  creds, _ = google.auth.default(
      scopes=['https://www.googleapis.com/auth/cloud-platform']
  )
  if not impersonated_service_account:
    return creds
  target_scopes = ['https://www.googleapis.com/auth/cloud-platform']
  target_credentials = impersonated_credentials.Credentials(
      source_credentials=creds,
      target_principal=impersonated_service_account,
      target_scopes=target_scopes,
      lifetime=3600,
  )
  # Override the source credentials so refresh will work.
  # See https://github.com/googleapis/google-auth-library-python/issues/416.
  # pylint: disable=protected-access
  target_credentials._source_credentials._scopes = creds.scopes
  return target_credentials


def _GetOauthToken(impersonated_service_account):
  """Gets an oauth token to use for HTTP requests to GCP.

  Assumes usage of Gcloud credentials.

  Args:
      impersonated_service_account: The service account to impersonate.

  Returns:
      The oauth token.
  """
  creds = _GetClientCredentials(impersonated_service_account)
  auth_req = google.auth.transport.requests.Request()
  creds.refresh(auth_req)
  return creds.token


# Needs modification based on customer's XML structure/fields
def _GetMetaData(file):
  """Parse XML file to get metadata.

  Args:
      file: XML file name

  Returns:
      data: Dictionary consisting of metadata
  """
  tree = ET.parse(file)
  root = tree.getroot()

  data = {}
  data['duration'] = str(root[0][1].text)
  data['agent_id'] = str(root[0][6].text)
  data['channel'] = str(root[0][8].text)
  data['sid'] = str(root[0][10].text)
  data['dbs'] = str(root[0][11].text)
  data['no_of_holds'] = str(root[0][13].text)
  data['hold_time'] = str(root[0][16].text)

  return data
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



