Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CLI command to push policy schemas #992

Merged
merged 4 commits into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- New routing policy that selects an upstream based on the request path, a header, a query argument, or a jwt claim [PR #976](https://github.com/3scale/apicast/pull/976), [PR #983](https://github.com/3scale/apicast/pull/983), [PR #984](https://github.com/3scale/apicast/pull/984), [THREESCALE-1709](https://issues.jboss.org/browse/THREESCALE-1709)
- Added "last" attribute in the mapping rules. When set to true indicates that, if the rule matches, APIcast should not try to match the rules placed after this one [PR #982](https://github.com/3scale/apicast/pull/982), [THREESCALE-1344](https://issues.jboss.org/browse/THREESCALE-1344)
- Added TLS Validation policy to verify TLS Client Certificate against a whitelist. [PR #966](https://github.com/3scale/apicast/pull/966), [THREESCALE-1671](https://issues.jboss.org/browse/THREESCALE-1671)
- New CLI command "push_policy" that pushes a policy schema to the 3scale admin portal [PR #986](https://github.com/3scale/apicast/pull/986), [THREESCALE-871](https://issues.jboss.org/browse/THREESCALE-871)
- New CLI command "push_policy" that pushes a policy schema to the 3scale admin portal [PR #986](https://github.com/3scale/apicast/pull/986), [PR #992](https://github.com/3scale/apicast/pull/992), [THREESCALE-871](https://issues.jboss.org/browse/THREESCALE-871)
- Added support for experimental standalone YAML configuration [PR #926](https://github.com/3scale/apicast/pull/926)

### Changed
Expand Down
2 changes: 1 addition & 1 deletion doc/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ The value will also be used in the header `X-3scale-User-Agent` in the authorize

### `THREESCALE_PORTAL_ENDPOINT`

URI that includes your password and portal endpoint in the following format: `<schema>://<password>@<admin-portal-domain>`. The `<password>` can be either the [provider key](https://support.3scale.net/docs/terminology#apikey) or an [access token](https://support.3scale.net/docs/terminology#tokens) for the 3scale Account Management API. `<admin-portal-domain>` is the URL used to log into the admin portal.
URI that includes your password and portal endpoint in the following format: `<schema>://<password>@<admin-portal-domain>`. The `<password>` can be either the provider key or an access token for the 3scale Account Management API. `<admin-portal-domain>` is the URL used to log into the admin portal.

**Example:** `https://[email protected]`.

Expand Down
11 changes: 7 additions & 4 deletions gateway/src/apicast/policy_pusher.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local policy_manifests_loader = require('apicast.policy_manifests_loader')
local http_ng = require('resty.http_ng')
local resty_env = require('resty.env')

local setmetatable = setmetatable
local format = string.format
Expand All @@ -17,15 +18,17 @@ end

local system_endpoint = '/admin/api/registry/policies'

local function system_url(access_token, admin_portal_domain)
return format('https://%s:%s%s', access_token, admin_portal_domain, system_endpoint)
local function system_url(admin_portal_domain)
return format('https://%s%s', admin_portal_domain, system_endpoint)
end

local function push_to_system(name, version, manifest, admin_portal_domain, access_token, http_client)
local url = system_url(access_token, admin_portal_domain)
local url = system_url(admin_portal_domain)

return http_client.json.post(
url, { name = name, version = version, schema = manifest }
url,
{ access_token = access_token, name = name, version = version, schema = manifest },
{ ssl = { verify = resty_env.enabled('OPENSSL_VERIFY') } }
)
end

Expand Down
6 changes: 4 additions & 2 deletions spec/policy_pusher_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ describe('Policy pusher', function()
describe('if the policy exists', function()
it('pushes the policy to the 3scale admin portal', function()
local request_body = {
access_token = access_token,
name = policy_name,
version = policy_version,
schema = policy_manifest
}

test_backend.expect{
url = 'https://' .. access_token .. ':' .. admin_portal_domain ..
url = 'https://' .. admin_portal_domain ..
'/admin/api/registry/policies',
body = cjson.encode(request_body)
}.respond_with{ status = 200 }
Expand Down Expand Up @@ -66,6 +67,7 @@ describe('Policy pusher', function()
stub(ngx, 'log')

local request_body = {
access_token = access_token,
name = policy_name,
version = policy_version,
schema = policy_manifest
Expand All @@ -74,7 +76,7 @@ describe('Policy pusher', function()
local error_msg_returned = 'Some error'

test_backend.expect{
url = 'https://' .. access_token .. ':' .. admin_portal_domain ..
url = 'https://' .. admin_portal_domain ..
'/admin/api/registry/policies',
body = cjson.encode(request_body)
}.respond_with{ status = 400, body = error_msg_returned }
Expand Down