automate your automation with rudder’s api! \o

22

Upload: normation

Post on 14-Feb-2017

81 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Automate your automation with Rudder’s API! \o
Page 2: Automate your automation with Rudder’s API! \o

RUDDER REST APILET'S AUTOMATE YOUR AUTOMATION

\O/Vincent Membré - Configuration Management Camp 2017

Page 3: Automate your automation with Rudder’s API! \o

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

General presentation of Rudder APIHow to use itDemoquestions / what do you want to build ?

Page 5: Automate your automation with Rudder’s API! \o

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

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

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

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

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

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

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

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

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

PASSING PARAMETERSUrl parametersform dataJson

Page 15: Automate your automation with Rudder’s API! \o

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

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

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

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

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 20: Automate your automation with Rudder’s API! \o

DEMOGO TO DEMO

Page 21: Automate your automation with Rudder’s API! \o

QUESTIONS ?WHAT DO YOU WANT TO

AUTOMATE ?HOW WOULD I DO THAT ?

Page 22: Automate your automation with Rudder’s API! \o

THE END