Skip to content

Commit

Permalink
[policy] rename apicast.policy.policy to apicast.policy
Browse files Browse the repository at this point in the history
  • Loading branch information
mikz committed Feb 1, 2018
1 parent a1064da commit bc23f85
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 22 deletions.
2 changes: 1 addition & 1 deletion doc/policies.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ replaceable with custom ones.
## Write your own policy

To write your own policy you need to write a Lua module that instantiates a
[Policy](../gateway/src/apicast/policy/policy.lua) and defines a method for
[Policy](../gateway/src/apicast/policy.lua) and defines a method for
each of the phases where it needs to execute something.

Suppose that we wanted to run a policy that logged a message in the `rewrite`
Expand Down
3 changes: 3 additions & 0 deletions gateway/src/apicast/loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
-- Policies can be packaged as `some_name/policy.lua` so the directory also contains the JSON spec.

local loadfile = loadfile
local find = string.find

local map = {
['apicast'] = 'apicast.policy.apicast'
Expand All @@ -25,6 +26,8 @@ end

--- Try to load a policy. Policies can have a `.policy` suffix.
local function policy_loader(name, path)
if not find(name, '.policy.', 1, true) then return end

local policy = name .. '.policy'

return loader(policy, path or package.path)
Expand Down
File renamed without changes.
72 changes: 51 additions & 21 deletions t/deprecation-warnings.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,68 @@ run_tests();
__DATA__
=== TEST 1: deprecation warnings
APIcast should emit deprecation warnings when loading code using the old paths.
APIcast should emit deprecation warnings when loading renamed files.
--- configuration
{
"services": [
{
"backend_version": 1,
"proxy": {
"policy_chain": [
{ "name": "policy.echo" },
{ "name": "apicast" }
],
"proxy_rules": [
{ "pattern": "/", "http_method": "GET", "metric_system_name": "hits", "delta": 2 }
]
{ "services": [
{ "proxy":
{ "policy_chain": [
{ "name": "apicast.policy.upstream",
"configuration": {
"rules": [{
"regex": "/",
"url": "http://test:$TEST_NGINX_SERVER_PORT"
}]
}
}
}
]
}
--- backend
location /transactions/authrep.xml {
] }
}
] }
--- upstream
location /{
content_by_lua_block {
require('apicast')
ngx.exit(200)
}
}
--- request
GET /echo?user_key=foo
--- response_body
GET /echo?user_key=foo HTTP/1.1
--- error_code: 200
--- no_error_log
[error]
--- grep_error_log eval: qr/DEPRECATION:[^,]+/
--- grep_error_log_out
DEPRECATION: when loading apicast code use correct prefix: require("apicast.policy.echo")
DEPRECATION: file renamed - change: require("apicast") to: require("apicast.policy.apicast")
=== TEST 2: deprecation warnings
APIcast should emit deprecation warnings when loading not namespaced code.
--- configuration
{ "services": [
{ "proxy":
{ "policy_chain": [
{ "name": "apicast.policy.upstream",
"configuration": {
"rules": [{
"regex": "/",
"url": "http://test:$TEST_NGINX_SERVER_PORT"
}]
}
}
] }
}
] }
--- upstream
location /{
content_by_lua_block {
require('cli')
ngx.exit(200)
}
}
--- request
GET /echo?user_key=foo
--- error_code: 200
--- no_error_log
[error]
--- grep_error_log eval: qr/DEPRECATION:[^,]+/
--- grep_error_log_out
DEPRECATION: when loading apicast code use correct prefix: require("apicast.cli")

0 comments on commit bc23f85

Please sign in to comment.