Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiline String Support #58

Closed
ephos opened this issue Mar 23, 2020 · 2 comments
Closed

Multiline String Support #58

ephos opened this issue Mar 23, 2020 · 2 comments

Comments

@ephos
Copy link

ephos commented Mar 23, 2020

Hello, I saw another issue open and then closed by the person that opened it regarding this with no other comments.

Current state:

something:
  name: test
  key:
  - '-----BEGIN PGP MESSAGE-----'
  - 'Version: GnuPG v2.0.22 (GNU/Linux)'
  - 'blah'
  - 'blah'
  - 'blah'
  - '-----END PGP MESSAGE-----'

Desired state:

something:
  name: test
  key: |
    -----BEGIN PGP MESSAGE-----
    Version: GnuPG v2.0.22 (GNU/Linux)
    blah
    blah
    blah
    -----END PGP MESSAGE-----

Apologies if it is something I am doing, I tried various options but couldn't seem to get it to handle the multiline string.

@gabriel-samfira
Copy link
Member

Hi @ephos,

First of all, my apologies for not getting back to you sooner.

Secondly, I tried this:

PS /home/gabriel> $data = @'
>> something:
>>   name: test
>>   key: |
>>     -----BEGIN PGP MESSAGE-----
>>     Version: GnuPG v2.0.22 (GNU/Linux)
>>     blah
>>     blah
>>     blah
>>     -----END PGP MESSAGE-----
>> '@
PS /home/gabriel> $x = ConvertFrom-Yaml $data
PS /home/gabriel> $x["something"]["key"]
-----BEGIN PGP MESSAGE-----
Version: GnuPG v2.0.22 (GNU/Linux)
blah                              
blah                                     
blah       
-----END PGP MESSAGE-----
           
PS /home/gabriel> ConvertTo-Yaml $x          
something:             
  key: |        
    -----BEGIN PGP MESSAGE-----
    Version: GnuPG v2.0.22 (GNU/Linux)
    blah
    blah
    blah
    -----END PGP MESSAGE-----
  name: test

Would you mind pasting an example of what you tried?

@ephos
Copy link
Author

ephos commented Jun 18, 2020

Sorry I also just saw this reply! I just tried it out and it looks like it may work, I am going to try it tomorrow to see if it fixes what I saw when I originally opened the issue. Below is what I tried and it seems to honor the multi line string.

$yaml = @"
something:
  name: test
  key: |
    -----BEGIN PGP MESSAGE-----
    Version: GnuPG v2.0.22 (GNU/Linux)
    blah
    blah
    blah
    -----END PGP MESSAGE-----
"@

# Deserialize
$object = $yaml | ConvertFrom-Yaml

# Updated value
$newPGPMsg = @"
-----BEGIN PGP MESSAGE-----
Version: GnuPG v2.0.22 (GNU/Linux)
foo
foo
foo
-----END PGP MESSAGE-----
"@

# Update the value
$object.something.key = $newPGPMsg
$object.something.key 

# Serialize back to YAML
$object | ConvertTo-Yaml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants