Skip to content

Commit 6b06ba2

Browse files
authored
docs: Quick pass (#15)
1 parent 643211b commit 6b06ba2

File tree

7 files changed

+58
-69
lines changed

7 files changed

+58
-69
lines changed

README.md

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
# Azure API Management policy toolkit
22

3-
**Azure API management policy toolkit** is a set of libraries and tools for **Azure API Management** which target
4-
**policy document**. The toolkit was design to help **create** and **test** policy documents with complex expressions.
3+
**Azure API management policy toolkit** is a set of libraries and tools for authoring [**policy documents**](https://learn.microsoft.com/azure/api-management/api-management-howto-policies) for [**Azure API Management**](https://learn.microsoft.com/azure/api-management/). The toolkit was designed to help **create** and **test** policy documents with complex expressions.
54

6-
Before the Policy toolkit, policy documents were written in Razor format.
7-
The Razor format is hard to read and understand, especially when there are a lot of expressions.
8-
The feedback loop on new documents or event the smallest changes was very long.
9-
It required live Azure API Management instance,
10-
a policy document deployment and manual testing through the API request.
5+
Before the Policy toolkit, policy documents were written in Razor format, which is hard to read and understand, especially when there are multiple expressions. The feedback loop on new documents or even the smallest changes was very long, requiring a live Azure API Management instance, a policy document deployment, and manual testing through the API request.
116

12-
The policy toolkit changes that. It allows you to write policy documents in C# language.
13-
The C# language is more natural and shows a process nature of policy.
14-
There is as well, no need to jump between C# and XML for expression creation.
15-
Creating policy documents in C# brings another advantage.
16-
Simple C# code can test the policy document in the unit test.
7+
The policy toolkit changes that. It allows you to write policy documents in C# language, which is more natural and doesn't require you to jump between C# and XML for expression creation. Creating policy documents in C# also brings the advantage of using simple C# code for unit testing of policy documents.
178

189
## Documentation
1910

docs/AvaliablePolicies.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
The Project is in the development stage.
44
That means that not all policies are implemented yet.
5-
In this document, you can find a list of implemented policies and their description.
5+
In this document, you can find a list of implemented policies. For policy details, see the Azure API Management [policy reference](https://learn.microsoft.com/azure/api-management/api-management-policies).
66

77
#### :white_check_mark: Implemented policies
88

@@ -35,7 +35,7 @@ Policies not listed here are not implemented yet.
3535

3636
## InlinePolicy
3737

38-
Inline Policy is a workaround until all the policies are implemented.
38+
InlinePolicy is a workaround until all the policies are implemented.
3939
It allows you to include policy not implemented yet to the document.
4040

4141
```csharp

docs/DevEnvironmentSetup.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Dev container
44

5-
Repository contains a dev container which contains all the required SDKs to develop toolkit.
5+
This repository contains a dev container which contains all the required SDKs to develop toolkit.
66
See dev container [website](https://containers.dev/supporting) for more information how to run it.
77

88
## Setting up the development environment
@@ -25,19 +25,19 @@ From the repository root directory:
2525
### Set up the example solution
2626

2727
* Open repository folder in terminal.
28-
* Run script to set up example solution or check [manual](#manual-example-project-build) project build.
28+
* Run the script to set up example solution or check [manual](#manual-example-project-build) project build.
2929
```shell
3030
setup-example.cmd
3131
```
32-
* Open `examples` folder in your IDE of choice (tested: VS, VS code, Raider).
32+
* Open `examples` folder in your IDE of choice (tested: Visual Studio, Visual Studio Code, Raider).
3333

3434
### Manual example project build
3535

3636
* Run command to build the project.
3737
```shell
3838
dotnet build
3939
```
40-
* Run command to create nuget package. Package will be created in `output` folder.
40+
* Run command to create NuGet package. Package will be created in `output` folder.
4141
```shell
4242
dotnet pack
4343
```
@@ -50,7 +50,7 @@ From the repository root directory:
5050
```shell
5151
dotnet test
5252
```
53-
* Run command restore compiler tool in the example project.
53+
* Run command to restore compiler tool in the example project.
5454
```shell
5555
dotnet tool restore
5656
```

docs/IntegratePolicySolution.md

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# Steps for deploying policies created by the policy toolkit
22

3-
The Azure API Management policy toolkit targets the advance user who leverages a CI/CD pipeline to check and deploy
3+
The Azure API Management policy toolkit targets the advanced user who leverages a CI/CD pipeline to check and deploy
44
changes made to Azure API Management instance.
5-
The solution with policy documents can be easily integrated with any infrastructure as a code repository
5+
The solution with policy documents can be easily integrated with any infrastructure as code repository
66
containing data about Azure API Management instance like ARM templates, Bicep, Terraform or APIOps.
77

88
In this tutorial, we will show you what steps need to be added to the CI/CD pipeline to integrate the policy documents
99
created by the policy toolkit. We will execute them locally to understand what is happening under the hood.
1010

1111
## Prerequisites
1212

13-
### Infrastructure as a code repository
13+
### Infrastructure as code repository
1414

1515
We assume that you have a policy document solution created, and you use a hierarchical approach for the project
1616
structure. You can read about the hierarchical structure in
1717
the [Policy documents repository and solution structure](./SolutionStructureRecomendation.md).
18-
The repository which we will be talking about is looking like the one in the following schema:
18+
The repository which we will be talking about looks like the one in the following schema:
1919

2020
```
2121
.
@@ -40,19 +40,18 @@ The repository which we will be talking about is looking like the one in the fol
4040
### Azure API Management instance
4141

4242
We assume that you have an Azure API Management instance created and that you have access to it.
43-
We assume that you have an API created in the Azure API Management instance.
44-
The API is named `echo-api`. We assume that you can test the policy by invoking some operations on the API.
43+
We assume that you have an API created in the Azure API Management instance named `echo-api`. We assume that you can test the policy by invoking some operations on the API.
4544

4645
### Azure CLI
4746

48-
In this tutorial, we will use a bicep file for the deployment description.
49-
To be able to use the bicep file, an Azure CLI tool needs to be available in the environment.
47+
In this tutorial, we will use a Bicep file for the deployment description.
48+
To be able to use the Bicep file, an Azure CLI tool needs to be available in the environment.
5049
You can download the Azure CLI from the [official site](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli).
5150

5251
## Building and testing
5352

54-
The policy documents solution is standard .NET project.
55-
Because of that, building and testing, the solution is straightforward.
53+
The policy document's solution is a standard .NET project.
54+
Because of that, building and testing the solution is straightforward.
5655
You need to execute standard .NET commands to build and test the solution in the root of the solution folder.
5756
These steps are essential to know that the policy documents are correct and that they are not breaking the build.
5857

@@ -74,7 +73,7 @@ these two commands should be split into separate steps, and if any of them fails
7473
## Compiling the policy documents
7574

7675
After standard C# compilation and testing is done, the policy documents can be compiled by the policy toolkit compiler.
77-
Because, the bicep file for deployment is in the `.\infrastructure\` folder, the compilation target folder should be
76+
Because the Bicep file for deployment is in the `.\infrastructure\` folder, the compilation target folder should be
7877
`.\infrastructure\` as well. This will allow easy referencing of the policy documents in the bicep file.
7978

8079
```shell
@@ -99,13 +98,13 @@ The command will produce the policy documents and the folder structure will look
9998
└── ...
10099
```
101100

102-
Your CI/CD pipeline should as well fail if the compilation of the policy documents fails.
101+
Your CI/CD pipeline should also fail if the compilation of the policy documents fails.
103102

104103
## Deploying the policy documents
105104

106-
The bicep file for the deployment is in the `.\infrastructure\` folder.
107-
The bicep file is referencing the service, the API and the policy document.
108-
The bicep file should look like this:
105+
The Bicep file for the deployment is in the `.\infrastructure\` folder.
106+
The Bicep file is referencing the service, the API and the policy document.
107+
The Bicep file should look like this:
109108

110109
```bicep
111110
param servicename string
@@ -133,7 +132,7 @@ resource echoApiPolicy 'Microsoft.ApiManagement/service/apis/policies@2023-03-01
133132
Please notice that the `loadTextContent` function is used to load the content of the policy document.
134133
The content is loaded from the file under following path `./apis/echo-api/ApiEchoApiPolicy.xml`.
135134

136-
The Azure CLI can do the deployment. The following command will deploy the policy document to the Azure API:
135+
The Azure CLI can do the deployment. The following command will deploy the policy document to the Azure API Management instance:
137136

138137
```shell
139138
cd .\infrastructure\
@@ -150,12 +149,12 @@ With above knowledge, creating a pipeline should be straightforward.
150149
In this section, we will show you two examples of pipelines definitions:
151150
152151
* The GitHub Actions pipeline
153-
* The Azure DevOps pipeline
152+
* The Azure Pipelines definition
154153
155154
Both pipelines will look similar. The following steps will be present in both of them:
156155
157-
1. Checkout the repository
158-
2. Setup build and test the .NET SDK
156+
1. Check out the repository
157+
2. Set up build and test using the .NET SDK
159158
3. Build the solution
160159
4. Test the solution
161160
5. Restore the policy document compiler
@@ -234,7 +233,7 @@ jobs:
234233
--name deploy-$RUN_NUMBER
235234
```
236235
237-
### Azure DevOps pipeline example
236+
### Azure Pipelines example
238237
239238
```yaml
240239
parameters:
@@ -301,6 +300,6 @@ steps:
301300
Now you know what steps are required to deploy the policy documents.
302301
You can replicate these steps in the CI/CD pipeline.
303302
304-
We papered a short guides how to integrate the policy documents solution with APIOps.
303+
We prepared a short guide to integrate the policy documents solution with APIOps.
305304
You can read about it in the [APIOps integration](./IntegratePolicySolutionWithApiOps.md) document.
306305

docs/IntegratePolicySolutionWithApiOps.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Integrate policy solution with repository containing data for APIOps
22

33
Azure API Management policy toolkit is very elastic and allows a developer to define how the structure of the repository
4-
will look. In this guide, we will touch how a toolkit project can produce policies which can be easily published
4+
will look. In this guide, we will cover how a toolkit project can produce policies which can be easily published
55
by [APIOps tool](https://azure.github.io/apiops) to Azure API Management instance.
66

77
## APIOps repository structure
88

9-
Repository with Azure API Management data created by APIOps tool should have structure similar to below a folder tree.
9+
The repository with Azure API Management data created by APIOps tool should have a structure similar to the folder tree below.
1010
We included folders and files about policies in the repository, and we skipped folders and files not relevant in the
1111
example.
1212

@@ -32,7 +32,7 @@ example.
3232

3333
The best way to add a policy project to the repository is to add it as a subfolder of repository root.
3434
This way, the policy project can separate from the APIOps data and can be easily updated and maintained.
35-
In the example below we added the policy project to the`policies` folder.
35+
In the example below we added the policy project to the `policies` folder.
3636
We added a dotnet tool to be available from the root of the repository (`./.config/dotnet-tools.json`).
3737

3838
```
@@ -91,12 +91,12 @@ structure and other recommended structures.
9191
## Updating policy files in APIOps artifacts folder
9292

9393
Now, as we have all the pieces in place, we can run the compiler.
94-
Compiler should target `artifacts` folder with APIOps data.
95-
Example of the command to run the compiler is below.
94+
The compiler should target `artifacts` folder with APIOps data.
95+
An example of the command to run the compiler is below.
9696

9797
```shell
9898
dotnet policy-compiler --s .\policies\src\ --o .\artifacts\
9999
```
100100

101101
After the command is executed the `artifacts` folder should contain all the policy files which can be easily published
102-
by APIOps tool to Azure API Management instance.
102+
by APIOps tool to an Azure API Management instance.

docs/QuickStart.md

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ We will cover the following topics:
1010
4. Writing complex policy document
1111
5. Testing expressions in policy document
1212

13-
## Setup project for authoring policies
13+
## Set up project for authoring policies
1414

1515
* Check that you have latest [.NET SDK 8 sdk](https://dotnet.microsoft.com/en-us/download/dotnet/8.0) version installed.
1616
* Open terminal and create a new solution by executing
@@ -28,19 +28,19 @@ We will cover the following topics:
2828
dotnet add package Azure.ApiManagement.PolicyToolkit.Authoring
2929
```
3030

31-
| :exclamation: Azure API Management Policy toolkit is not yet published to nuget. For now, please follow the repository setup guide to obtain packages mentioned in the document. |
31+
| :exclamation: Azure API Management Policy toolkit is not yet published to NuGet. For now, please follow the repository setup guide to obtain packages mentioned in the document. |
3232
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
3333

3434
* Open the solution in your IDE of choice. We
35-
tested [VS](https://visualstudio.microsoft.com), [Raider](https://www.jetbrains.com/rider/), [VS code](https://code.visualstudio.com/)
36-
with [C# devkit](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csdevkit),
35+
tested [Visual Studio ](https://visualstudio.microsoft.com), [Raider](https://www.jetbrains.com/rider/), [Visual Studio Code](https://code.visualstudio.com/)
36+
with [C# Dev Kit](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csdevkit),
3737
but any IDE with C# support should work.
3838

3939
## Writing a simple policy document
4040

41-
Azure API Management policy toolkit define new way of writing policy documents. One policy document is one C# class in
41+
Azure API Management policy toolkit defines a new way of writing policy documents: One policy document is one C# class in
4242
one `cs` file.
43-
Let's create a new `ApiOperationPolicy.cs` file in the project which will be our policy document by executing following
43+
Let's create a new `ApiOperationPolicy.cs` file in the project which will be our policy document by executing the following
4444
command.
4545
4646
```shell
@@ -65,7 +65,7 @@ public class ApiOperationPolicy : IDocument
6565
The `IDocument` type contains methods `Inbound`, `Outbound`, `Backend` and `OnError` which are used to define policy
6666
sections.
6767
68-
Let's implement `Inbound` method. In the method lets add the policy to set header `X-Hello` to value `World`.
68+
Let's implement `Inbound` method. In the method let's add the policy to set header `X-Hello` to value `World`.
6969
7070
```csharp
7171
[Document]
@@ -99,7 +99,7 @@ Azure API Management supports policy documents in Razor format. The Azure API Ma
9999
dotnet tool called a compiler which can generate
100100
Razor policy documents from C# classes.
101101
102-
To use the compiler, we firstly need to add it to our solution folder. To do that execute the following command in the
102+
To use the compiler, we first need to add it to our solution folder. To do that execute the following command in the
103103
solution folder.
104104
105105
```shell
@@ -118,7 +118,7 @@ The compiler is a dotnet tool named `policy-compiler`. The `--s` parameter is a
118118
The `--o` parameter is an output folder for generated policy documents. The `--format` parameter is a flag which tells
119119
the compiler to format the generated document.
120120
121-
The compiler will generate `ApiOperationPolicy.xml` file in the solution folder. Generated file should have the
121+
The compiler will generate `ApiOperationPolicy.xml` file in the solution folder. The generated file should have the
122122
following
123123
content:
124124
@@ -149,9 +149,9 @@ The Azure API Management policy toolkit allows you to naturally create expressio
149149
policy document.
150150

151151
Let's assume that we want to add authorization header to the request.
152-
If requests comes from Company IP addresses `10.0.0.0/24` it should use basic authorization with `username`
152+
If a request comes from Company IP addresses `10.0.0.0/24` it should use basic authorization with `username`
153153
and `password` from named values.
154-
If request comes from other IP addresses it should use `Bearer` token received from https://graph.microsoft.com.
154+
If a request comes from other IP addresses it should use `Bearer` token received from https://graph.microsoft.com.
155155
For every request we want to add header with the user id.
156156
157157
```csharp
@@ -201,10 +201,10 @@ Let's unpack the code above it:
201201
* `AuthenticationManagedIdentity` method is mapped to `authentication-managed-identity` policy.
202202
* `SetHeader` method is mapped to `set-header` policy with override.
203203

204-
Expressions are a methods in the class. They may be static or instance methods, and they can be private or public.
204+
Expressions are methods in the class. They may be static or instance methods, and they can be private or public.
205205
They need to accept one parameter of type `IExpressionContext` with name `context`.
206206

207-
To use expression you just need to call that method in the place were you want to use it. Like in our example, we call
207+
To use an expression you just need to call that method in the place were you want to use it. In our example, we call
208208
`IsCompanyIP` method in the `if` statement, and we call `GetUserId` method in the `SetHeader` method in value parameter.
209209
In other more complex policies, which accept a configuration object, you will invoke method in the field initialization
210210
assignment like in example below.
@@ -248,7 +248,7 @@ Isn't it great, right? I hope it is. But we can now test the expressions in the
248248

249249
The Azure API Management policy toolkit provides a way to test expressions in policy documents. To do that we need to
250250
create a test project from a solution folder. Then we will need to add a reference to the policy project and the testing
251-
library. Lastly we need to create a test class and write a test for the expression. All of that you can do by executing
251+
library. Last, we need to create a test class and write a test for the expression. All of that you can do by executing
252252
the following commands.
253253

254254
```shell
@@ -290,11 +290,10 @@ public class ApiOperationPolicyTest
290290

291291
Let's unpack the code above:
292292
293-
* Test class is a standard MSTest class with one test method. You can use your favorite testing framework in place of MS
294-
test. Policy framework is not dependent on any testing framework.
293+
* Test class is a standard MSTest class with one test method. You can use your favorite testing framework in place of MSTest. Policy framework is not dependent on any testing framework.
295294
* `MockExpressionContext` is a class which is used to mock request context. It is available in
296295
`Azure.ApiManagement.PolicyToolkit.Emulator.Expressions` namespace. It implements `IExpressionContext`
297-
interface and expose a helper properties to set up request context.
296+
interface and exposes helper properties to set up request context.
298297
* `context.MockRequest.IpAddress = "10.0.0.12"` is setting a IpAddress for request.
299298
300299
To check that the expression works as expected, run the test by executing the following command.

0 commit comments

Comments
 (0)