platformstore

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RoleAdmin is the platform-wide administrator role.
	RoleAdmin = "admin"
	// RoleUser is the regular signed-in platform user role.
	RoleUser = "user"
)
View Source
const (
	// SharedCatalogNamespace is the legacy shared MCP server catalog namespace.
	SharedCatalogNamespace = mcpdefaults.MCPServersNamespace
	// TeamNamespacePrefix is prepended to normalized team slugs for managed namespaces.
	TeamNamespacePrefix = "mcp-team-"
	// TeamRoleOwner grants team administration privileges.
	TeamRoleOwner = "owner"
	// TeamRoleMember grants regular team membership privileges.
	TeamRoleMember = "member"
	// NamespaceScopeUser marks a namespace owned by a single platform user.
	NamespaceScopeUser = "user"
	// NamespaceScopeTeam marks a namespace owned by a platform team.
	NamespaceScopeTeam = "team"
)
View Source
const OIDCProviderPrefix = "oidc:"

OIDCProviderPrefix prefixes provider names stored for OIDC identities.

Variables

View Source
var (
	ErrAgentNotFound    = errors.New("agent not found")
	ErrAgentNameTaken   = errors.New("agent name already exists in team")
	ErrInvalidAgentName = errors.New("agent name must contain 1 to 64 characters")
)

Functions

func AdminOperationsUserSearch

func AdminOperationsUserSearch(filter OperationsFilter) string

AdminOperationsUserSearch returns a normalized user search string for operations filters.

func AuditTimeWhere

func AuditTimeWhere(alias string, filter OperationsFilter, args *[]any) string

AuditTimeWhere adds audit timestamp predicates to an existing argument list.

func GenerateAgentID

func GenerateAgentID() (string, error)

func NewAgentID

func NewAgentID(now time.Time, entropy []byte) (string, error)

NewAgentID returns a platform-generated ID with a lowercase ULID suffix.

func NormalizeAgentName

func NormalizeAgentName(name string) (string, string, error)

NormalizeAgentName applies the directory's stable whitespace and case rule.

func NormalizeTeamSlug

func NormalizeTeamSlug(raw string) string

NormalizeTeamSlug trims and lowercases a team slug.

func UserActivityWhere

func UserActivityWhere(filter OperationsFilter) (string, []any)

UserActivityWhere builds the SQL WHERE clause and arguments for user activity queries.

func ValidateTeamNamespace

func ValidateTeamNamespace(namespace string) error

ValidateTeamNamespace validates a managed team namespace name.

func ValidateTeamSlug

func ValidateTeamSlug(slug string) error

ValidateTeamSlug validates the normalized slug used for team URLs and names.

Types

type APIKeySummary

type APIKeySummary struct {
	ID        string     `json:"id"`
	Name      string     `json:"name"`
	Prefix    string     `json:"prefix"`
	CreatedAt time.Time  `json:"created_at"`
	Revoked   bool       `json:"revoked"`
	RevokedAt *time.Time `json:"revoked_at,omitempty"`
}

APIKeySummary is the non-secret metadata for a user API key or registry credential.

type Agent

type Agent struct {
	ID            string     `json:"id"`
	TeamID        string     `json:"team_id"`
	TeamSlug      string     `json:"team_slug"`
	Name          string     `json:"name"`
	Status        string     `json:"status"`
	CreatedBy     string     `json:"created_by,omitempty"`
	CreatedAt     time.Time  `json:"created_at"`
	UpdatedAt     time.Time  `json:"updated_at"`
	DeactivatedAt *time.Time `json:"deactivated_at,omitempty"`
	DeactivatedBy string     `json:"deactivated_by,omitempty"`
}

Agent is a team-owned governance record for attributing MCP actions.

type AgentListFilter

type AgentListFilter struct {
	TeamSlug string
	Status   string
	Query    string
	Cursor   string
	Limit    int
}

AgentListFilter bounds and filters an agent directory query.

type AgentPage

type AgentPage struct {
	Agents     []Agent `json:"agents"`
	NextCursor string  `json:"next_cursor,omitempty"`
}

AgentPage is a bounded page of agent records.

type AuditEvent

