Documentation
¶
Index ¶
- Constants
- Variables
- func CopyDir(fromDir, toDir string, keepParent bool) error
- func CopyPath(path string, toDir string) error
- func CreateFile(path string, r io.Reader) error
- func FileExists(filePath string) (bool, error)
- func JoinPaths(trustedRoot string, untrustedPaths ...string) string
- func MoveDirectory(originalPath, newPath string) error
- func WriteToFile(dst string, content []byte) error
- type Service
- func (service *Service) ClearEdgeJobTaskLogs(edgeJobID string, taskID string) error
- func (service *Service) Copy(fromFilePath string, toFilePath string, deleteIfExists bool) error
- func (service *Service) CopySSLCACert(caCertPath string) (string, error)
- func (service *Service) CopySSLCertPair(certPath, keyPath string) (string, string, error)
- func (service *Service) DeleteTLSFile(folder string, fileType portainer.TLSFileType) error
- func (service *Service) DeleteTLSFiles(folder string) error
- func (service *Service) FileExists(filePath string) (bool, error)
- func (service *Service) GetBinaryFolder() string
- func (service *Service) GetCustomTemplateProjectPath(identifier string) string
- func (service *Service) GetDatastorePath() string
- func (service *Service) GetDefaultSSLCertsPath() (string, string)
- func (service *Service) GetDockerConfigPath() string
- func (service *Service) GetEdgeJobFolder(identifier string) string
- func (service *Service) GetEdgeJobTaskLogFileContent(edgeJobID string, taskID string) (string, error)
- func (service *Service) GetEdgeStackProjectPath(edgeStackIdentifier string) string
- func (service *Service) GetFileContent(trustedRoot, filePath string) ([]byte, error)
- func (service *Service) GetPathForTLSFile(folder string, fileType portainer.TLSFileType) (string, error)
- func (service *Service) GetStackProjectPath(stackIdentifier string) string
- func (service *Service) GetTemporaryPath() (string, error)
- func (service *Service) KeyPairFilesExist() (bool, error)
- func (service *Service) LoadKeyPair() ([]byte, []byte, error)
- func (service *Service) RemoveDirectory(directoryPath string) error
- func (service *Service) RemoveStackFileBackup(stackIdentifier, fileName string) error
- func (service *Service) Rename(oldPath, newPath string) error
- func (service *Service) RollbackStackFile(stackIdentifier, fileName string) error
- func (service *Service) StoreCustomTemplateFileFromBytes(identifier, fileName string, data []byte) (string, error)
- func (service *Service) StoreEdgeJobFileFromBytes(identifier string, data []byte) (string, error)
- func (service *Service) StoreEdgeJobTaskLogFileFromBytes(edgeJobID, taskID string, data []byte) error
- func (service *Service) StoreEdgeStackFileFromBytes(edgeStackIdentifier, fileName string, data []byte) (string, error)
- func (service *Service) StoreFDOProfileFileFromBytes(fdoProfileIdentifier string, data []byte) (string, error)
- func (service *Service) StoreKeyPair(private, public []byte, privatePEMHeader, publicPEMHeader string) error
- func (service *Service) StoreMTLSCertificates(cert, caCert, key []byte) (string, string, string, error)
- func (service *Service) StoreRegistryManagementFileFromBytes(folder, fileName string, data []byte) (string, error)
- func (service *Service) StoreSSLCertPair(cert, key []byte) (string, string, error)
- func (service *Service) StoreStackFileFromBytes(stackIdentifier, fileName string, data []byte) (string, error)
- func (service *Service) StoreTLSFileFromBytes(folder string, fileType portainer.TLSFileType, data []byte) (string, error)
- func (service *Service) UpdateStoreStackFileFromBytes(stackIdentifier, fileName string, data []byte) (string, error)
- func (service *Service) WriteJSONToFile(path string, content interface{}) error
Constants ¶
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 ¶
var ErrUndefinedTLSFileType = errors.New("Undefined TLS file type")
ErrUndefinedTLSFileType represents an error returned on undefined TLS file type
Functions ¶
func CopyDir ¶
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 FileExists ¶
FileExists checks for the existence of the specified file.
func JoinPaths ¶
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 WriteToFile ¶
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 ¶
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 ¶
ClearEdgeJobTaskLogs clears the Edge job task logs
func (*Service) Copy ¶
Copy copies the file on fromFilePath to toFilePath if toFilePath exists func will fail unless deleteIfExists is true
func (*Service) CopySSLCACert ¶
CopySSLCACert copies the specified caCert pem file
func (*Service) CopySSLCertPair ¶
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 ¶
DeleteTLSFiles deletes a folder in the TLS store path.
func (*Service) FileExists ¶
FileExists checks for the existence of the specified file.
func (*Service) GetBinaryFolder ¶
GetBinaryFolder returns the full path to the binary store on the filesystem
func (*Service) GetCustomTemplateProjectPath ¶
GetCustomTemplateProjectPath returns the absolute path on the FS for a custom template based on its identifier.
func (*Service) GetDatastorePath ¶
GetDataStorePath returns path to data folder
func (*Service) GetDefaultSSLCertsPath ¶
GetDefaultSSLCertsPath returns the ssl certs path
func (*Service) GetDockerConfigPath ¶
GetDockerConfigPath returns the full path to the docker config store on the filesystem
func (*Service) GetEdgeJobFolder ¶
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 ¶
GetEdgeStackProjectPath returns the absolute path on the FS for a edge stack based on its identifier.
func (*Service) GetFileContent ¶
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 ¶
GetStackProjectPath returns the absolute path on the FS for a stack based on its identifier.
func (*Service) GetTemporaryPath ¶
GetTemporaryPath returns a temp folder
func (*Service) KeyPairFilesExist ¶
KeyPairFilesExist checks for the existence of the key files.
func (*Service) LoadKeyPair ¶
LoadKeyPair retrieve the content of both key files on disk.
func (*Service) RemoveDirectory ¶
RemoveDirectory removes a directory on the filesystem.
func (*Service) RemoveStackFileBackup ¶
RemoveStackFileBackup removes the stack file backup in the ComposeStorePath.
func (*Service) RollbackStackFile ¶
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 ¶
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) 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 ¶
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 ¶
WriteJSONToFile writes JSON to the specified file.