supabase

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: MIT Imports: 4 Imported by: 0

README

Secrets Supabase Repository

Supabase database layer for secrets management (encrypted secret storage, per-service access policies, and audit logs).

Overview

This package provides Secrets-specific data access for secrets, access policies, and audit logs.

File Structure

File Purpose
repository.go Repository interface and implementation
models.go Data models

Data Models

Secret

Represents an encrypted secret stored in the database.

type Secret struct {
    ID             string    `json:"id"`
    UserID         string    `json:"user_id"`
    Name           string    `json:"name"`
    EncryptedValue []byte    `json:"encrypted_value"`
    Version        int       `json:"version"`
    CreatedAt      time.Time `json:"created_at"`
    UpdatedAt      time.Time `json:"updated_at"`
}
Policy

Defines which services are allowed to access a specific secret.

type Policy struct {
    ID         string    `json:"id"`
    UserID     string    `json:"user_id"`
    SecretName string    `json:"secret_name"`
    ServiceID  string    `json:"service_id"`
    CreatedAt  time.Time `json:"created_at"`
}
AuditLog

Records all operations performed on secrets for security compliance.

type AuditLog struct {
    ID           string    `json:"id"`
    UserID       string    `json:"user_id"`
    SecretName   string    `json:"secret_name"`
    Action       string    `json:"action"`
    ServiceID    string    `json:"service_id,omitempty"`
    IPAddress    string    `json:"ip_address,omitempty"`
    UserAgent    string    `json:"user_agent,omitempty"`
    Success      bool      `json:"success"`
    ErrorMessage string    `json:"error_message,omitempty"`
    CreatedAt    time.Time `json:"created_at"`
}

Repository Interface

type RepositoryInterface interface {
    // Secret Operations
    GetSecrets(ctx context.Context, userID string) ([]Secret, error)
    GetSecretByName(ctx context.Context, userID, name string) (*Secret, error)
    CreateSecret(ctx context.Context, secret *Secret) error
    UpdateSecret(ctx context.Context, secret *Secret) error
    DeleteSecret(ctx context.Context, userID, name string) error

    // Policy Operations
    GetPolicies(ctx context.Context, userID string) ([]Policy, error)
    CreatePolicy(ctx context.Context, policy *Policy) error
    DeletePolicy(ctx context.Context, id, userID string) error
    GetPoliciesForSecret(ctx context.Context, userID, secretName string) ([]Policy, error)
    GetAllowedServices(ctx context.Context, userID, secretName string) ([]string, error)
    SetAllowedServices(ctx context.Context, userID, secretName string, services []string) error

    // Audit Log Operations
    CreateAuditLog(ctx context.Context, log *AuditLog) error
    GetAuditLogs(ctx context.Context, userID string, limit int) ([]AuditLog, error)
    GetAuditLogsForSecret(ctx context.Context, userID, secretName string, limit int) ([]AuditLog, error)
}

Database Tables

Table Purpose
secrets Encrypted secret storage
secret_policies Service access permissions
secret_audit_logs Operation audit trail

Usage

import secretssupabase "github.com/R3E-Network/service_layer/infrastructure/secrets/supabase"

repo := secretssupabase.NewRepository(baseRepo)

// Create a secret
err := repo.CreateSecret(ctx, &secretssupabase.Secret{
    ID:             uuid.New().String(),
    UserID:         userID,
    Name:           "api_key",
    EncryptedValue: encryptedData,
    Version:        1,
})

// Get secret by name
secret, err := repo.GetSecretByName(ctx, userID, "api_key")

// Set allowed services
err := repo.SetAllowedServices(ctx, userID, "api_key", []string{"neoflow", "neocompute"})

// Get audit logs
logs, err := repo.GetAuditLogs(ctx, userID, 100)

Audit Log Actions

Action Description
create Secret created
read Secret value retrieved
update Secret value updated
delete Secret deleted
grant Service access granted
revoke Service access revoked

Query Builder Usage

The repository uses the internal query builder for complex queries:

query := database.NewQuery().
    Eq("user_id", userID).
    Eq("name", name).
    Limit(1).
    Build()

rows, err := database.GenericListWithQuery[Secret](r.base, ctx, secretsTable, query)

Documentation

Overview

Package supabase provides Secrets-specific database operations.

Package supabase provides Secrets-specific database operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuditLog

type AuditLog struct {
	ID           string    `json:"id"`
	UserID       string    `json:"user_id"`
	SecretName   string    `json:"secret_name"`
	Action       string    `json:"action"`               // create, read, update, delete, grant, revoke
	ServiceID    string    `json:"service_id,omitempty"` // Service that accessed the secret
	IPAddress    string    `json:"ip_address,omitempty"`
	UserAgent    string    `json:"user_agent,omitempty"`
	Success      bool      `json:"success"`
	ErrorMessage string    `json:"error_message,omitempty"`
	CreatedAt    time.Time `json:"created_at"`
}

