settings

package
v2.11.0 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2025 License: MIT Imports: 6 Imported by: 10

Documentation

Overview

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.

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

View Source
const (
	ProjectID    = "PROJECT_ID"
	ClientID     = "CLIENT_ID"
	ClientSecret = "CLIENT_SECRET"
	AccessToken  = "ACCESS_TOKEN"

	StateInit       State = iota - 2 // waiting to swap tokens
	StateInvalid                     // a config in this state should not be used
	StateUndefined                   // logged out
	StateAuthorized                  // logged in
)

Variables

This section is empty.

Functions

func WriteCredentials added in v2.10.0

func WriteCredentials(cred *Credentials, path string) error

func WriteDialSettings added in v2.10.0

func WriteDialSettings(ds *DialSettings, path string) error

Types

type Credentials

type Credentials struct {
	ProjectID    string `json:"project_id,omitempty"`
	ClientID     string `json:"client_id,omitempty"` // email for users, some UUID for API clients
	ClientSecret string `json:"client_secret,omitempty"`
	Token        string `json:"token,omitempty"`
	Status       State  `json:"status,omitempty"`  // -2 = state_init, -1 = state_invalid, 0 = logged_out, 1 = logged_in
	Expires      int64  `json:"expires,omitempty"` // 0 = never, > 0 = unix timestamp, < 0 = invalid
}

func CredentialsFromEnv added in v2.5.0

func CredentialsFromEnv() *Credentials

func ReadCredentials added in v2.10.0

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

func (*Credentials) Clone added in v2.5.0

func (c *Credentials) Clone() *Credentials

Clone returns a deep copy of the credentials

func (*Credentials) Expired added in v2.5.0

func (c *Credentials) Expired() bool

Expired only verifies just that, does not check all other attributes

func (*Credentials) HashedKey added in v2.5.0

func (c *Credentials) HashedKey() string

func (*Credentials) IsValid added in v2.5.0

func (c *Credentials) IsValid() bool

IsValid test if Crendentials is valid

func (*Credentials) Key added in v2.5.0

func (c *Credentials) Key() string

type DialSettings

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

	Credentials *Credentials `json:"credentials,omitempty"`

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

	UserAgent string `json:"user_agent,omitempty"`

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

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

func ReadDialSettings added in v2.10.0

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

func (*DialSettings) Clone added in v2.5.0

func (ds *DialSettings) Clone() DialSettings

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.

type Option added in v2.10.0

type Option interface {
	Apply(ds *DialSettings)
}

type State added in v2.5.0

type State int

Jump to

Keyboard shortcuts

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