credential

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 credential provides the base implementation detail for the go-credentials library.

All of the logic for handling individual credentials is contained within this package. Before a Credential can be created, global application-level settings must be set in a factory.Factory object. Attributes aside from Username and Password are stored in a Profile object.

Index

Constants

View Source
const ERR_ATTRIBUTE_NOT_EXIST = "sorry that attribute hasn't been set on this credential"
View Source
const ERR_CREDENTIAL_NOT_INITIALIZED = "sorry, this credential has not been initialized"
View Source
const ERR_FACTORY_MUST_BE_INITIALIZED = "sorry the factory must be created correctly before proceeding"
View Source
const ERR_FACTORY_PRIVATE_ATTEMPT_DEPLOY = "you have attempted to deploy environment variables but your factory is private"
View Source
const ERR_JSON_FUNCTIONALITY_NOT_IMPLEMENTED = "sorry, that feature has not been implemented yet"
View Source
const ERR_KEY_MUST_MATCH_REGEX = "sorry the key must only include numbers, letters and underscores [0-9A-Za-z_]"
View Source
const ERR_NOT_INITIALIZED = "sorry something has not been initialized, make sure you use New and do not create a struct manually"
View Source
const ERR_USERNAME_OR_PASSWORD_NOT_SET = "sorry you must set a username or password"

Variables

This section is empty.

Functions

This section is empty.

Types

type Credential

type Credential struct {
	Username    string
	Password    string
	Initialized bool
	Factory     *factory.Factory
	Profile     *profile.Profile
	// contains filtered or unexported fields
}

Credential is the main object used by the go-credential library to manage user credentials. Username and Password are exported by default. The attributes of the Credential are not exported, as they should only be accessed via SetAttribute or GetAttribute.

func Deserialize

func Deserialize(sourceFactory *factory.Factory, profileName string, username string, password string, attributes map[string]map[string]string) (*Credential, error)

Deserialize takes all of the values required to build a Credential and Profile and uses those values to do so.

This function is designed to be used as part of a serializer.Deserialize() call.

func Load

func Load(sourceFactory *factory.Factory) (*Credential, error)

Load uses LoadFromProfile to create a Credential set to the default profile.

func LoadFromProfile

func LoadFromProfile(profileName string, sourceFactory *factory.Factory) (*Credential, error)

LoadFromProfile uses Serializer to load an object from the relevant source. The source is determined based on the OUTPUT_TYPE of the sourceFactory.

func New

func New(sourceFactory *factory.Factory, username string, password string) (*Credential, error)

func NewProfile

func NewProfile(profileName string, sourceFactory *factory.Factory, username string, password string) (*Credential, error)

func (*Credential) GetAttribute

func (thisCredential *Credential) GetAttribute(key string) (string, error)

GetAttribute retrieves an attribute that has been stored on the Credential's associated Profile. A key is passed in, and if the key does not have a value stored in the Profile, an error is returned.

func (*Credential) GetSectionAttribute

func (thisCredential *Credential) GetSectionAttribute(section string, key string) (string, error)

GetSectionAttribute retrieves an attribute that has been stored on the Credential's associated Profile. Section can be blank, and the Profile will redirect the output to the default section. The key is mandatory, and if the key does not have a value stored in the Profile, an error is returned.

func (*Credential) Save

func (thisCredential *Credential) Save() error

Save is responsible for saving the credential at ~/.application_name/credentials in the specified output format that has been set on the Credentials' Factory object.

func (*Credential) Serialize

func (thisCredential *Credential) Serialize() (string, string, map[string]map[string]string)

Serialize retrieves the data values from a Credential object.

This function is designed to be used as part of a serializer.Serialize() call.

func (*Credential) SetAttribute

func (thisCredential *Credential) SetAttribute(key string, value string) error

SetAttribute sets an attribute on a Credential object. key must match the regex '(?m)^[0-9A-Za-z_]+$'. There are no restrictions on the value of an attribute, aside from Go-level restrictions on strings. When these values are processed by Save(), they are stored in the config file for the Credential's currently set Profile. If username or password is passed as the attribute key, the set is redirected to the Username or Password property on the Credential object.

func (*Credential) SetSectionAttribute

func (thisCredential *Credential) SetSectionAttribute(section string, key string, value string) error

SetSectionAttribute sets an attribute on a Credential's associated Profile object. key must match the regex '(?m)^[0-9A-Za-z_]+$'. Section can be blank, and the Profile will redirect the output to the default section. The key is mandatory, and if the key does not have a value stored in the Profile, an error is returned. There are no restrictions on the value of an attribute, aside from Go-level restrictions on strings.

When these values are processed by Save(), they are stored in the config file for the Credential's currently set Profile. If username or password is passed as the attribute key, the set is redirected to the Username or Password property on the Credential object.

Jump to

Keyboard shortcuts

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