vault

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 25, 2024 License: MIT Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Go Reference Version Badge

xk6-hashicorp-vault

A k6 extension for interacting with Hashicorp Vault servers while testing. Mostly a wrapper for vault-client-go.

Build

To build a custom k6 binary with this extension, first ensure you have the prerequisites:

  1. Download xk6:

    go install go.k6.io/xk6/cmd/xk6@latest
    
  2. Build the k6 binary:

    xk6 build --with github.com/delamart/xk6-hashicorp-vault
    

    The xk6 build command creates a k6 binary that includes the xk6-hashicorp-vault extension in your local folder.

Development

To make development a little smoother, use the Makefile in the root folder. The default target will format your code, run tests, and create a k6 binary with your local code rather than from GitHub.

git clone git@github.com:delamart/xk6-hashicorp-vault.git
cd xk6-hashicorp-vault
make

Using the k6 binary with xk6-hashicorp-vault, run the k6 test as usual:

./k6 run k8s-test-script.js

Usage

  • Create a new Vault instance which will create a vault client to a specific server url
  • Set the authentication using one of the three methods
    1. vault.setToken( token )
    2. vault.AppRoleLogin( roleid, secretid, mount )
    3. vault.KubernetesLogin( jwt, role, mount )
  • Use the provided methods
    • vault.read( path )
    • vault.write( path, data )
    • vault.list( path )
    • vault.delete( path )

Examples

Connect, write, read, list and delete a secret
import { Vault } from 'k6/x/hashicorp-vault';

// run a DEV vault server with docker using:
// docker run --rm --cap-add=IPC_LOCK -p 8200:8200 hashicorp/vault server -dev -dev-root-token-id=root
export default function () {
    const vault = new Vault('http://localhost:8200')
    vault.setToken('root')

    var w = vault.write('secret/data/test', {'data': {'key': 'value'}})
    console.log(w.version)

    var r = vault.read('secret/data/test')
    console.log(r.data.key)

    var l = vault.list('secret/metadata')
    console.log(l.keys)

    var d = vault.delete('secret/data/test')
    console.log(d)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ModuleInstance

type ModuleInstance struct {
	// contains filtered or unexported fields
}

ModuleInstance represents an instance of the JS module.

func (*ModuleInstance) Exports

func (mi *ModuleInstance) Exports() modules.Exports

Exports implements the modules.Instance interface and returns the exports of the JS module.

type RootModule

type RootModule struct{}

RootModule is the global module instance that will create module instances for each VU.

func New

func New() *RootModule

New returns a pointer to a new RootModule instance.

func (*RootModule) NewModuleInstance

func (*RootModule) NewModuleInstance(vu modules.VU) modules.Instance

NewModuleInstance implements the modules.Module interface to return a new instance for each VU.

type Vault

type Vault struct {
	// contains filtered or unexported fields
}

func (*Vault) AppRoleLogin

func (v *Vault) AppRoleLogin(roleid, secretid, mount string) error

Vault AppRole Login

func (*Vault) Delete

func (v *Vault) Delete(path string) (interface{}, error)

Vault Delete

func (*Vault) KubernetesLogin

func (v *Vault) KubernetesLogin(role, jwt, mount string) error

Vault Kubernetes Login

func (*Vault) List

func (v *Vault) List(path string) (interface{}, error)

Vault List

func (*Vault) Read

func (v *Vault) Read(path string) (interface{}, error)

Vault Read

func (*Vault) SetToken

func (v *Vault) SetToken(token string) error

Vault set Token

func (*Vault) Write

func (v *Vault) Write(path string, body map[string]interface{}) (interface{}, error)

Vault Write

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址