Skip to content

Commit 36e4bf4

Browse files
authored
Merge pull request #474 from 1Password/omar/fix-ngrok-version-check
[BUG FIX] Remove ngrok version check everytime a op plugin command is called
2 parents d36189b + 67fff70 commit 36e4bf4

File tree

5 files changed

+20
-56
lines changed

5 files changed

+20
-56
lines changed

plugins/ngrok/credentials.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func Credentials() schema.CredentialType {
4545
},
4646
},
4747
},
48-
DefaultProvisioner: ngrokEnvVarProvisioner{},
48+
DefaultProvisioner: ngrokProvisioner{},
4949
Importer: importer.TryAll(
5050
importer.TryEnvVarPair(defaultEnvVarMapping),
5151
importer.MacOnly(

plugins/ngrok/credentials_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
)
1111

1212
func TestCredentialsProvisioner(t *testing.T) {
13-
plugintest.TestProvisioner(t, ngrokProvisioner(), map[string]plugintest.ProvisionCase{
13+
plugintest.TestProvisioner(t, ngrokProvisioner{}, map[string]plugintest.ProvisionCase{
1414
"temp file": {
1515
ItemFields: map[sdk.FieldName]string{
1616
fieldname.Authtoken: "cxG2Im21Yzkh8VnvFQaetlPHcQ9ZDUUk1IzzyHhcGcEXAMPLE",

plugins/ngrok/env_var_provisioner.go

Lines changed: 0 additions & 42 deletions
This file was deleted.

plugins/ngrok/ngrok.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ func ngrokCLI() schema.Executable {
2323
),
2424
Uses: []schema.CredentialUsage{
2525
{
26-
Name: credname.Credentials,
27-
Provisioner: ngrokProvisioner(),
26+
Name: credname.Credentials,
2827
},
2928
},
3029
}

plugins/ngrok/provisioner.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ const (
2525
envVarAuthVersion = "v3.2.1"
2626
)
2727

28-
type fileProvisioner struct {
28+
type ngrokProvisioner struct {
2929
}
3030

31-
func ngrokProvisioner() sdk.Provisioner {
31+
func HasEnvVarSupport() bool {
3232
currentVersion, err := getNgrokVersion()
3333
if err != nil {
3434
// When ngrok version check fails for any reason,
3535
// use config file to provision as a fallback
36-
return fileProvisioner{}
36+
return false
3737
}
3838

3939
// If the current ngrok CLI version is 3.2.1 or higher,
@@ -42,14 +42,21 @@ func ngrokProvisioner() sdk.Provisioner {
4242
// semver.Compare resulting in 0 means 3.2.1 is in use
4343
// semver.Compare resulting in +1 means >3.2.1 is in use
4444
if semver.Compare(currentVersion, envVarAuthVersion) >= 0 {
45-
return ngrokEnvVarProvisioner{}
45+
return true
4646
}
4747

4848
// Otherwise use config file to provision credentials
49-
return fileProvisioner{}
49+
return false
5050
}
5151

52-
func (f fileProvisioner) Provision(ctx context.Context, in sdk.ProvisionInput, out *sdk.ProvisionOutput) {
52+
func (p ngrokProvisioner) Provision(ctx context.Context, in sdk.ProvisionInput, out *sdk.ProvisionOutput) {
53+
54+
if HasEnvVarSupport() {
55+
out.AddEnvVar("NGROK_AUTHTOKEN", in.ItemFields[fieldname.Authtoken])
56+
out.AddEnvVar("NGROK_API_KEY", in.ItemFields[fieldname.APIKey])
57+
return
58+
}
59+
5360
provisionedConfigFilePath := filepath.Join(in.TempDir, "config.yml")
5461
config := make(map[string]interface{})
5562

@@ -137,10 +144,10 @@ func getNgrokVersion() (string, error) {
137144
return currentVersion, nil
138145
}
139146

140-
func (f fileProvisioner) Deprovision(ctx context.Context, in sdk.DeprovisionInput, out *sdk.DeprovisionOutput) {
141-
// nothing to do here: files get deleted automatically by 1Password CLI
147+
func (p ngrokProvisioner) Deprovision(ctx context.Context, in sdk.DeprovisionInput, out *sdk.DeprovisionOutput) {
148+
// nothing to do here: files get deleted automatically by 1Password CLI and environment variables get wiped when process exits
142149
}
143150

144-
func (f fileProvisioner) Description() string {
145-
return "Config file aware provisioner. It will first check if an already existing config file is present."
151+
func (p ngrokProvisioner) Description() string {
152+
return "If ngrok version is 3.2.1 or higher than provision ngrok credentials as environment variables NGROK_AUTH_TOKEN and NGROK_API_KEY otherwise config file aware provisioner. It will first check if an already existing config file is present."
146153
}

0 commit comments

Comments
 (0)