@@ -88,18 +88,19 @@ String getCredentialName() {
8888 return credentialName ;
8989 }
9090
91+ @ Nullable
9192 String getFileType () {
9293 return fileType ;
9394 }
9495 }
9596
96- /* The following package-private fields to provide additional info for errors message */
97+ // The following package-private fields to provide additional info for errors message
9798 // Source of the credential (e.g. env var value or well know file location)
9899 String source ;
99100 // User-friendly name of the Credential class
100101 String name ;
101102 // Identity of the credential
102- // Note: This field is marked transient to prevent it from being serialized
103+ // Note: This field may contain data such as serviceAccountEmail which should not be serialized
103104 transient String principal ;
104105
105106 private final String universeDomain ;
@@ -245,24 +246,23 @@ public static GoogleCredentials fromStream(
245246 throw new IOException ("Error reading credentials from stream, 'type' field not specified." );
246247 }
247248
248- if (GoogleCredentialsInfo .USER_CREDENTIALS .getFileType (). equals ( fileType )) {
249+ if (fileType . equals ( GoogleCredentialsInfo .USER_CREDENTIALS .getFileType ())) {
249250 return UserCredentials .fromJson (fileContents , transportFactory );
250251 }
251- if (GoogleCredentialsInfo .SERVICE_ACCOUNT_CREDENTIALS .getFileType (). equals ( fileType )) {
252+ if (fileType . equals ( GoogleCredentialsInfo .SERVICE_ACCOUNT_CREDENTIALS .getFileType ())) {
252253 return ServiceAccountCredentials .fromJson (fileContents , transportFactory );
253254 }
254- if (GoogleCredentialsInfo .GDCH_CREDENTIALS .getFileType (). equals ( fileType )) {
255+ if (fileType . equals ( GoogleCredentialsInfo .GDCH_CREDENTIALS .getFileType ())) {
255256 return GdchCredentials .fromJson (fileContents );
256257 }
257- if (GoogleCredentialsInfo .EXTERNAL_ACCOUNT_CREDENTIALS .getFileType (). equals ( fileType )) {
258+ if (fileType . equals ( GoogleCredentialsInfo .EXTERNAL_ACCOUNT_CREDENTIALS .getFileType ())) {
258259 return ExternalAccountCredentials .fromJson (fileContents , transportFactory );
259260 }
260- if (GoogleCredentialsInfo .EXTERNAL_ACCOUNT_AUTHORIZED_USER_CREDENTIALS
261- .getFileType ()
262- .equals (fileType )) {
261+ if (fileType .equals (
262+ GoogleCredentialsInfo .EXTERNAL_ACCOUNT_AUTHORIZED_USER_CREDENTIALS .getFileType ())) {
263263 return ExternalAccountAuthorizedUserCredentials .fromJson (fileContents , transportFactory );
264264 }
265- if (GoogleCredentialsInfo .IMPERSONATED_CREDENTIALS .getFileType (). equals ( fileType )) {
265+ if (fileType . equals ( GoogleCredentialsInfo .IMPERSONATED_CREDENTIALS .getFileType ())) {
266266 return ImpersonatedCredentials .fromJson (fileContents , transportFactory );
267267 }
268268 throw new IOException (
@@ -556,9 +556,14 @@ GoogleCredentials withSource(String source) {
556556 * <li>principal - Identity used for the credential
557557 * </ul>
558558 *
559- * Unknown field values are not included in the mapping (e.g. ComputeCredentials may not know the
560- * principal value until after a call to MDS is made and will be excluded if `getCredentialInfo`
561- * is called prior to retrieving that value)
559+ * Unknown field values (i.e. null) are not included in the mapping (e.g. ComputeCredentials may
560+ * not know the principal value until after a call to MDS is made and the field will be excluded
561+ * if `getCredentialInfo` is called prior to retrieving that value). A new map of the fields is
562+ * created on every time this method is called as fields may be updated throughout the Credential
563+ * lifecycle. This mapping is intended to provide information about the Credential that is created
564+ * via ADC. Some fields may not be known if a Credential is directly created (e.g.
565+ * `ServiceAccountCredential.fromStream(InputStream)` may not know the source of the file stream).
566+ * These fields are populated on a best effort basis.
562567 *
563568 * @return ImmutableMap of information regarding how the Credential was initialized
564569 */
0 commit comments