Documentation ¶
Index ¶
- Constants
- Variables
- func FileExists(directory string, fileName string) bool
- func GetConfigFromNonJsonFile(configFile string) (map[string]string, error)
- func GetEnvVars() map[string]string
- func GetProjectConfigFile(dir string) (string, error)
- func GetVarsFromConfig(config *HorizonCliConfig) (map[string]string, map[string]string)
- func GetVarsFromFile(configFile string) (map[string]string, map[string]string, error)
- func ReadJsonFileWithLocalConfig(filePath string) []byte
- func RestoreEnvVars(orig_env_vars, hzn_vars, metadata_vars map[string]string) error
- func SetEnvVars(new_env_vars, orig_env_vars map[string]string, override bool) error
- func SetEnvVarsFromConfigFile(configFile string, orig_env_vars map[string]string, override_env bool) (map[string]string, map[string]string, error)
- func SetEnvVarsFromConfigFiles(project_dir string) error
- func SetEnvVarsFromNonJsonFile(configFile string, orig_env_vars map[string]string, override_env bool) (map[string]string, error)
- func SetEnvVarsFromProjectConfigFile(project_dir string) error
- type HorizonCliConfig
Constants ¶
const CONFIG_FILE_NAME = "hzn.json"
const DEFAULT_CONFIG_FILE = "hzn.json"
const DEV_DEFAULT_DEPENDENCY_DIR = "dependencies"
const DEV_DEFAULT_WORKING_DIR = "horizon"
const DEV_SERVICE_DEFINITION_FILE = "service.definition.json"
Variables ¶
var PACKAGE_CONFIG_FILE string
var PROJECT_CONFIG_FILE string
var USER_CONFIG_FILE string
Functions ¶
func FileExists ¶
Check for file existence and return any errors. Treat error as file does not exists because os.Stat() only returns PathError.
func GetEnvVars ¶
get all the env vars and convert them to a map for easy referencing later.
func GetProjectConfigFile ¶
check the project's configuration file, it could be under current directory or the ./horizon directory or ../ directory if current directory is dependecies. it is usually setup by 'hzn dev service create' command
func GetVarsFromConfig ¶
func GetVarsFromConfig(config *HorizonCliConfig) (map[string]string, map[string]string)
returns the hzn level env vars and metadata vars from the config in the map format
func GetVarsFromFile ¶
returns the hzn level env vars and metadata vars from the config file
func ReadJsonFileWithLocalConfig ¶
ReadJsonFile reads json from a file or stdin, eliminates comments, setup env vars from local hzn.json configuration file if any, substitutes env vars, and returns it.
func RestoreEnvVars ¶
restore the env vars to its original state after setting up hzn_vars and metadata_vars
func SetEnvVars ¶
func SetEnvVarsFromConfigFile ¶
func SetEnvVarsFromConfigFile(configFile string, orig_env_vars map[string]string, override_env bool) (map[string]string, map[string]string, error)
set up the environment variables from the given config file. skip the ones that's alrady there originally if override_env is false it returns the hzn env vars and metadata env vars from the given file
func SetEnvVarsFromConfigFiles ¶
set up the environment variables from the config files. the precedence order is: environmental variables, user config file, package config file
func SetEnvVarsFromNonJsonFile ¶
func SetEnvVarsFromNonJsonFile(configFile string, orig_env_vars map[string]string, override_env bool) (map[string]string, error)
set up the environment variables from the given non-jsonfile. skip the ones that's alrady there originally if override_env is false it returns the hzn env vars from the given file
func SetEnvVarsFromProjectConfigFile ¶
set up the environment variables from the project config files. the precedence order is: environmental variables, project config file
Types ¶
type HorizonCliConfig ¶
type HorizonCliConfig struct { // user usually needs to setup these, or input them with the flags for a hzn command HZN_EXCHANGE_USER_AUTH string `json:"HZN_EXCHANGE_USER_AUTH,omitempty"` HZN_EXCHANGE_NODE_AUTH string `json:"HZN_EXCHANGE_NODE_AUTH,omitempty"` HZN_ORG_ID string `json:"HZN_ORG_ID,omitempty"` // the locale that the hzn cli will run under, for example pt-BR, es, fr, de, it, ja, ko, zh-CN, zh-TW. HZN_LANG string `json:"HZN_LANG,omitempty"` // the url to the horizon agent, the default is "http://localhost" for linux and "http://localhost:8081" for mac HORIZON_URL string `json:"HORIZON_URL,omitempty"` // exchange url, the default is shipped with the horizon-cli package HZN_EXCHANGE_URL string `json:"HZN_EXCHANGE_URL,omitempty"` // the CSS url, the default is shipped with the horizon-cli package HZN_FSS_CSSURL string `json:"HZN_FSS_CSSURL,omitempty"` // keys to sign the service or pattern, the default is ~/.hzn/keys/service.private.key and ~/.hzn/keys/service.public.pem HZN_PRIVATE_KEY_FILE string `json:"HZN_PRIVATE_KEY_FILE,omitempty"` HZN_PUBLIC_KEY_FILE string `json:"HZN_PUBLIC_KEY_FILE,omitempty"` // the following are only used by 'hzn dev' commands HZN_DEVICE_ID string `json:"HZN_DEVICE_ID,omitempty"` HZN_PATTERN string `json:"HZN_PATTERN,omitempty"` HZN_DEV_FSS_IMAGE_TAG string `json:"HZN_DEV_FSS_IMAGE_TAG,omitempty"` HZN_DEV_FSS_CSS_PORT string `json:"HZN_DEV_FSS_CSS_PORT,omitempty"` HZN_DEV_FSS_MONGO_IMAGE string `json:"HZN_DEV_FSS_MONGO_IMAGE,omitempty"` HZN_DEV_FSS_WORKING_DIR string `json:"HZN_DEV_FSS_WORKING_DIR,omitempty"` // used to substitute the env variables in a file MetadataVars map[string]string `json:"MetadataVars,omitempty"` }
configuration for hzn command
func GetConfig ¶
func GetConfig(configFile string) (*HorizonCliConfig, error)
get the config from the given file. Assume file exists.