Open briancr-ms opened 8 months ago
what's the reason of passing the api-version in the username? Should it use UserProperties in the connect packet ? https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901054
Some services require this api-version structure in the MQTT connect username, so clients need to be able to provide this.
Using the USERNAME field to specify api-version seems questionable. Can we discuss with service owners?
btw, I guess you could specify the value with quotes:
MQTT_USERNAME="reg-cp-1/registrations/device-1/api-version=2023-12-01-preview"
But the client doesn't control what the server requires in the connect username field. The "api-version=" is one case I ran across but I suppose a username could have an '=' in it, like a username "foo=bar".
The current implementation does not support surrounding the value with quotes.
If supporting quoted values is the preferred solution to this problem, then let's specify that (and ensure that the implementation supports escaping quotes as well for values that contain quotes).
BTW, is there a spec for .env files that describes what they should and should not support? I couldn't find one with a quick search.
Yeah, I'd say that allowing quotes is the preferred solution.
AFAIK there is no "formal" spec, see this doc from docker
https://docs.docker.com/compose/environment-variables/env-file/ https://stackoverflow.com/questions/68267862/what-is-an-env-or-dotenv-file-exactly
Okay, so in order to address this issue, the designers of the MQTTnet client extensions library will need to define what features are supported in a .env file:
well, there is no such extension library, just a project used in these samples :)
We started with .env files to avoid loading connection strings in C (that requires more parsing), other languages/tools have .env files already implemented, so we added basic .NET support based on https://dusted.codes/dotenv-in-dotnet. But it was not a core requirement for .NET.
For .NET I'd recommend using connection strings instead of .env files.
Okay, but is there a standard definition for an MQTT connection string? I couldn't find this, either. For readability, which is probably one of the points of these samples, the .env key=value approach is nice. Either way, the connection settings input format should be specified and then implemented.
Since this issue is narrowly about the .env file and the '=' character, would you prefer that I open an issue that is used for specifying the connection settings for these samples?
This issue is for a: (mark with an
x
)Minimal steps to reproduce
Call MqttConnectionSettings.CreateFromEnvVars with a file containing a variable that contains an '=' in the value, such as MQTT_USERNAME=reg-cp-1/registrations/device-1/api-version=2023-12-01-preview
Any log messages given by the failure
Silent failure.
Expected/desired behavior
Environment variables with '=' in value are used.
Language
C#
OS and Version?
Any