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
update(ngrok): switch to envvars provisioner for ngrok 3.2.1 and higher #222
update(ngrok): switch to envvars provisioner for ngrok 3.2.1 and higher #222
Conversation
71c06b5
to
04bef9a
Compare
The CI test is failing with |
Thanks for this great addition @arunsathiya ! I really like the logic of using the env var provisioning from versions equal or higher than 3.2.1, and still use the file provisioner based on versions lower than that, so that the shell plugin works for ngrok users regardless of their installed version.
For this reason, I think an improvement we could make on the OP CLI side is to also provision the tool's version via the |
@AndyTitu That fits nicely into a plan I had a while back to make the Provisioner metadata more intelligent, which you can find on this branch. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be great to pull out the logic for version comparison to make it easier to re-use. Worth exploring if we can go even further than the code on that branch Floris pushed and also take care of parsing the version, and maybe even the comparison func, so all the user needs to do is pass the version number.
In order to support non-standard versioning schemes (i.e. not semver) or with non-standard version command output that requires custom parsing logic, we can make it possible to pass funcs to overwrite the default behavior. but in the most common scenarios the user/plugin should require as little as possible work/code.
I believe making the code re-usable is an additive improvement, and doesn't need to block the improvement in this PR to go out. Can we already release this work from @arunsathiya then we (1Password) can take on the internal changes to add the version meta support in 1Password CLI to make it re-usable for other plugins?
Thanks for the review, all of you! This should be ready for one more look, and hopefully good to merge. 🤞🏼 |
I have one concern related to this MR - I think it ingrains too deeply the version comparison functionality in the The pattern where different versions of a tool would default to different provisioners should not be isolated only to For example, I can imagine something along the lines of:
together with a validation function that would assert that all versions are covered. I'd love to hear what y'all think! An additional question: are there any known limitations to the current temp file approach, when it comes to ngrok? |
A helper function to switch provisioners based on certain conditions could be useful indeed, but I agree with Simon that it doesn't have to block this PR. |
As far as I know/remember, the only concern is that the temp file approach requires a "Version" field, without which the ngrok binary doesn't work. At this point, "version: 2" is a valid field, but when in the future ngrok moves to a different version as the required/default version, we'd have to make that change on the Shell Plugins side too. Environment variables-based approach doesn't require that field. |
Very eager to bring versioning to all plugin provisioners! Before then, I agree, let's not hold this back. 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm. I have created an internal issue for tackling the versioning logic discussed here.
…her, or use config file provisioners
efa1da5
to
e4bcfc4
Compare
…ovisioner for all plugins that use ngrok credentials
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This generally looks good! I have left a few minor comments.
It would be good to test these changes with the Terraform plugin to make sure using ngrok Credentials
with Terraform
no longer returns the not supported
error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This generally looks good! I have left a few minor comments.
It would be good to test these changes with the Terraform plugin to make sure using ngrok Credentials
with Terraform
no longer returns the not supported
error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This generally looks good! I have left a few minor comments.
It would be good to test these changes with the Terraform plugin to make sure using ngrok Credentials
with Terraform
no longer returns the not supported
error.
…rovisioner struct and calling Provision method on it
…kProvisioner. The test will use only file provisioner for now. This is because ngrok program is not available on the CI/CD, which in turn means that version checking does not work and defaults to file provisioner
Thanks for the guidance, @AndyTitu. I have tested with the Terraform plugin and it works as expected. My config file is as below:
The resource block is from here: https://github.com/ngrok/terraform-provider-ngrok/tree/main/examples/resources |
Fixes #274 |
Testing instructions:
Terraform config file:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-approving to mark that I'm okay with the latest changes.
Fixes #216 and fixes #274
Description
This PR updates the ngrok Shell Plugin to use environment variables to provision credentials when the ngrok CLI is 3.2.1 or higher. We'd retain the config file-based provisioner for older versions.
Testing instructions
ngrok --version
. If it's 3.2.1 or higher, anyngrok api
command (examplengrok api tunnels list
) should succeed. During this run, the credentials are provisioned using the NGROK_AUTH_TOKEN and NGROK_API_KEY environment variables. (Note that only NGROK_API_KEY is new as of 3.2.1, NGROK_AUTH_TOKEN was already supported in previous versions)ngrok api tunnels list
should still succeed, but this time the provisioning happens with configuration files.Another way to test
plugins/ngrok/provisioner.go
, changereturn fileProvisioner{}
toreturn provision.EnvVars(defaultEnvVarMapping)
(line 64)ngrok api tunnels list
. It should fail withERROR: API key is missing; either use '--api-key' flag or set it as 'api_key' in the configuration file
because at this point the provisioning happens with the env vars NGROK_AUTH_TOKEN and NGROK_API_KEY of which NGROK_API_KEY is not supported on 3.1.1Download ngrok 3.1.1
To download ngrok 3.1.1, download the binary from one of these two links depending on your system architecture:
https://github.com/ngrok/homebrew-ngrok/blob/668bb053898e0f767916083f3fdeaf4a0f6eac84/Casks/ngrok.rb#L4-L10
And then run
sudo unzip ~/Downloads/ngrok-v3-3.1.1-darwin-arm64.zip -d /usr/local/bin
Ensure you are running the ngrok binary that you downloaded now by running
which ngrok
. You don't want to be testing with another binary, say Homebrew's version if you had it installed previously.which ngrok
should read/usr/local/bin/ngrok