{"modulePath":"github.com/data-preservation-programs/singularity","version":"v1.0.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package storage\n\nCode generated. DO NOT EDIT.\n\n## Functions\n\n```go\nfunc OverrideStorageWithClientConfig(storage *model.Storage, config model.ClientConfig)\n```\n\n## Types\n\n```go\ntype CreateRequest struct {\n\tProvider     string             `json:\"provider\"`\n\tName         string             `binding:\"required\"  json:\"name\"`\n\tPath         string             `json:\"path\"`\n\tConfig       map[string]string  `json:\"config\"`\n\tClientConfig model.ClientConfig `json:\"clientConfig\"`\n}\n```\n\n```go\ntype DefaultHandler struct{}\n```\n\n```go\nfunc (DefaultHandler) CreateStorageHandler(\n\tctx context.Context,\n\tdb *gorm.DB,\n\tstorageType string,\n\trequest CreateRequest,\n) (*model.Storage, error)\n```\nCreateStorageHandler initializes a new storage using the provided configurations and attempts to create a connection to the storage to ensure it is valid. If successful, it creates a new storage entry in the database.\n\nParameters:\n\n  - ctx: The context for database transactions and other operations.\n  - db: A pointer to the gorm.DB instance representing the database connection.\n  - storageType: The type of storage system (e.g., S3, GCS, local).\n  - provider: The provider for the storage system (e.g., AWS, Google, etc.).\n  - name: A unique name to represent the storage in the database.\n  - path: The path or endpoint to access the storage.\n  - config: A map containing the configuration key-value pairs required by the storage backend.\n\nReturns:\n\n  - A pointer to the newly created Storage model if successful.\n  - An error, if any occurred during the operation.\n\n```go\nfunc (DefaultHandler) ExploreHandler(\n\tctx context.Context,\n\tdb *gorm.DB,\n\tname string,\n\tpath string,\n) ([]DirEntry, error)\n```\nExploreHandler fetches directory entries (files and sub-directories) for a given storage system and directory path using rclone. It returns a list of these entries, allowing you to view the contents of a directory in a remote storage system.\n\nThis function starts by fetching the desired Storage record based on the provided name. It then initializes an RCloneHandler for this storage. Using rclone, it lists the contents of the given directory path. Each entry is processed to determine if it is a file or a directory and the relevant information for each entry is returned.\n\nParameters:\n\n  - ctx: The context for database transactions and other operations.\n  - db: A pointer to the gorm.DB instance representing the database connection.\n  - name: The name of the desired Storage record.\n  - path: The directory path in the storage system to explore.\n\nReturns:\n\n  - A slice of DirEntry structs representing the entries in the explored directory.\n  - An error, if any occurred during the operation.\n\n```go\nfunc (DefaultHandler) ListStoragesHandler(\n\tctx context.Context,\n\tdb *gorm.DB,\n) ([]model.Storage, error)\n```\nListStoragesHandler fetches all the storage entries from the database.\n\nParameters:\n\n  - ctx: The context for database transactions and other operations.\n  - db: A pointer to the gorm.DB instance representing the database connection.\n\nReturns:\n\n  - A slice containing all Storage model entries found in the database.\n  - An error, if any occurred during the operation.\n\n```go\nfunc (DefaultHandler) RemoveHandler(\n\tctx context.Context,\n\tdb *gorm.DB,\n\tname string,\n) error\n```\nRemoveHandler deletes the storage entry with the specified name from the database. Before deletion, it checks if any attachments are still using the storage, and if so, returns an error.\n\nParameters:\n\n  - ctx: The context for database transactions and other operations.\n  - db: A pointer to the gorm.DB instance representing the database connection.\n  - name: The ID or name of the storage entry to be deleted.\n\nReturns:\n\n  - An error, if any occurred during the operation. Returns a specific error if the storage is still in use or if the storage does not exist.\n\n```go\nfunc (DefaultHandler) RenameStorageHandler(\n\tctx context.Context,\n\tdb *gorm.DB,\n\tname string,\n\trequest RenameRequest,\n) (*model.Storage, error)\n```\nRenameStorageHandler updates the name of a storage entry in the database.\n\nThis handler finds a storage entry by its ID or name and then updates its name with a new name provided in the request payload. The new name cannot be entirely numeric or empty.\n\nParameters:\n\n  - ctx: The context for managing timeouts and cancellation.\n  - db: The gorm.DB instance for making database queries.\n  - name: The current name or ID of the storage entry to be renamed.\n  - request: A RenameRequest object containing the new name for the storage entry.\n\nReturns:\n\n  - A pointer to the updated model.Storage entry, reflecting the new name.\n  - An error if any issues occur during the operation, especially if the provided new name is invalid, or if there are database-related errors.\n\n```go\nfunc (DefaultHandler) UpdateStorageHandler(\n\tctx context.Context,\n\tdb *gorm.DB,\n\tname string,\n\trequest UpdateRequest,\n) (*model.Storage, error)\n```\nUpdateStorageHandler updates the configuration of a given storage system.\n\nThis method performs the following operations:\n\n  - Retrieves the storage system with the specified name.\n  - Merges the new configuration with the current configuration.\n  - Ensures the provided configuration is valid by checking the storage type's backend compatibility.\n  - Initializes an RCloneHandler with the merged configuration to validate the config against the actual storage backend.\n  - Updates the storage system's configuration in the database.\n\nParameters:\n\n  - ctx: A context.Context for request-scoped values, cancellation signals, and deadlines.\n  - db: A \\*gorm.DB instance for database interactions.\n  - name: The name of the storage system to be updated.\n  - config: A map representing the new configuration values to be merged with the existing configuration.\n\nReturns:\n\n  - A pointer to the updated storage model.\n  - An error if there's an issue during the update process, otherwise nil.\n\nNote:\n\n\tIf the specified storage system does not exist, an error will be returned.\n\tThe method also ensures that the merged configuration is valid and the storage backend is accessible\n\tusing RCloneHandler. If the new configuration is invalid, or if the backend is inaccessible, an error is returned.\n\n```go\ntype DirEntry struct {\n\tPath         string    `json:\"path\"`\n\tLastModified time.Time `json:\"lastModified\" table:\"format:2006-01-02 15:04:05\"`\n\tSize         int64     `json:\"size\"`\n\tIsDir        bool      `json:\"isDir\"`\n\tDirID        string    `json:\"dirId\"        table:\"verbose\"`\n\tNumItems     int64     `json:\"numItems\"     table:\"verbose\"`\n\tHash         string    `json:\"hash\"         table:\"verbose\"`\n}\n```\n\n```go\ntype Handler interface {\n\tCreateStorageHandler(\n\t\tctx context.Context,\n\t\tdb *gorm.DB,\n\t\tstorageType string,\n\t\trequest CreateRequest,\n\t) (*model.Storage, error)\n\tExploreHandler(\n\t\tctx context.Context,\n\t\tdb *gorm.DB,\n\t\tname string,\n\t\tpath string,\n\t) ([]DirEntry, error)\n\tListStoragesHandler(\n\t\tctx context.Context,\n\t\tdb *gorm.DB) ([]model.Storage, error)\n\tRemoveHandler(\n\t\tctx context.Context,\n\t\tdb *gorm.DB,\n\t\tname string) error\n\tUpdateStorageHandler(\n\t\tctx context.Context,\n\t\tdb *gorm.DB,\n\t\tname string,\n\t\trequest UpdateRequest,\n\t) (*model.Storage, error)\n\tRenameStorageHandler(\n\t\tctx context.Context,\n\t\tdb *gorm.DB,\n\t\tname string,\n\t\trequest RenameRequest,\n\t) (*model.Storage, error)\n}\n```\n\n```go\nvar Default Handler = \u0026DefaultHandler{}\n```\n\n```go\ntype MockStorage struct {\n\tmock.Mock\n}\n```\n\n```go\nfunc (m *MockStorage) CreateStorageHandler(ctx context.Context, db *gorm.DB, storageType string, request CreateRequest) (*model.Storage, error)\n```\n\n```go\nfunc (m *MockStorage) ExploreHandler(ctx context.Context, db *gorm.DB, name string, path string) ([]DirEntry, error)\n```\n\n```go\nfunc (m *MockStorage) ListStoragesHandler(ctx context.Context, db *gorm.DB) ([]model.Storage, error)\n```\n\n```go\nfunc (m *MockStorage) RemoveHandler(ctx context.Context, db *gorm.DB, name string) error\n```\n\n```go\nfunc (m *MockStorage) RenameStorageHandler(ctx context.Context, db *gorm.DB, name string, request RenameRequest) (*model.Storage, error)\n```\n\n```go\nfunc (m *MockStorage) UpdateStorageHandler(ctx context.Context, db *gorm.DB, name string, request UpdateRequest) (*model.Storage, error)\n```\n\n```go\ntype RenameRequest struct {\n\tName string `binding:\"required\" json:\"name\"`\n}\n```\n\n```go\ntype UpdateRequest struct {\n\tConfig       map[string]string  `json:\"config\"`\n\tClientConfig model.ClientConfig `json:\"clientConfig\"`\n}\n```\n\n","path":"github.com/data-preservation-programs/singularity/handler/storage","name":"storage","synopsis":"Code generated.","isRedistributable":true}
