filesystem

package
v0.0.0-...-270f78c Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2023 License: Zlib Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TLSStorePath represents the subfolder where TLS files are stored in the file store folder.
	TLSStorePath = "tls"
	// LDAPStorePath represents the subfolder where LDAP TLS files are stored in the TLSStorePath.
	LDAPStorePath = "ldap"
	// TLSCACertFile represents the name on disk for a TLS CA file.
	TLSCACertFile = "ca.pem"
	// TLSCertFile represents the name on disk for a TLS certificate file.
	TLSCertFile = "cert.pem"
	// TLSKeyFile represents the name on disk for a TLS key file.
	TLSKeyFile = "key.pem"
	// ComposeStorePath represents the subfolder where compose files are stored in the file store folder.
	ComposeStorePath = "compose"
	// ComposeFileDefaultName represents the default name of a compose file.
	ComposeFileDefaultName = "docker-compose.yml"
	// ManifestFileDefaultName represents the default name of a k8s manifest file.
	ManifestFileDefaultName = "k8s-deployment.yml"
	// EdgeStackStorePath represents the subfolder where edge stack files are stored in the file store folder.
	EdgeStackStorePath = "edge_stacks"
	// FDOProfileStorePath represents the subfolder where FDO profiles files are stored in the file store folder.
	FDOProfileStorePath = "fdo_profiles"
	// PrivateKeyFile represents the name on disk of the file containing the private key.
	PrivateKeyFile = "portainer.key"
	// PublicKeyFile represents the name on disk of the file containing the public key.
	PublicKeyFile = "portainer.pub"
	// BinaryStorePath represents the subfolder where binaries are stored in the file store folder.
	BinaryStorePath = "bin"
	// EdgeJobStorePath represents the subfolder where schedule files are stored.
	EdgeJobStorePath = "edge_jobs"
	// DockerConfigPath represents the subfolder where docker configuration is stored.
	DockerConfigPath = "docker_config"
	// ExtensionRegistryManagementStorePath represents the subfolder where files related to the
	// registry management extension are stored.
	ExtensionRegistryManagementStorePath = "extensions"
	// CustomTemplateStorePath represents the subfolder where custom template files are stored in the file store folder.
	CustomTemplateStorePath = "custom_templates"
	// TempPath represent the subfolder where temporary files are saved
	TempPath = "tmp"
	// SSLCertPath represents the default ssl certificates path
	SSLCertPath = "certs"
	// SSLCertFilename represents the ssl certificate file name
	SSLCertFilename = "cert.pem"
	// SSLKeyFilename represents the ssl key file name
	SSLKeyFilename = "key.pem"
	// SSLCACertFilename represents the CA ssl certificate file name for mTLS
	SSLCACertFilename = "ca-cert.pem"

	MTLSCertFilename   = "mtls-cert.pem"
	MTLSCACertFilename = "mtls-ca-cert.pem"
	MTLSKeyFilename    = "mtls-key.pem"
)

Variables

View Source
var ErrUndefinedTLSFileType = errors.New("Undefined TLS file type")

ErrUndefinedTLSFileType represents an error returned on undefined TLS file type

Functions

func CopyDir

func CopyDir(fromDir, toDir string, keepParent bool) error

CopyDir copies contents of fromDir to toDir. When keepParent is true, contents will be copied with their immediate parent dir, i.e. given /from/dirA and /to/dirB with keepParent == true, result will be /to/dirB/dirA/<children>

func CopyPath

func CopyPath(path string, toDir string) error

CopyPath copies file or directory defined by the path to the toDir path

func CreateFile

func CreateFile(path string, r io.Reader) error

func FileExists

func FileExists(filePath string) (bool, error)

FileExists checks for the existence of the specified file.

func JoinPaths

func JoinPaths(trustedRoot string, untrustedPaths ...string) string

JoinPaths takes a trusted root path and a list of untrusted paths and joins them together using directory separators while enforcing that the untrusted paths cannot go higher up than the trusted root

func MoveDirectory

func MoveDirectory(originalPath, newPath string) error

func WriteToFile

func WriteToFile(dst string, content []byte) error

WriteToFile creates a file in the filesystem storage

Types

type Service

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

