Skip to content
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/upcloud/plugin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package upcloud

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

func New() schema.Plugin {
return schema.Plugin{
Name: "upcloud",
Platform: schema.PlatformInfo{
Name: "UpCloud",
Homepage: sdk.URL("https://upcloud.com"),
},
Credentials: []schema.CredentialType{
UserLogin(),
},
Executables: []schema.Executable{
UpCloudCLI(),
},
}
}
26 changes: 26 additions & 0 deletions plugins/upcloud/upctl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package upcloud

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 UpCloudCLI() schema.Executable {
return schema.Executable{
Name: "UpCloud CLI",
Runs: []string{"upctl"},
DocsURL: sdk.URL("https://upcloudltd.github.io/upcloud-cli/"),
NeedsAuth: needsauth.IfAll(
needsauth.NotForHelpOrVersion(),
needsauth.NotWithoutArgs(),
needsauth.NotWhenContainsArgs("completion"),
),
Uses: []schema.CredentialUsage{
{
Name: credname.UserLogin,
},
},
}
}
54 changes: 54 additions & 0 deletions plugins/upcloud/user_login.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package upcloud

import (
"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 UserLogin() schema.CredentialType {
return schema.CredentialType{
Name: credname.UserLogin,
DocsURL: sdk.URL("https://upcloudltd.github.io/upcloud-cli/"),
ManagementURL: sdk.URL("https://hub.upcloud.com/people/accounts"),
Fields: []schema.CredentialField{
{
Name: fieldname.Username,
MarkdownDescription: "Username.",
Secret: false,
Optional: false,
Composition: &schema.ValueComposition{
Length: 20,
Charset: schema.Charset{
Uppercase: true,
Digits: true,
},
},
},
{
Name: fieldname.Password,
MarkdownDescription: "Password.",
Secret: true,
Optional: false,
Composition: &schema.ValueComposition{
Length: 36,
Charset: schema.Charset{
Lowercase: true,
Digits: true,
},
},
},
},
DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping),
Importer: importer.TryAll(
importer.TryEnvVarPair(defaultEnvVarMapping),
)}
}

var defaultEnvVarMapping = map[string]sdk.FieldName{
"UPCLOUD_USERNAME": fieldname.Username,
"UPCLOUD_PASSWORD": fieldname.Password,
}
45 changes: 45 additions & 0 deletions plugins/upcloud/user_login_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package upcloud

import (
"testing"

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

func TestAccessKeyProvisioner(t *testing.T) {
plugintest.TestProvisioner(t, UserLogin().DefaultProvisioner, map[string]plugintest.ProvisionCase{
"default": {
ItemFields: map[sdk.FieldName]string{
fieldname.Username: "theuser",
fieldname.Password: "SuperS3cret",
},
ExpectedOutput: sdk.ProvisionOutput{
Environment: map[string]string{
"UPCLOUD_USERNAME": "theuser",
"UPCLOUD_PASSWORD": "SuperS3cret",
},
},
},
})
}

func TestUserLoginImporter(t *testing.T) {
plugintest.TestImporter(t, UserLogin().Importer, map[string]plugintest.ImportCase{
"default": {
Environment: map[string]string{
"UPCLOUD_USERNAME": "theuser",
"UPCLOUD_PASSWORD": "SuperS3cret",
},
ExpectedCandidates: []sdk.ImportCandidate{
{
Fields: map[sdk.FieldName]string{
fieldname.Username: "theuser",
fieldname.Password: "SuperS3cret",
},
},
},
},
})
}
Loading