Skip to content

Commit

Permalink
[cli] allow passing context to environment files
Browse files Browse the repository at this point in the history
  • Loading branch information
mikz committed Feb 1, 2019
1 parent d1b258d commit 090566f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ busted = {std = "+busted", globals = { 'fixture' } }
files["**/spec/**/*_spec.lua"] = busted

globals = { 'rawlen' }

files['gateway/config/*.lua'] = { globals = { 'context' } }
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Added

- Environment files now can use global `context` variable to share data [PR #964](https://github.com/3scale/apicast/pull/964)

### Changed

- Improve startup time by improving templating performance and caching filesystem access [PR #964](https://github.com/3scale/apicast/pull/964)
Expand Down
5 changes: 4 additions & 1 deletion gateway/src/apicast/cli/command/start.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ end


local function build_environment_config(options)
local config = Environment.new()
local config = Environment.new(options)

resty_env.set('APICAST_POLICY_LOAD_PATH', concat(options.policy_load_path,':'))

Expand Down Expand Up @@ -139,6 +139,9 @@ local function build_context(options, config)

context.access_log_file = options.access_log_file

-- expose parsed CLI options
context.options = options

return context
end

Expand Down
5 changes: 3 additions & 2 deletions gateway/src/apicast/cli/environment.lua
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ _M.default_config = {
policy_chain = require('apicast.policy_chain').default(),
nameservers = parse_nameservers(),
worker_processes = cpus() or 'auto',
template = 'http.d/apicast.conf.liquid',
package = {
path = package.path,
cpath = package.cpath,
Expand Down Expand Up @@ -151,8 +152,8 @@ end

--- Initialize new environment.
-- @treturn Environment
function _M.new()
return setmetatable({ _context = linked_list.readonly(_M.default_config), loaded = {} }, mt)
function _M.new(context)
return setmetatable({ _context = linked_list.readonly(_M.default_config, context), loaded = {} }, mt)
end

local function expand_environment_name(name)
Expand Down
14 changes: 14 additions & 0 deletions spec/cli/environment_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
local _M = require('apicast.cli.environment')

describe('Environment Configuration', function ()

describe('.new', function()
it('accepts default', function()
local default = { foo = 'bar' }
local env = _M.new(default)

assert.contains(default, env:context())
end)
end)

end)

0 comments on commit 090566f

Please sign in to comment.