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.



    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_]"


    This section is empty.


    This section is empty.


    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) (*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() (string, string)

              GetAlternates returns the username and password.

              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

                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) SetAlternates

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

                        SetAlternates 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. If you enter a blank value in either parameter, it won't be set and an error will be returned. However, the other variable will be set.

                        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.