Name the S3 keys when storage_url moves to s3:// first (closes #428)
check / check (push) Successful in 18m8s
check / check (push) Successful in 18m8s
On a config that loads, `config set storage_url s3://...` is refused until `s3.access_key_id` and `s3.secret_access_key` are set. The refusal now says to set those two keys first, then `storage_url`. Model: opus-5-5
This commit is contained in:
1 parent
d8d13d1c8b
commit
45d758e08e
3 files changed
+78
-7
No files matched your search
+22
-1
@@ -49,8 +49,14 @@ var (
|
||||
errWouldNotLoad = errors.New(
|
||||
"vaultik would not load the config after this change, " +
|
||||
"so the file was not changed")
|
||||
errSetS3KeysFirst = errors.New(
|
||||
"set s3.access_key_id and s3.secret_access_key first, " +
|
||||
"then storage_url")
|
||||
)
|
||||
|
||||
// storageURLKey is the config key that selects the storage backend.
|
||||
const storageURLKey = "storage_url"
|
||||
|
||||
// macOS is the value of runtime.GOOS on macOS.
|
||||
const macOS = "darwin"
|
||||
|
||||
@@ -512,7 +518,7 @@ func writeConfigSet(out *ui.Writer, path, key, value string) error {
|
||||
|
||||
err = checkConfigChange(oldData, data, settingData)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: %w", errWouldNotLoad, err)
|
||||
return wouldNotLoadError(key, err)
|
||||
}
|
||||
|
||||
err = os.WriteFile(path, data, configFileMode)
|
||||
@@ -536,6 +542,21 @@ func writeConfigSet(out *ui.Writer, path, key, value string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// wouldNotLoadError returns the refusal of a change to key that vaultik
|
||||
// would not load for reason. When storage_url moves to s3:// before the S3
|
||||
// credentials are set, it says to set them first: they can be set while
|
||||
// the old storage_url is still in place.
|
||||
func wouldNotLoadError(key string, reason error) error {
|
||||
if key == storageURLKey &&
|
||||
(errors.Is(reason, config.ErrS3KeyIDRequired) ||
|
||||
errors.Is(reason, config.ErrS3SecretRequired)) {
|
||||
return fmt.Errorf("%w: %w; %w", errWouldNotLoad, reason,
|
||||
errSetS3KeysFirst)
|
||||
}
|
||||
|
||||
return fmt.Errorf("%w: %w", errWouldNotLoad, reason)
|
||||
}
|
||||
|
||||
// checkConfigChange returns the reason vaultik would not load newData, the
|
||||
// config after a change, if the change brings that failure in. If oldData,
|
||||
// the config before it, loads, the new one must load too. A config that
|
||||
|
||||
Reference in new issue
Block a user