View
77
Download
1
Category
Preview:
Citation preview
RUDDER REST APILET'S AUTOMATE YOUR AUTOMATION
\O/Vincent Membré - Configuration Management Camp 2017
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)
General presentation of Rudder APIHow to use itDemoquestions / what do you want to build ?
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/
EXAMPLE WITH CURLBase url: https//your.server.rudder/rudder/api
curl -k https//your.server.rudder/rudder/api
AUTHENTICATIONAuthenticate using tokens.
Created in API accounts page
Pass them as Headers
Give access to the whole api
EXAMPLE WITH CURL curl -k https//your.server.rudder/rudder/api -H "X-Api-Token: yourToken"
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
SELECTING VERSION
Use a Headercurl -k https//your.server.rudder/rudder/api -H "X-Api-Token: yourToken" -H "X-Api-Version: latest"
SELECTING VERSION
Put in Urlcurl -k https//your.server.rudder/rudder/api/latest -H "X-Api-Token: yourToken"
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"
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"
PASSING PARAMETERSUrl parametersform dataJson
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
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
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"
JSON CONTENT{ "policy" : "audit" , "properties" : [ { "name": "env_type" , "value": "production" } , { "name": "shell" , "value": "/bin/sh" } , { "name": "utf-8 poetry", "value": "ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ" ] }
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}
QUESTIONS ?WHAT DO YOU WANT TO
AUTOMATE ?HOW WOULD I DO THAT ?
THE END
Recommended