serializer

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: 8 Imported by: 0

Documentation

Overview

Package serializer is responsible for de/serializing Credential and Profile objects into different file formats.

Index

Constants

View Source
const ERR_REQUIRED_VARIABLE_PASSWORD_NOT_FOUND = "password has not been set via the environment and is required, load failed"
View Source
const ERR_REQUIRED_VARIABLE_USERNAME_NOT_FOUND = "username has not been set via the environment and is required, load failed"
View Source
const ERR_UNRECOGNIZED_OUTPUT_TYPE string = "sorry I do not recognize that output type, valid values are (ini)"

Variables

This section is empty.

Functions

func GetSupportedFileTypes added in v1.2.0

func GetSupportedFileTypes() []string

Types

type Serializer

type Serializer struct {
	Factory        *factory.Factory
	ProfileName    string
	CredentialFile string
	ConfigFile     string
	Initialized    bool
}

Serializer represents the basic settings required to (de)serialize a Credential and Profile.

func New

func New(sourceFactory *factory.Factory, profileName string) *Serializer

New returns a Serializer object with all the defaults required to de(serialize) objects based on the Factory settings.

func (*Serializer) Deserialize

func (thisSerializer *Serializer) Deserialize() (string, string, map[string]map[string]string, error)

Deserialize is responsible for deserializing an Credential and Profile, determining the file input type based on the value of thisSerializer.Factory.OutputType.

For the format expected of each file, please see the appropriate From<Type> function.

func (*Serializer) FromEnv

func (thisSerializer *Serializer) FromEnv() (string, string, map[string]map[string]string, error)

FromEnv is responsible for scanning environment variables and retrieves applicable variables that have the prefix of applicationName and that have at least two "::" in them (which is the separator). The format for an environment variable managed by serializer is:

APPLICATION_NAME::PROFILE_NAME::FIELD_TYPE::SECTION_NAME::KEY_VALUE

Important to note is that if SECTION_NAME is blank then the default profile will be filled, and FIELD_TYPE can be one of three values which are USERNAME, PASSWORD, or ATTRIBUTE. If the FIELD_TYPE is ATTRIBUTE, then KEY_VALUE is mandatory.

func (*Serializer) FromIni

func (thisSerializer *Serializer) FromIni() (string, string, map[string]map[string]string, error)

FromIni is responsible for deserializing a Credential and Profile from an ini file. Attribute sections are directly translatable to sections in the Profile. Alternate field labels are restored from the ini, so the same Factory object will need to be used when deserializing.

func (*Serializer) FromJson

func (thisSerializer *Serializer) FromJson() (string, string, map[string]map[string]string, error)

FromJson is responsible for deserializing a Credential and Profile from an json file. Attribute sections are directly translatable to parent keys in the config file. Alternate field labels are restored from the json, so the same Factory object will need to be used when deserializing.

func (*Serializer) ParseEnvironmentVariable

func (thisSerializer *Serializer) ParseEnvironmentVariable(environmentVariable string) (string, string, string, bool)

ParseEnvironmentVariable is able to process an environment variable and see if matches the expected format for our environment variables.

The format for an environment variable managed by serializer is:

APPLICATION_NAME::PROFILE_NAME::FIELD_TYPE::SECTION_NAME::KEY_VALUE

Important to note is that if SECTION_NAME is blank then the default profile will be filled, and FIELD_TYPE can be one of three values which are USERNAME, PASSWORD, or ATTRIBUTE. If the FIELD_TYPE is ATTRIBUTE, then KEY_VALUE is mandatory.

func (*Serializer) Serialize

func (thisSerializer *Serializer) Serialize(username string, password string, attributes map[string]map[string]string) error

Serialize is responsible for serializing an Credential and Profile, determining the file output type based on the value of thisSerializer.Factory.OutputType. It is possible to serialize into multiple formats by initiating new factories, but there is only one version of config with no extension. Every time a Serialize call is made, the file contents are overwritten with the new values. Two formats cannot exist together.

The one exception to these rules is Environment, which doesn't save settings to file, although won't persists between sessions.

func (*Serializer) ToEnv

func (thisSerializer *Serializer) ToEnv(username string, password string, attributes map[string]map[string]string) error

ToEnv is responsible for serializing a Credential/Profile combination into the environment. Both of the credential values are serialized as so:

APPLICATION_NAME::PROFILE_NAME::USERNAME (or alternate)
APPLICATION_NAME::PROFILE_NAME::PASSWORD (or alternate)

Profile attributes are also added to the profile in the following format:

APPLICATION_NAME::PROFILE_NAME::ATTRIBUTE::SECTION_NAME::KEY_VALUE

SECTION_NAME can be blank.

func (*Serializer) ToIni

func (thisSerializer *Serializer) ToIni(username string, password string, attributes map[string]map[string]string) error

ToIni is responsible for serializing a Credential and Profile to an ini file. Attribute sections are directly translatable to sections in the Profile. Username and Password will have an appropriate label (either the default or an alternate set in the Credential's related Factory.

func (*Serializer) ToJson

func (thisSerializer *Serializer) ToJson(username string, password string, attributes map[string]map[string]string) error

ToJson is responsible for serializing a Credential and Profile to an json file. Attribute sections are directly translatable to parent keys in the config file. Username and Password will have an appropriate label (either the default or an alternate set in the Credential's related Factory.

Jump to

Keyboard shortcuts

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