Documentation

Overview

    Package profile contains all of the code for managing multiple credential files. A profile consists of a section in the default credentials file, with both the username and password, and a configuration file that is contained under the config directory and named after the profile.

    Index

    Constants

    View Source
    const ERR_DELETED_ATTRIBUTE_NOT_EXIST = "the attribute you have attempted to delete does not exist"
    View Source
    const ERR_MUST_MATCH_REGEX = "sorry the section name and value must only include letters, numbers and underscores [0-9A-Za-z_]"
    View Source
    const ERR_NOT_YET_IMPLEMENTED = "that feature has not been implemented yet"
    View Source
    const ERR_PROFILE_DID_NOT_EXIST = "the config file did not exist and a profile has not been loaded"
    View Source
    const ERR_PROFILE_NAME_MUST_MATCH_REGEX = "sorry the profile name must only include letters, numbers and underscores [0-9A-Za-z_]"
    View Source
    const ERR_PROFILE_NOT_INITIALIZED = "sorry the profile is not initialized"
    View Source
    const ERR_SECTION_NOT_EXIST = "that section does not exist in the profile"

    Variables

    This section is empty.

    Functions

    This section is empty.

    Types

    type Profile

    type Profile struct {
    	Name               string
    	ConfigFileLocation string
    
    	Initialized bool
    	Factory     *factory.Factory
    	// contains filtered or unexported fields
    }

      Profile is used to hold information about the user settings or metadata attached to a Credential. Each profile stores its credential in the main credentials file, then the other information is held under config/profile_name

      func New

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

        New is responsible for constructing a new, blank profile to be used by a Credential. It is important to note, that this function does not save a profile, and this needs to be done using the Save() function.

        func (*Profile) DeleteAttribute

        func (thisProfile *Profile) DeleteAttribute(sectionName string, key string) error

          DeleteAttribute removes an attribute from a profile. It is important to note that until the Profile is Save()d, the attribute may still exist on the file system.

          func (*Profile) GetAllAttributes

          func (thisProfile *Profile) GetAllAttributes() map[string]map[string]string

            GetAllAttribute simply returns the a nested map that has two sets of keys, a section key, and then a normal key. Any attributes without a section will be returned under the section key of "default".

            Example: Map Structure

            default:
            	my_key: my_value
            a_section:
            	my_key: my_value
            	a_key: a_value
            b_section:
            	my_key: my_value
            	b_key: b_value
            

            func (*Profile) GetAllSectionAttributes

            func (thisProfile *Profile) GetAllSectionAttributes(sectionName string) (map[string]string, error)

              GetAllSection attributes is responsible for returning all of the attributes for one section. It returns this as a simple map with the key and value for each attribute only. There are no section references returned by this function.

              func (*Profile) GetAttribute

              func (thisProfile *Profile) GetAttribute(sectionName string, key string) string

                GetAttribute retrieves an attribute from a profile section. If the section name is blank, the attribute will be retrieved from the default store which has no section name.

                func (*Profile) SetAttribute

                func (thisProfile *Profile) SetAttribute(sectionName string, key string, value string) error

                  SetAttribute is responsible for setting an attribute against a section name. If the section name is blank, the attribute will be stored without a section.

                  Example: With Section

                  myProfile.SetAttribute("a_section", "a_key", "a_value")
                  
                  // my_profile (ini)
                  // [a_section]
                  // a_key = a_value <-- this value will be set
                  

                  Example: No Section

                  myProfile.SetAttribute("", "a_key", "a_value")
                  
                  // my_profile (ini)
                  // a_key = a_value <-- this value will be set
                  
                  // [a_section]
                  // a_key = a_value