Skip to content
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

Initial Commit for SSH Plugin #426

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions plugins/ssh/plugin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ssh

import (
"github.com/1Password/shell-plugins/sdk"
"github.com/1Password/shell-plugins/sdk/schema"
)

func New() schema.Plugin {
return schema.Plugin{
Name: "ssh",
Platform: schema.PlatformInfo{
Name: "SSH",
Homepage: sdk.URL("https://www.openssh.com"),
},
Credentials: []schema.CredentialType{
UserLogin(),
},
Executables: []schema.Executable{
SSHCLI(),
},
}
}
24 changes: 24 additions & 0 deletions plugins/ssh/sshpass.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ssh

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 SSHCLI() schema.Executable {
return schema.Executable{
Name: "SSH CLI",
Runs: []string{"sshpass"},
DocsURL: sdk.URL("https://linux.die.net/man/1/sshpass"),
NeedsAuth: needsauth.IfAll(
needsauth.NotForHelpOrVersion(),
),
Uses: []schema.CredentialUsage{
{
Name: credname.UserLogin,
},
},
}
}
51 changes: 51 additions & 0 deletions plugins/ssh/user_login.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package ssh

import (
"context"
"github.com/1Password/shell-plugins/sdk/importer"

"github.com/1Password/shell-plugins/sdk"
"github.com/1Password/shell-plugins/sdk/schema"
"github.com/1Password/shell-plugins/sdk/schema/credname"
"github.com/1Password/shell-plugins/sdk/schema/fieldname"
)

func UserLogin() schema.CredentialType {
return schema.CredentialType{
Name: credname.UserLogin,
DocsURL: sdk.URL("https://linux.die.net/man/1/sshpass"),
Fields: []schema.CredentialField{
{
Name: fieldname.Host,
AlternativeNames: []string{fieldname.HostAddress.String(), fieldname.URL.String()},
MarkdownDescription: "SSH Host to connect to.",
},
{
Name: fieldname.Username,
MarkdownDescription: "User to authenticate as.",
},
{
Name: fieldname.Password,
MarkdownDescription: "Password used to authenticate.",
Secret: true,
},
},
DefaultProvisioner: sshProvisioner{},
Importer: importer.NoOp(),
}
}

type sshProvisioner struct{}

func (s sshProvisioner) Description() string {
return "SSH password provisioner"
}

func (s sshProvisioner) Provision(_ context.Context, input sdk.ProvisionInput, output *sdk.ProvisionOutput) {
output.AddArgs("-p", input.ItemFields[fieldname.Password],
"ssh", input.ItemFields[fieldname.Username]+"@"+input.ItemFields[fieldname.Host])
}

func (s sshProvisioner) Deprovision(_ context.Context, _ sdk.DeprovisionInput, _ *sdk.DeprovisionOutput) {
// no-op
}
24 changes: 24 additions & 0 deletions plugins/ssh/user_login_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ssh

import (
"testing"

"github.com/1Password/shell-plugins/sdk"
"github.com/1Password/shell-plugins/sdk/plugintest"
"github.com/1Password/shell-plugins/sdk/schema/fieldname"
)

func TestUserLoginProvisioner(t *testing.T) {
plugintest.TestProvisioner(t, UserLogin().DefaultProvisioner, map[string]plugintest.ProvisionCase{
"default": {
ItemFields: map[sdk.FieldName]string{
fieldname.Password: "zhexample",
fieldname.Username: "user",
fieldname.Host: "192.168.1.20",
},
ExpectedOutput: sdk.ProvisionOutput{
CommandLine: []string{"-p", "zhexample", "ssh", "[email protected]"},
},
},
})
}