-
Notifications
You must be signed in to change notification settings - Fork 161
/
api_token.go
82 lines (71 loc) · 2.12 KB
/
api_token.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package vercel
import (
"context"
"github.com/1Password/shell-plugins/sdk"
"github.com/1Password/shell-plugins/sdk/importer"
"github.com/1Password/shell-plugins/sdk/schema"
"github.com/1Password/shell-plugins/sdk/schema/credname"
"github.com/1Password/shell-plugins/sdk/schema/fieldname"
)
func APIToken() schema.CredentialType {
return schema.CredentialType{
Name: credname.APIToken,
DocsURL: sdk.URL("https://vercel.com/docs/rest-api#authentication"),
ManagementURL: sdk.URL("https://vercel.com/account/tokens"),
Fields: []schema.CredentialField{
{
Name: fieldname.Token,
MarkdownDescription: "Token used to authenticate to Vercel.",
Secret: true,
Composition: &schema.ValueComposition{
Length: 24,
Charset: schema.Charset{
Lowercase: true,
Uppercase: true,
Digits: true,
},
},
},
},
DefaultProvisioner: vercelProvisioner{},
Importer: importer.TryAll(
importer.MacOnly(TryVercelConfigFile("~/Library/Application Support/com.vercel.cli/auth.json")),
importer.LinuxOnly(TryVercelConfigFile("~/.config/com.vercel.cli/auth.json")),
),
}
}
type vercelProvisioner struct{}
func (v vercelProvisioner) Description() string {
return "Vercel cli token provisioner"
}
func (v vercelProvisioner) Provision(ctx context.Context, input sdk.ProvisionInput, output *sdk.ProvisionOutput) {
output.AddArgs("--token", input.ItemFields[fieldname.Token])
}
func (v vercelProvisioner) Deprovision(ctx context.Context, input sdk.DeprovisionInput, output *sdk.DeprovisionOutput) {
// No-op
}
func TryVercelConfigFile(path string) sdk.Importer {
return importer.TryFile(
path,
func(ctx context.Context, contents importer.FileContents, in sdk.ImportInput, out *sdk.ImportAttempt) {
var config Config
if err := contents.ToJSON(&config); err != nil {
out.AddError(err)
return
}
if config.Token == "" {
return
}
out.AddCandidate(
sdk.ImportCandidate{
Fields: map[sdk.FieldName]string{
fieldname.Token: config.Token,
},
},
)
},
)
}
type Config struct {
Token string `json:"token"`
}