Skip to content

Conversation

mothslaw
Copy link
Contributor

Context:

This aims to make it easier for plugins to construct simple, parameterized Bash commands, without having to worry about escaping, quoting, or special characters.

Problem:

Suppose a plugin wants to construct a very simple Bash command line, with a command and some parameters that are based on data provided by the user. For example, if a user provisions a new VDB named foo, then maybe the plugin wants to place a sentinel file somewhere on a remote host, something like this:

touch /some/path/foo.txt

The plugin code to do this might look like this:

command = "touch {}/{}.txt".format(my_dir, my_vdb_name)

Okay, so now imagine the name of the VDB is "Bob's $10B idea". The Bash command constructed will be:

touch /some/path/Bob's $100B idea

This is a syntax error. In order to do this properly, the plugin has to take special care to quote/escape that single-quote in Bob's, and also that dollar sign.

It's very easy to forget to do this (in fact, our docs have this problem!). This work is fairly fussy and error-prone, and really is not something a plugin should have to deal with just to run a simple command.

Solution:

Provide a function which will construct a valid Bash string, if given the name of a command and a set of arguments to that command. The passed-in strings will be quoted/escaped as necessary such that the command sees the same string contents that the plugin code does... even if those strings contain special characters.

Testing

I wrote a number of unit test cases (included in this PR)

I also hand-tested the code by copy/pasting results directly to a Bash prompt.

I did not have time to do any testing with a real plugin or a real engine. And, I will stop having access to engines very soon, so I will not be able to do any such testing in future either.

Implementation:

See code/comments

Notes To Reviewers:

I'm losing access to this github account soon, and will not be able to make modifications to this PR, nor to respond to any feedback.

Feel free to do whatever you want with this:

  • Throw it away and don't use it at all
  • Accept it as/is
  • Someone else takes this as a baseline and modifies it
  • Something else?

@mothslaw mothslaw requested a review from nhlien93 as a code owner December 16, 2021 21:05
@mothslaw mothslaw linked an issue Dec 17, 2021 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

"12/16/2021: Make it easier to construct simple Bash commands"
1 participant