From 9211bbe1af3904b022196d8ba68cbe9d7bf6a50b Mon Sep 17 00:00:00 2001 From: Nicolas MASSE Date: Mon, 26 Jul 2021 20:07:46 +0200 Subject: [PATCH] improve application plan support --- samples/01-api-with-apikey.sh | 19 +++++++++++++++++++ samples/11-api-with-oidc.sh | 19 +++++++++++++++++++ src/00-factory.sh | 8 ++++---- src/01-common.sh | 2 +- 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/samples/01-api-with-apikey.sh b/samples/01-api-with-apikey.sh index 1b5996c..715f9e1 100755 --- a/samples/01-api-with-apikey.sh +++ b/samples/01-api-with-apikey.sh @@ -89,6 +89,25 @@ declare -A application_plan_def=( ["system_name"]="test" ["name"]="Test plan" ) apply application_plan present application_plan_def application_plan_id=$last_object_id +# Create Limits for the sayHello method +breadcrumb=( application_plans $application_plan_id metrics $method_id ) +declare -A limit_def=( ["period"]="minute" ["value"]="5" ) +apply limit present limit_def +declare -A limit_def=( ["period"]="day" ["value"]="100" ) +apply limit present limit_def + +# Re-Create Pricing Rules for the sayHello method +breadcrumb=( application_plans $application_plan_id metrics $method_id ) +delete_all "pricing_rule" +declare -A pricing_rule_def=( ["min"]="1" ["max"]="10" ["cost_per_unit"]="1.0" ) +pricing_rule_create pricing_rule_def +declare -A pricing_rule_def=( ["min"]="11" ["max"]="100" ["cost_per_unit"]="0.9" ) +pricing_rule_create pricing_rule_def +declare -A pricing_rule_def=( ["min"]="101" ["max"]="1000" ["cost_per_unit"]="0.8" ) +pricing_rule_create pricing_rule_def +declare -A pricing_rule_def=( ["min"]="1001" ["max"]="" ["cost_per_unit"]="0.75" ) +pricing_rule_create pricing_rule_def + ## ## Create a test application ## diff --git a/samples/11-api-with-oidc.sh b/samples/11-api-with-oidc.sh index a19039c..291220f 100755 --- a/samples/11-api-with-oidc.sh +++ b/samples/11-api-with-oidc.sh @@ -101,6 +101,25 @@ declare -A application_plan_def=( ["system_name"]="test" ["name"]="Test plan" ) apply application_plan present application_plan_def application_plan_id=$last_object_id +# Create Limits for the sayHello method +breadcrumb=( application_plans $application_plan_id metrics $method_id ) +declare -A limit_def=( ["period"]="minute" ["value"]="5" ) +apply limit present limit_def +declare -A limit_def=( ["period"]="day" ["value"]="100" ) +apply limit present limit_def + +# Re-Create Pricing Rules for the sayHello method +breadcrumb=( application_plans $application_plan_id metrics $method_id ) +delete_all "pricing_rule" +declare -A pricing_rule_def=( ["min"]="1" ["max"]="10" ["cost_per_unit"]="1.0" ) +pricing_rule_create pricing_rule_def +declare -A pricing_rule_def=( ["min"]="11" ["max"]="100" ["cost_per_unit"]="0.9" ) +pricing_rule_create pricing_rule_def +declare -A pricing_rule_def=( ["min"]="101" ["max"]="1000" ["cost_per_unit"]="0.8" ) +pricing_rule_create pricing_rule_def +declare -A pricing_rule_def=( ["min"]="1001" ["max"]="" ["cost_per_unit"]="0.75" ) +pricing_rule_create pricing_rule_def + ## ## Create a test application ## diff --git a/src/00-factory.sh b/src/00-factory.sh index 710e986..93ad563 100644 --- a/src/00-factory.sh +++ b/src/00-factory.sh @@ -1,7 +1,7 @@ -declare -A threescale_object_types=( ["backend"]="backend_apis" ["service"]="services" ["metric"]="metrics" ["method"]="methods" ["mapping_rule"]="mapping_rules" ["backend_usage"]="backend_usages" ["application_plan"]="application_plans" ["application_apikey"]="applications" ["application_appid"]="applications" ) -declare -A threescale_contains_external_id=( ["metric"]="contains_external_id_with_prefix" ["method"]="contains_external_id_with_prefix" ["backend_usage"]="contains_numerical_external_id") -declare -A threescale_id_of_external_id=( ["metric"]="id_of_external_id_with_prefix" ["method"]="id_of_external_id_with_prefix" ["backend_usage"]="id_of_numerical_external_id") -declare -A threescale_external_id=( ["backend_usage"]="backend_id" ["application_apikey"]="user_key" ["application_appid"]="application_id" ) +declare -A threescale_object_types=( ["backend"]="backend_apis" ["service"]="services" ["metric"]="metrics" ["method"]="methods" ["mapping_rule"]="mapping_rules" ["backend_usage"]="backend_usages" ["application_plan"]="application_plans" ["application_apikey"]="applications" ["application_appid"]="applications" ["limit"]="limits" ["pricing_rule"]="pricing_rules" ) +declare -A threescale_contains_external_id=( ["metric"]="contains_external_id_with_prefix" ["method"]="contains_external_id_with_prefix" ["backend_usage"]="contains_numerical_external_id" ) +declare -A threescale_id_of_external_id=( ["metric"]="id_of_external_id_with_prefix" ["method"]="id_of_external_id_with_prefix" ["backend_usage"]="id_of_numerical_external_id" ) +declare -A threescale_external_id=( ["backend_usage"]="backend_id" ["application_apikey"]="user_key" ["application_appid"]="application_id" ["limit"]="period" ["mapping_rule"]="no external id" ["pricing_rule"]="no external id" ) template=$(cat <<"EOF" function OBJECT_TYPE_list () { diff --git a/src/01-common.sh b/src/01-common.sh index f894668..59617b9 100644 --- a/src/01-common.sh +++ b/src/01-common.sh @@ -40,7 +40,7 @@ function threescale_call () { echo "=> HTTP $(cat "$tmp/$request_name.code")" >&2 fi - if ! egrep -q "^$expected_http_codes\$" "$tmp/$request_name.code"; then + if ! egrep -q "^($expected_http_codes)\$" "$tmp/$request_name.code"; then echo "Unexpected HTTP code: $(cat "$tmp/$request_name.code")" >&2 return 1 fi