Contact Us 1-800-596-4880

Creating a New Project

To begin developing a new custom policy with Flex Gateway Policy Development Kit (PDK), generate a new custom policy project.

To create a new project, complete the following tasks:

Before You Begin

Before you can create a custom policy project, ensure that you have installed all PDK prerequisites.

Create a New Policy Project

To create a custom policy project, run the PDK CLI create command, replacing <my-custom-policy> with the name of your new policy:

anypoint-cli-v4 pdk policy-project create --name <my-custom-policy>
If you receive a prompt requesting your group ID, see Troubleshooting Group ID.

Running the create command creates a custom policy project with the specified name. The project appears in a new directory with the same name as your policy or a directory specified using the --output-dir flag. The following tutorials refer to this as your project’s root directory.

The assetID of the new policy is the policy’s name in lower case with the spaces amended together with a -. For example, a policy with the name My Header Injection Policy has the assetID of my-header-injection-policy.

The groupID of the new policy is the ID of the organization configured in Anypoint CLI.

The create command supports the following flags:

Flag Default Value Required Description

--name=<value> or -n

N/A

Yes

Name of the new policy.

--description=<value> or -d

N/A

No

Description of the new policy.

--output-dir=<value> of -o

assetID

No

Directory the new policy is created in.
If the directory does not exist, it is created. If no directory is specified, the directory name is the policy assetID.

--version=<value>

1.0.0

No

Version of the new policy.
The version format is <major-release>.<minor-release>.<patch-release>.

--group-id=<value>

N/A

No

Organization ID of the organization that owns the policy.
For additional information about this flag, see Troubleshooting Group ID.

Set Up the PDK Build Environment

After you create a new policy project, you must run the make setup command to download additional software dependencies:

make setup

Project Structure

After running the make setup command, the policy’s root directory contains the following directories and files shown in the directory tree:

├─ definition/  # Contains the files that describe the policy Definition
│  ├── target/  # Contains the build definition asset files
│  └── gcl.yaml # GCL file managed by the developer that describes the policy Definition
├─ target/      # Contains the implementation asset files and the output of the policy build
├─ src/         # Contains the implementation source code
├─ playground/  # Contains the artifacts required for running the policy locally
├─ tests/        # Contains the source and configuration files to write and run integration tests
├─ Makefile     # Provides all the callable actions required during the policy development lifecycle
├─ Cargo.toml   # Rust language standard file that contains the metadata required to build the policy
└─.project.yaml # Project manifest used by PDK

target/ and definition/target/

There are two separate target directories:

  • definition/target/: Contains the policy asset definition published to Exchange.

  • target/: Contains the files for the policy’s Exchange asset implementation and the output of the project build.

Both target directories and their content are included in the .gitignore file. You must compile the targets on each individual devices using the make build command. For example, if you develop a policy as part of the team, your team can publish the policy and its source code to a remote repository, but each team member must build the target on their device to work with the policy.

definition/

The definition directory contains the gcl.yaml file that defines the policy’s metadata and the configuration properties.

To configure the gcl.yaml file, see Defining a Policy Schema Definition.

Cargo.toml

Custom policies for Flex Gateway are developed in the Rust programming language and compiled to a WebAssembly binary.

The Cargo.toml is the Rust project manifest. Its [package] section contains the basic information about the policy implementation. The version specified in Cargo.toml matches the policy asset version. You can manage the policy version by editing the version number in Cargo.toml. The version follows the format <major-version>.<minor-version>.<patch-version>.

src/

The src directory contains the policy’s source code:

  • lib.rs: Contains a set of methods that implement the behavior of the policy. PDK includes these methods to implement custom policies behavior. For additional information about these methods, see Implementing Your Custom Policy Features in Rust. For complete policy examples, see Custom Policy Examples.

  • generated/config.rs and generated/mod.rs: Auto-generated modules that make the policy configuration, as defined in the gcl.yaml, available for use in the lib.rs and any of the policy source files.

Makefile

The Makefile contains all the callable actions, such as make commands, required for the policy development lifecycle. Execute all make commands at the root level of your custom policy directory directory:

  • make setup: Installs PDK internal dependencies for the rest of the Makefile goals.

    For more information about setting up your project, see Set Up the PDK Build Environment.

  • make build-asset-files: Generates all the policy asset files required to build, execute, and publish the policy. This command also updates the config.rs source code file with the latest configurations defined in the gcl.yaml file.

    For more information about compiling a policy, see Compiling Custom Policies.

  • make build: Runs the make build-asset-files command and compiles the WebAssembly binary of the policy.

    For more information about compiling a policy, see Compiling Custom Policies.

  • make run: Provides a simple way to execute the current build of the policy in a Docker containerized environment.

    For more information about running and debugging your policy, see Debugging Custom Policies with the PDK Debugging Playground.

  • make test: Executes the tests contained in tests/ by using the testing framework provided by PDK.

    For more information about testing your policy, see Writing Integration Tests.

  • make publish: Publishes the policy asset in Exchange.

    For more information about publishing policies in Exchange, see Uploading Custom Policies to Exchange.

  • make release: Releases the policy asset in Exchange.

    For more information about releasing policies in Exchange, see Uploading Custom Policies to Exchange.

  • make help: Lists all the make commands provided by PDK.