feat(config): Add clouds add command - #1888
Conversation
Add `osc config clouds add`, a hand-written command that reads the JSON of an application credential from stdin and merges a ready-to-use cloud entry into clouds.yaml. Connection settings (auth_url, region, TLS options) are inherited from the cloud selected with --os-cloud; no authentication is performed. Supports --split to keep the credential in a separate secure.yaml, --overwrite to replace an existing entry, and --file to target a specific path. Files carrying the secret are written with mode 0600 and the credential is zeroized in memory after use. The command is dispatched in entry_point before a session is established, as it edits local files only. Closes gtema#1323 Signed-off-by: dmbuil <dariomartinbuil@outlook.com>
gtema
left a comment
There was a problem hiding this comment.
One problem that I see with this approach is that it overwrites the concrete yaml file (loosing comments and everything else in it). It would immediately break lot of things in the configs at least for me. What if instead of serde_yaml we use rust-yaml which is a "port" of python's ruamel that allows to preserve all comments of the yaml in the de/ser roundtrip to be less disruptive
| } | ||
|
|
||
| /// One entry under the `clouds:` key of a clouds.yaml/secure.yaml file. | ||
| #[derive(Debug, Default, Serialize)] |
There was a problem hiding this comment.
I guess it would be more logical to reuse structures from the sdk/core crate. This would enable adding not only app_cred connections, but also something else (who knows what) and at the same time prevent code deviation.
You're right about the file rewrite, and it can get worse if one uses advanced YAML features. Round-tripping through (I already knew this issue from other projects such as lazy-ssh, but thought of it as a necessary evil) So for anyone using &base / <<: *base across regions the file comes back structurally different, not just stripped of comments. I did try rust-yaml before replying, and I don't think it gets us there. On this input:
Giving it a second thought, I'd suggest instead is to stop re-serializing the file at all: parse only to validate and to detect a name collision, then splice the rendered entry into the existing text and write the original bytes back untouched everywhere else: not as elegant, but at least should work. On the other hand, serde_yaml is archived, and maybe worth revisiting... but I'd keep that separate from this, for now. Happy to go implement the splice approach unless you'd rather take this somewhere else :) |
|
what about yamlpatch or yaml-edit? |
|
I thought of the harcoded serde_yaml not to include many other "foreign crates". But now this door has been opened, I've gone through a couple of them (using a little bit of AI for the comparison).
Biggest downside of yamlpatch (the most popular) is that it imposes Rust min vers 1.97, which is way higher than OSC's 1.89. Next candidate would be noyalib, but it is a single-maintainer crate. The other projects will scramble, drop or duplicate comments / advanced YAML configs. Given that |
Add
osc config clouds add, a hand-written command that reads the JSON of an application credential from stdin and merges a ready-to-use cloud entry into clouds.yaml. Connection settings (auth_url, region, TLS options) are inherited from the cloud selected with --os-cloud; no authentication is performed.Supports
--splitto keep the credential in a separate secure.yaml,--overwriteto replace an existing entry, and--fileto target a specific path. Files carrying the secret are written with mode 0600 and the credential is zeroized in memory after use.The command is dispatched in entry_point before a session is established, as it edits local files only.
Closes #1323