credential

package
Version: v1.2.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 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_CANNOT_REMOVE_PASSWORD = "you cannot remove the username from the Credential"
View Source
const ERR_CANNOT_REMOVE_USERNAME = "you cannot remove the username from the Credential"
View Source
const ERR_CANNOT_SET_PASSWORD_WHEN_USING_SECTION = "you cannot set password via this method when using the Section() method"
View Source
const ERR_CANNOT_SET_USERNAME_WHEN_USING_SECTION = "you cannot set username via this method when using the Section() method"
View Source
const ERR_FACTORY_MUST_BE_INITIALIZED = "sorry the factory must be created correctly before proceeding"
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) DeleteAttribute added in v1.2.0

func (thisCredential *Credential) DeleteAttribute(key string) error

DeleteAttribute removes an attribute that has been stored on the Credential's associated Profile. If the value is deleted an error is not returned. Otherwise, an error will be returned.

func (*Credential) GetAttribute

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

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) 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) Section added in v1.2.0

func (thisCredential *Credential) Section(section string) *Credential

Section is used as an intermediary function between a credential and GetAttribute or SetAttribute. When you pass a section name, the subsequent method attribute function will be called against that section.

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.

Jump to

Keyboard shortcuts

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