Пример #1
0
def _UpdateADC(creds):
    """Updates the ADC json with the credentials creds."""
    old_adc_json = command_auth_util.GetADCAsJson()
    command_auth_util.WriteGcloudCredentialsToADC(creds)
    new_adc_json = command_auth_util.GetADCAsJson()
    if new_adc_json and new_adc_json != old_adc_json:
        adc_msg = '\nApplication default credentials (ADC) were updated.'
        quota_project = command_auth_util.GetQuotaProjectFromADC()
        if quota_project:
            adc_msg = adc_msg + (
                "\n'{}' is added to ADC as the quota project.\nTo "
                'just update the quota project in ADC, use $gcloud auth '
                'application-default set-quota-project.'.format(quota_project))
        log.status.Print(adc_msg)
Пример #2
0
def GetUserCredential():
    """Get a copy of the application default credential for a user.

  Returns:
    Text version of the user's application default credential.
  """
    auth_util.AssertADCExists()
    return json.dumps(auth_util.GetADCAsJson())
Пример #3
0
def GetUserCredential():
  """Get a copy of the application default credential for a user.

  Returns:
    Text version of the user's application default credential.
  Raises:
    ADCMissingError: Application Default Credential is not present.
  """
  adc = auth_util.GetADCAsJson()
  if not adc:
    raise ADCMissingError('No user credential present. Run '
                          '`$ gcloud auth application-default login`.')
  return json.dumps(adc)