config

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAdminAPIKeyNotConfigured is the error returned when the loaded profile is missing the admin_api_key property
	ErrAdminAPIKeyNotConfigured = errors.New("you have not configured your admin API key yet")
	// ErrApplicationIDNotConfigured is the error returned when the loaded profile is missing the application_id property
	ErrApplicationIDNotConfigured = errors.New("you have not configured your Application ID yet")
)

Functions

func AdminAPIKey

func AdminAPIKey(input string) error

AdminAPIKey validates that a string looks like an Admin API key.

Types

type Config

type Config struct {
	ApplicationName string

	CurrentProfile Profile

	File string
}

Config handles all overall configuration for the CLI

func (*Config) ApplicationIDExists

func (c *Config) ApplicationIDExists(appID string) (bool, string)

ApplicationIDExists check if an application ID exists in any profiles

func (*Config) ConfiguredProfiles

func (c *Config) ConfiguredProfiles() []*Profile

ConfiguredProfiles return the profiles in the configuration file

func (*Config) Default

func (c *Config) Default() *Profile

Default returns the default profile

func (*Config) GetConfigFolder

func (c *Config) GetConfigFolder(xdgPath string) string

GetConfigFolder retrieves the folder where the configuration file is stored It searches for the xdg environment path first and will secondarily place it in the home directory

func (*Config) InitConfig

func (c *Config) InitConfig()

InitConfig reads in profiles file and ENV variables if set.

func (*Config) Profile

func (c *Config) Profile() *Profile

Profile returns the current profile

func (*Config) ProfileExists

func (c *Config) ProfileExists(appName string) bool

ProfileExists check if a profile with the given name exists

func (*Config) ProfileNames

func (c *Config) ProfileNames() []string

ProfileNames returns the list of name of the configured profiles

func (*Config) RemoveProfile

func (c *Config) RemoveProfile(name string) error

RemoveProfile remove a profile from the configuration

func (*Config) SetDefaultProfile

func (c *Config) SetDefaultProfile(name string) error

SetDefaultProfile set the default profile

type IConfig

type IConfig interface {
	InitConfig()

	ConfiguredProfiles() []*Profile
	ProfileNames() []string

	ProfileExists(name string) bool
	RemoveProfile(name string) error
	SetDefaultProfile(name string) error

	ApplicationIDExists(appID string) (bool, string)

	Profile() *Profile
	Default() *Profile
}

type Profile

type Profile struct {
	Name string

	ApplicationID string `mapstructure:"application_id"`
	AdminAPIKey   string `mapstructure:"admin_api_key"`

	Default bool `mapstructure:"default"`
}

func (*Profile) Add

func (p *Profile) Add() error

Add add a profile to the configuration

func (*Profile) GetAdminAPIKey

func (p *Profile) GetAdminAPIKey() (string, error)

func (*Profile) GetApplicationID

func (p *Profile) GetApplicationID() (string, error)

func (*Profile) GetFieldName

func (p *Profile) GetFieldName(field string) string

func (*Profile) LoadDefault

func (p *Profile) LoadDefault()

Jump to

Keyboard shortcuts

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