Documentation
¶
Overview ¶
Package admin provides HTTP client functionality for communicating with the Management API from the Admin UI server.
Package admin provides the HTTP server for the Admin UI. This package implements a separate web interface for managing projects and tokens via the Management API.
Index ¶
- func ObfuscateAPIKey(apiKey string) string
- func ObfuscateToken(token string) string
- type APIClient
- func (c *APIClient) CreateProject(ctx context.Context, name, apiKey string) (*Project, error)
- func (c *APIClient) CreateToken(ctx context.Context, projectID string, durationMinutes int, maxRequests *int) (*TokenCreateResponse, error)
- func (c *APIClient) DeleteProject(ctx context.Context, id string) error
- func (c *APIClient) GetAuditEvent(ctx context.Context, id string) (*AuditEvent, error)
- func (c *APIClient) GetAuditEvents(ctx context.Context, filters map[string]string, page, pageSize int) ([]AuditEvent, *Pagination, error)
- func (c *APIClient) GetDashboardData(ctx context.Context) (*DashboardData, error)
- func (c *APIClient) GetProject(ctx context.Context, id string) (*Project, error)
- func (c *APIClient) GetProjects(ctx context.Context, page, pageSize int) ([]Project, *Pagination, error)
- func (c *APIClient) GetToken(ctx context.Context, tokenID string) (*Token, error)
- func (c *APIClient) GetTokens(ctx context.Context, projectID string, page, pageSize int) ([]Token, *Pagination, error)
- func (c *APIClient) RevokeProjectTokens(ctx context.Context, projectID string) error
- func (c *APIClient) RevokeToken(ctx context.Context, tokenID string) error
- func (c *APIClient) UpdateProject(ctx context.Context, id, name, apiKey string, isActive *bool) (*Project, error)
- func (c *APIClient) UpdateToken(ctx context.Context, tokenID string, isActive *bool, maxRequests *int) (*Token, error)
- type APIClientInterface
- type AuditEvent
- type AuditEventsResponse
- type AuditMetadata
- type DashboardData
- type Pagination
- type Project
- type Server
- type Session
- type Token
- type TokenCreateResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ObfuscateAPIKey ¶
ObfuscateAPIKey obfuscates an API key for display purposes Shows first 8 characters followed by dots and last 4 characters
func ObfuscateToken ¶
ObfuscateToken obfuscates a token for display purposes. Use centralized helper to avoid linter warning on deprecated wrapper.
Types ¶
type APIClient ¶
type APIClient struct {
// contains filtered or unexported fields
}
APIClient handles communication with the Management API
func NewAPIClient ¶
NewAPIClient creates a new Management API client
func (*APIClient) CreateProject ¶
CreateProject creates a new project
func (*APIClient) CreateToken ¶
func (c *APIClient) CreateToken(ctx context.Context, projectID string, durationMinutes int, maxRequests *int) (*TokenCreateResponse, error)
CreateToken creates a new token for a project with a given duration in minutes
func (*APIClient) DeleteProject ¶
DeleteProject deletes a project
func (*APIClient) GetAuditEvent ¶
GetAuditEvent retrieves a specific audit event by ID
func (*APIClient) GetAuditEvents ¶
func (c *APIClient) GetAuditEvents(ctx context.Context, filters map[string]string, page, pageSize int) ([]AuditEvent, *Pagination, error)
GetAuditEvents retrieves a paginated list of audit events with optional filters
func (*APIClient) GetDashboardData ¶
func (c *APIClient) GetDashboardData(ctx context.Context) (*DashboardData, error)
GetDashboardData retrieves dashboard statistics
func (*APIClient) GetProject ¶
GetProject retrieves a single project by ID
func (*APIClient) GetProjects ¶
func (c *APIClient) GetProjects(ctx context.Context, page, pageSize int) ([]Project, *Pagination, error)
GetProjects retrieves a paginated list of projects
func (*APIClient) GetTokens ¶
func (c *APIClient) GetTokens(ctx context.Context, projectID string, page, pageSize int) ([]Token, *Pagination, error)
GetTokens retrieves a paginated list of tokens
func (*APIClient) RevokeProjectTokens ¶
RevokeProjectTokens revokes all tokens for a project in bulk
func (*APIClient) RevokeToken ¶
RevokeToken revokes a single token by setting is_active to false
type APIClientInterface ¶
type APIClientInterface interface {
GetDashboardData(ctx context.Context) (*DashboardData, error)
GetProjects(ctx context.Context, page, pageSize int) ([]Project, *Pagination, error)
GetTokens(ctx context.Context, projectID string, page, pageSize int) ([]Token, *Pagination, error)
CreateToken(ctx context.Context, projectID string, durationMinutes int, maxRequests *int) (*TokenCreateResponse, error)
GetProject(ctx context.Context, projectID string) (*Project, error)
UpdateProject(ctx context.Context, projectID string, name string, openAIAPIKey string, isActive *bool) (*Project, error)
DeleteProject(ctx context.Context, projectID string) error
CreateProject(ctx context.Context, name string, openAIAPIKey string) (*Project, error)
GetAuditEvents(ctx context.Context, filters map[string]string, page, pageSize int) ([]AuditEvent, *Pagination, error)
GetAuditEvent(ctx context.Context, id string) (*AuditEvent, error)
GetToken(ctx context.Context, tokenID string) (*Token, error)
UpdateToken(ctx context.Context, tokenID string, isActive *bool, maxRequests *int) (*Token, error)
RevokeToken(ctx context.Context, tokenID string) error
RevokeProjectTokens(ctx context.Context, projectID string) error
}
type AuditEvent ¶
type AuditEvent struct {
ID string `json:"id"`
Timestamp time.Time `json:"timestamp"`
Action string `json:"action"`
Actor string `json:"actor"`
ProjectID *string `json:"project_id,omitempty"`
RequestID *string `json:"request_id,omitempty"`
CorrelationID *string `json:"correlation_id,omitempty"`
ClientIP *string `json:"client_ip,omitempty"`
Method *string `json:"method,omitempty"`
Path *string `json:"path,omitempty"`
UserAgent *string `json:"user_agent,omitempty"`
Outcome string `json:"outcome"`
Reason *string `json:"reason,omitempty"`
TokenID *string `json:"token_id,omitempty"`
Metadata *string `json:"metadata,omitempty"` // JSON string
ParsedMeta *AuditMetadata `json:"-"` // Parsed metadata for template use
}
AuditEvent represents an audit log entry for the admin UI
type AuditEventsResponse ¶
type AuditEventsResponse struct {
Events []AuditEvent `json:"events"`
Pagination Pagination `json:"pagination"`
}
AuditEventsResponse represents the API response for audit events listing
type AuditMetadata ¶
type AuditMetadata map[string]interface{}
AuditMetadata represents parsed metadata for easier template access
type DashboardData ¶
type DashboardData struct {
TotalProjects int `json:"total_projects"`
TotalTokens int `json:"total_tokens"`
ActiveTokens int `json:"active_tokens"`
ExpiredTokens int `json:"expired_tokens"`
TotalRequests int `json:"total_requests"`
RequestsToday int `json:"requests_today"`
RequestsThisWeek int `json:"requests_this_week"`
}
DashboardData represents dashboard statistics
type Pagination ¶
type Pagination struct {
Page int `json:"page"`
PageSize int `json:"page_size"`
TotalItems int `json:"total_items"`
TotalPages int `json:"total_pages"`
HasNext bool `json:"has_next"`
HasPrev bool `json:"has_prev"`
}
Pagination represents pagination metadata
type Project ¶
type Project struct {
ID string `json:"id"`
Name string `json:"name"`
APIKey string `json:"api_key"`
IsActive bool `json:"is_active"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Project represents a project from the Management API
type Server ¶
type Server struct {
// For testability: allow injection of token validation logic
ValidateTokenWithAPI func(context.Context, string) bool
// contains filtered or unexported fields
}
Server represents the Admin UI HTTP server. It provides a web interface for managing projects and tokens by communicating with the Management API.
func NewServer ¶
NewServer creates a new Admin UI server with the provided configuration. It initializes the Gin engine, sets up routes, and configures the HTTP server.
type Session ¶
type Session struct {
ID string
Token string
CreatedAt time.Time
ExpiresAt time.Time
RememberMe bool
}
Session represents a user session
type Token ¶
type Token struct {
ID string `json:"id"` // Token UUID (for API operations)
Token string `json:"token"` // Obfuscated token string (for display)
ProjectID string `json:"project_id"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
IsActive bool `json:"is_active"`
RequestCount int `json:"request_count"`
MaxRequests *int `json:"max_requests,omitempty"`
CreatedAt time.Time `json:"created_at"`
LastUsedAt *time.Time `json:"last_used_at,omitempty"`
CacheHitCount int `json:"cache_hit_count"`
}
Token represents a token from the Management API (sanitized)