provider

package
v0.0.0-...-d771ed5 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package provider resolves effective third-party API keys at lookup time. Precedence, first match wins:

  1. DB override (settings table, set via the Settings UI)
  2. Baked-in default from config.DefaultTMDBKey / DefaultTraktClientID
  3. Empty string — callers should treat this as "no key configured" and return a 503-level error.

The DB-override mechanism lets operators rotate a leaked or rate- limited baked key without rebuilding the image. The baked default is never returned through any API; the Settings UI shows only a redacted preview for overrides.

Index

Constants

View Source
const (
	TMDB  = "tmdb"
	Trakt = "trakt"
)

Provider identifiers — used as DB keys in the settings table and as API path segments.

Variables

This section is empty.

Functions

This section is empty.

Types

type Resolver

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

Resolver reads and writes provider API key overrides in the settings table and falls back to the ldflag-baked defaults when no override is set.

func NewResolver

func NewResolver(store Store) *Resolver

NewResolver constructs a Resolver backed by the given settings store.

func (*Resolver) ClearOverride

func (r *Resolver) ClearOverride(ctx context.Context, name string) error

ClearOverride removes any stored override for the named provider, so the next lookup falls back to the baked default.

func (*Resolver) EffectiveKey

func (r *Resolver) EffectiveKey(ctx context.Context, name string) (string, Source, error)

EffectiveKey returns the key that should actually be used for API calls to the named provider. Empty string means "not configured" — callers should return a 503 to the caller with a helpful message.

func (*Resolver) HasOverride

func (r *Resolver) HasOverride(ctx context.Context, name string) (bool, error)

HasOverride reports whether an override is currently stored for the named provider (separate from whether a baked default exists).

func (*Resolver) Preview

func (r *Resolver) Preview(ctx context.Context, name string) (string, Source, error)

Preview returns a redacted representation of the effective key for Settings-page display: "•••..." with the last 3 characters revealed. An empty effective key becomes "not configured".

func (*Resolver) SetOverride

func (r *Resolver) SetOverride(ctx context.Context, name, value string) error

SetOverride persists a user-supplied key as the override for the named provider. Trims surrounding whitespace; rejects empty values (use ClearOverride to revert to the baked default).

type Source

type Source string

Source reports where an effective key came from.

const (
	// SourceOverride — the DB holds a user-set value.
	SourceOverride Source = "override"
	// SourceDefault — no override; binary default (possibly empty).
	SourceDefault Source = "default"
)

type Store

type Store interface {
	GetSetting(ctx context.Context, key string) (string, error)
	SetSetting(ctx context.Context, arg db.SetSettingParams) error
	DeleteSetting(ctx context.Context, key string) error
}

Store is the subset of the DB queries interface this package needs. Accepts *db.Queries and any handwritten implementation that matches.

Jump to

Keyboard shortcuts

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