type AuditEvent struct {
	UserID           string `json:"user_id,omitempty"`
	Action           string `json:"action"`
	Resource         string `json:"resource"`
	Namespace        string `json:"namespace,omitempty"`
	Status           string `json:"status"`
	Message          string `json:"message,omitempty"`
	ActorIP          string `json:"actor_ip,omitempty"`
	RequestID        string `json:"request_id,omitempty"`
	Source           string `json:"source,omitempty"`
	AuthIdentity     string `json:"auth_identity,omitempty"`
	ImageRef         string `json:"image_ref,omitempty"`
	ServerName       string `json:"server_name,omitempty"`
	DeploymentTarget string `json:"deployment_target,omitempty"`
	AgentID          string `json:"agent_id,omitempty"`
	TeamID           string `json:"team_id,omitempty"`
}

AuditEvent is the write-side platform audit envelope.

type AuditLog

type AuditLog struct {
	ID               int64     `json:"id"`
	UserID           string    `json:"user_id,omitempty"`
	Email            string    `json:"email,omitempty"`
	Action           string    `json:"action"`
	Resource         string    `json:"resource"`
	Namespace        string    `json:"namespace,omitempty"`
	Status           string    `json:"status"`
	Message          string    `json:"message,omitempty"`
	ActorIP          string    `json:"actor_ip,omitempty"`
	RequestID        string    `json:"request_id,omitempty"`
	Source           string    `json:"source,omitempty"`
	AuthIdentity     string    `json:"auth_identity,omitempty"`
	ImageRef         string    `json:"image_ref,omitempty"`
	ServerName       string    `json:"server_name,omitempty"`
	DeploymentTarget string    `json:"deployment_target,omitempty"`
	AgentID          string    `json:"agent_id,omitempty"`
	TeamID           string    `json:"team_id,omitempty"`
	CreatedAt        time.Time `json:"created_at"`
}

AuditLog is the read-side platform audit record returned to administrators.

type ImageActivity

type ImageActivity struct {
	UserID           string    `json:"user_id,omitempty"`
	Email            string    `json:"email,omitempty"`
	Namespace        string    `json:"namespace,omitempty"`
	ImageRef         string    `json:"image_ref"`
	SourceImage      string    `json:"source_image,omitempty"`
	ServerName       string    `json:"server_name,omitempty"`
	DeploymentTarget string    `json:"deployment_target,omitempty"`
	Action           string    `json:"action"`
	Status           string    `json:"status"`
	Source           string    `json:"source,omitempty"`
	CreatedAt        time.Time `json:"created_at"`
}

ImageActivity describes an image publish or deploy-related audit entry.

type OperationsFilter

type OperationsFilter struct {
	User       string
	UserSearch string
	Since      time.Time
	Until      time.Time
	Limit      int
}

OperationsFilter constrains platform operations and activity queries.

type OperationsFilterResponse

type OperationsFilterResponse struct {
	User  string `json:"user,omitempty"`
	Since string `json:"since,omitempty"`
	Until string `json:"until,omitempty"`
	Limit int    `json:"limit"`
}

OperationsFilterResponse is the API echo of an operations filter.

type OperationsSnapshot

type OperationsSnapshot struct {
	Users     []UserActivity  `json:"users"`
	AuditLogs []AuditLog      `json:"audit_logs"`
	Images    []ImageActivity `json:"images"`
}

OperationsSnapshot bundles platform activity for internal operations queries.

type Principal

type Principal = platformauth.Principal

type PrincipalTeam

type PrincipalTeam = platformauth.PrincipalTeam

type Store

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

Store owns platform identity, API key, team, namespace, and audit persistence.

func NewForTest

func NewForTest(jwtSecret []byte) *Store

NewForTest returns an in-memory Store shell for tests that stub persistence.

func Open

func Open(ctx context.Context, dsn string, jwtSecret []byte) (*Store, error)

Open connects to Postgres, applies schema migrations, and returns a Store.

func (*Store) AuthenticateJWT

func (s *Store) AuthenticateJWT(token string) (Principal, bool)

AuthenticateJWT validates a platform JWT and resolves it to the current principal.

func (*Store) AuthenticatePassword

func (s *Store) AuthenticatePassword(ctx context.Context, email, password string) (User, bool, error)

AuthenticatePassword validates password-login credentials and returns the matching user.

func (*Store) AuthenticateRegistryCredential

func (s *Store) AuthenticateRegistryCredential(ctx context.Context, username, password string) (Principal, bool, error)

AuthenticateRegistryCredential validates Docker registry basic-auth credentials. It supports both registry-specific API keys (mcpr_ prefix) and regular platform passwords.

func (*Store) AuthenticateUserAPIKey

func (s *Store) AuthenticateUserAPIKey(ctx context.Context, rawKey string) (Principal, bool, error)

