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

Setting custom dictionaries through environment doesn't work #189

Closed
Edu4rdSHL opened this Issue Jan 24, 2019 · 6 comments

Comments

Projects
None yet
3 participants
@Edu4rdSHL
Copy link

Edu4rdSHL commented Jan 24, 2019

First, make sure that none of the open and closed issues is about the same issue as you are describing, and make sure to check the frequently asked questions in the README file.
Then, replace the parts of this template that are between with the data relative to your issue.

If you're reporting a bug, use the template below. Otherwise, delete this template and write your issue normally.

Context

Please select one:

  • I use the docker image ullaakut/cameradar
  • I use my own build of the docker image
  • I use the pre-compiled binary
  • I use my own build of the binary
  • None of the above / I don't know

Please select one:

  • I use a specific version:
  • I use the latest commit of the master branch
  • I use the latest commit of the develop branch
  • I use a forked version of the repository:
  • I use a specific commit:

Environment

My operating system:

  • Windows
  • OSX
  • Linux
  • Other

OS version: ArchLinux
OS architecture: x64

Issue

What was expected?

When building the package with go build -ldflags "-X main.CAMERADAR_CUSTOM_CREDENTIALS=/usr/share/cameradar/dictionaries/credentials.json -X main.CAMERADAR_CUSTOM_ROUTES=/usr/share/cameradar/dictionaries/routes" it should respect the environment variables according to #143

What happened?

It's still pointing to the default directory.

@DHowett

This comment has been minimized.

Copy link

DHowett commented Jan 24, 2019

@Edu4rdSHL (sorry, I followed you here from Freenode/#go-nuts)
What you're setting with -ldflags "-X ..." isn't environment variables, it's package variables.

The environment variables are only ever picked up from the runtime environment of the final application binary, and they can't be manipulated at compile time whatsoever.

To support building with embedded default values, cameradar will have to be updated to consult the environment and then look for a local package variable that's been defined by the compiler. That would look somewhat like this:

customCredentials := os.GetEnv("CAMERADAR_CUSTOM_CREDENTIALS")
if customCredentials == "" {
    customCredentials = DEFAULT_CAMERADAR_CUSTOM_CREDENTIALS
}

where then you could define main.DEFAULT_... using the linker flag -X.

In absence of that, you'd usually set them like this (at runtime, not build time.)

CAMERADAR_CUSTOM_CREDENTIALS=/path cameradar
@Edu4rdSHL

This comment has been minimized.

Copy link
Author

Edu4rdSHL commented Jan 24, 2019

Hello, @DHowett thank you much. I tried running with that syntax but seems that doesn't work also:

[edu4rdshl@blackarch cameradar]$ CAMERADAR_CUSTOM_CREDENTIALS="/usr/share/cameradar/dictionaries/credentials.json" CAMERADAR_CUSTOM_ROUTES="/usr/share/cameradar/dictionaries/routes" ./cameradar
⠋ Loading dictionaries...Invalid credentials dictionary: could not read credentials dictionary file at /src/github.com/Ullaakut/cameradar/dictionaries/credentials.json:: open /src/github.com/Ullaakut/cameradar/dictionaries/credentials.json: no such file or directory

Edit:

Also changing the GOPATH doesn't work.

[edu4rdshl@blackarch cameradar]$ GOPATH=/usr/share/cameradar ./cameradar
Invalid credentials dictionary: could not read credentials dictionary file at /usr/share/cameradar/src/github.com/Ullaakut/cameradar/dictionaries/credentials.json:: open /usr/share/cameradar/src/github.com/Ullaakut/cameradar/dictionaries/credentials.json: no such file or directory

The var is changed correctly but it's still pointing to src/ when according to https://github.com/Ullaakut/cameradar/blob/b62b431a54e6bb4b30df12d54c78792d2c1327b4/README.md#cameradar_custom_routes-cameradar_custom_credentials it should point to $GOPATH/dictionaries/

@Ullaakut

This comment has been minimized.

Copy link
Owner

Ullaakut commented Jan 24, 2019

I'm on this, I might have introduced a regression with the 3.0.0, since I made a few changes to the environment variables.

Thanks for the issue @Edu4rdSHL and thanks for the help @DHowett 🙏🏽

EDIT: Confirmed, the custom credentials and routes don't work using environment variables at the moment! Working on it 🔧

@Ullaakut Ullaakut changed the title Package don't respect environment variables Setting custom dictionaries through environment doesn't work Jan 24, 2019

@Ullaakut Ullaakut self-assigned this Jan 24, 2019

@Ullaakut Ullaakut added the bug label Jan 24, 2019

@Ullaakut

This comment has been minimized.

Copy link
Owner

Ullaakut commented Jan 24, 2019

Found the origin of the issue. The way I changed the implementation made it so that the variables were using a dash separator instead of an underscore: CAMERADAR_CUSTOM-CREDENTIALS.

I'll push a 3.0.1 release with a bugfix for this! Thanks again to the both of you for bringing this issue to my attention! 🌮

@Ullaakut

This comment has been minimized.

Copy link
Owner

Ullaakut commented Jan 24, 2019

Fixed in 0984607, along with another bug that I discovered thanks to this issue! 🎉

@Edu4rdSHL

This comment has been minimized.

Copy link
Author

Edu4rdSHL commented Jan 24, 2019

Thank you a lot @Ullaakut and @DHowett.

@Edu4rdSHL Edu4rdSHL closed this Jan 24, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment