- Added internal/vault/client.go for creating a Vault client with configuration settings. - Introduced internal/vault/errors.go to classify Vault API errors for better UI handling. - Created internal/vault/kv.go to manage KV secrets, including listing, reading, writing, and deleting operations. - Implemented internal/vault/mounts.go to list and describe secret engine mounts. - Developed internal/vault/service.go to provide a unified entry point for Vault operations. - Added internal/vault/kv_test.go for comprehensive testing of KV operations. - Introduced internal/ui/toast.go for transient notifications in the UI. - Added renovate.json for dependency management and updates.
40 lines
1.3 KiB
Go
40 lines
1.3 KiB
Go
package auth
|
|
|
|
import (
|
|
"context"
|
|
"net/url"
|
|
|
|
"github.com/hashicorp/vault/api"
|
|
)
|
|
|
|
func init() {
|
|
register(
|
|
userpassMethod{name: "userpass", display: "Username & Password", mount: "userpass"},
|
|
userpassMethod{name: "radius", display: "RADIUS", mount: "radius"},
|
|
)
|
|
}
|
|
|
|
// userpassMethod covers both userpass and radius: upstream's own CLI
|
|
// handler registers radius as credUserpass with DefaultMount "radius", i.e.
|
|
// they are the same request shape.
|
|
type userpassMethod struct{ name, display, mount string }
|
|
|
|
func (m userpassMethod) Name() string { return m.name }
|
|
func (m userpassMethod) DisplayName() string { return m.display }
|
|
func (m userpassMethod) DefaultMount() string { return m.mount }
|
|
|
|
func (m userpassMethod) Fields() []Field {
|
|
return []Field{
|
|
{Name: "username", Label: "Username", Kind: FieldText, Required: true,
|
|
EnvFallback: []string{"VAULT_USERNAME", "LOGNAME", "USER"}},
|
|
{Name: "password", Label: "Password", Kind: FieldSecret, Required: true,
|
|
EnvFallback: []string{"VAULT_PASSWORD"}},
|
|
}
|
|
}
|
|
|
|
func (m userpassMethod) Login(ctx context.Context, c *api.Client, req Request) (*api.Secret, error) {
|
|
mount := mountOf(req, m.mount)
|
|
return loginWrite(ctx, c, mount, "login/"+url.PathEscape(req.Creds.Get("username")),
|
|
map[string]interface{}{"password": req.Creds.Get("password")})
|
|
}
|