Service represents a service for managing files and directories.

func NewService

func NewService(dataStorePath, fileStorePath string) (*Service, error)

NewService initializes a new service. It creates a data directory and a directory to store files inside this directory if they don't exist.

func (*Service) ClearEdgeJobTaskLogs

func (service *Service) ClearEdgeJobTaskLogs(edgeJobID string, taskID string) error

ClearEdgeJobTaskLogs clears the Edge job task logs

func (*Service) Copy

func (service *Service) Copy(fromFilePath string, toFilePath string, deleteIfExists bool) error

Copy copies the file on fromFilePath to toFilePath if toFilePath exists func will fail unless deleteIfExists is true

func (*Service) CopySSLCACert

func (service *Service) CopySSLCACert(caCertPath string) (string, error)

CopySSLCACert copies the specified caCert pem file

func (*Service) CopySSLCertPair

func (service *Service) CopySSLCertPair(certPath, keyPath string) (string, string, error)

CopySSLCertPair copies a ssl certificate pair

func (*Service) DeleteTLSFile

func (service *Service) DeleteTLSFile(folder string, fileType portainer.TLSFileType) error

DeleteTLSFile deletes a specific TLS file from a folder.

func (*Service) DeleteTLSFiles

func (service *Service) DeleteTLSFiles(folder string) error

DeleteTLSFiles deletes a folder in the TLS store path.

func (*Service) FileExists

func (service *Service) FileExists(filePath string) (bool, error)

FileExists checks for the existence of the specified file.

func (*Service) GetBinaryFolder

func (service *Service) GetBinaryFolder() string

GetBinaryFolder returns the full path to the binary store on the filesystem

func (*Service) GetCustomTemplateProjectPath

func (service *Service) GetCustomTemplateProjectPath(identifier string) string

GetCustomTemplateProjectPath returns the absolute path on the FS for a custom template based on its identifier.

func (*Service) GetDatastorePath

func (service *Service) GetDatastorePath() string

GetDataStorePath returns path to data folder

func (*Service) GetDefaultSSLCertsPath

func (service *Service) GetDefaultSSLCertsPath() (string, string)

GetDefaultSSLCertsPath returns the ssl certs path

func (*Service) GetDockerConfigPath

func (service *Service) GetDockerConfigPath() string

GetDockerConfigPath returns the full path to the docker config store on the filesystem

func (*Service) GetEdgeJobFolder

func (service *Service) GetEdgeJobFolder(identifier string) string

GetEdgeJobFolder returns the absolute path on the filesystem for an Edge job based on its identifier.

func (*Service) GetEdgeJobTaskLogFileContent

func (service *Service) GetEdgeJobTaskLogFileContent(edgeJobID string, taskID string) (string, error)

GetEdgeJobTaskLogFileContent fetches the Edge job task logs

func (*Service) GetEdgeStackProjectPath

func (service *Service) GetEdgeStackProjectPath(edgeStackIdentifier string) string

GetEdgeStackProjectPath returns the absolute path on the FS for a edge stack based on its identifier.

func (*Service) GetFileContent

func (service *Service) GetFileContent(trustedRoot, filePath string) ([]byte, error)

GetFileContent returns the content of a file as bytes.

func (*Service) GetPathForTLSFile

func (service *Service) GetPathForTLSFile(folder string, fileType portainer.TLSFileType) (string, error)

GetPathForTLSFile returns the absolute path to a specific TLS file for an environment(endpoint).

func (*Service) GetStackProjectPath

func (service *Service) GetStackProjectPath(stackIdentifier string) string

GetStackProjectPath returns the absolute path on the FS for a stack based on its identifier.

func (*Service) GetTemporaryPath

func (service *Service) GetTemporaryPath() (string, error)

GetTemporaryPath returns a temp folder

func (*Service) KeyPairFilesExist

func (service *Service) KeyPairFilesExist() (bool, error)

KeyPairFilesExist checks for the existence of the key files.

func (*Service) LoadKeyPair

func (service *Service) LoadKeyPair() ([]byte, []byte, error)

LoadKeyPair retrieve the content of both key files on disk.

func (*Service) RemoveDirectory

func (service *Service) RemoveDirectory(directoryPath string) error

