How to implement a custom validation server using Miru webhooks and APIs.
config_instance.target_status.validated
webhook to your endpoint(s).
The config instance must then be approved or rejected by your validation server using the approve or reject APIs.
After the config instance has been approved, the validation server can deploy the config instance to it’s target device using the deploy API.
server-sdk
directory inside the repository.
flask
directory you’ll find a simple flask application (app.py
) which demonstrates webhook verification using the Miru server-side SDK.
To run the server, create a virtual environment and install the dependencies.
{"message":"ok"}
ngrok
ngrok
. This will provision a temporary domain that forwards requests to your local machine, a useful method for locally testing webhooks.
ngrok
to your machine according to their installation instructions and add your authoken to the ngrok
configuration file.
https://c1971566f336.ngrok-free.app
being forward to your Flask server.
c1971566f336
with your own ngrok host) in your browser. You should see {"message":"ok"}
.
/webhooks/miru
route appended (e.g. https://c1971566f336.ngrok-free.app/webhooks/miru
) to the webhook endpoint in the dashboard. Subscribe to the config_instance.target_status.validated
event and click Create.
On the far right of the page, you’ll see the webhook secret. Copy this value and store it in a secure location for use in your validation server.
For simplicity the flask server uses the SECRET
as a globally defined variable but you should not do this in practice. Webhook secrets should be stored in a secrets manager or other secure location, not inside your codebase.
config_instance.target_status.validated
event and click Send Example.
If your secret is key is invalid or not specified, you’ll see an error message in Miru for that request similar to:
config_instance.target_status.validated
webhook will not be triggered.validating
state, indicating that it is awaiting approval from your validation server before deployment to it’s target device.
config_instance.target_status.validated
webhook, you’ll need to approve the config instance using the approve API.
The approve API stores a success message
field and moves the config instance’s activity_status
to be validated
.
You can approve the config instance by making the appropriate POST request in the API Playground
. We recommend making a dedicated docs-api-key for this purpose which you delete after you’re done testing.
Alternatively, if the config instance is invalid you can use the reject API to reject the config instance. This will move the config instance’s error_status
to be failed
, preventing any deployments to it’s target device.
The reject API stores a failure message
field as well as a list of parameter errors
that caused the validation to fail. Be sure to give a descriptive message and errors, as these will be displayed in the UI for rejected config instances.