Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Kaggle CLI #341

Merged
merged 4 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
51 changes: 51 additions & 0 deletions plugins/kaggle/api_token.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package kaggle

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 APIToken() schema.CredentialType {
return schema.CredentialType{
Name: credname.APIToken,
DocsURL: sdk.URL("https://www.kaggle.com/docs/api"),
ManagementURL: sdk.URL("https://www.kaggle.com/settings/account"),
Fields: []schema.CredentialField{
{
Name: fieldname.Token,
MarkdownDescription: "API Token used to authenticate to Kaggle.",
Secret: true,
Composition: &schema.ValueComposition{
Length: 32,
Charset: schema.Charset{
Lowercase: true,
Digits: true,
},
},
},
{
Name: fieldname.Username,
MarkdownDescription: "Username to authenticate to Kaggle.",
Secret: true,
arunsathiya marked this conversation as resolved.
Show resolved Hide resolved
Composition: &schema.ValueComposition{
Charset: schema.Charset{
Lowercase: true,
Digits: true,
},
},
},
},
DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping),
Importer: importer.TryAll(
rajapri28613 marked this conversation as resolved.
Show resolved Hide resolved
importer.TryEnvVarPair(defaultEnvVarMapping),
)}
}

var defaultEnvVarMapping = map[string]sdk.FieldName{
"KAGGLE_KEY": fieldname.Token,
"KAGGLE_USERNAME": fieldname.Username,
}
26 changes: 26 additions & 0 deletions plugins/kaggle/api_token_test.go
rajapri28613 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package kaggle

import (
"testing"

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

func TestAPITokenProvisioner(t *testing.T) {
plugintest.TestProvisioner(t, APIToken().DefaultProvisioner, map[string]plugintest.ProvisionCase{
"default": {
ItemFields: map[sdk.FieldName]string{
fieldname.Token: "z2pifkruzgbb17plmz2gux21fexample",
fieldname.Username: "username",
},
ExpectedOutput: sdk.ProvisionOutput{
Environment: map[string]string{
"KAGGLE_KEY": "z2pifkruzgbb17plmz2gux21fexample",
"KAGGLE_USERNAME": "username",
},
},
},
})
}
25 changes: 25 additions & 0 deletions plugins/kaggle/kaggle.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package kaggle

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 KaggleCLI() schema.Executable {
return schema.Executable{
Name: "Kaggle CLI",
Runs: []string{"kaggle"},
DocsURL: sdk.URL("https://github.com/Kaggle/kaggle-api"),
NeedsAuth: needsauth.IfAll(
needsauth.NotForHelpOrVersion(),
needsauth.NotWithoutArgs(),
),
Uses: []schema.CredentialUsage{
{
Name: credname.APIToken,
},
},
}
}
22 changes: 22 additions & 0 deletions plugins/kaggle/plugin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package kaggle

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

func New() schema.Plugin {
return schema.Plugin{
Name: "kaggle",
Platform: schema.PlatformInfo{
Name: "Kaggle",
Homepage: sdk.URL("https://kaggle.com"),
},
Credentials: []schema.CredentialType{
APIToken(),
},
Executables: []schema.Executable{
KaggleCLI(),
},
}
}