@@ -62,21 +62,22 @@ public class GoogleCredentials extends OAuth2Credentials implements QuotaProject
6262
6363 static final String QUOTA_PROJECT_ID_HEADER_KEY = "x-goog-user-project" ;
6464
65- enum GoogleCredentialsType {
65+ enum GoogleCredentialsInfo {
6666 USER_CREDENTIALS ("User Credentials" , "authorized_user" ),
6767 SERVICE_ACCOUNT_CREDENTIALS ("Service Account Credentials" , "service_account" ),
6868 GDCH_CREDENTIALS ("GDCH Credentials" , "gdch_service_account" ),
6969 EXTERNAL_ACCOUNT_CREDENTIALS ("External Account Credentials" , "external_account" ),
70- EXTERNAL_ACCOUNT_AUTHORIZED_USER_CREDENTIALS ("External Account Authorized User Credentials" , "external_account_authorized_user" ),
71- IMPERSONATED_CREDENTIALS ("Impersonated Credentials" ,"impersonated_service_account" ),
70+ EXTERNAL_ACCOUNT_AUTHORIZED_USER_CREDENTIALS (
71+ "External Account Authorized User Credentials" , "external_account_authorized_user" ),
72+ IMPERSONATED_CREDENTIALS ("Impersonated Credentials" , "impersonated_service_account" ),
7273 APP_ENGINE_CREDENTIALS ("App Engine Credentials" , null ),
7374 CLOUD_SHELL_CREDENTIALS ("Cloud Shell Credentials" , null ),
7475 COMPUTE_ENGINE_CREDENTIALS ("Compute Engine Credentials" , null );
7576
7677 private final String credentialName ;
7778 private final String fileType ;
7879
79- GoogleCredentialsType (String credentialName , String fileType ) {
80+ GoogleCredentialsInfo (String credentialName , String fileType ) {
8081 this .credentialName = credentialName ;
8182 this .fileType = fileType ;
8283 }
@@ -90,12 +91,11 @@ public String getFileType() {
9091 }
9192 }
9293
93-
9494 /* The following package-private fields provide additional info for errors message */
9595 // Source of the credential (e.g. env var value or well know file location)
9696 String source ;
9797 // User-friendly name of actual Credential class
98- String type ;
98+ String name ;
9999 // Identity of the credential (not all credentials will have this)
100100 String principal ;
101101
@@ -242,35 +242,37 @@ public static GoogleCredentials fromStream(
242242 throw new IOException ("Error reading credentials from stream, 'type' field not specified." );
243243 }
244244
245- if (GoogleCredentialsType .USER_CREDENTIALS .getFileType ().equals (fileType )) {
245+ if (GoogleCredentialsInfo .USER_CREDENTIALS .getFileType ().equals (fileType )) {
246246 return UserCredentials .fromJson (fileContents , transportFactory );
247247 }
248- if (GoogleCredentialsType .SERVICE_ACCOUNT_CREDENTIALS .getFileType ().equals (fileType )) {
248+ if (GoogleCredentialsInfo .SERVICE_ACCOUNT_CREDENTIALS .getFileType ().equals (fileType )) {
249249 return ServiceAccountCredentials .fromJson (fileContents , transportFactory );
250250 }
251- if (GoogleCredentialsType .GDCH_CREDENTIALS .getFileType ().equals (fileType )) {
251+ if (GoogleCredentialsInfo .GDCH_CREDENTIALS .getFileType ().equals (fileType )) {
252252 return GdchCredentials .fromJson (fileContents );
253253 }
254- if (GoogleCredentialsType .EXTERNAL_ACCOUNT_CREDENTIALS .getFileType ().equals (fileType )) {
254+ if (GoogleCredentialsInfo .EXTERNAL_ACCOUNT_CREDENTIALS .getFileType ().equals (fileType )) {
255255 return ExternalAccountCredentials .fromJson (fileContents , transportFactory );
256256 }
257- if (GoogleCredentialsType .EXTERNAL_ACCOUNT_AUTHORIZED_USER_CREDENTIALS .getFileType ().equals (fileType )) {
257+ if (GoogleCredentialsInfo .EXTERNAL_ACCOUNT_AUTHORIZED_USER_CREDENTIALS
258+ .getFileType ()
259+ .equals (fileType )) {
258260 return ExternalAccountAuthorizedUserCredentials .fromJson (fileContents , transportFactory );
259261 }
260- if (GoogleCredentialsType .IMPERSONATED_CREDENTIALS .getFileType ().equals (fileType )) {
262+ if (GoogleCredentialsInfo .IMPERSONATED_CREDENTIALS .getFileType ().equals (fileType )) {
261263 return ImpersonatedCredentials .fromJson (fileContents , transportFactory );
262264 }
263265 throw new IOException (
264266 String .format (
265267 "Error reading credentials from stream, 'type' value '%s' not recognized."
266268 + " Valid values are '%s', '%s', '%s', '%s', '%s', '%s'." ,
267269 fileType ,
268- GoogleCredentialsType .USER_CREDENTIALS .getFileType (),
269- GoogleCredentialsType .SERVICE_ACCOUNT_CREDENTIALS .getFileType (),
270- GoogleCredentialsType .GDCH_CREDENTIALS .getFileType (),
271- GoogleCredentialsType .EXTERNAL_ACCOUNT_CREDENTIALS .getFileType (),
272- GoogleCredentialsType .EXTERNAL_ACCOUNT_AUTHORIZED_USER_CREDENTIALS .getFileType (),
273- GoogleCredentialsType .IMPERSONATED_CREDENTIALS .getFileType ()));
270+ GoogleCredentialsInfo .USER_CREDENTIALS .getFileType (),
271+ GoogleCredentialsInfo .SERVICE_ACCOUNT_CREDENTIALS .getFileType (),
272+ GoogleCredentialsInfo .GDCH_CREDENTIALS .getFileType (),
273+ GoogleCredentialsInfo .EXTERNAL_ACCOUNT_CREDENTIALS .getFileType (),
274+ GoogleCredentialsInfo .EXTERNAL_ACCOUNT_AUTHORIZED_USER_CREDENTIALS .getFileType (),
275+ GoogleCredentialsInfo .IMPERSONATED_CREDENTIALS .getFileType ()));
274276 }
275277
276278 /**
@@ -543,11 +545,14 @@ GoogleCredentials withSource(String source) {
543545
544546 /**
545547 * Provides additional information regarding credential initialization source
548+ *
546549 * <ul>
547- * <li> credential source - Initialized via the GOOGLE_APPLICATION_CREDENTIALS env var or well known file type
548- * <li> credential type - The type of credential created
549- * <li> principal - Identity used for the credential
550+ * <li>credential source - Initialized via the GOOGLE_APPLICATION_CREDENTIALS env var or well
551+ * known file type
552+ * <li>credential name - The user-friendly name of the credential created
553+ * <li>principal - Identity used for the credential
550554 * </ul>
555+ *
551556 * These fields are populated on a best-effort basis and may be populated missing
552557 *
553558 * @return Map of information regarding how the Credential was initialized
@@ -557,8 +562,8 @@ public Map<String, String> getCredentialInfo() {
557562 if (!Strings .isNullOrEmpty (source )) {
558563 infoMap .put ("Credential Source" , source );
559564 }
560- if (!Strings .isNullOrEmpty (type )) {
561- infoMap .put ("Credential Type " , type );
565+ if (!Strings .isNullOrEmpty (name )) {
566+ infoMap .put ("Credential Name " , name );
562567 }
563568 if (!Strings .isNullOrEmpty (principal )) {
564569 infoMap .put ("Principal" , principal );
0 commit comments