@@ -59,17 +59,34 @@ func CreateEndpointOption(endpointName string, service ServiceNameGCP) option.Cl
5959 return option .WithEndpoint (endpoint )
6060}
6161
62+ // CredentialOptions returns the client options for authenticating with GCP,
63+ // including universe domain support for Google Cloud Dedicated.
64+ // When credential JSON is available, it is passed via WithCredentialsJSON so
65+ // the client library can use self-signed JWTs for non-default universe
66+ // domains (where the OAuth2 token endpoint is unavailable). Falls back to
67+ // WithCredentials for metadata-based credentials that have no JSON.
68+ func CredentialOptions (ssn * Session ) ([]option.ClientOption , error ) {
69+ ud , err := ssn .Credentials .GetUniverseDomain ()
70+ if err != nil {
71+ return nil , fmt .Errorf ("failed to get universe domain: %w" , err )
72+ }
73+ var opts []option.ClientOption
74+ if len (ssn .Credentials .JSON ) > 0 {
75+ opts = append (opts , option .WithCredentialsJSON (ssn .Credentials .JSON ))
76+ } else {
77+ opts = append (opts , option .WithCredentials (ssn .Credentials ))
78+ }
79+ opts = append (opts , option .WithUniverseDomain (ud ))
80+ return opts , nil
81+ }
82+
6283// getOptions creates the options for use during service creation.
6384func getOptions (ctx context.Context ) ([]option.ClientOption , error ) {
6485 ssn , err := GetSession (ctx )
6586 if err != nil {
6687 return nil , fmt .Errorf ("failed to get session: %w" , err )
6788 }
68-
69- options := []option.ClientOption {
70- option .WithCredentials (ssn .Credentials ),
71- }
72- return options , nil
89+ return CredentialOptions (ssn )
7390}
7491
7592// GetComputeService creates the compute service. The service is created with credentials and any service
0 commit comments