Skip to content

Commit

Permalink
Merge pull request #31 from Keloran/updateInterface
Browse files Browse the repository at this point in the history
updated the interface
  • Loading branch information
Keloran authored Jun 28, 2024
2 parents 5679164 + 136b300 commit 7104cd9
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
10 changes: 9 additions & 1 deletion mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
})
Expand Down
34 changes: 31 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Simple helper for Vault

## Usage
## Remote Usage

```go
package main
Expand All @@ -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)
}
Expand All @@ -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)
}
```
3 changes: 2 additions & 1 deletion vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7104cd9

Please sign in to comment.