Skip to content

abdelhamidfg/random-blocker-policy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

3scale Random Blocker Policy

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.

Policy Installation on OpenShift using 3scale APIcast self-managed

  1. Install the APIcast operator as described in the documentation
  2. Create a Kubernetes secret that contains a 3scale Porta admin portal endpoint information
oc create secret generic 3scaleportal --from-literal=AdminPortalURL=https://[email protected]
  1. 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
  1. 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
  1. Add the policy to the policy chain to your API Product.

About

3scale API Gateway custom policy example

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published