github.com/ablease/cli@v6.37.1-0.20180613014814-3adbb7d7fb19+incompatible/util/configv3/env.go (about) 1 package configv3 2 3 import ( 4 "strconv" 5 "strings" 6 "time" 7 ) 8 9 // EnvOverride represents all the environment variables read by the CF CLI 10 type EnvOverride struct { 11 BinaryName string 12 CFColor string 13 CFDialTimeout string 14 CFHome string 15 CFLogLevel string 16 CFPassword string 17 CFPluginHome string 18 CFStagingTimeout string 19 CFStartupTimeout string 20 CFTrace string 21 CFUsername string 22 DockerPassword string 23 Experimental string 24 ForceTTY string 25 HTTPSProxy string 26 Lang string 27 LCAll string 28 } 29 30 // BinaryName returns the running name of the CF CLI 31 func (config *Config) BinaryName() string { 32 return config.ENV.BinaryName 33 } 34 35 // CFPassword returns the value of the "CF_PASSWORD" environment variable. 36 func (config *Config) CFPassword() string { 37 return config.ENV.CFPassword 38 } 39 40 // CFUsername returns the value of the "CF_USERNAME" environment variable. 41 func (config *Config) CFUsername() string { 42 return config.ENV.CFUsername 43 } 44 45 // DialTimeout returns the timeout to use when dialing. This is based off of: 46 // 1. The $CF_DIAL_TIMEOUT environment variable if set 47 // 2. Defaults to 5 seconds 48 func (config *Config) DialTimeout() time.Duration { 49 if config.ENV.CFDialTimeout != "" { 50 envVal, err := strconv.ParseInt(config.ENV.CFDialTimeout, 10, 64) 51 if err == nil { 52 return time.Duration(envVal) * time.Second 53 } 54 } 55 56 return DefaultDialTimeout 57 } 58 59 // DockerPassword returns the docker password from the environment. 60 func (config *Config) DockerPassword() string { 61 return config.ENV.DockerPassword 62 } 63 64 // Experimental returns whether or not to run experimental CLI commands. This 65 // is based off of: 66 // 1. The $CF_CLI_EXPERIMENTAL environment variable if set 67 // 2. Defaults to false 68 func (config *Config) Experimental() bool { 69 if config.ENV.Experimental != "" { 70 envVal, err := strconv.ParseBool(config.ENV.Experimental) 71 if err == nil { 72 return envVal 73 } 74 } 75 76 return false 77 } 78 79 // HTTPSProxy returns the proxy url that the CLI should use. The url is based 80 // off of: 81 // 1. The $https_proxy environment variable if set 82 // 2. Defaults to the empty string 83 func (config *Config) HTTPSProxy() string { 84 if config.ENV.HTTPSProxy != "" { 85 return config.ENV.HTTPSProxy 86 } 87 88 return "" 89 } 90 91 // LogLevel returns the global log level. The levels follow Logrus's log level 92 // scheme. This value is based off of: 93 // - The $CF_LOG_LEVEL and an int/warn/info/etc... 94 // - Defaults to PANIC/0 (ie no logging) 95 func (config *Config) LogLevel() int { 96 if config.ENV.CFLogLevel != "" { 97 envVal, err := strconv.ParseInt(config.ENV.CFLogLevel, 10, 32) 98 if err == nil { 99 return int(envVal) 100 } 101 102 switch strings.ToLower(config.ENV.CFLogLevel) { 103 case "fatal": 104 return 1 105 case "error": 106 return 2 107 case "warn": 108 return 3 109 case "info": 110 return 4 111 case "debug": 112 return 5 113 } 114 } 115 116 return 0 117 } 118 119 // StagingTimeout returns the max time an application staging should take. The 120 // time is based off of: 121 // 1. The $CF_STAGING_TIMEOUT environment variable if set 122 // 2. Defaults to the DefaultStagingTimeout 123 func (config *Config) StagingTimeout() time.Duration { 124 if config.ENV.CFStagingTimeout != "" { 125 val, err := strconv.ParseInt(config.ENV.CFStagingTimeout, 10, 64) 126 if err == nil { 127 return time.Duration(val) * time.Minute 128 } 129 } 130 131 return DefaultStagingTimeout 132 } 133 134 // StartupTimeout returns the max time an application should take to start. The 135 // time is based off of: 136 // 1. The $CF_STARTUP_TIMEOUT environment variable if set 137 // 2. Defaults to the DefaultStartupTimeout 138 func (config *Config) StartupTimeout() time.Duration { 139 if config.ENV.CFStartupTimeout != "" { 140 val, err := strconv.ParseInt(config.ENV.CFStartupTimeout, 10, 64) 141 if err == nil { 142 return time.Duration(val) * time.Minute 143 } 144 } 145 146 return DefaultStartupTimeout 147 }