storage

package
v0.0.0-...-5b49586 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package storage defines the interface for persisting configuration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Storage

type Storage interface {
	// Load retrieves the full server configuration.
	//
	// Summary: Loads the entire server configuration.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//
	// Returns:
	//   - *configv1.McpAnyServerConfig: The loaded configuration.
	//   - error: An error if loading fails.
	//
	// Errors:
	//   - Returns an error if the underlying storage encounters a read error.
	Load(ctx context.Context) (*configv1.McpAnyServerConfig, error)

	// HasConfigSources returns true if the store has configuration sources (e.g., file paths) configured.
	//
	// Summary: Checks if the store has any configuration sources.
	//
	// Returns:
	//   - bool: True if sources exist.
	//
	// Side Effects:
	//   - None.
	HasConfigSources() bool

	// SaveService saves a single upstream service configuration.
	//
	// Summary: Persists a service configuration.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//   - service (*configv1.UpstreamServiceConfig): The service configuration.
	//
	// Returns:
	//   - error: An error if saving fails.
	//
	// Errors:
	//   - Returns an error if the service is invalid or storage write fails.
	//
	// Side Effects:
	//   - Persists the service configuration to the underlying storage.
	SaveService(ctx context.Context, service *configv1.UpstreamServiceConfig) error

	// GetService retrieves a single upstream service configuration by name.
	//
	// Summary: Retrieves a service configuration by name.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//   - name (string): The name of the service.
	//
	// Returns:
	//   - *configv1.UpstreamServiceConfig: The service configuration.
	//   - error: An error if retrieval fails.
	//
	// Errors:
	//   - Returns an error if the service is not found or storage read fails.
	GetService(ctx context.Context, name string) (*configv1.UpstreamServiceConfig, error)

	// ListServices lists all upstream service configurations.
	//
	// Summary: Lists all services.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//
	// Returns:
	//   - []*configv1.UpstreamServiceConfig: A list of service configurations.
	//   - error: An error if listing fails.
	//
	// Errors:
	//   - Returns an error if storage read fails.
	ListServices(ctx context.Context) ([]*configv1.UpstreamServiceConfig, error)

	// DeleteService deletes an upstream service configuration by name.
	//
	// Summary: Deletes a service configuration.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//   - name (string): The name of the service to delete.
	//
	// Returns:
	//   - error: An error if deletion fails.
	//
	// Errors:
	//   - Returns an error if storage delete fails.
	//
	// Side Effects:
	//   - Removes the service configuration from the underlying storage.
	DeleteService(ctx context.Context, name string) error

	// GetGlobalSettings retrieves the global configuration.
	//
	// Summary: Retrieves global settings.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//
	// Returns:
	//   - *configv1.GlobalSettings: The global settings.
	//   - error: An error if retrieval fails.
	//
	// Errors:
	//   - Returns an error if storage read fails.
	GetGlobalSettings(ctx context.Context) (*configv1.GlobalSettings, error)

	// SaveGlobalSettings saves the global configuration.
	//
	// Summary: Persists global settings.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//   - settings (*configv1.GlobalSettings): The settings to save.
	//
	// Returns:
	//   - error: An error if saving fails.
	//
	// Errors:
	//   - Returns an error if storage write fails.
	//
	// Side Effects:
	//   - Persists the global settings to the underlying storage.
	SaveGlobalSettings(ctx context.Context, settings *configv1.GlobalSettings) error

	// ListSecrets retrieves all secrets.
	//
	// Summary: Lists all secrets.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//
	// Returns:
	//   - []*configv1.Secret: A list of secrets.
	//   - error: An error if listing fails.
	//
	// Errors:
	//   - Returns an error if storage read fails.
	ListSecrets(ctx context.Context) ([]*configv1.Secret, error)

	// GetSecret retrieves a secret by ID.
	//
	// Summary: Retrieves a secret by ID.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//   - id (string): The secret ID.
	//
	// Returns:
	//   - *configv1.Secret: The secret.
	//   - error: An error if retrieval fails.
	//
	// Errors:
	//   - Returns an error if storage read fails or secret not found.
	GetSecret(ctx context.Context, id string) (*configv1.Secret, error)

	// SaveSecret saves a secret.
	//
	// Summary: Persists a secret.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//   - secret (*configv1.Secret): The secret to save.
	//
	// Returns:
	//   - error: An error if saving fails.
	//
	// Errors:
	//   - Returns an error if storage write fails.
	//
	// Side Effects:
	//   - Persists the secret to the underlying storage.
	SaveSecret(ctx context.Context, secret *configv1.Secret) error

	// SaveServiceTemplate saves a service template.
	//
	// Summary: Persists a service template.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//   - template (*configv1.ServiceTemplate): The template to save.
	//
	// Returns:
	//   - error: An error if saving fails.
	//
	// Errors:
	//   - Returns an error if storage write fails.
	//
	// Side Effects:
	//   - Persists the service template to the underlying storage.
	SaveServiceTemplate(ctx context.Context, template *configv1.ServiceTemplate) error

	// ListServiceTemplates lists all service templates.
	//
	// Summary: Lists all service templates.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//
	// Returns:
	//   - []*configv1.ServiceTemplate: A list of service templates.
	//   - error: An error if listing fails.
	//
	// Errors:
	//   - Returns an error if storage read fails.
	ListServiceTemplates(ctx context.Context) ([]*configv1.ServiceTemplate, error)

	// GetServiceTemplate retrieves a service template by ID.
	//
	// Summary: Retrieves a service template.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//   - id (string): The template ID.
	//
	// Returns:
	//   - *configv1.ServiceTemplate: The service template.
	//   - error: An error if retrieval fails.
	//
	// Errors:
	//   - Returns an error if storage read fails or template not found.
	GetServiceTemplate(ctx context.Context, id string) (*configv1.ServiceTemplate, error)

	// DeleteServiceTemplate deletes a service template by ID.
	//
	// Summary: Deletes a service template.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//   - id (string): The template ID to delete.
	//
	// Returns:
	//   - error: An error if deletion fails.
	//
	// Errors:
	//   - Returns an error if storage delete fails.
	//
	// Side Effects:
	//   - Removes the service template from the underlying storage.
	DeleteServiceTemplate(ctx context.Context, id string) error

	// DeleteSecret deletes a secret by ID.
	//
	// Summary: Deletes a secret.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//   - id (string): The secret ID to delete.
	//
	// Returns:
	//   - error: An error if deletion fails.
	//
	// Errors:
	//   - Returns an error if storage delete fails.
	//
	// Side Effects:
	//   - Removes the secret from the underlying storage.
	DeleteSecret(ctx context.Context, id string) error

	// CreateUser creates a new user.
	//
	// Summary: Creates a user.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//   - user (*configv1.User): The user to create.
	//
	// Returns:
	//   - error: An error if creation fails.
	//
	// Errors:
	//   - Returns an error if storage write fails.
	//
	// Side Effects:
	//   - Persists the new user to the underlying storage.
	CreateUser(ctx context.Context, user *configv1.User) error

	// GetUser retrieves a user by ID.
	//
	// Summary: Retrieves a user by ID.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//   - id (string): The user ID.
	//
	// Returns:
	//   - *configv1.User: The user.
	//   - error: An error if retrieval fails.
	//
	// Errors:
	//   - Returns an error if storage read fails or user not found.
	GetUser(ctx context.Context, id string) (*configv1.User, error)

	// ListUsers retrieves all users.
	//
	// Summary: Lists all users.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//
	// Returns:
	//   - []*configv1.User: A list of users.
	//   - error: An error if listing fails.
	//
	// Errors:
	//   - Returns an error if storage read fails.
	ListUsers(ctx context.Context) ([]*configv1.User, error)

	// UpdateUser updates an existing user.
	//
	// Summary: Updates a user.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//   - user (*configv1.User): The user to update.
	//
	// Returns:
	//   - error: An error if update fails.
	//
	// Errors:
	//   - Returns an error if storage write fails.
	//
	// Side Effects:
	//   - Persists the updated user to the underlying storage.
	UpdateUser(ctx context.Context, user *configv1.User) error

	// DeleteUser deletes a user by ID.
	//
	// Summary: Deletes a user.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//   - id (string): The user ID to delete.
	//
	// Returns:
	//   - error: An error if deletion fails.
	//
	// Errors:
	//   - Returns an error if storage delete fails.
	//
	// Side Effects:
	//   - Removes the user from the underlying storage.
	DeleteUser(ctx context.Context, id string) error

	// ListProfiles retrieves all profile definitions.
	//
	// Summary: Lists all profiles.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//
	// Returns:
	//   - []*configv1.ProfileDefinition: A list of profiles.
	//   - error: An error if listing fails.
	//
	// Errors:
	//   - Returns an error if storage read fails.
	ListProfiles(ctx context.Context) ([]*configv1.ProfileDefinition, error)

	// GetProfile retrieves a profile definition by name.
	//
	// Summary: Retrieves a profile by name.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//   - name (string): The profile name.
	//
	// Returns:
	//   - *configv1.ProfileDefinition: The profile.
	//   - error: An error if retrieval fails.
	//
	// Errors:
	//   - Returns an error if storage read fails or profile not found.
	GetProfile(ctx context.Context, name string) (*configv1.ProfileDefinition, error)

	// SaveProfile saves a profile definition.
	//
	// Summary: Persists a profile.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//   - profile (*configv1.ProfileDefinition): The profile to save.
	//
	// Returns:
	//   - error: An error if saving fails.
	//
	// Errors:
	//   - Returns an error if storage write fails.
	//
	// Side Effects:
	//   - Persists the profile to the underlying storage.
	SaveProfile(ctx context.Context, profile *configv1.ProfileDefinition) error

	// DeleteProfile deletes a profile definition by name.
	//
	// Summary: Deletes a profile.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//   - name (string): The profile name to delete.
	//
	// Returns:
	//   - error: An error if deletion fails.
	//
	// Errors:
	//   - Returns an error if storage delete fails.
	//
	// Side Effects:
	//   - Removes the profile from the underlying storage.
	DeleteProfile(ctx context.Context, name string) error

	// ListServiceCollections retrieves all service collections.
	//
	// Summary: Lists all collections.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//
	// Returns:
	//   - []*configv1.Collection: A list of collections.
	//   - error: An error if listing fails.
	//
	// Errors:
	//   - Returns an error if storage read fails.
	ListServiceCollections(ctx context.Context) ([]*configv1.Collection, error)

	// GetServiceCollection retrieves a service collection by name.
	//
	// Summary: Retrieves a collection by name.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//   - name (string): The collection name.
	//
	// Returns:
	//   - *configv1.Collection: The collection.
	//   - error: An error if retrieval fails.
	//
	// Errors:
	//   - Returns an error if storage read fails or collection not found.
	GetServiceCollection(ctx context.Context, name string) (*configv1.Collection, error)

	// SaveServiceCollection saves a service collection.
	//
	// Summary: Persists a collection.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//   - collection (*configv1.Collection): The collection to save.
	//
	// Returns:
	//   - error: An error if saving fails.
	//
	// Errors:
	//   - Returns an error if storage write fails.
	//
	// Side Effects:
	//   - Persists the collection to the underlying storage.
	SaveServiceCollection(ctx context.Context, collection *configv1.Collection) error

	// DeleteServiceCollection deletes a service collection by name.
	//
	// Summary: Deletes a collection.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//   - name (string): The collection name to delete.
	//
	// Returns:
	//   - error: An error if deletion fails.
	//
	// Errors:
	//   - Returns an error if storage delete fails.
	//
	// Side Effects:
	//   - Removes the collection from the underlying storage.
	DeleteServiceCollection(ctx context.Context, name string) error

	// SaveToken saves a user token.
	//
	// Summary: Persists a user token.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//   - token (*configv1.UserToken): The token to save.
	//
	// Returns:
	//   - error: An error if saving fails.
	//
	// Errors:
	//   - Returns an error if storage write fails.
	//
	// Side Effects:
	//   - Persists the token to the underlying storage.
	SaveToken(ctx context.Context, token *configv1.UserToken) error

	// GetToken retrieves a user token by user ID and service ID.
	//
	// Summary: Retrieves a user token.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//   - userID (string): The user ID.
	//   - serviceID (string): The service ID.
	//
	// Returns:
	//   - *configv1.UserToken: The token.
	//   - error: An error if retrieval fails.
	//
	// Errors:
	//   - Returns an error if storage read fails.
	GetToken(ctx context.Context, userID, serviceID string) (*configv1.UserToken, error)

	// DeleteToken deletes a user token.
	//
	// Summary: Deletes a user token.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//   - userID (string): The user ID.
	//   - serviceID (string): The service ID.
	//
	// Returns:
	//   - error: An error if deletion fails.
	//
	// Errors:
	//   - Returns an error if storage delete fails.
	//
	// Side Effects:
	//   - Removes the token from the underlying storage.
	DeleteToken(ctx context.Context, userID, serviceID string) error

	// ListCredentials retrieves all credentials.
	//
	// Summary: Lists all credentials.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//
	// Returns:
	//   - []*configv1.Credential: A list of credentials.
	//   - error: An error if listing fails.
	//
	// Errors:
	//   - Returns an error if storage read fails.
	ListCredentials(ctx context.Context) ([]*configv1.Credential, error)

	// GetCredential retrieves a credential by ID.
	//
	// Summary: Retrieves a credential by ID.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//   - id (string): The credential ID.
	//
	// Returns:
	//   - *configv1.Credential: The credential.
	//   - error: An error if retrieval fails.
	//
	// Errors:
	//   - Returns an error if storage read fails or credential not found.
	GetCredential(ctx context.Context, id string) (*configv1.Credential, error)

	// SaveCredential saves a credential.
	//
	// Summary: Persists a credential.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//   - cred (*configv1.Credential): The credential to save.
	//
	// Returns:
	//   - error: An error if saving fails.
	//
	// Errors:
	//   - Returns an error if storage write fails.
	//
	// Side Effects:
	//   - Persists the credential to the underlying storage.
	SaveCredential(ctx context.Context, cred *configv1.Credential) error

	// DeleteCredential deletes a credential by ID.
	//
	// Summary: Deletes a credential.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//   - id (string): The credential ID to delete.
	//
	// Returns:
	//   - error: An error if deletion fails.
	//
	// Errors:
	//   - Returns an error if storage delete fails.
	//
	// Side Effects:
	//   - Removes the credential from the underlying storage.
	DeleteCredential(ctx context.Context, id string) error

	// Close closes the underlying storage connection.
	//
	// Summary: Closes the storage connection.
	//
	// Returns:
	//   - error: An error if closing fails.
	//
	// Errors:
	//   - Returns an error if the connection cannot be closed cleanly.
	//
	// Side Effects:
	//   - Closes the connection to the storage backend.
	Close() error

	// SaveLog saves a log entry.
	//
	// Summary: Persists a log entry.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//   - entry (*logging.LogEntry): The log entry to save.
	//
	// Returns:
	//   - error: An error if saving fails.
	//
	// Errors:
	//   - Returns an error if storage write fails.
	//
	// Side Effects:
	//   - Persists the log entry to the underlying storage.
	SaveLog(ctx context.Context, entry *logging.LogEntry) error

	// GetRecentLogs retrieves recent log entries.
	//
	// Summary: Retrieves recent log entries.
	//
	// Parameters:
	//   - ctx (context.Context): The context for the request.
	//   - limit (int): The maximum number of logs to retrieve.
	//
	// Returns:
	//   - []*logging.LogEntry: A list of log entries.
	//   - error: An error if retrieval fails.
	//
	// Errors:
	//   - Returns an error if storage read fails.
	GetRecentLogs(ctx context.Context, limit int) ([]*logging.LogEntry, error)
}

Storage defines the interface for persisting configuration.

Summary: Interface for backend storage operations.

Directories

Path Synopsis
Package memory provides an in-memory storage implementation for testing.
Package memory provides an in-memory storage implementation for testing.
Package postgres implements PostgreSQL storage for MCP Any configuration.
Package postgres implements PostgreSQL storage for MCP Any configuration.
Package sqlite implements SQLite storage for MCP Any configuration.
Package sqlite implements SQLite storage for MCP Any configuration.

Jump to

Keyboard shortcuts

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