settings

package
v2.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2022 License: MIT Imports: 6 Imported by: 10

Documentation

Overview

Most of the code is lifted from https://cs.opensource.google/go/x/oauth2/+/d3ed0bb2:google/default.go

For details and copyright etc. see above url.

Most of the code is lifted from https://github.com/googleapis/google-api-go-client/blob/main/option/option.go

For details and copyright etc. see above url.

Most of the code is lifted from https://github.com/googleapis/google-api-go-client/blob/main/internal/settings.go

For details and copyright etc. see above url.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientOption

type ClientOption interface {
	Apply(*DialSettings)
}

ClientOption implements a configuration option for an API client.

func WithAPIKey

func WithAPIKey(apiKey string) ClientOption

WithAPIKey returns a ClientOption that specifies an API key to be used as the basis for authentication.

func WithEndpoint

func WithEndpoint(url string) ClientOption

WithEndpoint returns a ClientOption that overrides the default endpoint to be used for a service.

func WithScopes

func WithScopes(scope ...string) ClientOption

WithScopes returns a ClientOption that overrides the default (OAuth2) scopes to be used for a service.

func WithUserAgent

func WithUserAgent(ua string) ClientOption

WithUserAgent returns a ClientOption that sets the User-Agent.

func WithoutAuthentication

func WithoutAuthentication() ClientOption

WithoutAuthentication returns a ClientOption that specifies that no authentication should be used. It is suitable only for testing and for accessing public resources. It is an error to provide both WithoutAuthentication and any of WithAPIKey, WithTokenSource, WithCredentialsFile or WithServiceAccountFile.

type Credentials

type Credentials struct {
	ProjectID string `json:"project_id,omitempty"` // may be empty
	UserID    string `json:"user_id,omitempty"`    // may be empty
	Token     string `json:"token,omitempty"`      // may be empty
	Expires   int64  `json:"expires,omitempty"`    // 0 = never
}

func ReadCredentialsFromFile

func ReadCredentialsFromFile(path string) (*Credentials, error)

func (*Credentials) WriteToFile

func (cred *Credentials) WriteToFile(path string) error

type DialSettings

type DialSettings struct {
	Endpoint        string `json:"endpoint,omitempty"`
	DefaultEndpoint string `json:"default_endpoint,omitempty"`

	Scopes        []string `json:"scopes,omitempty"`
	DefaultScopes []string `json:"default_scopes,omitempty"`

	Credentials         *Credentials `json:"credentials,omitempty"`
	InternalCredentials *Credentials `json:"internal_credentials,omitempty"`
	CredentialsFile     string       `json:"credentials_file,omitempty"`

	Options map[string]string `json:"options,omitempty"` // holds all other options ...

	UserAgent string `json:"user_agent,omitempty"`
	APIKey    string `json:"api_key,omitempty"` // aka ClientID

	NoAuth         bool `json:"no_auth,omitempty"`
	SkipValidation bool `json:"skip_validation,omitempty"`
}

DialSettings holds information needed to establish a connection with a backend API service or to simply configure some code.

func ReadSettingsFromFile

func ReadSettingsFromFile(path string) (*DialSettings, error)

func (*DialSettings) GetOption

func (ds *DialSettings) GetOption(opt string) string

GetOption returns the custom option opt if it exists or an empty string otherwise

func (*DialSettings) GetScopes

func (ds *DialSettings) GetScopes() []string

GetScopes returns the user-provided scopes, if set, or else falls back to the default scopes.

func (*DialSettings) HasOption

func (ds *DialSettings) HasOption(opt string) bool

HasOption returns true if ds has a custom option opt.

func (*DialSettings) SetOption

func (ds *DialSettings) SetOption(opt, o string)

SetOptions registers a custom option o with key opt.

func (*DialSettings) Validate

func (ds *DialSettings) Validate() error

Validate reports an error if ds is invalid.

func (*DialSettings) WriteToFile

func (ds *DialSettings) WriteToFile(path string) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL