Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrFileTypeIsDirectory = errors.New("ErrFileTypeIsDirectory") // TODO: fix this inconsistent error strings. ErrNotFound = errors.New("not found") ErrPathAlreadyExists = errors.New("ErrPathAlreadyExists") ErrNoParentDirectory = errors.New("ErrNoParentDirectory") ErrInvalidPathParameter = errors.New("ErrInvalidPathParameter") )
var AllFileTypes = []FileType{ FileTypeWorkflow, FileTypeEndpoint, FileTypeConsumer, FileTypeService, FileTypeFile, FileTypeDirectory, }
var DefaultCalculateChecksum = Sha256CalculateChecksum
Functions ¶
func GetPathDepth ¶
GetPathDepth reads the path and returns the depth value. Use SanitizePath first, because if an error happens here the function may produce invalid results.
func SanitizePath ¶
SanitizePath standardizes and sanitizes the path, and validates it against naming requirements.
Types ¶
type CalculateChecksumFunc ¶
CalculateChecksumFunc is a function type used to calculate files checksums.
type File ¶
type File struct { ID uuid.UUID `json:"-"` // Path is the full path of the file, files and directories are only different when they have different paths. As // in typical filesystems, paths are unique within the filesystem. Path string `json:"path,omitempty"` // Depth tells how many levels deep the file in the filesystem. This field is needed for sql querying purposes. Depth int `json:"-"` Typ FileType `json:"type,omitempty"` Data []byte `json:"data,omitempty"` Checksum string `json:"checksum,omitempty"` Size int `json:"size,omitempty"` // Root is a filestore instance, users can create multiple filestore roots and RootID tells which root the file // belongs too. RootID uuid.UUID `json:"-"` MIMEType string `json:"mimeType,omitempty"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` }
File represents a file in the filestore, File can be either ordinary file or directory.
type FileQuery ¶
type FileQuery interface { // GetData returns reader for the file, this method is not applicable for directory file type. GetData(ctx context.Context) ([]byte, error) // Delete deletes the file (or the directory). Delete(ctx context.Context, force bool) error SetData(ctx context.Context, data []byte) (string, error) // SetPath sets a new path for the file, this method is used to rename files and directories or move them // to a new location. Param path should be a new path that doesn't already exist and the directory of Param path // should already exist. SetPath(ctx context.Context, path string) error }
FileQuery performs different queries associated to a file.
type FileStore ¶
type FileStore interface { // CreateRoot creates a new root in the filestore. For each direktiv CreateRoot(ctx context.Context, rootID uuid.UUID, namespace string) (*Root, error) CreateTempRoot(ctx context.Context, id uuid.UUID) (*Root, error) GetRoot(ctx context.Context, id uuid.UUID) (*Root, error) // GetAllRoots list all roots. GetAllRoots(ctx context.Context) ([]*Root, error) GetRootByNamespace(ctx context.Context, namespace string) (*Root, error) // ForRootID returns a query object to do further queries on root. ForRootID(rootID uuid.UUID) RootQuery // ForNamespace returns a query object to do further queries on root. ForNamespace(namespace string) RootQuery // ForFile returns a query object to do further queries on that file. ForFile(file *File) FileQuery // GetFileByID queries a file by id. GetFileByID(ctx context.Context, id uuid.UUID) (*File, error) }
type FileType ¶
type FileType string
FileType represents file types. Filestore files are basically two types, ordinary files and directories.
const ( // FileTypeWorkflow is special file type as we handle workflow differently. FileTypeWorkflow FileType = "workflow" FileTypeEndpoint FileType = "endpoint" FileTypeConsumer FileType = "consumer" FileTypeService FileType = "service" FileTypeFile FileType = "file" FileTypeDirectory FileType = "directory" )
func (FileType) IsDirektivSpecFile ¶ added in v0.8.3
type Root ¶
type Root struct { ID uuid.UUID Namespace string `gorm:"default:NULL"` CreatedAt time.Time UpdatedAt time.Time }
Root represents an isolated filesystems. Users of filestore can create and deletes multiple roots. In Direktiv, we create a dedicated root for every namespace.
type RootQuery ¶
type RootQuery interface { // GetFile grabs a file from the root. GetFile(ctx context.Context, path string) (*File, error) // CreateFile creates both files and directories, // param 'typ' indicates if file is of type directory or file. // Param 'path' should not already exist and the parent directory of 'path' should exist. // Param 'dataReader' should be nil when creating directories, and should be none nil when creating files. CreateFile(ctx context.Context, path string, typ FileType, mimeType string, data []byte) (*File, error) // ReadDirectory lists all files and directories in a path. ReadDirectory(ctx context.Context, path string) ([]*File, error) // Delete the root itself. Delete(ctx context.Context) error // ListAllFiles lists all files and directories in the filestore, this method used to help testing filestore logic. ListAllFiles(ctx context.Context) ([]*File, error) // ListDirektivFilesWithData lists all direktiv files(workflows and services, etc...) in the root. // It returns list of files with data fields already loaded, so the caller don't have to call GetData(). ListDirektivFilesWithData(ctx context.Context) ([]*File, error) SetNamespace(ctx context.Context, namespace string) error }
RootQuery performs different queries associated to a root.