...

Source file src/google.golang.org/api/option/internaloption/internaloption.go

Documentation: google.golang.org/api/option/internaloption

     1  // Copyright 2020 Google LLC.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Package internaloption contains options used internally by Google client code.
     6  package internaloption
     7  
     8  import (
     9  	"golang.org/x/oauth2/google"
    10  	"google.golang.org/api/internal"
    11  	"google.golang.org/api/option"
    12  )
    13  
    14  type defaultEndpointOption string
    15  
    16  func (o defaultEndpointOption) Apply(settings *internal.DialSettings) {
    17  	settings.DefaultEndpoint = string(o)
    18  }
    19  
    20  // WithDefaultEndpoint is an option that indicates the default endpoint.
    21  //
    22  // It should only be used internally by generated clients.
    23  //
    24  // This is similar to WithEndpoint, but allows us to determine whether the user has overridden the default endpoint.
    25  //
    26  // Deprecated: WithDefaultEndpoint does not support setting the universe domain.
    27  // Use WithDefaultEndpointTemplate and WithDefaultUniverseDomain to compose the
    28  // default endpoint instead.
    29  func WithDefaultEndpoint(url string) option.ClientOption {
    30  	return defaultEndpointOption(url)
    31  }
    32  
    33  type defaultEndpointTemplateOption string
    34  
    35  func (o defaultEndpointTemplateOption) Apply(settings *internal.DialSettings) {
    36  	settings.DefaultEndpointTemplate = string(o)
    37  }
    38  
    39  // WithDefaultEndpointTemplate provides a template for creating the endpoint
    40  // using a universe domain. See also WithDefaultUniverseDomain and
    41  // option.WithUniverseDomain. The placeholder UNIVERSE_DOMAIN should be used
    42  // instead of a concrete universe domain such as "googleapis.com".
    43  //
    44  // Example: WithDefaultEndpointTemplate("https://logging.UNIVERSE_DOMAIN/")
    45  //
    46  // It should only be used internally by generated clients.
    47  func WithDefaultEndpointTemplate(url string) option.ClientOption {
    48  	return defaultEndpointTemplateOption(url)
    49  }
    50  
    51  type defaultMTLSEndpointOption string
    52  
    53  func (o defaultMTLSEndpointOption) Apply(settings *internal.DialSettings) {
    54  	settings.DefaultMTLSEndpoint = string(o)
    55  }
    56  
    57  // WithDefaultMTLSEndpoint is an option that indicates the default mTLS endpoint.
    58  //
    59  // It should only be used internally by generated clients.
    60  func WithDefaultMTLSEndpoint(url string) option.ClientOption {
    61  	return defaultMTLSEndpointOption(url)
    62  }
    63  
    64  // SkipDialSettingsValidation bypasses validation on ClientOptions.
    65  //
    66  // It should only be used internally.
    67  func SkipDialSettingsValidation() option.ClientOption {
    68  	return skipDialSettingsValidation{}
    69  }
    70  
    71  type skipDialSettingsValidation struct{}
    72  
    73  func (s skipDialSettingsValidation) Apply(settings *internal.DialSettings) {
    74  	settings.SkipValidation = true
    75  }
    76  
    77  // EnableDirectPath returns a ClientOption that overrides the default
    78  // attempt to use DirectPath.
    79  //
    80  // It should only be used internally by generated clients.
    81  // This is an EXPERIMENTAL API and may be changed or removed in the future.
    82  func EnableDirectPath(dp bool) option.ClientOption {
    83  	return enableDirectPath(dp)
    84  }
    85  
    86  type enableDirectPath bool
    87  
    88  func (e enableDirectPath) Apply(o *internal.DialSettings) {
    89  	o.EnableDirectPath = bool(e)
    90  }
    91  
    92  // EnableDirectPathXds returns a ClientOption that overrides the default
    93  // DirectPath type. It is only valid when DirectPath is enabled.
    94  //
    95  // It should only be used internally by generated clients.
    96  // This is an EXPERIMENTAL API and may be changed or removed in the future.
    97  func EnableDirectPathXds() option.ClientOption {
    98  	return enableDirectPathXds(true)
    99  }
   100  
   101  type enableDirectPathXds bool
   102  
   103  func (x enableDirectPathXds) Apply(o *internal.DialSettings) {
   104  	o.EnableDirectPathXds = bool(x)
   105  }
   106  
   107  // AllowNonDefaultServiceAccount returns a ClientOption that overrides the default
   108  // requirement for using the default service account for DirectPath.
   109  //
   110  // It should only be used internally by generated clients.
   111  // This is an EXPERIMENTAL API and may be changed or removed in the future.
   112  func AllowNonDefaultServiceAccount(nd bool) option.ClientOption {
   113  	return allowNonDefaultServiceAccount(nd)
   114  }
   115  
   116  type allowNonDefaultServiceAccount bool
   117  
   118  func (a allowNonDefaultServiceAccount) Apply(o *internal.DialSettings) {
   119  	o.AllowNonDefaultServiceAccount = bool(a)
   120  }
   121  
   122  // WithDefaultAudience returns a ClientOption that specifies a default audience
   123  // to be used as the audience field ("aud") for the JWT token authentication.
   124  //
   125  // It should only be used internally by generated clients.
   126  func WithDefaultAudience(audience string) option.ClientOption {
   127  	return withDefaultAudience(audience)
   128  }
   129  
   130  type withDefaultAudience string
   131  
   132  func (w withDefaultAudience) Apply(o *internal.DialSettings) {
   133  	o.DefaultAudience = string(w)
   134  }
   135  
   136  // WithDefaultScopes returns a ClientOption that overrides the default OAuth2
   137  // scopes to be used for a service.
   138  //
   139  // It should only be used internally by generated clients.
   140  func WithDefaultScopes(scope ...string) option.ClientOption {
   141  	return withDefaultScopes(scope)
   142  }
   143  
   144  type withDefaultScopes []string
   145  
   146  func (w withDefaultScopes) Apply(o *internal.DialSettings) {
   147  	o.DefaultScopes = make([]string, len(w))
   148  	copy(o.DefaultScopes, w)
   149  }
   150  
   151  // WithDefaultUniverseDomain returns a ClientOption that sets the default universe domain.
   152  //
   153  // It should only be used internally by generated clients.
   154  //
   155  // This is similar to the public WithUniverse, but allows us to determine whether the user has
   156  // overridden the default universe.
   157  func WithDefaultUniverseDomain(ud string) option.ClientOption {
   158  	return withDefaultUniverseDomain(ud)
   159  }
   160  
   161  type withDefaultUniverseDomain string
   162  
   163  func (w withDefaultUniverseDomain) Apply(o *internal.DialSettings) {
   164  	o.DefaultUniverseDomain = string(w)
   165  }
   166  
   167  // EnableJwtWithScope returns a ClientOption that specifies if scope can be used
   168  // with self-signed JWT.
   169  //
   170  // EnableJwtWithScope is ignored when option.WithUniverseDomain is set
   171  // to a value other than the Google Default Universe (GDU) of "googleapis.com".
   172  // For non-GDU domains, token exchange is impossible and services must
   173  // support self-signed JWTs with scopes.
   174  func EnableJwtWithScope() option.ClientOption {
   175  	return enableJwtWithScope(true)
   176  }
   177  
   178  type enableJwtWithScope bool
   179  
   180  func (w enableJwtWithScope) Apply(o *internal.DialSettings) {
   181  	o.EnableJwtWithScope = bool(w)
   182  }
   183  
   184  // WithCredentials returns a client option to specify credentials which will be used to authenticate API calls.
   185  // This credential takes precedence over all other credential options.
   186  func WithCredentials(creds *google.Credentials) option.ClientOption {
   187  	return (*withCreds)(creds)
   188  }
   189  
   190  type withCreds google.Credentials
   191  
   192  func (w *withCreds) Apply(o *internal.DialSettings) {
   193  	o.InternalCredentials = (*google.Credentials)(w)
   194  }
   195  
   196  // EnableNewAuthLibrary returns a ClientOption that specifies if libraries in this
   197  // module to delegate auth to our new library. This option will be removed in
   198  // the future once all clients have been moved to the new auth layer.
   199  func EnableNewAuthLibrary() option.ClientOption {
   200  	return enableNewAuthLibrary(true)
   201  }
   202  
   203  type enableNewAuthLibrary bool
   204  
   205  func (w enableNewAuthLibrary) Apply(o *internal.DialSettings) {
   206  	o.EnableNewAuthLibrary = bool(w)
   207  }
   208  
   209  // EmbeddableAdapter is a no-op option.ClientOption that allow libraries to
   210  // create their own client options by embedding this type into their own
   211  // client-specific option wrapper. See example for usage.
   212  type EmbeddableAdapter struct{}
   213  
   214  func (*EmbeddableAdapter) Apply(_ *internal.DialSettings) {}
   215  

View as plain text