Skip to content

Commit 8f22194

Browse files
authored
Merge pull request #538 from jksolbakken/upcloud
Plugin for the UpCloud CLI
2 parents 57da617 + e53b2cd commit 8f22194

4 files changed

Lines changed: 147 additions & 0 deletions

File tree

plugins/upcloud/plugin.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package upcloud
2+
3+
import (
4+
"github.com/1Password/shell-plugins/sdk"
5+
"github.com/1Password/shell-plugins/sdk/schema"
6+
)
7+
8+
func New() schema.Plugin {
9+
return schema.Plugin{
10+
Name: "upcloud",
11+
Platform: schema.PlatformInfo{
12+
Name: "UpCloud",
13+
Homepage: sdk.URL("https://upcloud.com"),
14+
},
15+
Credentials: []schema.CredentialType{
16+
UserLogin(),
17+
},
18+
Executables: []schema.Executable{
19+
UpCloudCLI(),
20+
},
21+
}
22+
}

plugins/upcloud/upctl.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package upcloud
2+
3+
import (
4+
"github.com/1Password/shell-plugins/sdk"
5+
"github.com/1Password/shell-plugins/sdk/needsauth"
6+
"github.com/1Password/shell-plugins/sdk/schema"
7+
"github.com/1Password/shell-plugins/sdk/schema/credname"
8+
)
9+
10+
func UpCloudCLI() schema.Executable {
11+
return schema.Executable{
12+
Name: "UpCloud CLI",
13+
Runs: []string{"upctl"},
14+
DocsURL: sdk.URL("https://upcloudltd.github.io/upcloud-cli/"),
15+
NeedsAuth: needsauth.IfAll(
16+
needsauth.NotForHelpOrVersion(),
17+
needsauth.NotWithoutArgs(),
18+
needsauth.NotWhenContainsArgs("completion"),
19+
),
20+
Uses: []schema.CredentialUsage{
21+
{
22+
Name: credname.UserLogin,
23+
},
24+
},
25+
}
26+
}

plugins/upcloud/user_login.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package upcloud
2+
3+
import (
4+
"github.com/1Password/shell-plugins/sdk"
5+
"github.com/1Password/shell-plugins/sdk/importer"
6+
"github.com/1Password/shell-plugins/sdk/provision"
7+
"github.com/1Password/shell-plugins/sdk/schema"
8+
"github.com/1Password/shell-plugins/sdk/schema/credname"
9+
"github.com/1Password/shell-plugins/sdk/schema/fieldname"
10+
)
11+
12+
func UserLogin() schema.CredentialType {
13+
return schema.CredentialType{
14+
Name: credname.UserLogin,
15+
DocsURL: sdk.URL("https://upcloudltd.github.io/upcloud-cli/"),
16+
ManagementURL: sdk.URL("https://hub.upcloud.com/people/accounts"),
17+
Fields: []schema.CredentialField{
18+
{
19+
Name: fieldname.Username,
20+
MarkdownDescription: "Username.",
21+
Secret: false,
22+
Optional: false,
23+
Composition: &schema.ValueComposition{
24+
Length: 20,
25+
Charset: schema.Charset{
26+
Uppercase: true,
27+
Digits: true,
28+
},
29+
},
30+
},
31+
{
32+
Name: fieldname.Password,
33+
MarkdownDescription: "Password.",
34+
Secret: true,
35+
Optional: false,
36+
Composition: &schema.ValueComposition{
37+
Length: 36,
38+
Charset: schema.Charset{
39+
Lowercase: true,
40+
Digits: true,
41+
},
42+
},
43+
},
44+
},
45+
DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping),
46+
Importer: importer.TryAll(
47+
importer.TryEnvVarPair(defaultEnvVarMapping),
48+
)}
49+
}
50+
51+
var defaultEnvVarMapping = map[string]sdk.FieldName{
52+
"UPCLOUD_USERNAME": fieldname.Username,
53+
"UPCLOUD_PASSWORD": fieldname.Password,
54+
}

plugins/upcloud/user_login_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package upcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/1Password/shell-plugins/sdk"
7+
"github.com/1Password/shell-plugins/sdk/plugintest"
8+
"github.com/1Password/shell-plugins/sdk/schema/fieldname"
9+
)
10+
11+
func TestAccessKeyProvisioner(t *testing.T) {
12+
plugintest.TestProvisioner(t, UserLogin().DefaultProvisioner, map[string]plugintest.ProvisionCase{
13+
"default": {
14+
ItemFields: map[sdk.FieldName]string{
15+
fieldname.Username: "theuser",
16+
fieldname.Password: "SuperS3cret",
17+
},
18+
ExpectedOutput: sdk.ProvisionOutput{
19+
Environment: map[string]string{
20+
"UPCLOUD_USERNAME": "theuser",
21+
"UPCLOUD_PASSWORD": "SuperS3cret",
22+
},
23+
},
24+
},
25+
})
26+
}
27+
28+
func TestUserLoginImporter(t *testing.T) {
29+
plugintest.TestImporter(t, UserLogin().Importer, map[string]plugintest.ImportCase{
30+
"default": {
31+
Environment: map[string]string{
32+
"UPCLOUD_USERNAME": "theuser",
33+
"UPCLOUD_PASSWORD": "SuperS3cret",
34+
},
35+
ExpectedCandidates: []sdk.ImportCandidate{
36+
{
37+
Fields: map[sdk.FieldName]string{
38+
fieldname.Username: "theuser",
39+
fieldname.Password: "SuperS3cret",
40+
},
41+
},
42+
},
43+
},
44+
})
45+
}

0 commit comments

Comments
 (0)