server

package
v0.0.0-...-625bfc8 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2025 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VaultErrorRunning         string = "Vault failed to start with error: %v"
	VaultErrorCreatClient     string = "Error creating Vault client: %v"
	VaultErrorClient          string = "Error Vault client."
	VaultErrorNoKeyPath       string = "Key path is not supported."
	VaultErrorNoKeyName       string = "Key name is not supported."
	VaultErrorNoKeyData       string = "Key data is not supported."
	VaultErrorPermission      string = "Error give permission to Vault with error: %v:"
	VaultErrorWriting         string = "Error writing to Vault with error: %v:"
	VaultErrorReadResult      string = "Error reading from Vault or no data found:%v"
	VaultErrorResultNotString string = "Value is not a string: %v"
	VaultErrorResultNotExist  string = "Key not found:%v"
	VaultErrorUpdate          string = "Error updating Vault: %v"
)

Variables

View Source
var (

	// ErrBadRouting is returned when an expected path variable is missing, which is always programmer error.
	ErrBadRouting = fmt.Errorf("inconsistent mapping between route and handler, %s", bugReportHelp)
	ErrFoundABug  = fmt.Errorf("snuck into machine with err == nil, %s", bugReportHelp)
)
View Source
var (
	ErrNotFound      = errors.New("not found")
	ErrAlreadyExists = errors.New("already exists")
)

Functions

func Decrypt

func Decrypt(params UnifiedParams) (string, error)

func DecryptData

func DecryptData(params UnifiedParams) (string, error)

func Encrypt

func Encrypt(params UnifiedParams) (string, error)

func EncryptData

func EncryptData(params UnifiedParams) (string, error)

func InitialKey

func InitialKey(params UnifiedParams) (string, error)

func MakeHTTPHandler

func MakeHTTPHandler(s Service) http.Handler

func TransactionKey

func TransactionKey(params UnifiedParams) (string, error)

Types

type HeaderParams

type HeaderParams struct {
	VersionId     string
	KeyUsage      string
	Algorithm     string
	ModeOfUse     string
	KeyVersion    string
	Exportability string
}

type Machine

type Machine struct {
	InitialKey     string
	TransactionKey string
	CreatedAt      time.Time
	// contains filtered or unexported fields
}

func NewMachine

func NewMachine(vaultAuth Vault) *Machine

type MockVaultClient

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

MockVaultClient is a mock implementation of VaultClientInterface for testing.

func NewMockVaultClient

func NewMockVaultClient() *MockVaultClient

NewMockVaultClient creates a new instance of MockVaultClient.

func (*MockVaultClient) DeleteSecret

func (m *MockVaultClient) DeleteSecret(path, key string) *VaultError

DeleteSecret simulates removing a key-value pair from Vault.

func (*MockVaultClient) ListSecrets

func (m *MockVaultClient) ListSecrets(path string) ([]string, *VaultError)

func (*MockVaultClient) ReadSecret

func (m *MockVaultClient) ReadSecret(path, key string) (string, *VaultError)

ReadSecret simulates reading a key-value pair from Vault.

func (*MockVaultClient) SetAddress

func (m *MockVaultClient) SetAddress(address string) *VaultError

func (*MockVaultClient) SetToken

func (m *MockVaultClient) SetToken(token string) *VaultError

func (*MockVaultClient) WriteSecret

func (m *MockVaultClient) WriteSecret(path, key, value string) *VaultError

WriteSecret simulates saving a key-value pair in Vault.

type Repository

type Repository interface {
	StoreMachine(m *Machine) error
	FindMachine(ik string) (*Machine, error)
	FindAllMachines() []*Machine
	DeleteMachine(ik string) error
}

Repository is the Service storage mechanism abstraction

func NewRepositoryInMemory

func NewRepositoryInMemory(logger log.Logger) Repository

NewRepositoryInMemory is an in memory ach storage repository for machines

type RunningMode

type RunningMode string
var (
	MODE_MOCK  RunningMode = "MOCK"
	MODE_VAULT RunningMode = "VAULT"
)

type SecretManager

