automate your automation with rudder’s api! \o
TRANSCRIPT
![Page 1: Automate your automation with Rudder’s API! \o](https://reader034.vdocuments.us/reader034/viewer/2022042706/58a2ffb11a28abea508b4981/html5/thumbnails/1.jpg)
![Page 2: Automate your automation with Rudder’s API! \o](https://reader034.vdocuments.us/reader034/viewer/2022042706/58a2ffb11a28abea508b4981/html5/thumbnails/2.jpg)
RUDDER REST APILET'S AUTOMATE YOUR AUTOMATION
\O/Vincent Membré - Configuration Management Camp 2017
![Page 3: Automate your automation with Rudder’s API! \o](https://reader034.vdocuments.us/reader034/viewer/2022042706/58a2ffb11a28abea508b4981/html5/thumbnails/3.jpg)
WHOAMIDevelopper @ Normation on Rudder.
Mostly works on Scala parts ( backend / API )
But also lot of Javascript and python
I love to automate things (I'm lazy)
1,66 daughters (and not much sleep)
![Page 4: Automate your automation with Rudder’s API! \o](https://reader034.vdocuments.us/reader034/viewer/2022042706/58a2ffb11a28abea508b4981/html5/thumbnails/4.jpg)
General presentation of Rudder APIHow to use itDemoquestions / what do you want to build ?
![Page 5: Automate your automation with Rudder’s API! \o](https://reader034.vdocuments.us/reader034/viewer/2022042706/58a2ffb11a28abea508b4981/html5/thumbnails/5.jpg)
RUDDER REST APIAdded in Rudder 2.7.
Grew up over time, you can now manage almosteverything in Rudder (ie: miss authorized networks :( )
A legacy API is still existing from the old days, but onlylocalhost
Online documentation: http://www.rudder-project.org/rudder-api-doc/
![Page 6: Automate your automation with Rudder’s API! \o](https://reader034.vdocuments.us/reader034/viewer/2022042706/58a2ffb11a28abea508b4981/html5/thumbnails/6.jpg)
EXAMPLE WITH CURLBase url: https//your.server.rudder/rudder/api
curl -k https//your.server.rudder/rudder/api
![Page 7: Automate your automation with Rudder’s API! \o](https://reader034.vdocuments.us/reader034/viewer/2022042706/58a2ffb11a28abea508b4981/html5/thumbnails/7.jpg)
AUTHENTICATIONAuthenticate using tokens.
Created in API accounts page
Pass them as Headers
Give access to the whole api
![Page 8: Automate your automation with Rudder’s API! \o](https://reader034.vdocuments.us/reader034/viewer/2022042706/58a2ffb11a28abea508b4981/html5/thumbnails/8.jpg)
EXAMPLE WITH CURL curl -k https//your.server.rudder/rudder/api -H "X-Api-Token: yourToken"
![Page 9: Automate your automation with Rudder’s API! \o](https://reader034.vdocuments.us/reader034/viewer/2022042706/58a2ffb11a28abea508b4981/html5/thumbnails/9.jpg)
VERSIONNINGPOLICY
A new version when we change behavior ( response,parameters)We can add new endpoints in an existing version (techniques api)In practice a new version by new version of Rudder(9 for now)Use 'latest' version for 'latest' available
![Page 10: Automate your automation with Rudder’s API! \o](https://reader034.vdocuments.us/reader034/viewer/2022042706/58a2ffb11a28abea508b4981/html5/thumbnails/10.jpg)
SELECTING VERSION
Use a Headercurl -k https//your.server.rudder/rudder/api -H "X-Api-Token: yourToken" -H "X-Api-Version: latest"
![Page 11: Automate your automation with Rudder’s API! \o](https://reader034.vdocuments.us/reader034/viewer/2022042706/58a2ffb11a28abea508b4981/html5/thumbnails/11.jpg)
SELECTING VERSION
Put in Urlcurl -k https//your.server.rudder/rudder/api/latest -H "X-Api-Token: yourToken"
![Page 12: Automate your automation with Rudder’s API! \o](https://reader034.vdocuments.us/reader034/viewer/2022042706/58a2ffb11a28abea508b4981/html5/thumbnails/12.jpg)
ENDPOINTSOne endpoint for each element in Rudder
Rules,Directives, Groups, Nodes, ComplianceParameters, Settings, Techniques, Change requestscurl -k https//your.server.rudder/rudder/api/latest/nodes -H "X-Api-Token: yourToken"
![Page 13: Automate your automation with Rudder’s API! \o](https://reader034.vdocuments.us/reader034/viewer/2022042706/58a2ffb11a28abea508b4981/html5/thumbnails/13.jpg)
METHODS
HTTP method map to action type
GetPut (Create)Post (Modification / action)Delete
curl -k https//your.server.rudder/rudder/api/latest/nodes -X GET -H "X-Api-Token: yourToken"
![Page 14: Automate your automation with Rudder’s API! \o](https://reader034.vdocuments.us/reader034/viewer/2022042706/58a2ffb11a28abea508b4981/html5/thumbnails/14.jpg)
PASSING PARAMETERSUrl parametersform dataJson
![Page 15: Automate your automation with Rudder’s API! \o](https://reader034.vdocuments.us/reader034/viewer/2022042706/58a2ffb11a28abea508b4981/html5/thumbnails/15.jpg)
URL PARAMETERS
Part of the url
Mostly Ids of the element to accesscurl https//your.server.rudder/rudder/api/latest/nodes/nodeId -X GET -H "X-Api-Token: yourToken" -k
![Page 16: Automate your automation with Rudder’s API! \o](https://reader034.vdocuments.us/reader034/viewer/2022042706/58a2ffb11a28abea508b4981/html5/thumbnails/16.jpg)
FORM DATA
Key=value
Either in Url or form data
Great for small amount of data, simple and manualrequests
curl https//your.server.rudder/rudder/api/latest/nodes/nodeId\?include=ipAdresses -H "X-Api-Token: yourToken" -k
![Page 17: Automate your automation with Rudder’s API! \o](https://reader034.vdocuments.us/reader034/viewer/2022042706/58a2ffb11a28abea508b4981/html5/thumbnails/17.jpg)
JSON
Passing a json in request body
Need to add Header "Content-type: application/json"
Great when passing lots of parameters, complex andautomated requests
curl -k https//your.server.rudder/rudder/api/latest/nodes/nodeId -X POST -d @json -H "Content-type: application/json" -H "X-Api-Token: yourToken"
![Page 18: Automate your automation with Rudder’s API! \o](https://reader034.vdocuments.us/reader034/viewer/2022042706/58a2ffb11a28abea508b4981/html5/thumbnails/18.jpg)
JSON CONTENT{ "policy" : "audit" , "properties" : [ { "name": "env_type" , "value": "production" } , { "name": "shell" , "value": "/bin/sh" } , { "name": "utf-8 poetry", "value": "ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ" ] }
![Page 19: Automate your automation with Rudder’s API! \o](https://reader034.vdocuments.us/reader034/viewer/2022042706/58a2ffb11a28abea508b4981/html5/thumbnails/19.jpg)
RESPONSE FORMAT{ "action": The name of the called function, "id": The ID of the element you want, if relevant, "result": The result of your action: success or error, "data": Only present if this is a success and depends on the function, "errorDetails": Only present if this is an error, it contains}
![Page 21: Automate your automation with Rudder’s API! \o](https://reader034.vdocuments.us/reader034/viewer/2022042706/58a2ffb11a28abea508b4981/html5/thumbnails/21.jpg)
QUESTIONS ?WHAT DO YOU WANT TO
AUTOMATE ?HOW WOULD I DO THAT ?
![Page 22: Automate your automation with Rudder’s API! \o](https://reader034.vdocuments.us/reader034/viewer/2022042706/58a2ffb11a28abea508b4981/html5/thumbnails/22.jpg)
THE END