Skip to content

Commit

Permalink
Change naming of function and struct and clean up code
Browse files Browse the repository at this point in the history
Signed-off-by: Omar Miraj <omar.miraj@agilebits.com>
  • Loading branch information
MOmarMiraj committed Sep 24, 2024
1 parent fa1dd73 commit e19db8d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion plugins/ngrok/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func Credentials() schema.CredentialType {
},
},
},
DefaultProvisioner: fileProvisioner{},
DefaultProvisioner: ngrokProvisioner{},
Importer: importer.TryAll(
importer.TryEnvVarPair(defaultEnvVarMapping),
importer.MacOnly(
Expand Down
2 changes: 1 addition & 1 deletion plugins/ngrok/credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func TestCredentialsProvisioner(t *testing.T) {
plugintest.TestProvisioner(t, fileProvisioner{}, map[string]plugintest.ProvisionCase{
plugintest.TestProvisioner(t, ngrokProvisioner{}, map[string]plugintest.ProvisionCase{
"temp file": {
ItemFields: map[sdk.FieldName]string{
fieldname.Authtoken: "cxG2Im21Yzkh8VnvFQaetlPHcQ9ZDUUk1IzzyHhcGcEXAMPLE",
Expand Down
13 changes: 6 additions & 7 deletions plugins/ngrok/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ const (
envVarAuthVersion = "v3.2.1"
)

type fileProvisioner struct {
type ngrokProvisioner struct {
}

func IsNgrokAPIKeySupported() bool {
func HasEnvVarSupport() bool {
currentVersion, err := getNgrokVersion()
if err != nil {
// When ngrok version check fails for any reason,
Expand All @@ -49,10 +49,9 @@ func IsNgrokAPIKeySupported() bool {
return false
}

func (f fileProvisioner) Provision(ctx context.Context, in sdk.ProvisionInput, out *sdk.ProvisionOutput) {
ngrokProvisioner := IsNgrokAPIKeySupported()
func (p ngrokProvisioner) Provision(ctx context.Context, in sdk.ProvisionInput, out *sdk.ProvisionOutput) {

if ngrokProvisioner {
if ngrokProvisioner := HasEnvVarSupport(); ngrokProvisioner {
out.AddEnvVar("NGROK_AUTHTOKEN", in.ItemFields[fieldname.Authtoken])
out.AddEnvVar("NGROK_API_KEY", in.ItemFields[fieldname.APIKey])
return
Expand Down Expand Up @@ -145,10 +144,10 @@ func getNgrokVersion() (string, error) {
return currentVersion, nil
}

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

func (f fileProvisioner) Description() string {
func (p ngrokProvisioner) Description() string {
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."
}

0 comments on commit e19db8d

Please sign in to comment.