AuthenticateUserAPIKey validates a user API key and resolves its principal.

func (*Store) Close

func (s *Store) Close() error

func (*Store) CreateAccessToken

func (s *Store) CreateAccessToken(u User, ttl time.Duration) (string, error)

CreateAccessToken signs a short-lived platform JWT for a user.

func (*Store) CreateAgent

func (s *Store) CreateAgent(ctx context.Context, teamSlug, name, createdBy string) (Agent, error)

CreateAgent creates an active, team-owned agent with an immutable platform ID.

func (*Store) CreatePasswordUser

func (s *Store) CreatePasswordUser(ctx context.Context, email, password string, role string) (User, error)

CreatePasswordUser creates a password-login platform account with the requested role.

func (*Store) CreateRegistryCredential

func (s *Store) CreateRegistryCredential(ctx context.Context, userID, name string) (APIKeySummary, string, error)

CreateRegistryCredential creates a registry credential and returns its one-time raw value.

func (*Store) CreateTeam

func (s *Store) CreateTeam(ctx context.Context, slug, name, createdByUserID string) (Team, error)

CreateTeam creates a team, its namespace record, and an owner membership.

func (*Store) CreateUserAPIKey

func (s *Store) CreateUserAPIKey(ctx context.Context, userID, name string) (APIKeySummary, string, error)

CreateUserAPIKey creates a user API key and returns its one-time raw value.

func (*Store) DeleteTeamBySlug

func (s *Store) DeleteTeamBySlug(ctx context.Context, slug string) error

DeleteTeamBySlug soft-deletes a team and its derived namespace/membership records.

func (*Store) DeleteTeamMembership

func (s *Store) DeleteTeamMembership(ctx context.Context, teamSlug, userID string) error

DeleteTeamMembership soft-deletes a user's active team membership.

func (*Store) DeleteUser

func (s *Store) DeleteUser(ctx context.Context, userID string) error

DeleteUser deletes a platform user by id.

func (*Store) EnsureOIDCUser

func (s *Store) EnsureOIDCUser(ctx context.Context, provider, subject, email, role string) (User, error)

EnsureOIDCUser binds an OIDC subject to a platform account, creating it when needed.

func (*Store) EnsurePasswordUser

func (s *Store) EnsurePasswordUser(ctx context.Context, email, password string, role string) (User, error)

EnsurePasswordUser creates or updates a password-login account for a fixed role.

func (*Store) EnsureTeamPasswordUser

func (s *Store) EnsureTeamPasswordUser(ctx context.Context, email, password string) (User, error)

EnsureTeamPasswordUser ensures a regular password-login account exists for team membership flows. Existing platform roles are preserved so an admin is not accidentally demoted when they are added to a team.

func (*Store) GetAgent

func (s *Store) GetAgent(ctx context.Context, id string) (Agent, bool, error)

func (*Store) GetNamespace

func (s *Store) GetNamespace(ctx context.Context, namespace string) (map[string]any, bool, error)

GetNamespace returns one platform-managed namespace record by Kubernetes namespace.

func (*Store) GetTeamBySlug

func (s *Store) GetTeamBySlug(ctx context.Context, slug string) (Team, bool, error)

GetTeamBySlug returns one non-deleted team by normalized slug.

func (*Store) GetUser

func (s *Store) GetUser(ctx context.Context, userID string) (User, bool, error)

GetUser returns a non-deleted user by id.

func (*Store) ListAgents

func (s *Store) ListAgents(ctx context.Context, filter AgentListFilter) (AgentPage, error)

ListAgents returns a stable, bounded page of team agents.

func (*Store) ListAuditLogs

func (s *Store) ListAuditLogs(ctx context.Context, filter OperationsFilter) ([]AuditLog, error)

ListAuditLogs returns platform audit records matching an operations filter.

func (*Store) ListImageActivity

func (s *Store) ListImageActivity(ctx context.Context, filter OperationsFilter) ([]ImageActivity, error)

ListImageActivity returns audit-derived image publish and deploy activity.

func (*Store) ListNamespaces

func (s *Store) ListNamespaces(ctx context.Context) ([]map[string]any, error)

ListNamespaces returns platform-managed namespace records for admin views.

func (*Store) ListRegistryCredentials

func (s *Store) ListRegistryCredentials(ctx context.Context, userID string) ([]APIKeySummary, error)

ListRegistryCredentials returns non-secret registry credential metadata for a user.

func (*Store) ListTeamMemberships

