Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
23 changes: 23 additions & 0 deletions plugins/kubernetes/k9s.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package kubernetes

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

func K9sCLI() schema.Executable {
return schema.Executable{
Name: "k9s",
Runs: []string{"k9s"},
DocsURL: sdk.URL("https://k9scli.io/"),
NeedsAuth: needsauth.IfAll(
needsauth.NotForHelpOrVersion(),
),
Uses: []schema.CredentialUsage{
{
Name: sdk.CredentialName("Kubeconfig"),
},
},
}
}
56 changes: 56 additions & 0 deletions plugins/kubernetes/kubeconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package kubernetes

import (
"context"
"encoding/base64"

"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/fieldname"
)

func Kubeconfig() schema.CredentialType {
return schema.CredentialType{
Name: sdk.CredentialName("Kubeconfig"),
DocsURL: sdk.URL("https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/"),
Fields: []schema.CredentialField{
{
Name: fieldname.Credential,
MarkdownDescription: "Base64-encoded kubeconfig YAML file contents.",
Secret: true,
},
},
DefaultProvisioner: provision.TempFile(
kubeconfigFileContents,
provision.Filename("config"),
provision.SetPathAsEnvVar("KUBECONFIG"),
),
Importer: importer.TryAll(
TryKubeconfigFile(),
),
}
}

func kubeconfigFileContents(in sdk.ProvisionInput) ([]byte, error) {
encoded := in.ItemFields[fieldname.Credential]
decoded, err := base64.StdEncoding.DecodeString(encoded)
if err != nil {
return nil, err
}
return decoded, nil
}

func TryKubeconfigFile() sdk.Importer {
return importer.TryFile("~/.kube/config", func(ctx context.Context, contents importer.FileContents, in sdk.ImportInput, out *sdk.ImportAttempt) {
// Import existing kubeconfig as base64-encoded
encoded := base64.StdEncoding.EncodeToString(contents)
out.AddCandidate(sdk.ImportCandidate{
Fields: map[sdk.FieldName]string{
fieldname.Credential: encoded,
},
NameHint: importer.SanitizeNameHint("default"),
})
})
}
54 changes: 54 additions & 0 deletions plugins/kubernetes/kubeconfig_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package kubernetes

