-
Notifications
You must be signed in to change notification settings - Fork 186
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
Add support for tunnelto with config file importer and file-based provisioning #171
Draft
arunsathiya
wants to merge
5
commits into
1Password:main
Choose a base branch
from
arunsathiya:add/tunnelto
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a8e3e1d
Add support for tunnelto with file import and file-based provisioning
arunsathiya a74260a
Add tests for config file importer
arunsathiya 8877d7d
Remove 1Password authentication for set-auth command
arunsathiya c1f4b84
Introduce ArgumentsProvisioner and use it for provisioning TunnelTo s…
arunsathiya 0a836fb
Set up host, port, scheme and subdomain as fields
arunsathiya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package tunnelto | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/1Password/shell-plugins/sdk" | ||
"github.com/1Password/shell-plugins/sdk/importer" | ||
"github.com/1Password/shell-plugins/sdk/provision" | ||
"github.com/1Password/shell-plugins/sdk/schema" | ||
"github.com/1Password/shell-plugins/sdk/schema/credname" | ||
"github.com/1Password/shell-plugins/sdk/schema/fieldname" | ||
) | ||
|
||
func APIKey() schema.CredentialType { | ||
return schema.CredentialType{ | ||
Name: credname.APIKey, | ||
ManagementURL: sdk.URL("https://dashboard.tunnelto.dev/"), | ||
Fields: []schema.CredentialField{ | ||
{ | ||
Name: fieldname.APIKey, | ||
MarkdownDescription: "API Key used to authenticate to tunnelto.dev.", | ||
Secret: true, | ||
Composition: &schema.ValueComposition{ | ||
Length: 22, | ||
Charset: schema.Charset{ | ||
Uppercase: true, | ||
Lowercase: true, | ||
Digits: true, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Name: fieldname.Host, | ||
MarkdownDescription: "Host address to forward incoming traffic to.", | ||
Secret: false, | ||
Optional: true, | ||
Composition: &schema.ValueComposition{ | ||
Charset: schema.Charset{ | ||
Uppercase: true, | ||
Lowercase: true, | ||
Digits: true, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Name: fieldname.Port, | ||
MarkdownDescription: "Port on the host address to forward incoming traffic to.", | ||
Secret: false, | ||
Optional: true, | ||
Composition: &schema.ValueComposition{ | ||
Charset: schema.Charset{ | ||
Digits: true, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Name: fieldname.Scheme, | ||
MarkdownDescription: "Protocol (http or https) to use for the local host.", | ||
Secret: false, | ||
Optional: true, | ||
Composition: &schema.ValueComposition{ | ||
Charset: schema.Charset{ | ||
Lowercase: true, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Name: fieldname.Subdomain, | ||
MarkdownDescription: "Subdomain to use for the tunnel.", | ||
Secret: false, | ||
Optional: true, | ||
Composition: &schema.ValueComposition{ | ||
Charset: schema.Charset{ | ||
Uppercase: true, | ||
Lowercase: true, | ||
Digits: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
DefaultProvisioner: provision.Arguments(argumentsMapping), | ||
Importer: importer.TryAll( | ||
TrytunneltodevConfigFile(), | ||
)} | ||
} | ||
|
||
var argumentsMapping = map[string]sdk.FieldName{ | ||
"--key": fieldname.APIKey, | ||
"--host": fieldname.Host, | ||
"--port": fieldname.Port, | ||
"--scheme": fieldname.Scheme, | ||
"--subdomain": fieldname.Subdomain, | ||
} | ||
|
||
func TrytunneltodevConfigFile() sdk.Importer { | ||
return importer.TryFile("~/.tunnelto/key.token", func(ctx context.Context, contents importer.FileContents, in sdk.ImportInput, out *sdk.ImportAttempt) { | ||
if contents.ToString() == "" { | ||
return | ||
} | ||
|
||
out.AddCandidate(sdk.ImportCandidate{ | ||
Fields: map[sdk.FieldName]string{ | ||
fieldname.APIKey: contents.ToString(), | ||
}, | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package tunnelto | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/1Password/shell-plugins/sdk" | ||
"github.com/1Password/shell-plugins/sdk/plugintest" | ||
"github.com/1Password/shell-plugins/sdk/schema/fieldname" | ||
) | ||
|
||
func TestAPIKeyProvisioner(t *testing.T) { | ||
plugintest.TestProvisioner(t, APIKey().DefaultProvisioner, map[string]plugintest.ProvisionCase{ | ||
"temp file": { | ||
ItemFields: map[sdk.FieldName]string{ | ||
fieldname.APIKey: "XddpK7jZiQ0CpE3EXAMPLE", | ||
}, | ||
CommandLine: []string{"tunnelto"}, | ||
ExpectedOutput: sdk.ProvisionOutput{ | ||
CommandLine: []string{"tunnelto"}, | ||
Files: map[string]sdk.OutputFile{ | ||
"~/.tunnelto/key.token": { | ||
Contents: []byte(plugintest.LoadFixture(t, "key.token")), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAPIKeyImporter(t *testing.T) { | ||
plugintest.TestImporter(t, APIKey().Importer, map[string]plugintest.ImportCase{ | ||
"config file": { | ||
Files: map[string]string{ | ||
"~/.tunnelto/key.token": plugintest.LoadFixture(t, "key.token"), | ||
}, | ||
ExpectedCandidates: []sdk.ImportCandidate{ | ||
{ | ||
Fields: map[sdk.FieldName]string{ | ||
fieldname.APIKey: "XddpK7jZiQ0CpE3EXAMPLE", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package tunnelto | ||
|
||
import ( | ||
"github.com/1Password/shell-plugins/sdk" | ||
"github.com/1Password/shell-plugins/sdk/schema" | ||
) | ||
|
||
func New() schema.Plugin { | ||
return schema.Plugin{ | ||
Name: "tunnelto", | ||
Platform: schema.PlatformInfo{ | ||
Name: "tunnelto.dev", | ||
Homepage: sdk.URL("https://tunnelto.dev"), | ||
}, | ||
Credentials: []schema.CredentialType{ | ||
APIKey(), | ||
}, | ||
Executables: []schema.Executable{ | ||
tunneltodevCLI(), | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
XddpK7jZiQ0CpE3EXAMPLE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package tunnelto | ||
|
||
import ( | ||
"github.com/1Password/shell-plugins/sdk" | ||
"github.com/1Password/shell-plugins/sdk/needsauth" | ||
"github.com/1Password/shell-plugins/sdk/schema" | ||
"github.com/1Password/shell-plugins/sdk/schema/credname" | ||
) | ||
|
||
func tunneltodevCLI() schema.Executable { | ||
return schema.Executable{ | ||
Name: "tunnelto.dev CLI", | ||
Runs: []string{"tunnelto"}, | ||
DocsURL: sdk.URL("https://github.com/agrinman/tunnelto"), | ||
NeedsAuth: needsauth.IfAll( | ||
needsauth.NotForHelpOrVersion(), | ||
needsauth.NotWhenContainsArgs("-k"), | ||
needsauth.NotWhenContainsArgs("--key"), | ||
needsauth.NotWhenContainsArgs("set-auth"), | ||
), | ||
Uses: []schema.CredentialUsage{ | ||
{ | ||
Name: credname.APIKey, | ||
}, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package provision | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/1Password/shell-plugins/sdk" | ||
) | ||
|
||
// ArgumentsProvisioner provisions secrets as command line arguments | ||
type ArgumentsProvisioner struct { | ||
sdk.Provisioner | ||
|
||
Schema map[string]sdk.FieldName | ||
} | ||
|
||
// Arguments creates an ArgumentsProvisioner that provisions secrets as command line arguments, based | ||
// on the specified schema of argument flag/name and its value, which is a FieldName. | ||
func Arguments(schema map[string]sdk.FieldName) sdk.Provisioner { | ||
return ArgumentsProvisioner{ | ||
Schema: schema, | ||
} | ||
} | ||
|
||
func (p ArgumentsProvisioner) Provision(ctx context.Context, in sdk.ProvisionInput, out *sdk.ProvisionOutput) { | ||
for argName, fieldName := range p.Schema { | ||
if value, ok := in.ItemFields[fieldName]; ok { | ||
out.AddArgs(argName, value) | ||
} | ||
} | ||
} | ||
|
||
func (p ArgumentsProvisioner) Deprovision(ctx context.Context, in sdk.DeprovisionInput, out *sdk.DeprovisionOutput) { | ||
// Nothing to do here: passed argument values get wiped automatically when the process exits. | ||
} | ||
|
||
func (p ArgumentsProvisioner) Description() string { | ||
return "Provision secrets as command line arguments" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is provisioning of host, port, scheme and subdomain also available via envvars? If so, I'd propose we add these as well as optional fields.
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.
a few of them are: https://github.com/agrinman/tunnelto/blob/06428f13c638180dd349a4c42a17b569ab51a25f/tunnelto/src/config.rs#L6. This would be a nice improvement indeed.