Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Can we specify a key via an environment variable or via the config file #24

Open
drgr33n-vw opened this issue Aug 30, 2022 · 10 comments
Open

Comments

@drgr33n-vw
Copy link

Hi,

I'm not sure if this is possible but can I specify an API key within a config file? If not, would it be possible to add the functionality? If not from a config file, maybe read from an environment variable?

@emiliocampos-zevenet
Copy link

emiliocampos-zevenet commented Aug 31, 2022 via email

@nevola
Copy link
Contributor

nevola commented Aug 31, 2022

I'm not sure if this is possible but can I specify an API key within a config file? If not, would it be possible to add the functionality? If not from a config file, maybe read from an environment variable?

No, it is not supported. The key currently is only via command line but it's hidden.

@emiliocampos-zevenet
Copy link

emiliocampos-zevenet commented Aug 31, 2022 via email

@emiliocampos-zevenet
Copy link

emiliocampos-zevenet commented Aug 31, 2022 via email

@drgr33n-vw
Copy link
Author

drgr33n-vw commented Aug 31, 2022

OK, thanks for your replies. My use case is I've rolled this into a small Arch package and I would like to have a configuration file that I can use to control configuration variables when starting. Currently, I have it setup so SystemD reads an environment file and just adds those the the startup command but that's not ideal. I'd like to be able to specify variables like host, port and key from either a configuration file or environment variables. This would make it much easier to run as a SystemD service.

I initially thought you could add the key into a file and have the application collect this by specifying a config file but skimming through the code, it looks like this is for bootstrapping rules and not configuring the behavior of the daemon.

I've not programmed in C for many years but I could look at adding this functionality myself. If you feel like it would be a useful feature to have, I could submit a PR if you like. That's if I can manage to actually add that functionality.

@nevola
Copy link
Contributor

nevola commented Aug 31, 2022

Sure! It should be very easy.

Getting the key from the environment:
Just call to getenv() in the main() and then if the env variable exist, then call to server_set_key().

Getting the key from a file:
Add an optarg with the file path and then in the main() read the file with the first string, then call to server_set_key().

Regards.

@drgr33n-vw
Copy link
Author

Awesome, I've forked the repo and I've added the env var functionality. Seems to be working as expected. The configuration file part looks a little more difficult as I would have to write a parser to collect variables. I could use a third-party library and maybe use INI format but that's adding too much complexity for such a small change. I'll take a look later in the week

@drgr33n-vw
Copy link
Author

I've also added this project to the Arch AUR. Not sure if I can put URLs here but I'll try :)

https://aur.archlinux.org/packages/nftlb-git

@nevola
Copy link
Contributor

nevola commented Sep 1, 2022

Sure. thank you for the upload in archlinux. I revisit your patch and it seems that your editor changed the indentation. I'll made some changes to your patch and apply in the devel branch if this is ok for you.
Thanks!

@drgr33n-vw
Copy link
Author

No Problem. Yes, I used CLion and it always does that :) I'm not a very good programmer either so you might want to change how I've implemented that small change. I know you have to be careful with C when adding these types of user input so not to introduce vulnerabilities. I'll leave this ticket open for the time being as I'll probably add the file configuration option later this week.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants