| #/* |
| # * Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved. |
| # * |
| # * Permission is hereby granted, free of charge, to any person obtaining a |
| # * copy of this software and associated documentation files (the "Software"), |
| # * to deal in the Software without restriction, including without limitation |
| # * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| # * and/or sell copies of the Software, and to permit persons to whom the |
| # * Software is furnished to do so, subject to the following conditions: |
| # * |
| # * The above copyright notice and this permission notice shall be included in |
| # * all copies or substantial portions of the Software. |
| # * |
| # * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| # * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| # * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| # * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| # * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| # * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| # * DEALINGS IN THE SOFTWARE. |
| # * |
| # */ |
| # the following variable are set by request_validator.lua |
| set $validate_request_status 'na'; |
| set $validate_request_response_body 'na'; |
| set $validate_request_response_time -1; |
| # where to redirect to send an error response |
| set $validation_error_page '@handle_gateway_validation_error'; |
| |
| # the next vars are automatically set from the api_key values |
| # here they are initialized just so that they can be set later on by api_key_validator.lua |
| set $publisher_org_name TBD; |
| set $realm TBD; |
| # service_id should be set by each individual service |
| # set $service_id TBD; |
| set $key_secret TBD; |
| set $service_name TBD; |
| set $consumer_org_name TBD; |
| set $app_name TBD; |
| set $plan_name TBD; |
| set $service_env 'sandbox'; |
| |
| # |
| # default request validation impl |
| # |
| location /validate-request { |
| internal; |
| content_by_lua 'ngx.apiGateway.validation.defaultValidateRequestImpl()'; |
| } |
| |
| # |
| # default api-key validator impl |
| # |
| location /validate_api_key { |
| internal; |
| content_by_lua 'ngx.apiGateway.validation.validateApiKey()'; |
| } |
| |
| location /validate_hmac_signature { |
| internal; |
| content_by_lua 'ngx.apiGateway.validation.validateHmacSignature()'; |
| } |
| |
| # |
| # default OAuth Token validator impl along with the nginx variables it sets |
| # |
| set $oauth_token_scope ''; |
| set $oauth_token_client_id ''; |
| set $oauth_token_user_id ''; |
| location /validate_oauth_token { |
| internal; |
| content_by_lua 'ngx.apiGateway.validation.validateOAuthToken()'; |
| } |
| |
| # |
| # default user Profile validator impl along with the nginx variables it sets |
| # |
| set $user_email ''; |
| set $user_country_code ''; |
| set $user_region ''; |
| set $user_name ''; |
| location /validate_user_profile { |
| internal; |
| content_by_lua 'ngx.apiGateway.validation.validateUserProfile()'; |
| } |
| |
| # |
| # default validator for service plans that looks for Blocking rules to see if they match the requst |
| # |
| location /validate_service_plan { |
| internal; |
| content_by_lua 'ngx.apiGateway.tracking.validateServicePlan()'; |
| } |
| |
| # Error handler for validation errors |
| # NOTE: this endpoint assumes that $validate_request_status and $validate_request_response_body is set before |
| location @handle_gateway_validation_error { |
| internal; |
| content_by_lua ' |
| local ErrorDecorator = require "api-gateway.validation.validatorsHandlerErrorDecorator" |
| local decorator = ErrorDecorator:new() |
| decorator:setUserDefinedResponsesFromJson(ngx.var.validator_custom_error_responses) |
| decorator:decorateResponse(ngx.var.validate_request_status, ngx.var.validate_request_response_body) |
| '; |
| |
| # capture usage data |
| log_by_lua ' |
| if ( ngx.apiGateway.metrics ~= nil ) then |
| ngx.apiGateway.metrics.captureUsageData() |
| end |
| '; |
| } |