actions: add a specific protocol for data retention

This commit is contained in:
Nicola Murino 2021-10-03 10:22:47 +02:00
parent 22d28a37b6
commit ec81a7ac29
No known key found for this signature in database
GPG key ID: 2F1FB59433D5A8CB
5 changed files with 17 additions and 13 deletions

View file

@ -73,12 +73,13 @@ const (
// Supported protocols // Supported protocols
const ( const (
ProtocolSFTP = "SFTP" ProtocolSFTP = "SFTP"
ProtocolSCP = "SCP" ProtocolSCP = "SCP"
ProtocolSSH = "SSH" ProtocolSSH = "SSH"
ProtocolFTP = "FTP" ProtocolFTP = "FTP"
ProtocolWebDAV = "DAV" ProtocolWebDAV = "DAV"
ProtocolHTTP = "HTTP" ProtocolHTTP = "HTTP"
ProtocolDataRetention = "DataRetention"
) )
// Upload modes // Upload modes

View file

@ -69,7 +69,8 @@ func (c *ActiveRetentionChecks) Add(check RetentionCheck, user *dataprovider.Use
// we silently ignore file patterns // we silently ignore file patterns
user.Filters.FilePatterns = nil user.Filters.FilePatterns = nil
conn := NewBaseConnection("", "", "", "", *user) conn := NewBaseConnection("", "", "", "", *user)
conn.ID = fmt.Sprintf("retention_check_%v", user.Username) conn.SetProtocol(ProtocolDataRetention)
conn.ID = fmt.Sprintf("data_retention_%v", user.Username)
check.Username = user.Username check.Username = user.Username
check.StartTime = util.GetTimeAsMsSinceEpoch(time.Now()) check.StartTime = util.GetTimeAsMsSinceEpoch(time.Now())
check.conn = conn check.conn = conn

View file

@ -124,7 +124,8 @@ func TestEmailNotifications(t *testing.T) {
}, },
} }
conn := NewBaseConnection("", "", "", "", user) conn := NewBaseConnection("", "", "", "", user)
conn.ID = fmt.Sprintf("retention_check_%v", user.Username) conn.SetProtocol(ProtocolDataRetention)
conn.ID = fmt.Sprintf("data_retention_%v", user.Username)
check.conn = conn check.conn = conn
err = check.sendNotification(time.Now(), nil) err = check.sendNotification(time.Now(), nil)
assert.NoError(t, err) assert.NoError(t, err)
@ -177,7 +178,8 @@ func TestRetentionPermissionsAndGetFolder(t *testing.T) {
} }
conn := NewBaseConnection("", "", "", "", user) conn := NewBaseConnection("", "", "", "", user)
conn.ID = fmt.Sprintf("retention_check_%v", user.Username) conn.SetProtocol(ProtocolDataRetention)
conn.ID = fmt.Sprintf("data_retention_%v", user.Username)
check.conn = conn check.conn = conn
check.updateUserPermissions() check.updateUserPermissions()
assert.Equal(t, []string{dataprovider.PermListItems, dataprovider.PermDelete}, conn.User.Permissions["/"]) assert.Equal(t, []string{dataprovider.PermListItems, dataprovider.PermDelete}, conn.User.Permissions["/"])

View file

