@@ -75,8 +75,16 @@ public class GdchCredentials extends GoogleCredentials {
7575 private static final LoggerProvider LOGGER_PROVIDER =
7676 LoggerProvider .forClazz (GdchCredentials .class );
7777 private static final String PARSE_ERROR_PREFIX = "Error parsing token refresh response. " ;
78- @ VisibleForTesting static final String SUPPORTED_FORMAT_VERSION = "1" ;
7978
79+ /**
80+ * The expected format version for GDCH credential profiles.
81+ * Version "1" indicates the initial and currently supported JSON format for these credentials.
82+ * See go/gdch-python-auth-lib for more info.
83+ */
84+ @ VisibleForTesting static final String SUPPORTED_JSON_FORMAT_VERSION = "1" ;
85+
86+ // Custom URN used by GDCH to identify service account tokens in token exchange requests.
87+ // See go/gdch-python-auth-lib for more information.
8088 private static final String SERVICE_ACCOUNT_TOKEN_TYPE =
8189 "urn:k8s:params:oauth:token-type:serviceaccount" ;
8290
@@ -198,9 +206,9 @@ static GdchCredentials fromJson(Map<String, Object> json, HttpTransportFactory t
198206 validateField ((String ) json .get ("token_uri" ), "token_uri" );
199207 String caCertPath = (String ) json .get ("ca_cert_path" );
200208
201- if (!SUPPORTED_FORMAT_VERSION .equals (formatVersion )) {
209+ if (!SUPPORTED_JSON_FORMAT_VERSION .equals (formatVersion )) {
202210 throw new IOException (
203- String .format ("Only format version %s is supported." , SUPPORTED_FORMAT_VERSION ));
211+ String .format ("Only format version %s is supported." , SUPPORTED_JSON_FORMAT_VERSION ));
204212 }
205213
206214 URI tokenServerUriFromCreds = null ;
@@ -247,10 +255,8 @@ static GdchCredentials fromPkcs8(String privateKeyPkcs8, GdchCredentials.Builder
247255 */
248256 @ ObsoleteApi ("Use createWithGdchAudience(String) instead." )
249257 public GdchCredentials createWithGdchAudience (URI apiAudience ) {
250- if (apiAudience == null ) {
251- throw new IllegalArgumentException (
252- "Audience cannot be null or empty for GDCH service account credentials." );
253- }
258+ Preconditions .checkNotNull (
259+ apiAudience , "Audience are not configured for GDCH service account credentials." );
254260 return this .toBuilder ().setGdchAudience (apiAudience .toString ()).build ();
255261 }
256262
@@ -372,6 +378,9 @@ static String getIssuerSubjectValue(String projectId, String serviceIdentityName
372378 return String .format ("system:serviceaccount:%s:%s" , projectId , serviceIdentityName );
373379 }
374380
381+ /**
382+ * @return the projectId set in the GDCH SA Key file or the user set projectId
383+ */
375384 @ Override
376385 public final String getProjectId () {
377386 return projectId ;
@@ -571,16 +580,7 @@ public Builder setGdchAudience(String apiAudience) {
571580 return this ;
572581 }
573582
574- @ CanIgnoreReturnValue
575- @ ObsoleteApi ("Use setGdchAudience(String) instead" )
576- public Builder setGdchAudience (URI apiAudience ) {
577- if (apiAudience == null ) {
578- throw new IllegalArgumentException (
579- "Audience cannot be null for GDCH service account credentials." );
580- }
581- this .apiAudience = apiAudience .toString ();
582- return this ;
583- }
583+
584584
585585 public String getProjectId () {
586586 return projectId ;
0 commit comments