storage

package
v0.5.14 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0, MIT Imports: 14 Imported by: 0

Documentation

Overview

Code generated. DO NOT EDIT.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OverrideStorageWithClientConfig added in v0.5.0

func OverrideStorageWithClientConfig(storage *model.Storage, config model.ClientConfig)

Types

type CreateRequest

type CreateRequest struct {
	Provider     string             `json:"provider"`
	Name         string             `binding:"required"  json:"name"`
	Path         string             `json:"path"`
	Config       map[string]string  `json:"config"`
	ClientConfig model.ClientConfig `json:"clientConfig"`
}

type DefaultHandler

type DefaultHandler struct{}

func (DefaultHandler) CreateStorageHandler

func (DefaultHandler) CreateStorageHandler(
	ctx context.Context,
	db *gorm.DB,
	storageType string,
	request CreateRequest,
) (*model.Storage, error)

CreateStorageHandler 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.

Parameters:

  • ctx: The context for database transactions and other operations.
  • db: A pointer to the gorm.DB instance representing the database connection.
  • storageType: The type of storage system (e.g., S3, GCS, local).
  • provider: The provider for the storage system (e.g., AWS, Google, etc.).
  • name: A unique name to represent the storage in the database.
  • path: The path or endpoint to access the storage.
  • config: A map containing the configuration key-value pairs required by the storage backend.

Returns:

  • A pointer to the newly created Storage model if successful.
  • An error, if any occurred during the operation.

func (DefaultHandler) ExploreHandler

func (DefaultHandler) ExploreHandler(
	ctx context.Context,
	db *gorm.DB,
	name string,
	path string,
) ([]DirEntry, error)

ExploreHandler 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.

This 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.

Parameters:

  • ctx: The context for database transactions and other operations.
  • db: A pointer to the gorm.DB instance representing the database connection.
  • name: The name of the desired Storage record.
  • path: The directory path in the storage system to explore.

Returns:

  • A slice of DirEntry structs representing the entries in the explored directory.
  • An error, if any occurred during the operation.

func (DefaultHandler) ListStoragesHandler

func (DefaultHandler) ListStoragesHandler(
	ctx context.Context,
	db *gorm.DB) ([]model.Storage, error)

ListStoragesHandler fetches all the storage entries from the database.

Parameters:

  • ctx: The context for database transactions and other operations.
  • db: A pointer to the gorm.DB instance representing the database connection.

Returns:

  • A slice containing all Storage model entries found in the database.
  • An error, if any occurred during the operation.

func (DefaultHandler) RemoveHandler

func (DefaultHandler) RemoveHandler(
	ctx context.Context,
	db *gorm.DB,
	name string) error

RemoveHandler 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.

Parameters:

  • ctx: The context for database transactions and other operations.
  • db: A pointer to the gorm.DB instance representing the database connection.
  • name: The ID or name of the storage entry to be deleted.

Returns:

  • 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.

func (DefaultHandler) RenameStorageHandler added in v0.5.0

func (DefaultHandler) RenameStorageHandler(
	ctx context.Context,
	db *gorm.DB,
	name string,
	request RenameRequest,
) (*model.Storage, error)

RenameStorageHandler updates the name of a storage entry in the database.

This 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.

Parameters:

  • ctx: The context for managing timeouts and cancellation.
  • db: The gorm.DB instance for making database queries.
  • name: The current name or ID of the storage entry to be renamed.
  • request: A RenameRequest object containing the new name for the storage entry.

Returns:

  • A pointer to the updated model.Storage entry, reflecting the new name.
  • An error if any issues occur during the operation, especially if the provided new name is invalid, or if there are database-related errors.

func (DefaultHandler) UpdateStorageHandler

func (DefaultHandler) UpdateStorageHandler(
	ctx context.Context,
	db *gorm.DB,
	name string,
	request UpdateRequest,
) (*model.Storage, error)

UpdateStorageHandler updates the configuration of a given storage system.

