Skip to content

Commit

Permalink
Merge pull request #389 from 3scale/configuration-cli
Browse files Browse the repository at this point in the history
[cli] improve configuration handling
  • Loading branch information
mikz authored Jul 7, 2017
2 parents 292ff43 + c486586 commit 7623e7c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- APIcast module `balancer` method now accepts optional balancer [PR #362](https://github.com/3scale/apicast/pull/362)
- Extracted lua-resty-url [PR #384](https://github.com/3scale/apicast/pull/384)
- Extracted lua-resty-env [PR #386](https://github.com/3scale/apicast/pull/386)
- Do not load all services when APICAST_SERVICES is set [PR #388](https://github.com/3scale/apicast/pull/388)
- Do not load all services when APICAST\_SERVICES is set [PR #388](https://github.com/3scale/apicast/pull/388)

### Added

- APIcast published to [luarocks.org](https://luarocks.org/modules/3scale/apicast) [PR #366](https://github.com/3scale/apicast/pull/366)
- Support for passing remote configuratio URL through the CLI [PR #389](https://github.com/3scale/apicast/pull/389)
- CLI flag -b to load configuration on boot [PR #389](https://github.com/3scale/apicast/pull/389)

## [3.1.0-alpha1] - 2017-05-05

Expand Down
8 changes: 6 additions & 2 deletions apicast/bin/apicast
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,23 @@ usage () {
-m <on|off> Whether to start worker processes. Only for development.
-s <signal> Send signal to a master process: stop, quit, reopen, reload
-p <pid> Path to the PID file.
-b Load configuration on boot.
USAGE
}

main=("")
args=("")

while getopts ":dc:hvqi:rw:m:s:p:" opt; do
while getopts ":dc:hvbqi:rw:m:s:p:" opt; do
case "${opt}" in
d)
daemon="on"
;;
c)
export THREESCALE_CONFIG_FILE="$OPTARG"
export APICAST_CONFIGURATION="$OPTARG"
;;
b)
export APICAST_CONFIGURATION_LOADER="boot"
;;
v)
log_level=$((log_level == max_log_level ? max_log_level : log_level+1))
Expand Down
19 changes: 19 additions & 0 deletions apicast/src/configuration_loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ local remote_loader_v1 = require 'configuration_loader.remote_v1'
local remote_loader_v2 = require 'configuration_loader.remote_v2'
local util = require 'util'
local env = require('resty.env')
local resty_url = require('resty.url')
local synchronization = require('resty.synchronization').new(1)
local keycloak = require 'oauth.keycloak'
local cjson = require 'cjson'
Expand All @@ -23,6 +24,24 @@ local _M = {
}

function _M.load(host)
local configuration = env.get('APICAST_CONFIGURATION')
local uri = resty_url.parse(configuration)

if uri then
local scheme = uri.scheme

if scheme == 'file' then
env.set('THREESCALE_CONFIG_FILE', uri.path)
elseif scheme == 'http' or scheme == 'https' then
env.set('THREESCALE_PORTAL_ENDPOINT', uri)
else
ngx.log(ngx.WARN, 'unknown configuration URI: ', uri)
end
elseif configuration then
ngx.log(ngx.DEBUG, 'falling back to file system path for configuration')
env.set('THREESCALE_CONFIG_FILE', configuration)
end

return mock_loader.call() or file_loader.call() or remote_loader_v2:call(host) or remote_loader_v1.call(host)
end

Expand Down

0 comments on commit 7623e7c

Please sign in to comment.