feat: add profile support to the tedge cli and fix mosquitto configuration#3262
Conversation
tedge cli and fix mosquitto configurationtedge cli and fix mosquitto configuration
Codecov ReportAttention: Patch coverage is Additional details and impacted files📢 Thoughts on this report? Let us know! |
Robot Results
|
bc8fd93 to
8f9ab76
Compare
8f9ab76 to
dba0000
Compare
8081bf8 to
f9abca3
Compare
2883409 to
4acb430
Compare
didier-wenzek
left a comment
There was a problem hiding this comment.
The UX is really nice and it's a real plus to have a certificate per cloud.
$ tedge config set c8y@pki.device.key_path /etc/tedge/device-certs/demo-c8y-ca.key
$ tedge config set c8y@pki.device.cert_path /etc/tedge/device-certs/demo-c8y-ca.pem
$ tedge cert create --device-id demo-c8y-ca c8y@pki
Certificate was successfully created
$ tedge cert show c8y@pki
Device certificate: /etc/tedge/device-certs/demo-c8y-ca.pem
...
$ tedge cert show c8y
Device certificate: /etc/tedge/device-certs/demo-device-888.pem
... untouched! nice!
However, error messages might be improved regarding this new CLOUD parameter on many tedge commands. Could the error message list the clouds?
$ tedge cert show c8y@foo
Error: missing configuration parameter
Caused by:
Unknown profile `foo` for the multi-profile property c8y
But:
$ tedge cert show foo@pki
error: invalid value 'foo@pki' for '[CLOUD]': Unrecognised cloud type: "foo@pki"
For more information, try '--help'.
|
@jarhodes314 Overall it looks good, though I just have the following questions/observations:
|
4acb430 to
822cc8e
Compare
822cc8e to
677eb5b
Compare
@reubenmiller Not currently, although I'm not convinced of the value of such a feature, given the point of profiles is to allow us to store separate cloud configurations inside tedge.toml. If you're using environment variables to configure tedge, then surely you can just set the right variables per process to manually manage your cloud configurations? I guess for temporarily overriding a value it might make sense.
I agree, and I'll have a look into how easy this is to achieve.
I'm slightly worried allowing this to be controlled by an environment variable might lead to confusion/difficult to resolve scenarios. As far as I'm aware, it can be quite difficult to unset an environment variable, so if this was set and you wanted to modify the default profile, you'd have a hard time doing so. I don't think environment variables provide the same value when they're replacing a command line argument |
Signed-off-by: James Rhodes <jarhodes314@gmail.com>
677eb5b to
ec86468
Compare
tedge cli and fix mosquitto configurationtedge cli and fix mosquitto configuration
I've decided to put these changes in a separate PR as this one is already getting quite large and makes sense in itself. As neither of these suggestions are breaking changes, it will be easier to deal with these separately. |
albinsuresh
left a comment
There was a problem hiding this comment.
LGTM. Just some cosmetic comments and test/doc improvements.
| The device id is read from the device certificate and cannot be set directly.\n\ | ||
| To set 'device.id' to some <id>, you can use `tedge cert create --device-id <id>`.", |
There was a problem hiding this comment.
| The device id is read from the device certificate and cannot be set directly.\n\ | |
| To set 'device.id' to some <id>, you can use `tedge cert create --device-id <id>`.", | |
| The device id that is used to connect to this cloud instance, | |
| which defaults to the main `device.id` setting, but can be overridden for this cloud. | |
| The device id is read from the device certificate and cannot be set directly.\n\ | |
| To override the main `device.id` value for this cloud instance, | |
| create a new certificate at a different location using `tedge cert create --device-id <id> --config-dir /some/other/location`." | |
| and update the `key_path` and `cert_path` for this cloud instance using | |
| `tedge config set c8y@<instance>.device.key_path` and `tedge config set c8y@<instance>.device.cert_path` respectively |
|
|
||
| #[derive(Debug, Copy, Clone)] | ||
| enum ServiceCommand { | ||
| enum ServiceCommand<'a> { |
There was a problem hiding this comment.
One of the reasons why I hate adding lifetime parameters to structs (esp existing ones), unless absolutely necessary, as it just litters the whole call stack with that parameter.
Could we have used owned ProfileNames in SystemService as well, as done for the Cloud enum or BridgeConfigXyzParams structs, since the cost of having those owned copies here is very minimal in the grand scheme of things? Or was there some other reason other than efficiency that forced you to use references here?
| local_clientid: if let Some(profile) = &profile_name { | ||
| format!("c8y-bridge@{profile}") | ||
| } else { | ||
| "c8y-bridge".into() |
There was a problem hiding this comment.
| "c8y-bridge".into() | |
| "Cumulocity".into() |
If we don't use the same old client id, wouldn't that lead to message loses when thin-edge is self-updated, as the broker won't send any queued messages for the older client-id to the new one?
| C8y, | ||
| Azure, | ||
| Aws, | ||
| C8y(Option<Cow<'a, ProfileName>>), |
There was a problem hiding this comment.
You really love Cows, don't you? 😉
Not a request for change, but, in the context of these commands that are only executed just a handful of times during the entire lifetime of a device, I wonder if it's really worth the added complexity, unless I'm missing some hidden benefits.
| .collect::<Vec<_>>() | ||
| .join(", "); | ||
|
|
||
| bail!("The configurations: {keys} should be set to diffrent values, but are currently set to the same value"); |
There was a problem hiding this comment.
| bail!("The configurations: {keys} should be set to diffrent values, but are currently set to the same value"); | |
| bail!("The configurations: {keys} should be set to different values, but are currently set to the same value"); |
|
|
||
| Test Setup | ||
| Customize Operation Workflows ${PARENT_SN} | ||
| Copy Configuration Files ${PARENT_SN} |
There was a problem hiding this comment.
Even this step can be performed just once at the Suite Setup level itself, as repeating this step at Test Setup level just repeats the same steps on the same device.
| # Get configuration | ||
| # | ||
|
|
||
| Get Configuration from Main Device |
There was a problem hiding this comment.
| Get Configuration from Main Device | |
| Get Configuration from Primary Cloud Connection |
| Text file topic_prefix=c8y external_id=${PARENT_SN} config_type=CONFIG1 device_file=/etc/config1.json | ||
| Binary file topic_prefix=c8y external_id=${PARENT_SN} config_type=CONFIG1_BINARY device_file=/etc/binary-config1.tar.gz | ||
|
|
||
| Get Configuration from Second Device |
There was a problem hiding this comment.
| Get Configuration from Second Device | |
| Get Configuration from Profiled Cloud Connection |
|
|
||
|
|
||
| *** Variables *** | ||
| ${PARENT_SN} ${EMPTY} |
There was a problem hiding this comment.
| ${PARENT_SN} ${EMPTY} | |
| ${DEVICE_SN} ${EMPTY} |
Just because there's no parent or child devices in this test.
| @@ -0,0 +1,14 @@ | |||
| [Unit] | |||
| Description=tedge-mapper-aws checks Thin Edge JSON measurements and forwards to AWS IoT Hub. | |||
There was a problem hiding this comment.
| Description=tedge-mapper-aws checks Thin Edge JSON measurements and forwards to AWS IoT Hub. | |
| Description=tedge-mapper-aws checks Thin Edge JSON measurements and forwards to AWS IoT Core. |
You've only inherited this from the existing non-templated version, which was wrong.
| Execute Command | ||
| ... cmd=sudo env C8Y_USER='${C8Y_CONFIG.username}' C8Y_PASSWORD='${C8Y_CONFIG.password}' tedge cert upload c8y@second | ||
|
|
||
| Execute Command tedge connect c8y@second |
There was a problem hiding this comment.
One unforseen side effect of these "secondary device twins" are that they're never auto-deleted from the connected tenant.
Proposed changes
This changes
tedge connectetc. to use the<cloud>@<profile>syntax. For example,becomes
It also fixes some issues that were causing mosquitto to fail to start when multiple cloud profiles are configured.
Additionally it adds the missing systemd service definitions, so you can now start
tedge-mapper-c8y@profileto spawn a mapper instance with a profile selected.Types of changes
Paste Link to the issue
Checklist
cargo fmtas mentioned in CODING_GUIDELINEScargo clippyas mentioned in CODING_GUIDELINESFurther comments