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

MqttConnectionSettings.CreateFromEnvVars does not work if the env var value contains '=' #95

Open
briancr-ms opened this issue Mar 5, 2024 · 9 comments

Comments

@briancr-ms
Copy link

This issue is for a: (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

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

@rido-min
Copy link
Contributor

rido-min commented Mar 6, 2024

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

@briancr-ms
Copy link
Author

Some services require this api-version structure in the MQTT connect username, so clients need to be able to provide this.

@rido-min
Copy link
Contributor

rido-min commented Mar 6, 2024

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"

@briancr-ms
Copy link
Author

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.

@rido-min
Copy link
Contributor

rido-min commented Mar 6, 2024

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

@briancr-ms
Copy link
Author

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:

  • Comments
  • Single and double quote support
  • Interpolation
  • Escape sequences

@rido-min
Copy link
Contributor

rido-min commented Mar 6, 2024

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.

@briancr-ms
Copy link
Author

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?

@rido-min
Copy link
Contributor

rido-min commented Mar 7, 2024

is there a standard definition for an MQTT connection string?

I'm not aware neither, we are defining our own here

Is that document enough? if not, feel free to file a new issue

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