Service templates
...
provide a reusable foundation for new services.
...
This reduces repetitive coding for common elements.
Use the API Gateway Manager
...
to create templates
...
:
Include standard code blocks that are used across most services.
Add variables to be filled in during service deployment.
Define optional assertion blocks for flexible customization.
Table of Contents | ||||
---|---|---|---|---|
|
Template Parts
Templates consist of two parts. One part is a JSON file that describes the template and all of the variables and blocks that are contained in it. The second part is a XML file containing the policy for have two key components:
JSON file: Outlines the template structure, including all variables and conditional blocks.
XML file: Holds the policy that will govern the new service.
...
Definition descriptions
XML Policy Definition
How to get the policy XML
To get the policy XML you can either export a existing service using the Policy Manager or you can just select the assertions you would like to include and use Copy & Paste to insert the XML code into the form or editor you useGetting policy XML: Two easy methods:
Policy Manager: Export the XML from an existing service.
Copy & Paste: Select the assertions you want and directly paste the generated XML code into your editor/form.
JSON Definition
First, let’s look at an example and then break it down:
...
Variables, Blocks and Groups
Variables are replaced by what a user enters during creation of services that are based on the template. Blocks are parts within a policy that are either included in the resulting service or that are removed from its definition.
As you may have noticed you can assign a group to variables and blocks. This can be used to group settings that have a common theme. WIthin a group the blocks and variables are ordered the same way they are in the Templates use variables, blocks, and groups for customization:
Variables: Placeholders filled in by the user when creating a new service.
Blocks: Sections of policy code included or excluded based on user choices.
Groups: Organize related settings for a cleaner template structure. Within groups, variables and blocks maintain the order from your JSON definition.
Data Types
Type | Description |
---|---|
string | This datatype acts like a normal string. Please be advised that its inserted as it is. Which means that no base64 transformation happens. This datatype is not allowed to contain XML or HTML. |
integer | A number without a fractional component (i.e. 5) |
float | A number with a fractional component (i.e. 5.25) |
date | A date value without time information |
time | A time (formatted according to the format defined in the configuration) |
datetime | A date value with time information |
rawstring | In contrast to the string data type, this type allows any string, including XML or HTML. |
select | A list of options. The value that is inserted and the text that is shown can be different from each other. |
...
XML Policy Definition with placeholders to work with JSON Definition
Variables
...
: Replace placeholders with double braces
...
. Example: {{
...
service_name}}
...
Blocks: Embed definitions within XML comments
...
for valid structure. Example: ``
Select blocks: For dynamic content use this format: {{block_name=value}}. Example:
{{authentication_type=basic}}
The format for a block is:
...
Basic example:
XML Policy Definition
...
Get your policy XML
...
To get the policy XML you can either export a existing service using the Policy Manager or you can just select the assertions you would like to include and use Copy & Paste to insert the XML code into the form or editor you use.
In this example, we created a very basic policy with four (4) comments.
...
Which copied and pasted in a text editor would give you the following.
...
by:
Exporting from an existing service within the Policy Manager.
Selecting specific assertions and using Copy & Paste.
Example: We illustrate this with a basic policy containing four comments.
...
Example: Policy Manager Export
The code below shows what the export looks like. This is your starting point.
Important: You must edit this example to include placeholders and triggers (instructions provided 2 sections below).
Code Block | ||
---|---|---|
| ||
<wsp:Policy xmlns:L7p="http://www.layer7tech.com/ws/policy" xmlns:wsp="http://schemas.xmlsoap.org/ws/2002/12/policy"> <wsp:All wsp:Usage="Required"> <L7p:CommentAssertion> <L7p:Comment stringValue="some comment"/> </L7p:CommentAssertion> <L7p:CommentAssertion> <L7p:Comment stringValue="SSL"/> </L7p:CommentAssertion> <L7p:CommentAssertion> <L7p:Comment stringValue="Auth BASIC"/> </L7p:CommentAssertion> <L7p:CommentAssertion> <L7p:Comment stringValue="Auth CERT"/> </L7p:CommentAssertion> </wsp:All> </wsp:Policy> |
...