settings

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2024 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package settings contains the logic for reading, writing, associating profiles with a user's settings file. It also configures a Phobos SDK client.

Index

Constants

View Source
const (

	// DefaultProfileName is the name of the default profile
	DefaultProfileName = "default"
)

Variables

View Source
var ErrNoSettings = errors.New(noSettingsMessage)

ErrNoSettings is a special error if settings file does not exist.

Functions

func DefaultCredentialsFilepath

func DefaultCredentialsFilepath() (string, error)

DefaultCredentialsFilepath returns the OS-dependent path/name of the default credentials file.

Types

type Profile

type Profile struct {
	Endpoint      string `json:"endpoint"` // HTTP.
	TLSSkipVerify bool   `json:"tlsSkipVerify"`
	// contains filtered or unexported fields
}

Profile holds the contents of one profile from a settings file.

func (*Profile) NewClient added in v0.2.1

func (p *Profile) NewClient(ctx context.Context, withAuth bool) (*client.Client, error)

NewClient returns a Phobos client based on the specified profile.

func (*Profile) NewTokenGetter added in v0.2.1

func (p *Profile) NewTokenGetter(ctx context.Context) (client.TokenGetter, error)

NewTokenGetter creates a new token getter for the profile.

func (*Profile) SetToken added in v0.2.1

func (p *Profile) SetToken(token string)

SetToken sets the token for a profile.

type Settings

type Settings struct {
	Profiles       map[string]Profile `json:"profiles"`
	CurrentProfile *Profile           `json:"-"` // This field is not persistent, do not write it out.
}

Settings holds the contents of one settings file and a pointer to the profile specified by the current command.

func ReadSettings

func ReadSettings(name *string) (*Settings, error)

ReadSettings reads the settings file. If no argument, it reads the default settings file: ~/.phobos/settings.json

func (*Settings) SetCurrentProfile

func (s *Settings) SetCurrentProfile(profileName string) error

SetCurrentProfile sets the current profile pointer in a settings object.

func (*Settings) WriteSettingsFile

func (s *Settings) WriteSettingsFile(name *string) error

WriteSettingsFile writes the settings file. If no filename argument, it writes the default settings file: ~/.phobos/settings.json

Jump to

Keyboard shortcuts

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