Skip to content

Commit d4401e7

Browse files
authored
Merge pull request #207 from 1Password/wpark/203-zendesk-plugin-2
New plugin: Zendesk
2 parents b5e9094 + 022e43f commit d4401e7

File tree

5 files changed

+177
-0
lines changed

5 files changed

+177
-0
lines changed

plugins/zendesk/api_token.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package zendesk
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 APIToken() schema.CredentialType {
13+
return schema.CredentialType{
14+
Name: credname.APIToken,
15+
DocsURL: sdk.URL("https://developer.zendesk.com/api-reference/introduction/security-and-auth/#api-token"),
16+
Fields: []schema.CredentialField{
17+
{
18+
Name: fieldname.Subdomain,
19+
MarkdownDescription: "Subdomain of Zendesk account, often found in the account's URL.",
20+
Optional: false,
21+
Secret: false,
22+
Composition: &schema.ValueComposition{
23+
Charset: schema.Charset{
24+
Uppercase: true,
25+
Lowercase: true,
26+
Digits: true,
27+
Symbols: true,
28+
},
29+
},
30+
},
31+
{
32+
Name: fieldname.Email,
33+
MarkdownDescription: "Email used to authenticate to Zendesk.",
34+
Optional: false,
35+
Secret: false,
36+
Composition: &schema.ValueComposition{
37+
Charset: schema.Charset{
38+
Uppercase: true,
39+
Lowercase: true,
40+
Digits: true,
41+
Symbols: true,
42+
},
43+
},
44+
},
45+
{
46+
Name: fieldname.Token,
47+
MarkdownDescription: "API token used to authenticate to Zendesk.",
48+
Optional: false,
49+
Secret: true,
50+
Composition: &schema.ValueComposition{
51+
Length: 40,
52+
Charset: schema.Charset{
53+
Uppercase: true,
54+
Lowercase: true,
55+
Digits: true,
56+
Symbols: true,
57+
},
58+
},
59+
},
60+
},
61+
DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping),
62+
Importer: importer.TryAll(
63+
importer.TryEnvVarPair(defaultEnvVarMapping),
64+
)}
65+
}
66+
67+
var defaultEnvVarMapping = map[string]sdk.FieldName{
68+
"ZENDESK_SUBDOMAIN": fieldname.Subdomain,
69+
"ZENDESK_EMAIL": fieldname.Email,
70+
"ZENDESK_API_TOKEN": fieldname.Token,
71+
}

plugins/zendesk/api_token_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package zendesk
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 TestAPITokenProvisioner(t *testing.T) {
12+
plugintest.TestProvisioner(t, APIToken().DefaultProvisioner, map[string]plugintest.ProvisionCase{
13+
"default": {
14+
ItemFields: map[sdk.FieldName]string{
15+
fieldname.Subdomain: "subdomain",
16+
fieldname.Email: "[email protected]",
17+
fieldname.Token: "TPPmg1SEWr4fDGQhaUHsxETCUrBEIJKm0EXAMPLE",
18+
},
19+
ExpectedOutput: sdk.ProvisionOutput{
20+
Environment: map[string]string{
21+
"ZENDESK_SUBDOMAIN": "subdomain",
22+
"ZENDESK_EMAIL": "[email protected]",
23+
"ZENDESK_API_TOKEN": "TPPmg1SEWr4fDGQhaUHsxETCUrBEIJKm0EXAMPLE",
24+
},
25+
},
26+
},
27+
})
28+
}
29+
30+
func TestAPITokenImporter(t *testing.T) {
31+
plugintest.TestImporter(t, APIToken().Importer, map[string]plugintest.ImportCase{
32+
"environment": {
33+
Environment: map[string]string{
34+
"ZENDESK_SUBDOMAIN": "subdomain",
35+
"ZENDESK_EMAIL": "[email protected]",
36+
"ZENDESK_API_TOKEN": "TPPmg1SEWr4fDGQhaUHsxETCUrBEIJKm0EXAMPLE",
37+
},
38+
ExpectedCandidates: []sdk.ImportCandidate{
39+
{
40+
Fields: map[sdk.FieldName]string{
41+
fieldname.Subdomain: "subdomain",
42+
fieldname.Email: "[email protected]",
43+
fieldname.Token: "TPPmg1SEWr4fDGQhaUHsxETCUrBEIJKm0EXAMPLE",
44+
},
45+
},
46+
},
47+
},
48+
})
49+
}

plugins/zendesk/plugin.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package zendesk
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: "zendesk",
11+
Platform: schema.PlatformInfo{
12+
Name: "Zendesk",
13+
Homepage: sdk.URL("https://www.zendesk.com/"),
14+
},
15+
Credentials: []schema.CredentialType{
16+
APIToken(),
17+
},
18+
Executables: []schema.Executable{
19+
ZendeskCLI(),
20+
},
21+
}
22+
}

plugins/zendesk/zcli.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package zendesk
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 ZendeskCLI() schema.Executable {
11+
return schema.Executable{
12+
Name: "Zendesk CLI",
13+
Runs: []string{"zcli"},
14+
DocsURL: sdk.URL("https://developer.zendesk.com/documentation/apps/getting-started/using-zcli/"),
15+
NeedsAuth: needsauth.IfAll(
16+
needsauth.NotForHelpOrVersion(),
17+
needsauth.NotWithoutArgs(),
18+
needsauth.NotWhenContainsArgs("profiles"),
19+
needsauth.NotWhenContainsArgs("login"),
20+
needsauth.NotWhenContainsArgs("logout"),
21+
needsauth.NotWhenContainsArgs("autocomplete"),
22+
needsauth.NotWhenContainsArgs("apps:bump"),
23+
needsauth.NotWhenContainsArgs("apps:clean"),
24+
needsauth.NotWhenContainsArgs("apps:new"),
25+
needsauth.NotWhenContainsArgs("apps:server"),
26+
),
27+
Uses: []schema.CredentialUsage{
28+
{
29+
Name: credname.APIToken,
30+
},
31+
},
32+
}
33+
}

sdk/schema/fieldname/names.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const (
2424
Credentials = sdk.FieldName("Credentials")
2525
Database = sdk.FieldName("Database")
2626
DefaultRegion = sdk.FieldName("Default Region")
27+
Email = sdk.FieldName("Email")
2728
Endpoint = sdk.FieldName("Endpoint")
2829
Host = sdk.FieldName("Host")
2930
HostAddress = sdk.FieldName("Host Address")
@@ -40,6 +41,7 @@ const (
4041
Region = sdk.FieldName("Region")
4142
Secret = sdk.FieldName("Secret")
4243
SecretAccessKey = sdk.FieldName("Secret Access Key")
44+
Subdomain = sdk.FieldName("Subdomain")
4345
Token = sdk.FieldName("Token")
4446
URL = sdk.FieldName("URL")
4547
User = sdk.FieldName("User")

0 commit comments

Comments
 (0)