20.68. kb-00067: Storing Multi-Line Strings in Params

20.68.1. Knowledge Base Article: kb-00067

20.68.2. Description

Due to command line limitations, it can be difficult to store multi-line strings in Params from DRPCLI because newlines and certain characters are interpreted as end of line markers.

20.68.3. Solution

This KB provides two alternatives depending on your use case.

20.69. Option 1: Use JQ to convert file into a string

For most use cases, simply processing the input through jq provides sufficient protection. This has the advantage of being easily rendered in the UX.

With a file: drpcli profiles add [profile] param [mystring] to “$(cat data | jq -sR .)”

With a variable: drpcli profiles add [profile] param [mystring] to “$(jq -sR . <<< “@data”)”

20.70. Option 2: Use base64 to encode the file into a string

For use cases where file formatting is very specific, using base64 encoding is safer. The downside of this approach is that it requires decoding (base64 -d) before the value can be used.

This has the advantage of not being human readable without decoding. While this is NOT a security benefit, it does provide a layer of obfuscation. If you need secure storage, use the Secure flag!

With a file: drpcli profiles add [profile] param [mystring] to “$(base64 data | tr -d ‘n’)”

Note: some versions of base64 include a flag that eliminates n; however, the tr approach has a broader support across different operating systems.

20.70.1. Additional Information

Additional resources and information related to this Knowledge Base article.

20.70.1.1. See Also

It’s important to understand the different Param types and make sure you are using the correct one.

20.70.1.2. Versions

All

20.70.1.3. Keywords

multi-line, string, jq, base64

20.70.1.4. Revision Information

KB Article     :  kb-00067
initial release:  Thu 30 Sep 2021 01:10:16 PM CDT
updated release:  Thu 30 Sep 2021 01:10:16 PM CDT