API authentication for provisions

Hi all.

Short question: How can I push a provision script to GenieACS without using the GUI ?

Using the examples from the docs I was able to hack my way to paste curl code from the browser’ s debugger into bash and it works but it relies on a cookie for authorization which is not desirable in the long term.

curl ‘http://myACS:3000/api/provisions/otromas
-H ‘Accept: application/json, text/*’
-H ‘Origin: http://myACS3000
-H ‘Referer: http://myACS:3000/
-H ‘Cookie: genieacs-ui-jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiYXV0aE1ldGhvZCI6ImxvY2FsIiwiaWF0IjoxNjE3Mjg4ODAwfQ.W4hvrau1kYrFX3xQf8GAcgc5Y8DeuqR9phQG7nQ4H5M’
–compressed -H ‘Content-Type: application/json; charset=utf-8’
–data-raw ‘{“script”:“my provision script here”}’ ; echo

at the moment of writting this, it works, but I’m pretty sure it won’t once I close my browser. I could cheat it by using curl which involves saving a session cookie a file and reuse it later but I wonder if there’s a more elegant solution.

thank you.

Maby that will help.

@JonasGhost sorry about not elaborating a bit more and I think I phrased my question wrong: “How can I update a provision without using GUI?”

yes, as I mentioned in my first post, I saw that section at the docs, but there’s also a related problem:

this works OK:

curl -X PUT -i ‘http://localhost:7557/provisions/mynewprovision’ --data ‘log("Provision started at " + now);’

but this does not:

curl -X PUT -i ‘http://localhost:7557/provisions/mynewprovision’ --data ‘log("Provision started \n at " + now);’

Notice the \n in the code. Also seems like there’s some regular exp parsing done by mongodb because I get keep getting errors like:

SyntaxError: Invalid or unexpected token

which in turn lead me to the url in my first post. Seems to me the only “legal” way to update a provision would be to use a proper json document with the “script” tag, at least using GenieACS API. I could also connect directly to MongoDB but I think I will do better if don’t touch the db directly (just thinking aloud here while exploring options).

In case you wonder, final goal is to be able to edit provision externally (with some unit testing in place, that would be awesome) and have it in a git repository.

I tried it with Postman and it worked without any problems.

Also pushing a file worked:
curl -X PUT -i "http://localhost:7557/provisions/mynewprovision1" --data-binary "@testFile"

I am running Genieacs 1.2.4

1 Like

seems like I been doing all kinds of tests but that one. ty !

It is an intresting toppic.

I am already storing my provisions in a git repository, but I have not created a Pipeline for that.

this script is no exactly rocket science. It’s something I saw while watching a video from Kent Beck and I have been doing it over the years for several different tasks:

inotifywait -m --format %w%f -q -r -e close_write . …/tests |
while read CUAL
if [ $? == 0 ]; then
# TODO: unit testing ?
curl -X PUT -i ‘http://acstest:7557/provisions/default’ --data-binary “@provision_full_path_here.js

Place the script on the same dir as the provision or add a cd command to relocate to the path of the provision. Inotifywait will watch for changes on the files (parameter say “.” but it can be the provision filename). I ran the script from a console and leave it running on background. Each time I modify the provision file it’s automatically uploaded to the ACS.

1 Like