Search code examples
jsoncommand-lineterminalopenam

About Amster '--body' option (OpenAM command line)


There is a '--body' option for most of the Amster commands. This options allows you to send the body of a request with JSON syntax. However, if the body of your request is big, the --body option will be big and the Amster command will be huge for your terminal. Is there any option to specify this JSON text in a way that it is not so uncomfortable for the command-line? Maybe it exists an option that allows you to indicate the path of a JSON file or something like that. I will be very grateful for any answer.


Solution

  • My answer below is based on the latest available Amster (6.0.0)

    You can use Amster in Script mode. Essentially you can write your amster commands in a separate file, lets call it myscript.amster, please note, the extension is not important.

    You can then add your entire command including the json in your script, for e.x. to create a realm: Please note the use of: \ to spill the json across multiple lines.

    create Realms --global --body '{ \
        "name": "test", \
        "active": false, \
        "parentPath": "/", \
        "aliases": [ "testing" ] \
    }'
    

    Now, you can run this script in two modes:

    From within the amster shell:

    am> :load <pathToYourScript>
    

    Without having to enter the script mode:

    amster/amster <pathToYourScript>
    

    In this mode, do remember to connect to your openam server before running your commands and :quit at the end. You should find some more samples in the samples directory of your amster.