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.
- type Credential
- func Deserialize(sourceFactory *factory.Factory, profileName string, username string, ...) (*Credential, error)
- func Load(sourceFactory *factory.Factory) (*Credential, error)
- func LoadFromProfile(profileName string, sourceFactory *factory.Factory) (*Credential, error)
- func New(sourceFactory *factory.Factory, username string, password string) (*Credential, error)
- func NewProfile(profileName string, sourceFactory *factory.Factory, username string, ...) (*Credential, error)
- func (thisCredential *Credential) DeleteAttribute(key string) error
- func (thisCredential *Credential) GetAttribute(key string) string
- func (thisCredential *Credential) Save() error
- func (thisCredential *Credential) Section(section string) *Credential
- func (thisCredential *Credential) Serialize() (string, string, map[string]map[string]string)
- func (thisCredential *Credential) SetAttribute(key string, value string) error
const ERR_CANNOT_REMOVE_PASSWORD = "you cannot remove the username from the Credential"
const ERR_CANNOT_REMOVE_USERNAME = "you cannot remove the username from the Credential"
const ERR_CANNOT_SET_PASSWORD_WHEN_USING_SECTION = "you cannot set password via this method when using the Section() method"
const ERR_CANNOT_SET_USERNAME_WHEN_USING_SECTION = "you cannot set username via this method when using the Section() method"
const ERR_FACTORY_MUST_BE_INITIALIZED = "sorry the factory must be created correctly before proceeding"
const ERR_KEY_MUST_MATCH_REGEX = "sorry the key must only include numbers, letters and underscores [0-9A-Za-z_]"
const ERR_NOT_INITIALIZED = "sorry something has not been initialized, make sure you use New and do not create a struct manually"
const ERR_USERNAME_OR_PASSWORD_NOT_SET = "sorry you must set a username or password"
This section is empty.
This section is empty.
type Credential ¶
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 ¶
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.
Load uses LoadFromProfile to create a Credential set to the default profile.
func LoadFromProfile ¶
LoadFromProfile uses Serializer to load an object from the relevant source. The source is determined based on the OUTPUT_TYPE of the sourceFactory.
func NewProfile ¶
func (*Credential) DeleteAttribute ¶ added in v1.2.0
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 ¶
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.
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.
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.
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 ¶
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.