relation-get should have a "shell" output option

Bug #779713 reported by Clint Byrum
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
pyjuju
Fix Released
Low
Benjamin Saller

Bug Description

relation-get is used in shell scripts, but there isn't an easy way to parse json in shell scripts.

It would be awesome to be able to say eval `relation-get --output=shell` and have all of the variables just set as variables

So the output would be

VAR_SETTINGNAME=value\nVAR_SETTINGNAME2=value2\n

VAR_ is used to prefix relation get's variables before returning them with this output format. If VAR_ variables already exist in the environment they are unset and an error is noted on stderr.

Related branches

Changed in ensemble:
assignee: nobody → Benjamin Saller (bcsaller)
importance: Undecided → Low
status: New → In Progress
Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

This approach has some security implications we should consider. Doing this basically means that the other side of the relation has significant control over the local unit, since it may replace any environment variable at its will.

The relation-get command was actually designed with shell-specific needs in mind, so that one won't have to parse the JSON.

For instance, instead of doing:

    echo $SETTINGNAME

You can do

    echo `relation-get settingname`

The JSON support, as noted, is most useful for other languages.

Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

After some live debate today, supporting this feature with an approach like a fixed prefix (e.g. $VAR_*) might
be a good compromise between safety and convenience.

Changed in ensemble:
milestone: none → dublin
description: updated
Changed in ensemble:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.