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
56 changes: 56 additions & 0 deletions plugins/openbao/auth_token.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package openbao

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 AuthToken() schema.CredentialType {
return schema.CredentialType{
Name: credname.AuthToken,
DocsURL: sdk.URL("https://openbao.org/docs/concepts/tokens/"),
ManagementURL: nil,
Fields: []schema.CredentialField{
{
Name: fieldname.Token,
MarkdownDescription: "Token used to authenticate to OpenBao.",
Secret: true,
Composition: &schema.ValueComposition{
Charset: schema.Charset{
Uppercase: true,
Lowercase: true,
Digits: true,
},
},
},
{
Name: fieldname.Address,
MarkdownDescription: "Default address of the Vault server to use for this auth token.",
Optional: true,
},
{
Name: fieldname.Namespace,
MarkdownDescription: "Default namespace to use for this auth token.",
Optional: true,
},
},
DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping),
Importer: importer.TryAll(
importer.TryEnvVarPair(defaultEnvVarMapping),
TryOpenBaoConfigFile(),
)}
}

var defaultEnvVarMapping = map[string]sdk.FieldName{
"BAO_TOKEN": fieldname.Token,
"BAO_ADDR": fieldname.Address,
"BAO_NAMESPACE": fieldname.Namespace,
}

func TryOpenBaoConfigFile() sdk.Importer {
return importer.NoOp()
}
49 changes: 49 additions & 0 deletions plugins/openbao/auth_token_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package openbao

import (
"testing"

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

func TestAuthTokenProvisioner(t *testing.T) {
plugintest.TestProvisioner(t, AuthToken().DefaultProvisioner, map[string]plugintest.ProvisionCase{
"default": {
ItemFields: map[sdk.FieldName]string{
fieldname.Token: "s.UrpjvNwnaPjTFFj2RAyEXAMPLE",
fieldname.Address: "https://bao.acme.com",
fieldname.Namespace: "default",
},
ExpectedOutput: sdk.ProvisionOutput{
Environment: map[string]string{
"BAO_TOKEN": "s.UrpjvNwnaPjTFFj2RAyEXAMPLE",
"BAO_ADDR": "https://bao.acme.com",
"BAO_NAMESPACE": "default",
},
},
},
})
}

func TestAuthTokenImporter(t *testing.T) {
plugintest.TestImporter(t, AuthToken().Importer, map[string]plugintest.ImportCase{
"environment": {
Environment: map[string]string{
"BAO_TOKEN": "s.UrpjvNwnaPjTFFj2RAyEXAMPLE",
"BAO_ADDR": "https://bao.acme.com",
"BAO_NAMESPACE": "default",
},
ExpectedCandidates: []sdk.ImportCandidate{
{
Fields: map[sdk.FieldName]string{
fieldname.Token: "s.UrpjvNwnaPjTFFj2RAyEXAMPLE",
fieldname.Address: "https://bao.acme.com",
fieldname.Namespace: "default",
},
},
},
},
})
}
25 changes: 25 additions & 0 deletions plugins/openbao/bao.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package openbao

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 OpenBaoCLI() schema.Executable {
return schema.Executable{
Name: "OpenBao CLI", // TODO: Check if this is correct

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This todo can also be removed

Suggested change
Name: "OpenBao CLI", // TODO: Check if this is correct
Name: "OpenBao CLI",

Runs: []string{"bao"},
DocsURL: sdk.URL("https://openbao.com/docs/cli"), // TODO: Replace with actual URL

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the latest docs page is https://openbao.org/docs/commands/

Suggested change
DocsURL: sdk.URL("https://openbao.com/docs/cli"), // TODO: Replace with actual URL
DocsURL: sdk.URL("https://openbao.org/docs/commands"),

NeedsAuth: needsauth.IfAll(
needsauth.NotForHelpOrVersion(),
needsauth.NotWithoutArgs(),
),
Uses: []schema.CredentialUsage{
{
Name: credname.AuthToken,
},
},
}
}
22 changes: 22 additions & 0 deletions plugins/openbao/plugin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package openbao

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

func New() schema.Plugin {
return schema.Plugin{
Name: "openbao",
Platform: schema.PlatformInfo{
Name: "OpenBao",
Homepage: sdk.URL("https://openbao.org"),
},
Credentials: []schema.CredentialType{
AuthToken(),
},
Executables: []schema.Executable{
OpenBaoCLI(),
},
}
}
Loading