Documentation
¶
Index ¶
- Constants
- type AppRegistration
- type AppRegistrationSummary
- type Store
- func (s *Store) Count() int
- func (s *Store) Delete(id string) error
- func (s *Store) Get(id string) (*AppRegistration, bool)
- func (s *Store) GetByAPIKey(apiKey string) (*AppRegistration, bool)
- func (s *Store) GetByAPIKeyAnyStatus(apiKey string) (*AppRegistration, bool)
- func (s *Store) GetByEmail(email string) (*AppRegistration, bool)
- func (s *Store) HasEntries() bool
- func (s *Store) List() []AppRegistrationSummary
- func (s *Store) LoadFromDB() error
- func (s *Store) MarkStatus(apiKey, status string)
- func (s *Store) Register(reg *AppRegistration) error
- func (s *Store) SetDB(db *alerts.DB)
- func (s *Store) SetLogger(logger *slog.Logger)
- func (s *Store) Update(id string, assignedTo, label, status string) error
- func (s *Store) UpdateLastUsedAt(apiKey string)
Constants ¶
const ( StatusActive = "active" StatusDisabled = "disabled" StatusInvalid = "invalid" // Kite API rejected this key StatusReplaced = "replaced" // User re-authenticated with a different key SourceAdmin = "admin" SourceSelfProvisioned = "self-provisioned" SourceMigrated = "migrated" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AppRegistration ¶
type AppRegistration struct {
ID string `json:"id"`
APIKey string `json:"api_key"` // Kite API key (= client_id for Kite apps)
APISecret string `json:"api_secret"` // Kite API secret (encrypted at rest)
AssignedTo string `json:"assigned_to"` // expected email (empty = unassigned / open)
Label string `json:"label"` // e.g. "Personal Trading", "Mom's Account"
Status string `json:"status"` // active, disabled, invalid, replaced
RegisteredBy string `json:"registered_by"` // admin email who registered it
Source string `json:"source"` // "admin", "self-provisioned", "migrated"
LastUsedAt *time.Time `json:"last_used_at"` // last successful token exchange with this key
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
AppRegistration represents a pre-registered Kite app in the key registry. Admin registers these ahead of time; users are matched by email at login.
type AppRegistrationSummary ¶
type AppRegistrationSummary struct {
ID string `json:"id"`
APIKey string `json:"api_key"`
APISecretHint string `json:"api_secret_hint"`
AssignedTo string `json:"assigned_to"`
Label string `json:"label"`
Status string `json:"status"`
RegisteredBy string `json:"registered_by"`
Source string `json:"source"`
LastUsedAt *time.Time `json:"last_used_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
AppRegistrationSummary is a redacted view of a registration (API secret masked).
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a thread-safe in-memory key registry, optionally backed by SQLite.
func (*Store) Get ¶
func (s *Store) Get(id string) (*AppRegistration, bool)
Get retrieves a registration by ID.
func (*Store) GetByAPIKey ¶
func (s *Store) GetByAPIKey(apiKey string) (*AppRegistration, bool)
GetByAPIKey finds a registration by its API key.
func (*Store) GetByAPIKeyAnyStatus ¶
func (s *Store) GetByAPIKeyAnyStatus(apiKey string) (*AppRegistration, bool)
GetByAPIKeyAnyStatus finds a registration by its API key regardless of status.
func (*Store) GetByEmail ¶
func (s *Store) GetByEmail(email string) (*AppRegistration, bool)
GetByEmail finds the most recently updated active app registration assigned to this email. If no assigned entry is found, returns nil.
func (*Store) HasEntries ¶
HasEntries returns true if the registry has any entries.
func (*Store) List ¶
func (s *Store) List() []AppRegistrationSummary
List returns a redacted summary of all registered apps.
func (*Store) LoadFromDB ¶
LoadFromDB populates the in-memory store from the database.
func (*Store) MarkStatus ¶
MarkStatus sets the status of a registration found by API key. Unlike Update(), this does not require an ID and accepts any valid status.
func (*Store) Register ¶
func (s *Store) Register(reg *AppRegistration) error
Register adds a new app registration to the registry.
func (*Store) SetDB ¶
func (s *Store) SetDB(db *alerts.DB)
SetDB enables write-through persistence to the given SQLite database.
func (*Store) Update ¶
Update modifies a registration's mutable fields (assigned_to, label, status).
func (*Store) UpdateLastUsedAt ¶
UpdateLastUsedAt records the most recent successful token exchange for this API key.