credentials

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultCredentialsFile is the default place to load profiles from
	DefaultCredentialsFile = "credentials"
)
View Source
const DefaultProfileFile = "default-profile"

DefaultProfileFile is the configuration file containing the default profile name

Variables

View Source
var Command = &cobra.Command{
	Use:   "profile",
	Short: "Manage the authentication profiles for this tool",
	Aliases: []string{
		"profiles",
	},
}

Command is the base command for managing profiles

Functions

func LoadDefaultProfile

func LoadDefaultProfile(configDir string) (string, error)

LoadDefaultProfile reads the profile name from the default profile file.

func LoadProfiles

func LoadProfiles(configDir string) (*map[string]Profile, error)

LoadProfiles reads the credential profiles from the default path.

func StringToRegionHookFunc added in v0.6.2

func StringToRegionHookFunc() mapstructure.DecodeHookFunc

StringToRegionHookFunc takes a string and runs it through the region parser to create a valid region (or error)

func WithCredentials

func WithCredentials(f func(c *Credentials))

WithCredentials loads and returns the CLI credentials.

func WithCredentialsFrom

func WithCredentialsFrom(configDir string, f func(c *Credentials))

WithCredentialsFrom loads and returns the CLI credentials from a specified location.

Types

type Credentials

type Credentials struct {
	DefaultProfile  string
	Profiles        map[string]Profile
	ConfigDirectory string
}

Credentials is the metadata around all configured profiles

func LoadCredentials

func LoadCredentials(configDir string) (*Credentials, error)

LoadCredentials loads the current CLI credentials from disk.

func (*Credentials) AddProfile

func (c *Credentials) AddProfile(profileName, reg, apiKey string, insightsInsertKey string, accountID int) error

AddProfile adds a new profile to the credentials file.

func (*Credentials) Default

func (c *Credentials) Default() *Profile

Default returns the default profile

func (*Credentials) List

func (c *Credentials) List()

List outputs a list of all the configured Credentials

func (*Credentials) RemoveProfile

func (c *Credentials) RemoveProfile(profileName string) error

RemoveProfile removes an existing profile from the credentials file.

func (*Credentials) SetDefaultProfile

func (c *Credentials) SetDefaultProfile(profileName string) error

SetDefaultProfile modifies the profile name to use by default.

type Profile

type Profile struct {
	APIKey            string `mapstructure:"apiKey" json:"apiKey,omitempty"`                       // For accessing New Relic GraphQL resources
	InsightsInsertKey string `mapstructure:"insightsInsertKey" json:"insightsInsertKey,omitempty"` // For posting custom events
	Region            string `mapstructure:"region" json:"region,omitempty"`                       // Region to use for New Relic resources
	AccountID         int    `mapstructure:"accountID" json:"accountID"`                           // AccountID to use for New Relic resources
}

Profile contains data of a single profile

func (Profile) MarshalJSON added in v0.6.1

func (p Profile) MarshalJSON() ([]byte, error)

MarshalJSON allows us to override the default behavior on marshal and lowercase the region string for backwards compatibility

Jump to

Keyboard shortcuts

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