import (
"encoding/base64"
"testing"

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

func TestKubeconfigProvisioner(t *testing.T) {
rawConfig := plugintest.LoadFixture(t, "config")
encodedConfig := base64.StdEncoding.EncodeToString([]byte(rawConfig))

plugintest.TestProvisioner(t, Kubeconfig().DefaultProvisioner, map[string]plugintest.ProvisionCase{
"default": {
ItemFields: map[sdk.FieldName]string{
fieldname.Credential: encodedConfig,
},
ExpectedOutput: sdk.ProvisionOutput{
Environment: map[string]string{
"KUBECONFIG": "/tmp/config",
},
Files: map[string]sdk.OutputFile{
"/tmp/config": {
Contents: []byte(rawConfig),
},
},
},
},
})
}

func TestKubeconfigImporter(t *testing.T) {
rawConfig := plugintest.LoadFixture(t, "config")
encodedConfig := base64.StdEncoding.EncodeToString([]byte(rawConfig))

plugintest.TestImporter(t, Kubeconfig().Importer, map[string]plugintest.ImportCase{
"kubeconfig file": {
Files: map[string]string{
"~/.kube/config": rawConfig,
},
ExpectedCandidates: []sdk.ImportCandidate{
{
Fields: map[sdk.FieldName]string{
fieldname.Credential: encodedConfig,
},
NameHint: "",
},
},
},
})
}
24 changes: 24 additions & 0 deletions plugins/kubernetes/kubectl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package kubernetes

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

func KubectlCLI() schema.Executable {
return schema.Executable{
Name: "kubectl",
Runs: []string{"kubectl"},
DocsURL: sdk.URL("https://kubernetes.io/docs/reference/kubectl/"),
NeedsAuth: needsauth.IfAll(
needsauth.NotForHelpOrVersion(),
needsauth.NotWithoutArgs(),
),
Uses: []schema.CredentialUsage{
{
Name: sdk.CredentialName("Kubeconfig"),
},
},
}
}
24 changes: 24 additions & 0 deletions plugins/kubernetes/plugin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package kubernetes

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

func New() schema.Plugin {
return schema.Plugin{
Name: "kubernetes",
Platform: schema.PlatformInfo{
Name: "Kubernetes",
Homepage: sdk.URL("https://kubernetes.io"),
},
Credentials: []schema.CredentialType{
Kubeconfig(),
},
Executables: []schema.Executable{
KubectlCLI(),
SternCLI(),
K9sCLI(),
},
}
}
23 changes: 23 additions & 0 deletions plugins/kubernetes/stern.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package kubernetes

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

func SternCLI() schema.Executable {
return schema.Executable{
Name: "stern",
Runs: []string{"stern"},
DocsURL: sdk.URL("https://github.com/stern/stern"),
NeedsAuth: needsauth.IfAll(
needsauth.NotForHelpOrVersion(),
),
Uses: []schema.CredentialUsage{
{
Name: sdk.CredentialName("Kubeconfig"),
},
},
}
}
19 changes: 19 additions & 0 deletions plugins/kubernetes/test-fixtures/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: v1
kind: Config
clusters:
- cluster:
certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUJlRENDQVIyZ0F3SUJBZ0lCQURBS0JnZ3Foa2pPUFFRREFqQWpNU0V3SHdZRFZRUUREQmhyTTNNdGMyVnkKZG1WeUxXTmhRREUzTURBeU16TTJOREV3SGhjTk1qTXhNVEU1TVRBeU56SXhXaGNOTXpNeE1URTJNVEF5TnpJeApXakFqTVNFd0h3WURWUVFEREJock0zTXRjMlZ5ZG1WeUxXTmhRREUzTURBeU16TTJOREV3V1RBVEJnY3Foa2pPClBRSUJCZ2dxaGtqT1BRTUJCd05DQUFUMUZiY29ycjhBQ1NkcmNqQk5xQ3JSa0M2Y2tMYmZUQ0NSSUN2UndhN2IKUjZiNUxRZHZuOXZVYkhiVHN4Z3FJQ2pYYjZRTEtIRTRrQXlQQ3BDNnBPUEpvMEl3UURBT0JnTlZIUThCQWY4RQpCQU1DQXFRd0R3WURWUjBUQVFIL0JBVXdBd0VCL3pBZEJnTlZIUTRFRmdRVWVlUllndjZBbGFCNVc0dDV0Rm9ZCm9OSHVkVDB3Q2dZSUtvWkl6ajBFQXdJRFNRQXdSZ0loQUk0TlQyR3hxNHYwZExHRlFkNkdtbHdaZ0dBckVZRWoKL1FkeWZsOU12QTZyQWlFQWljVjdiVzlqcVJwNjh4cHdJeDlYak9OeUt2V3dZMVdQVWYzQU1kQTd6T2s9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
server: https://10.0.0.1:6443
name: default
contexts:
- context:
cluster: default
user: default
name: default
current-context: default
preferences: {}
users:
- name: default
user:
client-certificate-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUJrVENDQVRlZ0F3SUJBZ0lJVHVNdTNtNE8waTh3Q2dZSUtvWkl6ajBFQXdJd0l6RWhNQjhHQTFVRUF3d1kKYXpOekxXTnNhV1Z1ZEMxallVQXhOekF3TWpNek5qUXhNQjRYRFRJek1URXhPVEV3TWpjeU1Wb1hEVEkwTVRFeApPREV3TWpjeU1Wb3dNREVYTUJVR0ExVUVDaE1PYzNsemRHVnRPbTFoYzNSbGNuTXhGVEFUQmd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QTjg2dEpaTC9WCmtxTjJnZ2d3Q2dZSUtvWkl6ajBFQXdJRFNBQXdSUUloQUxoSER3UlllVXBoS0ZSOURKZ2EycjlLRlBmQ2dLSnUKd0JOK2ptOW4wdm1YQWlBenM5Q0hDN1F5aElFSnNmVjVLaGF1MHhqQ1pYdEJpblQ5aEt4d0RGMTJGUT09Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
client-key-data: LS0tLS1CRUdJTiBFQyBQUklWQVRFIEtFWS0tLS0tCk1IUUNBUUVFSUFTbE5FV3lPRWRuSWxYVWpRdG1Pc1cwWjdwYWxpTUlKdENMcmhKSGZRYlBvQWNHQlN1QkJBQUsKb1VRRFFnQUV6OGVnTzlOK0hxMHFGUlRmSVoybVJJME5oY1ZuUmR2bFRTMGtieksxQnNGcmVIeEFIWXZWSzNUawp3VlBxMGVwQ09WRUhPbWFNV3UvOWRrQzRRakZsMXc9PQotLS0tLUVORCBFQyBQUklWQVRFIEtFWS0tLS0tCg==
135 changes: 135 additions & 0 deletions plugins/plugins.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package plugins

// This file gets auto-generated by the "make registry" command, so should not be edited by hand.

import (
"github.com/1Password/shell-plugins/plugins/akamai"
"github.com/1Password/shell-plugins/plugins/argocd"
"github.com/1Password/shell-plugins/plugins/atlas"
"github.com/1Password/shell-plugins/plugins/aws"
"github.com/1Password/shell-plugins/plugins/axiom"
"github.com/1Password/shell-plugins/plugins/binance"
"github.com/1Password/shell-plugins/plugins/cachix"
"github.com/1Password/shell-plugins/plugins/cargo"
"github.com/1Password/shell-plugins/plugins/circleci"
"github.com/1Password/shell-plugins/plugins/civo"
"github.com/1Password/shell-plugins/plugins/confluent"
"github.com/1Password/shell-plugins/plugins/crowdin"
"github.com/1Password/shell-plugins/plugins/databricks"
"github.com/1Password/shell-plugins/plugins/datadog"
"github.com/1Password/shell-plugins/plugins/digitalocean"
"github.com/1Password/shell-plugins/plugins/fastly"
"github.com/1Password/shell-plugins/plugins/flyctl"
"github.com/1Password/shell-plugins/plugins/fossa"
"github.com/1Password/shell-plugins/plugins/gitea"
"github.com/1Password/shell-plugins/plugins/github"
"github.com/1Password/shell-plugins/plugins/gitlab"
"github.com/1Password/shell-plugins/plugins/hcloud"
"github.com/1Password/shell-plugins/plugins/heroku"
"github.com/1Password/shell-plugins/plugins/homebrew"
"github.com/1Password/shell-plugins/plugins/huggingface"
"github.com/1Password/shell-plugins/plugins/influxdb"
"github.com/1Password/shell-plugins/plugins/kaggle"
"github.com/1Password/shell-plugins/plugins/kubernetes"
"github.com/1Password/shell-plugins/plugins/lacework"
"github.com/1Password/shell-plugins/plugins/laravelforge"
"github.com/1Password/shell-plugins/plugins/laravelvapor"
"github.com/1Password/shell-plugins/plugins/linode"
"github.com/1Password/shell-plugins/plugins/localstack"
"github.com/1Password/shell-plugins/plugins/mysql"
"github.com/1Password/shell-plugins/plugins/ngrok"
"github.com/1Password/shell-plugins/plugins/ohdear"
"github.com/1Password/shell-plugins/plugins/okta"
"github.com/1Password/shell-plugins/plugins/openai"
"github.com/1Password/shell-plugins/plugins/pipedream"
"github.com/1Password/shell-plugins/plugins/postgresql"
"github.com/1Password/shell-plugins/plugins/pulumi"
"github.com/1Password/shell-plugins/plugins/readme"
"github.com/1Password/shell-plugins/plugins/scaleway"
"github.com/1Password/shell-plugins/plugins/sentry"
"github.com/1Password/shell-plugins/plugins/snowflake"
"github.com/1Password/shell-plugins/plugins/snyk"
"github.com/1Password/shell-plugins/plugins/sops"
"github.com/1Password/shell-plugins/plugins/sourcegraph"
"github.com/1Password/shell-plugins/plugins/stripe"
"github.com/1Password/shell-plugins/plugins/terraform"
"github.com/1Password/shell-plugins/plugins/todoist"
"github.com/1Password/shell-plugins/plugins/treasuredata"
"github.com/1Password/shell-plugins/plugins/tugboat"
"github.com/1Password/shell-plugins/plugins/twilio"
"github.com/1Password/shell-plugins/plugins/upstash"
"github.com/1Password/shell-plugins/plugins/vault"
"github.com/1Password/shell-plugins/plugins/vercel"
"github.com/1Password/shell-plugins/plugins/vertica"
"github.com/1Password/shell-plugins/plugins/vultr"
"github.com/1Password/shell-plugins/plugins/wrangler"
"github.com/1Password/shell-plugins/plugins/yugabytedb"
"github.com/1Password/shell-plugins/plugins/zapier"
"github.com/1Password/shell-plugins/plugins/zendesk"
)

func init() {
Register(akamai.New())
Register(argocd.New())
Register(atlas.New())
Register(aws.New())
Register(axiom.New())
Register(binance.New())
Register(cachix.New())
Register(cargo.New())
Register(circleci.New())
Register(civo.New())
Register(confluent.New())
Register(crowdin.New())
Register(databricks.New())
Register(datadog.New())
Register(digitalocean.New())
Register(fastly.New())
Register(flyctl.New())
Register(fossa.New())
Register(gitea.New())
Register(github.New())
Register(gitlab.New())
Register(hcloud.New())
Register(heroku.New())
Register(homebrew.New())
Register(huggingface.New())
Register(influxdb.New())
Register(kaggle.New())
Register(kubernetes.New())
Register(lacework.New())
Register(laravelforge.New())
Register(laravelvapor.New())
Register(linode.New())
Register(localstack.New())
Register(mysql.New())
Register(ngrok.New())
Register(ohdear.New())
Register(okta.New())
Register(openai.New())
Register(pipedream.New())
Register(postgresql.New())
Register(pulumi.New())
Register(readme.New())
Register(scaleway.New())
Register(sentry.New())
Register(snowflake.New())
Register(snyk.New())
Register(sops.New())
Register(sourcegraph.New())
Register(stripe.New())
Register(terraform.New())
Register(todoist.New())
Register(treasuredata.New())
Register(tugboat.New())
Register(twilio.New())
Register(upstash.New())
Register(vault.New())
Register(vercel.New())
Register(vertica.New())
Register(vultr.New())
Register(wrangler.New())
Register(yugabytedb.New())
Register(zapier.New())
Register(zendesk.New())
}
Loading