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())
def testDumpADCOptionalQuotaProject_NoQuotaProject(self): self.StartObjectPatch(creds, 'GetQuotaProject').return_value = None auth_util.DumpADCOptionalQuotaProject(self.MakeUserCredentials()) auth_util.AssertADCExists() self.AssertQuotaProjectEquals(None) self.AssertErrContains('Credentials saved to file') self.AssertErrContains('Cannot find a quota project') self.adc_permission_checking.assert_not_called()
def testDumpADCRequiredQuotaProject_WithPermission(self): self.adc_permission_checking.return_value = True auth_util.WriteGcloudCredentialsToADC( creds.FromJson(self.USER_CREDENTIALS_JSON)) auth_util.AddQuotaProjectToADC(self.fake_project) auth_util.AssertADCExists() self.AssertQuotaProjectEquals(self.fake_project) self.AssertErrContains('Credentials saved to file') self.AssertErrContains('Quota project "{}" was added to ADC'.format( self.fake_project)) self.adc_permission_checking.assert_called()
def testDumpADCOptionalQuotaProject_WithoutPermission(self): self.StartObjectPatch( creds, 'GetQuotaProject').return_value = self.fake_project self.adc_permission_checking.return_value = False auth_util.DumpADCOptionalQuotaProject(self.MakeUserCredentials()) auth_util.AssertADCExists() self.AssertQuotaProjectEquals(None) self.AssertErrContains('Credentials saved to file') self.AssertErrContains('Cannot add the project "{}" to ADC'.format( self.fake_project)) self.adc_permission_checking.assert_called()