This method performs the following operations:

  • Retrieves the storage system with the specified name.
  • Merges the new configuration with the current configuration.
  • Ensures the provided configuration is valid by checking the storage type's backend compatibility.
  • Initializes an RCloneHandler with the merged configuration to validate the config against the actual storage backend.
  • Updates the storage system's configuration in the database.

Parameters:

  • ctx: A context.Context for request-scoped values, cancellation signals, and deadlines.
  • db: A *gorm.DB instance for database interactions.
  • name: The name of the storage system to be updated.
  • config: A map representing the new configuration values to be merged with the existing configuration.

Returns:

  • A pointer to the updated storage model.
  • An error if there's an issue during the update process, otherwise nil.

Note:

If the specified storage system does not exist, an error will be returned.
The method also ensures that the merged configuration is valid and the storage backend is accessible
using RCloneHandler. If the new configuration is invalid, or if the backend is inaccessible, an error is returned.

type DirEntry

type DirEntry struct {
	Path         string    `json:"path"`
	LastModified time.Time `json:"lastModified" table:"format:2006-01-02 15:04:05"`
	Size         int64     `json:"size"`
	IsDir        bool      `json:"isDir"`
	DirID        string    `json:"dirId"        table:"verbose"`
	NumItems     int64     `json:"numItems"     table:"verbose"`
	Hash         string    `json:"hash"         table:"verbose"`
}

type Handler

type Handler interface {
	CreateStorageHandler(
		ctx context.Context,
		db *gorm.DB,
		storageType string,
		request CreateRequest,
	) (*model.Storage, error)
	ExploreHandler(
		ctx context.Context,
		db *gorm.DB,
		name string,
		path string,
	) ([]DirEntry, error)
	ListStoragesHandler(
		ctx context.Context,
		db *gorm.DB) ([]model.Storage, error)
	RemoveHandler(
		ctx context.Context,
		db *gorm.DB,
		name string) error
	UpdateStorageHandler(
		ctx context.Context,
		db *gorm.DB,
		name string,
		request UpdateRequest,
	) (*model.Storage, error)
	RenameStorageHandler(
		ctx context.Context,
		db *gorm.DB,
		name string,
		request RenameRequest,
	) (*model.Storage, error)
}
var Default Handler = &DefaultHandler{}

type MockStorage added in v0.5.0

type MockStorage struct {
	mock.Mock
}

func (*MockStorage) CreateStorageHandler added in v0.5.0

func (m *MockStorage) CreateStorageHandler(ctx context.Context, db *gorm.DB, storageType string, request CreateRequest) (*model.Storage, error)

func (*MockStorage) ExploreHandler added in v0.5.0

func (m *MockStorage) ExploreHandler(ctx context.Context, db *gorm.DB, name string, path string) ([]DirEntry, error)

func (*MockStorage) ListStoragesHandler added in v0.5.0

func (m *MockStorage) ListStoragesHandler(ctx context.Context, db *gorm.DB) ([]model.Storage, error)

func (*MockStorage) RemoveHandler added in v0.5.0

func (m *MockStorage) RemoveHandler(ctx context.Context, db *gorm.DB, name string) error

func (*MockStorage) RenameStorageHandler added in v0.5.0

func (m *MockStorage) RenameStorageHandler(ctx context.Context, db *gorm.DB, name string, request RenameRequest) (*model.Storage, error)

func (*MockStorage) UpdateStorageHandler added in v0.5.0

func (m *MockStorage) UpdateStorageHandler(ctx context.Context, db *gorm.DB, name string, request UpdateRequest) (*model.Storage, error)

type RenameRequest added in v0.5.0

type RenameRequest struct {
	Name string `binding:"required" json:"name"`
}

type UpdateRequest added in v0.5.0

type UpdateRequest struct {
	Config       map[string]string  `json:"config"`
	ClientConfig model.ClientConfig `json:"clientConfig"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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