Skip to content

Commit

Permalink
Namespace impelementations (#11)
Browse files Browse the repository at this point in the history
* Working dropdown but it hangs

* debug dump

* Adding var loading; working on solving the freeze on ns change

* Ns with a table: wip

* Working namespace change

* Updated yaml example
  • Loading branch information
dkyanakiev authored Jan 23, 2024
1 parent 98110d0 commit 09789e2
Show file tree
Hide file tree
Showing 38 changed files with 946 additions and 132 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## [0.1.0] - 2024-01-23

## Added
- Env variable loading in addition to a yaml
- Namespace support for enterprise vault instances

## Fixed
- Minor bugfixes around navigation

## Changes
- Housekeeping change

## [0.0.7] - 2023-12-03

## Added
Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,5 @@ The tool is in active development and is bug heavy. There are multiple things th
If anyone decides to use this and wants to request a specific feature or even fix a bug - please open an issue :smile:

## Short term TODO list:
1. [x] Finish implementing PUT/Patch to existing secrets
1. [X] Create new secret objects and paths.
1. [ ] Version select and rollback for secrets
2. [ ] Work on PKI and Certs
3. [ ] Support for namespace changes. (Requires enterprise license)
2. [ ] Work on PKI and Certs
1 change: 0 additions & 1 deletion cmd/vaul7y/helpers.go

This file was deleted.

50 changes: 30 additions & 20 deletions cmd/vaul7y/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log"
"os"
"strings"
"time"

"github.com/dkyanakiev/vaulty/internal/config"
Expand All @@ -17,8 +18,7 @@ import (
"github.com/rivo/tview"
)

var refreshIntervalDefault = time.Second * 30
var version = "0.0.7"
var version = "0.1.0"

type options struct {
Version bool `short:"v" long:"version" description:"Show Damon version"`
Expand All @@ -36,19 +36,22 @@ func main() {
fmt.Println("vaul7y", version)
os.Exit(0)
}

// Check for required Vault env vars
checkForVaultAddress()
cfg := config.LoadConfig()

logFile, logger := config.SetupLogger()
logFile, logger := config.SetupLogger(cfg.VaultyLogLevel, cfg.VaultyLogFile)
defer logFile.Close()
tview.Styles.PrimitiveBackgroundColor = tcell.NewRGBColor(40, 44, 48)

vaultClient, err := vault.New(func(v *vault.Vault) error {
return vault.Default(v, logger)
return vault.Default(v, logger, cfg)
})

state := initializeState(vaultClient)
refreshIntervalDefault := time.Duration(cfg.VaultyRefreshRate) * time.Second
state := initializeState(vaultClient, cfg.VaultNamespace)
toggles := component.NewTogglesInfo()
selections := component.NewSelections(state)
namespaces := component.NewNamespaceTable()
commands := component.NewCommands()
vaultInfo := component.NewVaultInfo()
mounts := component.NewMountsTable()
Expand All @@ -63,6 +66,8 @@ func main() {
components := &view.Components{
VaultInfo: vaultInfo,
Commands: commands,
Selections: selections,
NamespaceTable: namespaces,
MountsTable: mounts,
PolicyTable: policies,
PolicyAclTable: policyAcl,
Expand All @@ -87,26 +92,31 @@ func main() {

}

func initializeState(client *vault.Vault) *state.State {
func initializeState(client *vault.Vault, rootNs string) *state.State {
state := state.New()
addr := client.Address()
version, _ := client.Version()
version := client.Version
state.VaultAddress = addr
state.VaultVersion = version
state.Namespace = "default"
state.DefaultNamespace = "-"
state.RootNamespace = "-"

if strings.Contains(version, "ent") {
state.Enterprise = true
state.RootNamespace = getFirstPart(rootNs)
state.DefaultNamespace = rootNs
state.SelectedNamespace = rootNs
state.Namespaces, _ = client.ListNamespaces()
}
// state.Namespace = "default"

return state
}

func checkForVaultAddress() {
if os.Getenv("VAULT_ADDR") == "" {
fmt.Println("VAULT_ADDR is not set. Please set it and try again.")
os.Exit(1)
}

if os.Getenv("VAULT_TOKEN") == "" {
fmt.Println("VAULT_TOKEN is not set. Please set it and try again.")
os.Exit(1)
func getFirstPart(s string) string {
parts := strings.Split(s, "/")
if len(parts) > 0 {
return parts[0]
}

return ""
}
14 changes: 14 additions & 0 deletions docs/examples/vaul7y.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#r equired
vault_addr: http://127.0.0.1:8200
vault_token: hvs.token
# For ent users only
vault_namespace: admin
vault_ca_cert: /tmp/ca.crt
vault_client_cert: /tmp/client.crt
vault_client_key: /tmp/client.key
# optional
vaulty_log_file: /tmp/my-vault-log.log
vaulty_log_level: debug
# How often to pull information from Vault. Added in case rate limit is a problem
# Default is 30 seconds
# vaulty_refresh_rate: 30
2 changes: 1 addition & 1 deletion docs/local-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ $ make setup-test-data
```
* Note: This requires Vault tokent to be set in order to be able to write to Vault

3. Configure the env variables required to auth to vault
3. Configure the env variables required to auth to vault or `.vaul7y.yaml` in your home directory

4. Make sure to set
`VAULTY_LOG_FILE` env variable and point to a file, to log to a file
Expand Down
9 changes: 6 additions & 3 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ Required:

For the full list see the [official docs](https://developer.hashicorp.com/vault/docs/commands#environment-variables)

Another option is to store your configs in yaml file named `.vaul7y.yaml` stored in your home directory Example: [`/Users/myuser/.vaul7y.yaml`](./examples/vaul7y.yaml)


### Features

Expand All @@ -70,7 +72,8 @@ Currently the capabilities are limited.
* Currently only KV2
* Looking up secret objects
* Show/hide secrets and coping data
* Update/patch coming soon
* Update/patch secrets
* Create new secrets
* Filter paths/secrets
* Support for exploring and filtering ACL Policies

*Note*: Currently only supporting default namespace. Will implement the namespace change fairly soon.
* Namespace support for Enteprise versions
8 changes: 6 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/dkyanakiev/vaulty

go 1.20
go 1.21

toolchain go1.21.3

require (
github.com/atotto/clipboard v0.1.4
Expand All @@ -11,6 +13,7 @@ require (
github.com/rivo/tview v0.0.0-20230907083354-a39fe28ba466
github.com/rs/zerolog v1.31.0
github.com/stretchr/testify v1.8.4
gopkg.in/yaml.v2 v2.4.0
)

require (
Expand All @@ -31,9 +34,10 @@ require (
github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 // indirect
github.com/hashicorp/go-sockaddr v1.0.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand Down
15 changes: 12 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB
github.com/cenkalti/backoff/v3 v3.0.0 h1:ske+9nBpD9qZsTBoF41nW5L+AIuFBKMeze18XQ3eG1c=
github.com/cenkalti/backoff/v3 v3.0.0/go.mod h1:cIeZDE3IrqwwJl6VUwCN6trj1oXrTS4rc0ij+ULvLYs=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -52,11 +53,13 @@ github.com/hashicorp/vault/api v1.10.0 h1:/US7sIjWN6Imp4o/Rj1Ce2Nr5bki/AXi9vAW3p
github.com/hashicorp/vault/api v1.10.0/go.mod h1:jo5Y/ET+hNyz+JnKDt8XLAdKs+AM0G5W0Vp1IrFI8N8=
github.com/jessevdk/go-flags v1.5.0 h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LFvc=
github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
Expand All @@ -70,8 +73,9 @@ github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcME
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
Expand All @@ -82,6 +86,7 @@ github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUb
github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand All @@ -91,6 +96,8 @@ github.com/rivo/tview v0.0.0-20230907083354-a39fe28ba466/go.mod h1:nVwGv4MP47T0j
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.3 h1:utMvzDsuh3suAEnhH0RdHmoPbU648o6CvXxTx4SBMOw=
github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A=
github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
Expand Down Expand Up @@ -158,6 +165,8 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading

0 comments on commit 09789e2

Please sign in to comment.