Check storage_url with the storage parser at config load (closes #468)
check / check (push) Waiting to run
check / check (push) Waiting to run
config set accepted rclone:// values that every command then refused: no remote name, parameters in the remote name, a query parameter. The config only checked the URL's prefix, because config could not import the parser from storage, which imports config. The parser moves from internal/storage to a new package, internal/storageurl, that both import. ParseStorageURL becomes storageurl.Parse. Loading the config now runs it on every storage_url, so config set refuses such a value and leaves the file unchanged. Model: opus-5-5
This commit is contained in:
1 parent
d747ddef3a
commit
4e084a2746
8 files changed
+133
-129
No files matched your search
+24
-37
@@ -21,6 +21,7 @@ import (
|
||||
"gopkg.in/yaml.v3"
|
||||
"sneak.berlin/go/vaultik/internal/chunker"
|
||||
"sneak.berlin/go/vaultik/internal/log"
|
||||
"sneak.berlin/go/vaultik/internal/storageurl"
|
||||
)
|
||||
|
||||
const appName = "vaultik"
|
||||
@@ -63,13 +64,8 @@ var (
|
||||
errBlobSizeTooSmall = errors.New(
|
||||
"blob_size_limit must be at least the largest chunk the chunker can " +
|
||||
"emit (chunk_size times the FastCDC size spread)")
|
||||
errBadCompression = errors.New("compression_level must be between 1 and 19")
|
||||
errBadS3PartSize = errors.New("s3.part_size must be between 5MiB and 5GiB")
|
||||
errBadStorageScheme = errors.New(
|
||||
"storage_url must start with s3://, file://, or rclone://")
|
||||
errFileURLNotAbsolute = errors.New(
|
||||
"a file:// storage_url needs an absolute path, " +
|
||||
"as in file:///path/to/backup")
|
||||
errBadCompression = errors.New("compression_level must be between 1 and 19")
|
||||
errBadS3PartSize = errors.New("s3.part_size must be between 5MiB and 5GiB")
|
||||
errIndexPathNotAbsolute = errors.New(
|
||||
"index_path and VAULTIK_INDEX_PATH need an absolute path, " +
|
||||
"as in ~/.local/share/vaultik/index.sqlite")
|
||||
@@ -557,38 +553,29 @@ func (c *Config) validateStorage() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// validateStorageURL validates URL-based storage configuration. File and
|
||||
// rclone URLs need no credentials; S3 URLs require the legacy s3.*
|
||||
// credential fields. A file URL must name an absolute path: a relative one
|
||||
// would resolve against the working directory, so the destination would
|
||||
// move with it.
|
||||
// validateStorageURL checks storage_url with the same parser that opens
|
||||
// the destination, so a value every command would refuse fails at load.
|
||||
// File and rclone URLs need no credentials; S3 URLs require the legacy
|
||||
// s3.* credential fields.
|
||||
func (c *Config) validateStorageURL() error {
|
||||
switch {
|
||||
case strings.HasPrefix(c.StorageURL, "file://"):
|
||||
// storage.ParseStorageURL applies the same rule, but config
|
||||
// cannot import storage, which imports config.
|
||||
if !strings.HasPrefix(c.StorageURL, "file:///") {
|
||||
return errFileURLNotAbsolute
|
||||
}
|
||||
|
||||
return nil
|
||||
case strings.HasPrefix(c.StorageURL, "rclone://"):
|
||||
// Rclone storage uses rclone's own config
|
||||
return nil
|
||||
case strings.HasPrefix(c.StorageURL, "s3://"):
|
||||
// S3 storage needs credentials
|
||||
if c.S3.AccessKeyID == "" {
|
||||
return fmt.Errorf("%w for s3:// URLs", ErrS3KeyIDRequired)
|
||||
}
|
||||
|
||||
if c.S3.SecretAccessKey == "" {
|
||||
return fmt.Errorf("%w for s3:// URLs", ErrS3SecretRequired)
|
||||
}
|
||||
|
||||
return nil
|
||||
default:
|
||||
return errBadStorageScheme
|
||||
parsed, err := storageurl.Parse(c.StorageURL)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid storage_url: %w", err)
|
||||
}
|
||||
|
||||
if parsed.Scheme != storageurl.SchemeS3 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if c.S3.AccessKeyID == "" {
|
||||
return fmt.Errorf("%w for s3:// URLs", ErrS3KeyIDRequired)
|
||||
}
|
||||
|
||||
if c.S3.SecretAccessKey == "" {
|
||||
return fmt.Errorf("%w for s3:// URLs", ErrS3SecretRequired)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Module exports the config module for fx dependency injection.
|
||||
|
||||
Reference in new issue
Block a user