@ -45,7 +45,7 @@ The external program can also read the following environment variables:
- `SFTPGO_ACTION_BUCKET`, non-empty for S3, GCS and Azure backends - `SFTPGO_ACTION_BUCKET`, non-empty for S3, GCS and Azure backends
- `SFTPGO_ACTION_ENDPOINT`, non-empty for S3, SFTP and Azure backend if configured. For Azure this is the endpoint, if configured - `SFTPGO_ACTION_ENDPOINT`, non-empty for S3, SFTP and Azure backend if configured. For Azure this is the endpoint, if configured
- `SFTPGO_ACTION_STATUS`, integer. Status for `upload`, `download` and `ssh_cmd` actions. 0 means a generic error occurred. 1 means no error, 2 means quota exceeded error - `SFTPGO_ACTION_STATUS`, integer. Status for `upload`, `download` and `ssh_cmd` actions. 0 means a generic error occurred. 1 means no error, 2 means quota exceeded error
- `SFTPGO_ACTION_PROTOCOL`, string. Possible values are `SSH`, `SFTP`, `SCP`, `FTP`, `DAV`, `HTTP` - `SFTPGO_ACTION_PROTOCOL`, string. Possible values are `SSH`, `SFTP`, `SCP`, `FTP`, `DAV`, `HTTP`, `DataRetention`
- `SFTPGO_ACTION_OPEN_FLAGS`, integer. File open flags, can be non-zero for `pre-upload` action. If `SFTPGO_ACTION_FILE_SIZE` is greater than zero and `SFTPGO_ACTION_OPEN_FLAGS&512 == 0` the target file will not be truncated - `SFTPGO_ACTION_OPEN_FLAGS`, integer. File open flags, can be non-zero for `pre-upload` action. If `SFTPGO_ACTION_FILE_SIZE` is greater than zero and `SFTPGO_ACTION_OPEN_FLAGS&512 == 0` the target file will not be truncated
Previous global environment variables aren't cleared when the script is called. Previous global environment variables aren't cleared when the script is called.
@ -63,7 +63,7 @@ If the `hook` defines an HTTP URL then this URL will be invoked as HTTP POST. Th
- `bucket`, inlcuded for S3, GCS and Azure backends - `bucket`, inlcuded for S3, GCS and Azure backends
- `endpoint`, included for S3, SFTP and Azure backend if configured. For Azure this is the endpoint, if configured - `endpoint`, included for S3, SFTP and Azure backend if configured. For Azure this is the endpoint, if configured
- `status`, integer. Status for `upload`, `download` and `ssh_cmd` actions. 0 means a generic error occurred. 1 means no error, 2 means quota exceeded error - `status`, integer. Status for `upload`, `download` and `ssh_cmd` actions. 0 means a generic error occurred. 1 means no error, 2 means quota exceeded error
- `protocol`, string. Possible values are `SSH`, `SFTP`, `SCP`, `FTP`, `DAV`, `HTTP` - `protocol`, string. Possible values are `SSH`, `SFTP`, `SCP`, `FTP`, `DAV`, `HTTP`, `DataRetention`
- `open_flags`, integer. File open flags, can be non-zero for `pre-upload` action. If `file_size` is greater than zero and `file_size&512 == 0` the target file will not be truncated - `open_flags`, integer. File open flags, can be non-zero for `pre-upload` action. If `file_size` is greater than zero and `file_size&512 == 0` the target file will not be truncated
The HTTP hook will use the global configuration for HTTP clients and will respect the retry configurations. The HTTP hook will use the global configuration for HTTP clients and will respect the retry configurations.
@ -101,4 +101,4 @@ The structure for SFTPGo users can be found within the [OpenAPI schema](../httpd
## Pub/Sub services ## Pub/Sub services
You can forward SFTPGo events to serveral publish/subscribe systems using the [sftpgo-plugin-pubsub](https://github.com/sftpgo/sftpgo-plugin-pubsub). The notifiers SFTPGo plugins are not suitable for interactive actions such as `pre-*` events. Their scope is to simply forward events to external services. A custom hook is a better choice if you need to react to `pre-*` events. You can forward SFTPGo events to several publish/subscribe systems using the [sftpgo-plugin-pubsub](https://github.com/sftpgo/sftpgo-plugin-pubsub). The notifiers SFTPGo plugins are not suitable for interactive actions such as `pre-*` events. Their scope is to simply forward events to external services. A custom hook is a better choice if you need to react to `pre-*` events.

View file

@ -20,7 +20,7 @@ The logs can be divided into the following categories:
- `username`, string - `username`, string
- `file_path` string - `file_path` string
- `connection_id` string. Unique connection identifier - `connection_id` string. Unique connection identifier
- `protocol` string. `SFTP`, `SCP`, `SSH`, `FTP`, `HTTP`, `DAV` - `protocol` string. `SFTP`, `SCP`, `SSH`, `FTP`, `HTTP`, `DAV`, `DataRetention`
- `ftp_mode`, string. `active` or `passive`. Included only for `FTP` protocol - `ftp_mode`, string. `active` or `passive`. Included only for `FTP` protocol
- **"command logs"**, SFTP/SCP command logs: - **"command logs"**, SFTP/SCP command logs:
- `sender` string. `Rename`, `Rmdir`, `Mkdir`, `Symlink`, `Remove`, `Chmod`, `Chown`, `Chtimes`, `Truncate`, `SSHCommand` - `sender` string. `Rename`, `Rmdir`, `Mkdir`, `Symlink`, `Remove`, `Chmod`, `Chown`, `Chtimes`, `Truncate`, `SSHCommand`