3scale API Gateway Policy blocks/allows the request based on random number generation, If the generated number is even it will allow the request, otherwise it will block the request.
- Install the APIcast operator as described in the documentation
- Create a Kubernetes secret that contains a 3scale Porta admin portal endpoint information
oc create secret generic 3scaleportal --from-literal=AdminPortalURL=https://[email protected]
- create a secret containing the policy Lua files (the files exist in the folder /policies/random_blocker/1.0.0)
oc create secret generic random-blocker-policy --from-file=random_blocker.lua --from-file=init.lua --from-file=apicast-policy.json
4.Create APIcast custom resource instance
apiVersion: apps.3scale.net/v1alpha1
kind: APIcast
metadata:
name: apicast-random-blocker
spec:
adminPortalCredentialsRef:
name: 3scaleportal
replicas: 1
customPolicies:
- name: random_blocker
secretRef:
name: random-blocker-policy
version: 1.0.0
- Create 3scale API Manager CustomPolicyDefinition Custom Resource in order to view the policy configuration in the API Manager policy editor UI, the custom policy should be registered using customPolicyDefinition custom resource
apiVersion: capabilities.3scale.net/v1beta1
kind: CustomPolicyDefinition
metadata:
name: custompolicydefinition-random-blocker
spec:
name: "random_blocker"
version: "1.0.0"
schema:
name: "random_blocker"
version: "1.0.0"
summary: "Block the request based if the generated random number is even, otherwise it allows the request"
$schema: "http://json-schema.org/draft-07/schema#"
configuration:
type: object
properties:
error_message:
title: Error message
description: An error message to show to the user when traffic is blocked
type: string
- Add the policy to the policy chain to your API Product.