func getAliasUsingValue(value string) (string, error) {
	alias, err := getAliasUsingValueFromDB(value)
	if err != nil {
		return "", err
	} else {
		return alias, nil
	}
}
getAliasUsingValue returns the alias that has 'value'.
If more than one alias exist, it will return one selected at random.
package main
import (
	"fmt"
	"io/ioutil"
	"os"
	"os/user"
	"reflect"
	"strings"
	"text/tabwriter"
	"github.com/ghodss/yaml"
)
type localConfig struct {
	AutoSynch     string `json:"auto_synch"`
	EnvelopeUUID  string `json:"envelope_uuid"`
	Focus         string `json:"focus"`
	LedgerAddress string `json:"ledger_address"`
	LedgerNetwork string `json:"ledger_network"`
	PartUUID      string `json:"part_uuid"`
	PrivateKey    string `json:"private_key"`
	PublicKey     string `json:"public_key"`
	SupplierUUID  string `json:"supplier_uuid"`
}
const (
	_AUTO_SYNCH_KEY     = "auto_synch"
	_ENVELOPE_KEY       = "envelope_uuid"
	_FOCUS_KEY          = "focus"
	_LEDGER_ADDRESS_KEY = "ledger_address"
	_LEDGER_NETWORK_KEY = "ledger_network"
	_SUPPLIER_KEY       = "supplier_uuid"
	_PART_KEY           = "part_uuid"
	_PRIVATE_KEY        = "private_key"
	_PUBLIC_KEY         = "public_key"
)
type globalConfig struct {
	AtlasAddress string `json:"atlas_address"`
	UserName     string `json:"user_name"`
	UserEmail    string `json:"user_email"`
}
const (
	_ATLAS_ADDRESS_KEY = "atlas_address"
	_USER_NAME_KEY     = "user_name"
	_USER_EMAIL_KEY    = "user_email"
)
type AlisaRecord struct {
	Alias string `json:"name"`
	Value string `json:"value"`
}
func getLocalConfigValue(key string) string {
	spartsDir, err := getSpartsDirectory()
	if err != nil {
		fmt.Println(err)
		return ""
	}
	configFile := spartsDir + "/" + _LOCAL_CONFIG_FILE
	configData, err := readLocalConfig(configFile)
	if err != nil {
		fmt.Println(err)
		return ""
	}
	switch strings.ToLower(key) {
	case _LEDGER_ADDRESS_KEY:
		return configData.LedgerAddress
	case _ENVELOPE_KEY:
		return configData.EnvelopeUUID
	case _FOCUS_KEY:
		return configData.Focus
	case _PART_KEY:
		return configData.PartUUID
	case _PRIVATE_KEY:
		return configData.PrivateKey
	case _PUBLIC_KEY:
		return configData.PublicKey
	case _LEDGER_NETWORK_KEY:
		return configData.LedgerNetwork
	case _SUPPLIER_KEY:
		return configData.SupplierUUID
	case _AUTO_SYNCH_KEY:
		return configData.AutoSynch
	}
	return ""
}
func setLocalConfigValue(key string, newValue string) error {
	spartsDir, err := getSpartsDirectory()
	if err != nil {
		return err
	}
	configFile := spartsDir + "/" + _LOCAL_CONFIG_FILE
	configData, err := readLocalConfig(configFile)
	if err != nil {
		fmt.Println(err)
		return err
	}
	switch strings.ToLower(key) {
	case _LEDGER_ADDRESS_KEY:
		configData.LedgerAddress = newValue
	case _LEDGER_NETWORK_KEY:
		configData.LedgerNetwork = newValue
	case _ENVELOPE_KEY:
		configData.EnvelopeUUID = newValue
	case _FOCUS_KEY:
		configData.Focus = newValue
	case _PART_KEY:
		if isValidUUID(newValue) || strings.ToLower(newValue) == strings.ToLower(_NULL_UUID) {
			configData.PartUUID = newValue
		} else {
			return fmt.Errorf("UUID syntax is not valid.")
		}
	case _PRIVATE_KEY:
		configData.PrivateKey = newValue
	case _PUBLIC_KEY:
		configData.PublicKey = newValue
	case _SUPPLIER_KEY:
		if isValidUUID(newValue) {
			configData.SupplierUUID = newValue
		} else {
			return fmt.Errorf("UUID syntax is not valid.")
		}
	case _AUTO_SYNCH_KEY:
		configData.AutoSynch = newValue
	default:
		return fmt.Errorf("  '%s' is not a validate local configuration value\n", key)
	}
	d, err := yaml.Marshal(&configData)
	if err != nil {
		return err
	}
	err = ioutil.WriteFile(configFile, d, 0644)
	if err != nil {
		return err
	}
	return nil
}
func readLocalConfig(configPath string) (configData localConfig, err error) {
	y, err := ioutil.ReadFile(configPath)
	if err != nil {
		return configData, err
	}
	err = yaml.Unmarshal(y, &configData)
	if err != nil {
		return configData, fmt.Errorf("yaml.Unmarshal err   #%v ", err)
	}
	return configData, nil
}
func displayLocalConfigData() {
	spartsDir, err := getSpartsDirectory()
	if err != nil {
		fmt.Println(err)
		return
	}
	data, err := readLocalConfig(spartsDir + "/" + _LOCAL_CONFIG_FILE)
	if err != nil {
		fmt.Println(err)
		return
	}
	s := reflect.ValueOf(&data).Elem()
	typeOfT := s.Type()
	fmt.Println("|-----------------------------------------------------")
	fmt.Println("|	Local Configuration")
	fmt.Println("|-----------------------------------------------------")
	const padding = 0
	w := tabwriter.NewWriter(os.Stdout, 0, 0, padding, ' ', tabwriter.Debug)
	for i := 0; i < s.NumField(); i++ {
		f := s.Field(i)
		fmt.Fprintf(w, "\t %s\t %v\n", typeOfT.Field(i).Tag.Get("json"), f.Interface())
	}
	w.Flush()
}
func getGlobalConfigValue(value string) string {
	configFile, err := getGlobalConfigFile()
	if err != nil {
		fmt.Println(err)
		return ""
	}
	configData, err := readGlobalConfig(configFile)
	if err != nil {
		fmt.Println(err)
		return ""
	}
	switch strings.ToLower(value) {
	case _ATLAS_ADDRESS_KEY:
		return configData.AtlasAddress
	case _USER_NAME_KEY:
		return configData.UserName
	case _USER_EMAIL_KEY:
		return configData.UserEmail
	}
	return ""
}
func getGlobalConfigFile() (string, error) {
	usr, err := user.Current()
	if err != nil {
		fmt.Println("Error locating home directory")
		fmt.Println(err)
		return "", err
	}
	globalConfigFile := usr.HomeDir + "/" + _GLOBAL_CONFIG_FILE
	if _, err := os.Stat(globalConfigFile); os.IsNotExist(err) {
		fmt.Println("File does not exist:", globalConfigFile)
		fmt.Println("Creating config file")
		globalFile, err := os.Create(globalConfigFile)
		if err != nil {
			fmt.Println("Error Creating global config file: ", err)
			return "", err
		}
		defer globalFile.Close()
		_, err = globalFile.WriteString(_GLOBAL_CONFIG_FILE_CONTENT)
		if err != nil {
			fmt.Println("Error - writing to global config file: ", err)
			return "", err
		}
	}
	globalConfigFile = strings.Replace(globalConfigFile, `\`, `/`, -1)
	return globalConfigFile, nil
}
func setGlobalConfigValue(field string, newValue string) {
	globalConfigFile, _ := getGlobalConfigFile()
	configData, err := readGlobalConfig(globalConfigFile)
	if err != nil {
		fmt.Println("Error reading global configuation file")
		fmt.Println(err)
		return
	}
	switch strings.ToLower(field) {
	case _ATLAS_ADDRESS_KEY:
		configData.AtlasAddress = newValue
	case _USER_NAME_KEY:
		configData.UserName = newValue
	case _USER_EMAIL_KEY:
		configData.UserEmail = newValue
	}
	d, err := yaml.Marshal(&configData)
	if err != nil {
		panic(err)
	}
	err = ioutil.WriteFile(globalConfigFile, d, 0644)
	if err != nil {
		panic(err)
	}
}
func readGlobalConfig(configPath string) (configData globalConfig, err error) {
	y, err := ioutil.ReadFile(configPath)
	if err != nil {
		return configData, err
	}
	err = yaml.Unmarshal(y, &configData)
	if err != nil {
		return configData, fmt.Errorf("yaml.Unmarshal err   #%v ", err)
	}
	return configData, nil
}
func displayGlobalConfigData() {
	globalCoinfigFile, err := getGlobalConfigFile()
	data, err := readGlobalConfig(globalCoinfigFile)
	if err != nil {
		fmt.Println("Error reading the global configuration file")
		fmt.Println(err)
		return
	}
	if err != nil {
		fmt.Printf("error: %v", err)
	}
	s := reflect.ValueOf(&data).Elem()
	typeOfT := s.Type()
	fmt.Println("|-----------------------------------------------------")
	fmt.Println("|	Global Configuration")
	fmt.Println("|-----------------------------------------------------")
	const padding = 0
	w := tabwriter.NewWriter(os.Stdout, 0, 0, padding, ' ', tabwriter.Debug)
	for i := 0; i < s.NumField(); i++ {
		f := s.Field(i)
		fmt.Fprintf(w, "\t %s\t %v\n", typeOfT.Field(i).Tag.Get("json"), f.Interface())
	}
	w.Flush()
}
func setAlias(alias string, value string) error {
	addAliasValueToDB(alias, value)
	return nil
}
func getAlias(alias string) (string, error) {
	aliasValue, err := getAliasValueFromDB(alias)
	if err != nil {
		return "", err
	}
	return aliasValue, nil
}