func (s *Store) ListTeamMemberships(ctx context.Context, teamSlug string) ([]TeamMembership, error)

ListTeamMemberships returns active memberships for a team slug.

func (*Store) ListTeams

func (s *Store) ListTeams(ctx context.Context) ([]Team, error)

ListTeams returns all non-deleted platform teams.

func (*Store) ListUserAPIKeys

func (s *Store) ListUserAPIKeys(ctx context.Context, userID string) ([]APIKeySummary, error)

ListUserAPIKeys returns non-secret API key metadata for a user.

func (*Store) ListUserActivity

func (s *Store) ListUserActivity(ctx context.Context, filter OperationsFilter) ([]UserActivity, error)

ListUserActivity returns user accounts with login, failure, key, and credential counters.

func (*Store) ListUserTeams

func (s *Store) ListUserTeams(ctx context.Context, userID string) ([]TeamMembership, error)

ListUserTeams returns active team memberships for a user.

func (*Store) OperationsSnapshot

func (s *Store) OperationsSnapshot(ctx context.Context, filter OperationsFilter) (OperationsSnapshot, error)

OperationsSnapshot returns user, audit, and image activity for internal consumers.

func (*Store) Ping

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

Ping checks Postgres connectivity for readiness probes.

func (*Store) PrincipalForUserID

func (s *Store) PrincipalForUserID(ctx context.Context, userID string) (Principal, error)

PrincipalForUserID returns the platform principal for a non-deleted user.

func (*Store) RenameAgent

func (s *Store) RenameAgent(ctx context.Context, id, name string) (Agent, error)

func (*Store) ResolveTeamIDs

func (s *Store) ResolveTeamIDs(ctx context.Context, ids []string) (map[string]string, error)

ResolveTeamIDs returns a map of team UUID → slug for the given IDs. Unknown or deleted team IDs are silently omitted.

func (*Store) ResolveUserIDs

func (s *Store) ResolveUserIDs(ctx context.Context, ids []string) (map[string]string, error)

ResolveUserIDs returns a map of user UUID → email for the given IDs. Unknown or deleted user IDs are silently omitted.

func (*Store) RevokeRegistryCredential

func (s *Store) RevokeRegistryCredential(ctx context.Context, userID, id string) (APIKeySummary, error)

RevokeRegistryCredential marks a registry credential as revoked.

func (*Store) RevokeUserAPIKey

func (s *Store) RevokeUserAPIKey(ctx context.Context, userID, id string) (APIKeySummary, error)

RevokeUserAPIKey marks a user API key as revoked.

func (*Store) SetAgentStatus

func (s *Store) SetAgentStatus(ctx context.Context, id, status, actorID string) (Agent, error)

func (*Store) UpsertTeamMembership

func (s *Store) UpsertTeamMembership(ctx context.Context, teamSlug, userID, role string) (TeamMembership, error)

UpsertTeamMembership creates or updates a user's role in a team.

func (*Store) WriteAudit

func (s *Store) WriteAudit(ctx context.Context, ev AuditEvent)

WriteAudit records a platform audit event and logs failures without interrupting callers.

type Team

type Team struct {
	ID        string    `json:"id"`
	Slug      string    `json:"slug"`
	Name      string    `json:"name"`
	Namespace string    `json:"namespace"`
	CreatedAt time.Time `json:"created_at"`
}

Team is a managed platform team and its Kubernetes namespace.

type TeamMembership

type TeamMembership = platform.TeamMembership

TeamMembership is the platform team membership API contract.

type User

type User struct {
	ID        string `json:"id"`
	Email     string `json:"email"`
	Role      string `json:"role"`
	Namespace string `json:"namespace"`
}

User is the persisted platform account shape returned by identity operations.

type UserActivity

type UserActivity struct {
	ID                  string     `json:"id"`
	Email               string     `json:"email"`
	Role                string     `json:"role"`
	Namespace           string     `json:"namespace,omitempty"`
	CreatedAt           time.Time  `json:"created_at"`
	LastLoginAt         *time.Time `json:"last_login_at,omitempty"`
	LastActivityAt      *time.Time `json:"last_activity_at,omitempty"`
	LoginCount          int64      `json:"login_count"`
	FailedActionCount   int64      `json:"failed_action_count"`
	RegistryCredentials int64      `json:"registry_credentials"`
	APIKeys             int64      `json:"api_keys"`
}

UserActivity summarizes recent platform activity for a user account.

Jump to

Keyboard shortcuts

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