package
1.0.0
Repository: https://github.com/phanitejak/kptgolib.git
Documentation: pkg.go.dev

# README

Vault client for NEO services in golang

TODO: Enable integration tests once vault supports vendoring.

Usage

Start using vault client:

package main

import (
	"github.com/phanitejak/kptgolib/logging"
	"github.com/phanitejak/kptgolib/vault"
	"github.com/hashicorp/vault/api"
	"github.com/stretchr/testify/assert"
	"testing"
	"fmt"
)

func main(){
    log := logging.NewLogger()

    client, err := vault.NewClient(
    	"https://vault-server-address",
    	"my-service-role",
    	vault.JwtPath("/var/run/secrets/kubernetes.io/serviceaccount/token")) // This is default mount path of JWT inside the pod
    if err != nil {
    	log.Errorf("unable to create vault client: %v", err)
        return
    }
    defer client.Close()

    // read, write and delete secrets using vault client
}

Testing

You can use mock vault client implementation to test your application behavior using standard go testing library:

package main

import (
	"github.com/phanitejak/kptgolib/vault"
	"github.com/hashicorp/vault/api"
	"github.com/stretchr/testify/assert"
	"testing"
	"errors"
	"fmt"
)

func TestMyApp(t *testing.T) {
	c := vault.NewMockClient(t)
	c.WhenDelete("path/to/delete").ThenReturn(&api.Secret{RequestID: "delete request id"})
	c.WhenDelete("path/to/delete").ThenError(errors.New("delete error"))
	c.WhenRead("path/to/read").ThenReturn(&api.Secret{RequestID: "read request id"})

	secret, err := c.Delete("path/to/delete")
	assert.NoErrorf(t, err, "error should be nil")
	assert.Equal(t, "delete request id", secret.RequestID)

	secret, err = c.Delete("path/to/delete")
	assert.EqualError(t, err, "delete error")
	assert.Nil(t, secret)

	secret, err = c.Read("path/to/read")
	assert.NoErrorf(t, err, "error should be nil")
	assert.Equal(t, "read request id", secret.RequestID)
}

# Functions

AuthPath is Vault url path to make login request.
BreakerErrorTH amount of failures within BreakerTimeout period -> circuit breaker opens.
BreakerSuccessTH amount of consecutive successes -> circuit breaker moves from half-closed to closed.
BreakerTimeout error-free time -> circuit breaker moves from open to half-closed.
JwtPath is a path to Service Account Token file.
MaxRetries in case of 5xx errors from Vault server.
nolint:golint.
Provides mock implementation for vault client.
No description provided by the author
No description provided by the author
Timeout for HTTPClient.
Token is Vault url path to make login request.

# Structs

No description provided by the author

# Interfaces

No description provided by the author

# Type aliases

No description provided by the author