factory

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2020 License: MIT Imports: 7 Imported by: 2

Documentation

Overview

Package factory provides an API for managing application-level credential details.

Properties such as where credential files are stored, the name of the application, alternate username/password keys, and the credential file type are handled by factory.

Index

Constants

View Source
const ERR_ALTERNATE_PASSWORD_CANNOT_BE_BLANK = "the alternate password you provided is blank, please provide a string"
View Source
const ERR_ALTERNATE_USERNAME_CANNOT_BE_BLANK = "the alternate username you provided is blank, please provide a string"
View Source
const ERR_APPLICATION_NAME_BLANK = "sorry the application name must not be blank"
View Source
const ERR_FACTORY_INCONSISTENT_STATE = "the Factory is in an inconsistent state, please only use public methods to modify"
View Source
const ERR_FACTORY_NOT_INITIALIZED = "sorry the factory has not been initilalized please run f.Intialize() and try again"
View Source
const ERR_INVALID_OUTPUT_TYPE = "sorry the output type you have set is not valid and not supported"
View Source
const ERR_KEY_MUST_MATCH_REGEX = "sorry the key must only include letters and underscores [0-9A-Za-z_]"

Variables

This section is empty.

Functions

This section is empty.

Types

type Factory

type Factory struct {
	ApplicationName string
	ParentDirectory string
	CredentialFile  string
	ConfigDirectory string
	UseEnvironment  bool
	Initialized     bool
	OutputType      string
	Log             *zerolog.Logger
	// contains filtered or unexported fields
}

Factory is the object that is used to store all of the application-level global configuration. All the settings for saving, setting, searching and finding credentials are in this object.

Application Name: this is the name of the application. ParentDirectory: automatically set to ~/.application_name CredentialFile: automatically set to configurationDirectory + "/credentials". UseEnvironment: can I load variables into the environment. Only set this if you intend on use LoadEnv. Initialized: has all of my configuration been initialized correctly? Output Type: the file type that the CredentialFile contents should be. Alternates: if username or password are set, those names are set

func New

func New(applicationName string, useEnvironment bool) (*Factory, error)

New creates a very simple Factory object, with defaults based on the ApplicationName.

func (*Factory) GetAlternatePassword

func (thisFactory *Factory) GetAlternatePassword() string

GetAlternatePassword sets a label to be used in lieu of password in environment variables.

func (*Factory) GetAlternateUsername

func (thisFactory *Factory) GetAlternateUsername() string

GetAlternateUsername gets a label to be used in lieu of username in environment variables.

func (*Factory) GetAlternates

func (thisFactory *Factory) GetAlternates() map[string]string

GetAlternates the alternates map.

func (*Factory) Initialize

func (thisFactory *Factory) Initialize() error

Initialize sets computed properties a Factory object. Specifically, it sets the value of ParentDirectory, ConfigDirectory and CredentialFile. If ParentDirectory does not exist, it will also create it. Alternates is also initialized as an empty map and the Initialized flag is set to true. The logger for the Factory is also initialized here.

func (*Factory) ModifyLogger added in v1.1.0

func (thisFactory *Factory) ModifyLogger(logLevel string, pretty bool)

ModifyLogger is responsible for reconfiguring the log level and whether or not pretty output is used. Available log levels are panic, fatal, error, warn, info, debug, trace, and disabled. By default, all logging output is disabled.

func (*Factory) SetAlternatePassword

func (thisFactory *Factory) SetAlternatePassword(alternatePassword string) error

SetAlternatePassword sets a label to be used in lieu of password in environment variables.

func (*Factory) SetAlternateUsername

func (thisFactory *Factory) SetAlternateUsername(alternateUsername string) error

SetAlternateUsername sets a label to be used in lieu of username in environment variables.

func (*Factory) SetEnvironmentKeys

func (thisFactory *Factory) SetEnvironmentKeys(usernameKey string, passwordKey string) error

Set environment keys is a function that sets the alternates for both username and password at the same time. This is the same as calling SetAlternateUsername, then calling SetAlternatePassword in a separate call.

func (*Factory) SetOutputType

func (thisFactory *Factory) SetOutputType(outputType string) error

SetOutputType determines which of the supported file types Credentials should be serialized to file as. The currently supported file types are ini with plans to implement json.

Jump to

Keyboard shortcuts

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