Skip to content

Instantly share code, notes, and snippets.

@kevprice83
Last active July 27, 2018 13:13
Show Gist options
  • Save kevprice83/29137761b92845b8b5d76f62f6af5d63 to your computer and use it in GitHub Desktop.
Save kevprice83/29137761b92845b8b5d76f62f6af5d63 to your computer and use it in GitHub Desktop.
Apicast policies with AMP2.0

Steps to enable 3scale batcher policy

Follow the steps to download and modify the JSON config file for your gateway and then run the list of commands in OpenShift to enable the policy.

Modifying the JSON

  • Download the specific version of the apicast config file required from the API manager.
curl -X GET "https://{TENANT_NAME}-admin.{WILDCARD_DOMAIN}/admin/api/services/{service_id}/proxy/configs/{environment}/{version}.json?access_token={access_token}" > apicast.json
  • Wrap the JSON file in a JSON object and services array and remove the proxy_config.content parent objects.
  • Add the policy_chain to the proxy object within the new JSON.

An example policy_chain JSON would look like this:

{
	"policy_chain": [{
		"name": "3scale_batcher",
		"version": "builtin",
		"configuration": {
			"auths_ttl": 120,
			"batch_report_seconds": 120
		}
	}, {
		"name": "apicast",
		"version": "builtin",
		"configuration": {}
	}]
}

The values used above are just examples. You should end up with a JSON config file as shown here.

This JSON config file needs to be used by APIcast locally so we will use the env var THREESCALE_CONFIG_FILE which will reference the local path of the config file on the container. The following steps are to create the configmap and update the apicast dc to enable the policy in the new gateway.

OpenShift configmap

  • oc create configmap apicast-json --from-file=./apicast.json
  • oc volume dc/{dc_name} --add --name=apicast-configuration -m /tmp/foobar -t configmap --configmap-name=apicast-json
  • oc env dc/{dc_name} THREESCALE_CONFIG_FILE=/tmp/foobar/apicast.json
  • oc env dc/{dc_name} THREESCALE_PORTAL_ENDPOINT-
  • oc edit dc/{dc_name} You will enter the editor and need to add the subPath to end up with something like the following:
volumeMounts:
  - mountPath: /tmp/foobar/apicast.json
    name: apicast-configuration
    subPath: apicast.json
  • oc patch dc {dc_name} -p '{"spec": {"template": {"spec": {"containers": [{"name": "{dc_name}", "image": "quay.io/3scale/apicast:master" }]} }}}'

Ensure the deployment config has been redeployed with all the latest changes using oc describe dc/{dc_name} and verify all the above changes exist.

{
"services": [
{
"id": 2,
"account_id": 2,
"name": "API",
"oneline_description": null,
"description": null,
"txt_api": null,
"txt_support": null,
"txt_features": null,
"created_at": "2018-07-17T13:49:31Z",
"updated_at": "2018-07-19T15:39:06Z",
"logo_file_name": null,
"logo_content_type": null,
"logo_file_size": null,
"state": "incomplete",
"intentions_required": false,
"draft_name": "",
"infobar": null,
"terms": null,
"display_provider_keys": false,
"tech_support_email": null,
"admin_support_email": null,
"credit_card_support_email": null,
"buyers_manage_apps": true,
"buyers_manage_keys": true,
"custom_keys_enabled": true,
"buyer_plan_change_permission": "request",
"buyer_can_select_plan": false,
"notification_settings": {
"web_provider": [
0,
50,
80,
90,
100
],
"email_provider": [
0
],
"web_buyer": [
0,
50,
80,
90,
100
],
"email_buyer": [
0
]
},
"default_application_plan_id": 6,
"default_service_plan_id": 3,
"buyer_can_see_log_requests": false,
"default_end_user_plan_id": null,
"end_user_registration_required": true,
"tenant_id": 2,
"system_name": "api",
"backend_version": "1",
"mandatory_app_key": true,
"buyer_key_regenerate_enabled": true,
"support_email": "[email protected]",
"referrer_filters_required": false,
"deployment_option": "on_3scale",
"proxiable?": true,
"backend_authentication_type": "service_token",
"backend_authentication_value": "4f5b4f1038b4601917ea2352347984f22f1e66d23f44b5458b8ca2dc3058fc1b",
"proxy": {
"id": 2,
"tenant_id": 2,
"service_id": 2,
"endpoint": "https://api-3scale-apicast-production.54.174.155.26.xip.io:443",
"deployed_at": null,
"api_backend": "https://echo-api.3scale.net:443",
"auth_app_key": "app_key",
"auth_app_id": "app_id",
"auth_user_key": "user_key",
"credentials_location": "query",
"error_auth_failed": "Authentication failed",
"error_auth_missing": "Authentication parameters missing",
"created_at": "2018-07-17T13:49:32Z",
"updated_at": "2018-07-19T15:39:06Z",
"error_status_auth_failed": 403,
"error_headers_auth_failed": "text/plain; charset=us-ascii",
"error_status_auth_missing": 403,
"error_headers_auth_missing": "text/plain; charset=us-ascii",
"error_no_match": "No Mapping Rule matched",
"error_status_no_match": 404,
"error_headers_no_match": "text/plain; charset=us-ascii",
"secret_token": "Shared_secret_sent_from_proxy_to_API_backend_4b585222aba1714d",
"hostname_rewrite": "",
"oauth_login_url": null,
"sandbox_endpoint": "https://api-3scale-apicast-staging.54.174.155.26.xip.io:443",
"api_test_path": "/test",
"api_test_success": false,
"hostname_rewrite_for_sandbox": "echo-api.3scale.net",
"endpoint_port": 443,
"valid?": true,
"service_backend_version": "1",
"hosts": [
"api-3scale-apicast-production.54.174.155.26.xip.io",
"api-3scale-apicast-staging.54.174.155.26.xip.io"
],
"backend": {
"endpoint": "https://backend-3scale.54.174.155.26.xip.io",
"host": "backend-3scale.54.174.155.26.xip.io"
},
"proxy_rules": [
{
"id": 3,
"proxy_id": 2,
"http_method": "GET",
"pattern": "/test",
"metric_id": 3,
"metric_system_name": "test",
"delta": 1,
"tenant_id": 2,
"created_at": "2018-07-19T15:35:08Z",
"updated_at": "2018-07-19T15:39:06Z",
"redirect_url": null,
"parameters": [],
"querystring_parameters": {}
}
],
"policy_chain": [
{
"name": "3scale_batcher",
"version": "builtin",
"configuration": {
"auths_ttl": 120,
"batch_report_seconds": 120
}
},
{
"name": "apicast",
"version": "builtin",
"configuration": {}
}
]
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment