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
@@ -2,14 +2,20 @@ package storage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"go.uber.org/fx"
|
||||
"sneak.berlin/go/vaultik/internal/config"
|
||||
"sneak.berlin/go/vaultik/internal/s3"
|
||||
"sneak.berlin/go/vaultik/internal/storageurl"
|
||||
)
|
||||
|
||||
// ErrUnsupportedStorage is returned for a parsed storage URL whose scheme
|
||||
// has no storage backend.
|
||||
var ErrUnsupportedStorage = errors.New("unsupported storage scheme")
|
||||
|
||||
// defaultS3Region is used when neither the URL nor the config specify one.
|
||||
const defaultS3Region = "us-east-1"
|
||||
|
||||
@@ -40,19 +46,19 @@ func NewStorer(cfg *config.Config) (Storer, error) {
|
||||
|
||||
//nolint:ireturn // factory intentionally returns the Storer interface
|
||||
func storerFromURL(rawURL string, cfg *config.Config) (Storer, error) {
|
||||
parsed, err := ParseStorageURL(rawURL)
|
||||
parsed, err := storageurl.Parse(rawURL)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("parsing storage URL: %w", err)
|
||||
}
|
||||
|
||||
switch parsed.Scheme {
|
||||
case schemeFile:
|
||||
case storageurl.SchemeFile:
|
||||
return NewFileStorer(parsed.Prefix)
|
||||
|
||||
case schemeS3:
|
||||
case storageurl.SchemeS3:
|
||||
return storerFromParsedS3URL(parsed, cfg)
|
||||
|
||||
case schemeRclone:
|
||||
case storageurl.SchemeRclone:
|
||||
return NewRcloneStorer(
|
||||
context.Background(), parsed.RcloneRemote, parsed.Prefix)
|
||||
|
||||
@@ -65,7 +71,7 @@ func storerFromURL(rawURL string, cfg *config.Config) (Storer, error) {
|
||||
// filling endpoint protocol and region defaults from the config.
|
||||
//
|
||||
//nolint:ireturn // factory intentionally returns the Storer interface
|
||||
func storerFromParsedS3URL(parsed *URL, cfg *config.Config) (Storer, error) {
|
||||
func storerFromParsedS3URL(parsed *storageurl.URL, cfg *config.Config) (Storer, error) {
|
||||
// Build endpoint URL
|
||||
endpoint := parsed.Endpoint
|
||||
if endpoint == "" {
|
||||
|
||||
Reference in new issue
Block a user