-
Notifications
You must be signed in to change notification settings - Fork 80
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
issue with creating context in interactive mode (hcloud: context create is an interactive command) #819
Comments
While checking the issue and diving into the code i found the following, keep in mind i am not sure if this is the case and is just an assumption :) While this already happened before and saw it was fixed in the past already multiple times i think it has been broken by the last update by @phm07 with the change from I am not a go developer so this is just a suggestion and i see that it has been changed what could of course explain why? Is it not a better idea to skip the interactive check when the os environment variable is provided? |
Hey @jnovermars, I can not reproduce the issue on the latest version or on What is the output of the following commands?
For reproducing I used the following command: $ HCLOUD_CONFIG=hcloud-cli-819.toml HCLOUD_TOKEN=$(openssl rand -hex 64 | head -c 64) bash -c "hcloud context create foo <<<'Y'"
The HCLOUD_TOKEN environment variable is set. Do you want to use the token from HCLOUD_TOKEN for the new context? (Y/n): Context foo created and activated Its also not necessary to create a context in your CI pipeline, you can do everything with environment variables and or flags if you want to. |
It is easy to reproduce it in docker, i runned the commands you asked:
i quicky created a small version of our docker file, and you are totally right that for CI pipeline the commands could run without the context. But i found this and think this is a bug as the expectation is that it could run without TTY but still it is required. I converted your command to run it in docker:
The docker file:
|
I agree that we should support non-interactive mode, I think have an "assume yes" to bypass any yes/no prompt would be helpful in this scenario. But this might require a broader change across the CLI to support a such a global flag. |
This is currently low priority, as one can always use the HCLOUD_TOKEN environment variable when running a script. Using a context for a script seem to be a really specific use case. |
That is indeed the workaround we use now |
Creating a context in non-interactive mode would mean that you would have to pass the token as a command argument. This is potentially unsafe and bad practice, since the token would then be stored in your shell history, even if you deleted the context. (Edit: Getting it from the environment, like you suggested, would be viable though. We would still need an extra flag then) As a workaround, you can manually create contexts by manually appending to |
@jnovermars Can you try installing hcloud with: Then you can try using the following command: This should allow you to create a context using the CLI in a non-interactive TTY. Although be beware that this is not the recommended method, as it will store your token plain on disk and just using the |
TL;DR
not able to use HCLOUD_TOKEN while running hcloud create context
Expected behavior
when running
HCLOUD_TOKEN="x" hcloud context create dummy
this should work and use the token provided in the environment var.Observed behavior
i get the error:
Minimal working example
we use this in our gitlab ci pipeline where hcloud is installed via brew
brew install hcloud
:Log output
Additional information
See commend as there the links are working
The text was updated successfully, but these errors were encountered: