@@ -109,14 +109,38 @@ public class ComputeEngineCredentials extends GoogleCredentials
109109 static final int MAX_COMPUTE_PING_TRIES = 3 ;
110110 static final int COMPUTE_PING_CONNECTION_TIMEOUT_MS = 500 ;
111111
112- public enum Transport {
113- ALTS ,
114- MTLS
112+ public enum AuthTransport {
113+ // Authenticating to Google APIs via DirectPath
114+ ALTS ("alts" ),
115+ // Authenticating to Google APIs via GFE
116+ MTLS ("mtls" );
117+
118+ private final String label ;
119+
120+ private AuthTransport (String label ) {
121+ this .label = label ;
122+ }
123+
124+ public String getLabel () {
125+ return label ;
126+ }
115127 }
116128
117129 public enum BindingEnforcement {
118- ON ,
119- IAMPOLICY
130+ // Binding enforcement will always happen, irrespective of the IAM policy.
131+ ON ("on" ),
132+ // Binding enforcement will depend on IAM policy.
133+ IAMPOLICY ("iam-policy" );
134+
135+ private final String label ;
136+
137+ private BindingEnforcement (String label ) {
138+ this .label = label ;
139+ }
140+
141+ public String getLabel () {
142+ return label ;
143+ }
120144 }
121145
122146 private static final String METADATA_FLAVOR = "Metadata-Flavor" ;
@@ -132,7 +156,7 @@ public enum BindingEnforcement {
132156
133157 private final Collection <String > scopes ;
134158
135- private final Transport transport ;
159+ private final AuthTransport transport ;
136160 private final BindingEnforcement bindingEnforcement ;
137161
138162 private transient HttpTransportFactory transportFactory ;
@@ -218,15 +242,11 @@ String createTokenUrlWithScopes() {
218242 if (!scopes .isEmpty ()) {
219243 tokenUrl .set ("scopes" , Joiner .on (',' ).join (scopes ));
220244 }
221- if (transport == Transport .MTLS ) {
222- tokenUrl .set ("transport" , "mtls" );
223- } else if (transport == Transport .ALTS ) {
224- tokenUrl .set ("transport" , "alts" );
245+ if (transport != null ) {
246+ tokenUrl .set ("transport" , transport .getLabel ());
225247 }
226- if (bindingEnforcement == BindingEnforcement .ON ) {
227- tokenUrl .set ("binding-enforcement" , "on" );
228- } else if (bindingEnforcement == BindingEnforcement .IAMPOLICY ) {
229- tokenUrl .set ("binding-enforcement" , "iam-policy" );
248+ if (bindingEnforcement != null ) {
249+ tokenUrl .set ("binding-enforcement" , bindingEnforcement .getLabel ());
230250 }
231251 return tokenUrl .toString ();
232252 }
@@ -671,7 +691,7 @@ public static class Builder extends GoogleCredentials.Builder {
671691 private Collection <String > scopes ;
672692 private Collection <String > defaultScopes ;
673693
674- private Transport transport ;
694+ private AuthTransport transport ;
675695 private BindingEnforcement bindingEnforcement ;
676696
677697 protected Builder () {
@@ -716,7 +736,7 @@ public Builder setQuotaProjectId(String quotaProjectId) {
716736 }
717737
718738 @ CanIgnoreReturnValue
719- public Builder setTransport (Transport transport ) {
739+ public Builder setTransport (AuthTransport transport ) {
720740 this .transport = transport ;
721741 return this ;
722742 }
@@ -739,7 +759,7 @@ public Collection<String> getDefaultScopes() {
739759 return defaultScopes ;
740760 }
741761
742- public Transport getTransport () {
762+ public AuthTransport getTransport () {
743763 return transport ;
744764 }
745765
0 commit comments