Skip to content

Commit b08c53b

Browse files
Merge pull request #391 from 1Password/amanda/binance
Amanda/binance
2 parents 3e37102 + 45ff54c commit b08c53b

File tree

4 files changed

+154
-0
lines changed

4 files changed

+154
-0
lines changed

plugins/binance/api_key.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package binance
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 APIKey() schema.CredentialType {
13+
return schema.CredentialType{
14+
Name: credname.APIKey,
15+
DocsURL: sdk.URL("https://github.com/binance/binance-cli"),
16+
ManagementURL: sdk.URL("https://www.binance.com/en/my/settings/api-management"),
17+
Fields: []schema.CredentialField{
18+
{
19+
Name: fieldname.APIKey,
20+
MarkdownDescription: "API Key used to authenticate to Binance.",
21+
Secret: true,
22+
Composition: &schema.ValueComposition{
23+
Length: 64,
24+
Charset: schema.Charset{
25+
Uppercase: true,
26+
Lowercase: true,
27+
Digits: true,
28+
},
29+
},
30+
},
31+
{
32+
Name: fieldname.APISecret,
33+
MarkdownDescription: "API Key secret used to authenticate to Binance.",
34+
Secret: true,
35+
Composition: &schema.ValueComposition{
36+
Length: 64,
37+
Charset: schema.Charset{
38+
Uppercase: true,
39+
Lowercase: true,
40+
Digits: true,
41+
},
42+
},
43+
},
44+
},
45+
DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping),
46+
Importer: importer.TryEnvVarPair(defaultEnvVarMapping)}
47+
}
48+
49+
var defaultEnvVarMapping = map[string]sdk.FieldName{
50+
"BINANCE_API_KEY": fieldname.APIKey,
51+
"BINANCE_API_SECRET": fieldname.APISecret,
52+
}

plugins/binance/api_key_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package binance
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 TestAPIKeyProvisioner(t *testing.T) {
12+
plugintest.TestProvisioner(t, APIKey().DefaultProvisioner, map[string]plugintest.ProvisionCase{
13+
"default": {
14+
ItemFields: map[sdk.FieldName]string{
15+
fieldname.APIKey: "jThmEycY2J0RgJgNNrWQBq2raPzKvxCkcwPQFk8AuWUu5QxQSWaItIB1qEXAMPLE",
16+
fieldname.APISecret: "2raPzKvxCkcwPQFk8AuWUu5QxQSWaItIB1qjThmEycY2J0RgJgNNrWQBqEXAMPLE",
17+
},
18+
ExpectedOutput: sdk.ProvisionOutput{
19+
Environment: map[string]string{
20+
"BINANCE_API_KEY": "jThmEycY2J0RgJgNNrWQBq2raPzKvxCkcwPQFk8AuWUu5QxQSWaItIB1qEXAMPLE",
21+
"BINANCE_API_SECRET": "2raPzKvxCkcwPQFk8AuWUu5QxQSWaItIB1qjThmEycY2J0RgJgNNrWQBqEXAMPLE",
22+
},
23+
},
24+
},
25+
})
26+
}
27+
28+
func TestAPIKeyImporter(t *testing.T) {
29+
plugintest.TestImporter(t, APIKey().Importer, map[string]plugintest.ImportCase{
30+
"environment": {
31+
Environment: map[string]string{
32+
"BINANCE_API_KEY": "jThmEycY2J0RgJgNNrWQBq2raPzKvxCkcwPQFk8AuWUu5QxQSWaItIB1qEXAMPLE",
33+
"BINANCE_API_SECRET": "2raPzKvxCkcwPQFk8AuWUu5QxQSWaItIB1qjThmEycY2J0RgJgNNrWQBqEXAMPLE",
34+
},
35+
ExpectedCandidates: []sdk.ImportCandidate{
36+
{
37+
Fields: map[sdk.FieldName]string{
38+
fieldname.APIKey: "jThmEycY2J0RgJgNNrWQBq2raPzKvxCkcwPQFk8AuWUu5QxQSWaItIB1qEXAMPLE",
39+
fieldname.APISecret: "2raPzKvxCkcwPQFk8AuWUu5QxQSWaItIB1qjThmEycY2J0RgJgNNrWQBqEXAMPLE",
40+
},
41+
},
42+
},
43+
},
44+
})
45+
}

plugins/binance/binance_cli.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package binance
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 BinanceCLI() schema.Executable {
11+
return schema.Executable{
12+
Name: "Binance CLI",
13+
Runs: []string{"binance-cli"},
14+
DocsURL: sdk.URL("https://github.com/binance/binance-cli"),
15+
NeedsAuth: needsauth.IfAll(
16+
needsauth.NotForHelpOrVersion(),
17+
needsauth.NotWithoutArgs(),
18+
needsauth.NotWhenContainsArgs("t"),
19+
needsauth.NotWhenContainsArgs("i"),
20+
needsauth.NotWhenContainsArgs("book"),
21+
needsauth.NotWhenContainsArgs("at"),
22+
needsauth.NotWhenContainsArgs("k"),
23+
needsauth.NotWhenContainsArgs("ap"),
24+
needsauth.NotWhenContainsArgs("ticker"),
25+
needsauth.NotWhenContainsArgs("price"),
26+
needsauth.NotWhenContainsArgs("bt"),
27+
needsauth.NotWhenContainsArgs("listen"),
28+
),
29+
Uses: []schema.CredentialUsage{
30+
{
31+
Name: credname.APIKey,
32+
},
33+
},
34+
}
35+
}

plugins/binance/plugin.go

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

0 commit comments

Comments
 (0)