type SecretManager interface {
	// SetAddress set a vault server url
	SetAddress(address string) *VaultError
	// SetToken set a vault token
	SetToken(token string) *VaultError
	// WriteSecret writes a secret to the specified path
	WriteSecret(path, key, value string) *VaultError
	// ReadSecret retrieves a secret from the specified path
	ReadSecret(path, key string) (string, *VaultError)
	// ListSecrets lists all secrets under a specified path
	ListSecrets(path string) ([]string, *VaultError)
	// DeleteSecret removes a secret at the specified path
	DeleteSecret(path, key string) *VaultError
}

type Service

type Service interface {
	GetSecretManager() SecretManager
	CreateMachine(m *Machine) error
	GetMachine(ik string) (*Machine, error)
	GetMachines() []*Machine
	DeleteMachine(ik string) error
	EncryptData(vaultAddr, vaultToken, keyPath, keyName, encKey string, header HeaderParams, timeout time.Duration) (string, error)
	DecryptData(vaultAddr, vaultToken, keyPath, keyName, keyBlock string, timeout time.Duration) (string, error)
}

Service is a REST interface for interacting with machine structures

func NewService

func NewService(r Repository, mode RunningMode) Service

NewService creates a new concrete service

type UnifiedParams

type UnifiedParams struct {
	VaultAddr  string
	VaultToken string
	KeyPath    string
	KeyName    string
	Kbkp       string
	KeyBlock   string
	EncKey     string
	Header     HeaderParams
	// contains filtered or unexported fields
}

type Vault

type Vault struct {
	VaultAddress string
	VaultToken   string
}

type VaultClient

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

func NewVaultClient

func NewVaultClient(v Vault) (*VaultClient, error)

func (*VaultClient) DeleteSecret

func (v *VaultClient) DeleteSecret(path, key string) *VaultError

DeleteSecret removes a specific key from a stored secret in the Vault secrets engine.

This function reads the existing secret data from Vault, removes the specified key, and updates the stored secret. It is designed for use with a local Vault running in development mode.

Parameters: - path: The Vault path where the secret is stored (e.g., "secret/myapp"). - key: The specific key within the secret that should be removed.

Returns: - *VaultError: An error object if the operation fails; otherwise, nil.

func (*VaultClient) ListSecrets

func (v *VaultClient) ListSecrets(path string) ([]string, *VaultError)

ListSecrets retrieves a specific key's value from the Vault secrets engine.

This function reads a stored secret from Vault at the specified path and extracts the requested key's value.

Parameters: - path: The Vault path where the secret is stored (e.g., "secret/myapp"). - key: The specific key within the secret to retrieve.

Returns: - string: The value associated with the key, if found. - *VaultError: An error object if the operation fails or the key does not exist.

func (*VaultClient) ReadSecret

func (v *VaultClient) ReadSecret(path, key string) (string, *VaultError)

ReadSecret retrieves a specific key's value from the Vault secrets engine.

This function reads a stored secret from Vault at the specified path and extracts the requested key's value.

Parameters: - path: The Vault path where the secret is stored (e.g., "secret/myapp"). - key: The specific key within the secret to retrieve.

Returns: - string: The value associated with the key, if found. - *VaultError: An error object if the operation fails or the key does not exist.

func (*VaultClient) SetAddress

func (v *VaultClient) SetAddress(address string) *VaultError

func (*VaultClient) SetToken

func (v *VaultClient) SetToken(token string) *VaultError

func (*VaultClient) WriteSecret

func (v *VaultClient) WriteSecret(path, key, value string) *VaultError

WriteSecret stores a key-value pair in the Vault secrets engine in development mode.

This function is intended for use with a local Vault instance. It validates input parameters and writes the specified key-value pair to the given path in Vault.

Parameters: - path: The Vault path where the secret should be stored (e.g., "secret/myapp"). - key: The name of the key to store in the secret (e.g., "API_KEY"). - value: The value associated with the key.

Returns: - *VaultError: An error object if the operation fails; otherwise, nil.

type VaultError

type VaultError struct {
	Message string
}

func (*VaultError) Error

func (e *VaultError) Error() string

type WrapperCall

type WrapperCall func(params UnifiedParams) (string, error)

Jump to

Keyboard shortcuts

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