RemoveDirectory removes a directory on the filesystem.

func (*Service) RemoveStackFileBackup

func (service *Service) RemoveStackFileBackup(stackIdentifier, fileName string) error

RemoveStackFileBackup removes the stack file backup in the ComposeStorePath.

func (*Service) Rename

func (service *Service) Rename(oldPath, newPath string) error

Rename renames a file or directory

func (*Service) RollbackStackFile

func (service *Service) RollbackStackFile(stackIdentifier, fileName string) error

RollbackStackFile rollbacks the stack file backup in the ComposeStorePath.

func (*Service) StoreCustomTemplateFileFromBytes

func (service *Service) StoreCustomTemplateFileFromBytes(identifier, fileName string, data []byte) (string, error)

StoreCustomTemplateFileFromBytes creates a subfolder in the CustomTemplateStorePath and stores a new file from bytes. It returns the path to the folder where the file is stored.

func (*Service) StoreEdgeJobFileFromBytes

func (service *Service) StoreEdgeJobFileFromBytes(identifier string, data []byte) (string, error)

StoreEdgeJobFileFromBytes creates a subfolder in the EdgeJobStorePath and stores a new file from bytes. It returns the path to the folder where the file is stored.

func (*Service) StoreEdgeJobTaskLogFileFromBytes

func (service *Service) StoreEdgeJobTaskLogFileFromBytes(edgeJobID, taskID string, data []byte) error

StoreEdgeJobTaskLogFileFromBytes stores the log file

func (*Service) StoreEdgeStackFileFromBytes

func (service *Service) StoreEdgeStackFileFromBytes(edgeStackIdentifier, fileName string, data []byte) (string, error)

StoreEdgeStackFileFromBytes creates a subfolder in the EdgeStackStorePath and stores a new file from bytes. It returns the path to the folder where the file is stored.

func (*Service) StoreFDOProfileFileFromBytes

func (service *Service) StoreFDOProfileFileFromBytes(fdoProfileIdentifier string, data []byte) (string, error)

StoreFDOProfileFileFromBytes creates a subfolder in the FDOProfileStorePath and stores a new file from bytes. It returns the path to the folder where the file is stored.

func (*Service) StoreKeyPair

func (service *Service) StoreKeyPair(private, public []byte, privatePEMHeader, publicPEMHeader string) error

StoreKeyPair store the specified keys content as PEM files on disk.

func (*Service) StoreMTLSCertificates

func (service *Service) StoreMTLSCertificates(cert, caCert, key []byte) (string, string, string, error)

func (*Service) StoreRegistryManagementFileFromBytes

func (service *Service) StoreRegistryManagementFileFromBytes(folder, fileName string, data []byte) (string, error)

StoreRegistryManagementFileFromBytes creates a subfolder in the ExtensionRegistryManagementStorePath and stores a new file from bytes. It returns the path to the folder where the file is stored.

func (*Service) StoreSSLCertPair

func (service *Service) StoreSSLCertPair(cert, key []byte) (string, string, error)

StoreSSLCertPair stores a ssl certificate pair

func (*Service) StoreStackFileFromBytes

func (service *Service) StoreStackFileFromBytes(stackIdentifier, fileName string, data []byte) (string, error)

StoreStackFileFromBytes creates a subfolder in the ComposeStorePath and stores a new file from bytes. It returns the path to the folder where the file is stored.

func (*Service) StoreTLSFileFromBytes

func (service *Service) StoreTLSFileFromBytes(folder string, fileType portainer.TLSFileType, data []byte) (string, error)

StoreTLSFileFromBytes creates a folder in the TLSStorePath and stores a new file from bytes. It returns the path to the newly created file.

func (*Service) UpdateStoreStackFileFromBytes

func (service *Service) UpdateStoreStackFileFromBytes(stackIdentifier, fileName string, data []byte) (string, error)

UpdateStoreStackFileFromBytes makes stack file backup and updates a new file from bytes. It returns the path to the folder where the file is stored.

func (*Service) WriteJSONToFile

func (service *Service) WriteJSONToFile(path string, content interface{}) error

WriteJSONToFile writes JSON to the specified file.

Jump to

Keyboard shortcuts

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