Skip to content

Commit

Permalink
[cli] use resty_env.value instead of .get
Browse files Browse the repository at this point in the history
* .value returns nil when the value is empty string
* so it can be chain with `or` for a default value
  • Loading branch information
mikz committed Nov 28, 2017
1 parent fdeb3a0 commit 20504a8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## Changed

- Namespace all APIcast code in `apicast` folder. Possible BREAKING CHANGE for some customizations. [PR #486](https://github.com/3scale/apicast/pull/486)
- CLI ignores environment variables that are empty strings [PR #504](https://github.com/3scale/apicast/pull/504)

## Fixed

Expand Down
18 changes: 9 additions & 9 deletions gateway/src/apicast/cli/command/start.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ end


local function apicast_root()
return resty_env.get('APICAST_DIR') or pl.path.abspath('.')
return resty_env.value('APICAST_DIR') or pl.path.abspath('.')
end

local function nginx_config(context,path)
Expand Down Expand Up @@ -167,31 +167,31 @@ local function configure(cmd)
cmd:option("--template", "Nginx config template.", 'conf/nginx.conf.liquid')


cmd:option('-e --environment', "Deployment to start. Can also be a path to a Lua file.", resty_env.get('THREESCALE_DEPLOYMENT_ENV') or 'production'):count('*')
cmd:option('-e --environment', "Deployment to start. Can also be a path to a Lua file.", resty_env.value('THREESCALE_DEPLOYMENT_ENV') or 'production'):count('*')
cmd:flag('--dev', 'Start in development environment')

cmd:flag("-m --master", "Test the nginx config"):args('?')
cmd:flag("-t --test", "Test the nginx config")
cmd:flag("--debug", "Debug mode. Prints more information.")
cmd:option("-c --configuration",
"Path to custom config file (JSON)",
resty_env.get('APICAST_CONFIGURATION'))
resty_env.value('APICAST_CONFIGURATION'))
cmd:flag("-d --daemon", "Daemonize.")
cmd:option("-w --workers",
"Number of worker processes to start.",
resty_env.get('APICAST_WORKERS') or 1)
resty_env.value('APICAST_WORKERS') or 1)
cmd:option("-p --pid", "Path to the PID file.")
cmd:mutex(
cmd:flag('-b --boot',
"Load configuration on boot.",
resty_env.get('APICAST_CONFIGURATION_LOADER') == 'boot'),
resty_env.value('APICAST_CONFIGURATION_LOADER') == 'boot'),
cmd:flag('-l --lazy',
"Load configuration on demand.",
resty_env.get('APICAST_CONFIGURATION_LOADER') == 'lazy')
resty_env.value('APICAST_CONFIGURATION_LOADER') == 'lazy')
)
cmd:option("-i --refresh-interval",
"Cache configuration for N seconds. Using 0 will reload on every request (not for production).",
resty_env.get('APICAST_CONFIGURATION_CACHE'))
resty_env.value('APICAST_CONFIGURATION_CACHE'))

cmd:mutex(
cmd:flag('-v --verbose',
Expand All @@ -200,8 +200,8 @@ local function configure(cmd)
cmd:flag('-q --quiet', "Decrease logging verbosity.")
:count(("0-%s"):format(_M.log_level - 1))
)
cmd:option('--log-level', 'Set log level', resty_env.get('APICAST_LOG_LEVEL') or 'warn')
cmd:option('--log-file', 'Set log file', resty_env.get('APICAST_LOG_FILE') or 'stderr')
cmd:option('--log-level', 'Set log level', resty_env.value('APICAST_LOG_LEVEL') or 'warn')
cmd:option('--log-file', 'Set log file', resty_env.value('APICAST_LOG_FILE') or 'stderr')

cmd:epilog([[
Example: apicast start --dev
Expand Down
4 changes: 2 additions & 2 deletions gateway/src/apicast/cli/environment.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ _M.default_environment = 'production'
-- @tfield ?string ca_bundle path to CA store file
-- @table environment.default_config default configuration
_M.default_config = {
ca_bundle = resty_env.get('SSL_CERT_FILE'),
ca_bundle = resty_env.value('SSL_CERT_FILE'),
}

local mt = { __index = _M }
Expand Down Expand Up @@ -59,7 +59,7 @@ function _M.new()
end

local function expand_environment_name(name)
local root = resty_env.get('APICAST_DIR') or pl_path.abspath('.')
local root = resty_env.value('APICAST_DIR') or pl_path.abspath('.')
local pwd = resty_env.value('PWD')

local path = pl_path.abspath(name, pwd)
Expand Down
2 changes: 1 addition & 1 deletion gateway/src/apicast/configuration_loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ local modes = {
}

function _M.new(mode)
mode = mode or env.get('APICAST_CONFIGURATION_LOADER') or modes.default
mode = mode or env.value('APICAST_CONFIGURATION_LOADER') or modes.default
local loader = modes[mode]
ngx.log(ngx.INFO, 'using ', mode, ' configuration loader')
return assert(loader, 'invalid config loader mode')
Expand Down

0 comments on commit 20504a8

Please sign in to comment.