From 136b3008c4a4aa8fdbfc95627fe92ed5ec190bda Mon Sep 17 00:00:00 2001 From: Keloran Date: Fri, 28 Jun 2024 22:17:17 +0100 Subject: [PATCH] updated the interface --- mock.go | 10 +++++++++- mock_test.go | 2 +- readme.md | 34 +++++++++++++++++++++++++++++++--- vault.go | 3 ++- 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/mock.go b/mock.go index c290c7c..b7b9fab 100644 --- a/mock.go +++ b/mock.go @@ -39,7 +39,15 @@ type MockVaultHelper struct { Lease int } -func (m *MockVaultHelper) GetSecrets(path string) error { +func (m *MockVaultHelper) GetRemoteSecrets(path string) error { + if path == "" { + return fmt.Errorf("path not found: %s", path) + } + + return nil +} + +func (m *MockVaultHelper) GetLocalSecrets(path string) error { if path == "" { return fmt.Errorf("path not found: %s", path) } diff --git a/mock_test.go b/mock_test.go index 820a43f..3bc2b4a 100644 --- a/mock_test.go +++ b/mock_test.go @@ -15,7 +15,7 @@ func TestMock(t *testing.T) { // Test GetSecrets t.Run("Get Empty Secrets", func(t *testing.T) { - if err := mvh.GetSecrets(""); err == nil { + if err := mvh.GetRemoteSecrets(""); err == nil { t.Error("Expected error, got nil") } }) diff --git a/readme.md b/readme.md index f3cbc14..79a0672 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ # Simple helper for Vault -## Usage +## Remote Usage ```go package main @@ -14,7 +14,7 @@ import ( func main() { v := vault.NewVault("vault.vault", "vault-token") - err := v.GetSecrets("kv/secret") + err := v.GetRemoteSecrets("kv/secret") if err != nil { log.Fatal(err) } @@ -24,8 +24,36 @@ func main() { log.Fatal(err) } - fmt.Println(v.Secrets) + fmt.Println(v.KVSecrets) fmt.Println(sec) } ``` +## Local Usage + +```go +package main + +import ( + "fmt" + "log" + + vault "github.com/keloran/vault-helper" +) + +func main() { + v := vault.NewVault("vault.vault", "vault-token") + err := v.GetLocalSecrets("/secrets/secrets.json") + if err != nil { + log.Fatal(err) + } + + sec, err := v.GetSecret("tester") + if err != nil { + log.Fatal(err) + } + + fmt.Println(v.KVSecrets) + fmt.Println(sec) +} +``` diff --git a/vault.go b/vault.go index 711057b..9ca9ba5 100644 --- a/vault.go +++ b/vault.go @@ -21,7 +21,8 @@ type VaultDetails struct { } type VaultHelper interface { - GetSecrets(path string) error + GetRemoteSecrets(path string) error + GetLocalSecrets(path string) error GetSecret(key string) (string, error) Secrets() []KVSecret LeaseDuration() int