settings

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package settings is each user's own GitHub/Forgejo credentials — saved through the Settings page, encrypted at rest, and what dashboard.Manager builds that user's forge sources from. Replaces v1's GITHUB_TOKEN/FORGEJO_* environment variables, which configured one dashboard for everyone rather than one per signed-in user.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoEncryptionKey = errors.New("settings: ENCRYPTION_KEY must decode to 32 bytes")

ErrNoEncryptionKey is returned by NewCipher when key isn't valid AES-256 key material — a service holding real credentials has to fail loudly at startup rather than silently store them in the clear.

View Source
var ErrNotFound = errors.New("settings: not found")

ErrNotFound is returned when a user has never saved any credentials.

Functions

This section is empty.

Types

type Cipher

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

Cipher encrypts and decrypts credential fields with AES-256-GCM.

func NewCipher

func NewCipher(base64Key string) (*Cipher, error)

NewCipher builds a Cipher from base64Key, the raw form of ENCRYPTION_KEY. Generate one with `openssl rand -base64 32`.

func (*Cipher) Decrypt

func (c *Cipher) Decrypt(encoded string) (string, error)

Decrypt reverses Encrypt. An empty input decrypts to an empty string.

func (*Cipher) Encrypt

func (c *Cipher) Encrypt(plaintext string) (string, error)

Encrypt returns plaintext sealed under a fresh random nonce, both base64-encoded together so Decrypt needs nothing else to reverse it. An empty plaintext encrypts to an empty string — an unset credential field stays unset rather than becoming a real ciphertext of nothing.

type Credentials

type Credentials struct {
	GitHubToken     string
	GitHubUsername  string
	ForgejoURL      string
	ForgejoToken    string
	ForgejoUsername string
	UpdatedAt       time.Time
}

Credentials is one user's forge configuration, decrypted and ready to use — never itself serialized back to a client once saved; see internal/api's settings handlers for what does reach the browser.

type Store

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

Store persists Credentials, encrypted at rest, one row per user.

func NewStore

func NewStore(db *sql.DB, cipher *Cipher) *Store

NewStore wraps db, encrypting and decrypting every token field through cipher. Init must be called once before any other method.

func (*Store) Delete added in v0.9.0

func (s *Store) Delete(ctx context.Context, userID []byte) error

Delete removes userID's saved credentials — a no-op, not an error, if they never saved any. Used when an admin removes the account outright.

func (*Store) Get

func (s *Store) Get(ctx context.Context, userID []byte) (Credentials, error)

Get returns ErrNotFound when userID has never saved any credentials.

func (*Store) Init

func (s *Store) Init(ctx context.Context) error

Init creates the schema if it doesn't already exist. Safe to call every startup.

func (*Store) Set

func (s *Store) Set(ctx context.Context, userID []byte, c Credentials) error

Set replaces userID's entire credential row — a Settings save is always a full form submit, not a partial patch.

Jump to

Keyboard shortcuts

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