AuditLog represents an audit log entry for secret operations.

type Policy

type Policy struct {
	ID         string    `json:"id"`
	UserID     string    `json:"user_id"`
	SecretName string    `json:"secret_name"`
	ServiceID  string    `json:"service_id"`
	CreatedAt  time.Time `json:"created_at"`
}

Policy represents an allowed service for a secret.

type Repository

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

Repository provides Secrets-specific data access methods.

func NewRepository

func NewRepository(base *database.Repository) *Repository

NewRepository creates a new Secrets repository.

func (*Repository) CreateAuditLog

func (r *Repository) CreateAuditLog(ctx context.Context, log *AuditLog) error

CreateAuditLog creates a new audit log entry.

func (*Repository) CreatePolicy

func (r *Repository) CreatePolicy(ctx context.Context, policy *Policy) error

CreatePolicy creates a new secret policy.

func (*Repository) CreateSecret

func (r *Repository) CreateSecret(ctx context.Context, secret *Secret) error

CreateSecret creates a new secret.

func (*Repository) DeletePolicy

func (r *Repository) DeletePolicy(ctx context.Context, id, userID string) error

DeletePolicy deletes a secret policy.

func (*Repository) DeleteSecret

func (r *Repository) DeleteSecret(ctx context.Context, userID, name string) error

DeleteSecret deletes a secret by user ID and name.

func (*Repository) GetAllowedServices

func (r *Repository) GetAllowedServices(ctx context.Context, userID, secretName string) ([]string, error)

GetAllowedServices returns the list of service IDs allowed to access a user's secret.

func (*Repository) GetAuditLogs

func (r *Repository) GetAuditLogs(ctx context.Context, userID string, limit int) ([]AuditLog, error)

GetAuditLogs retrieves audit logs for a user with optional limit.

func (*Repository) GetAuditLogsForSecret

func (r *Repository) GetAuditLogsForSecret(ctx context.Context, userID, secretName string, limit int) ([]AuditLog, error)

GetAuditLogsForSecret retrieves audit logs for a specific secret with optional limit.

func (*Repository) GetPolicies

func (r *Repository) GetPolicies(ctx context.Context, userID string) ([]Policy, error)

GetPolicies retrieves all policies for a user.

func (*Repository) GetPoliciesForSecret

func (r *Repository) GetPoliciesForSecret(ctx context.Context, userID, secretName string) ([]Policy, error)

GetPoliciesForSecret retrieves policies for a specific secret.

func (*Repository) GetSecretByName

func (r *Repository) GetSecretByName(ctx context.Context, userID, name string) (*Secret, error)

GetSecretByName retrieves a secret by user ID and name.

func (*Repository) GetSecrets

func (r *Repository) GetSecrets(ctx context.Context, userID string) ([]Secret, error)

GetSecrets retrieves all secrets for a user.

func (*Repository) SetAllowedServices

func (r *Repository) SetAllowedServices(ctx context.Context, userID, secretName string, services []string) error

SetAllowedServices replaces the allowed service list for a user's secret.

func (*Repository) UpdateSecret

func (r *Repository) UpdateSecret(ctx context.Context, secret *Secret) error

UpdateSecret updates an existing secret.

type RepositoryInterface

type RepositoryInterface interface {
	// Secret Operations
	GetSecrets(ctx context.Context, userID string) ([]Secret, error)
	GetSecretByName(ctx context.Context, userID, name string) (*Secret, error)
	CreateSecret(ctx context.Context, secret *Secret) error
	UpdateSecret(ctx context.Context, secret *Secret) error
	DeleteSecret(ctx context.Context, userID, name string) error
	// Policy Operations
	GetPolicies(ctx context.Context, userID string) ([]Policy, error)
	CreatePolicy(ctx context.Context, policy *Policy) error
	DeletePolicy(ctx context.Context, id, userID string) error
	GetPoliciesForSecret(ctx context.Context, userID, secretName string) ([]Policy, error)
	GetAllowedServices(ctx context.Context, userID, secretName string) ([]string, error)
	SetAllowedServices(ctx context.Context, userID, secretName string, services []string) error
	// Audit Log Operations
	CreateAuditLog(ctx context.Context, log *AuditLog) error
	GetAuditLogs(ctx context.Context, userID string, limit int) ([]AuditLog, error)
	GetAuditLogsForSecret(ctx context.Context, userID, secretName string, limit int) ([]AuditLog, error)
}

RepositoryInterface defines Secrets-specific data access methods. This interface allows for easy mocking in tests.

type Secret

type Secret struct {
	ID             string    `json:"id"`
	UserID         string    `json:"user_id"`
	Name           string    `json:"name"`
	EncryptedValue []byte    `json:"encrypted_value"`
	Version        int       `json:"version"`
	CreatedAt      time.Time `json:"created_at"`
	UpdatedAt      time.Time `json:"updated_at"`
}

Secret represents an encrypted secret.

Jump to

Keyboard shortcuts

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