mirror of https://github.com/rclone/rclone
configfile: add piped config support - fixes #9012
This commit is contained in:
parent
b9586c3e03
commit
233fef5c4d
|
|
@ -2,6 +2,7 @@ package configfile
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
@ -362,3 +363,39 @@ func TestConfigFileSaveSymlinkAbsolute(t *testing.T) {
|
||||||
testSymlink(t, link, target, resolvedTarget)
|
testSymlink(t, link, target, resolvedTarget)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type pipedInput struct {
|
||||||
|
io.Reader
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *pipedInput) Read(b []byte) (int, error) {
|
||||||
|
return p.Reader.Read(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_ *pipedInput) Seek(_ int64, _ int) (int64, error) {
|
||||||
|
return 0, fmt.Errorf("Seek not supported")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPipedConfig(t *testing.T) {
|
||||||
|
t.Run("DoesNotSupportSeeking", func(t *testing.T) {
|
||||||
|
r := &pipedInput{strings.NewReader("")}
|
||||||
|
_, err := r.Seek(0, io.SeekStart)
|
||||||
|
require.Error(t, err)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("IsSupported", func(t *testing.T) {
|
||||||
|
r := &pipedInput{strings.NewReader(configData)}
|
||||||
|
_, err := config.Decrypt(r)
|
||||||
|
require.NoError(t, err)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("PlainTextConfigIsNotConsumedByCryptCheck", func(t *testing.T) {
|
||||||
|
in := &pipedInput{strings.NewReader(configData)}
|
||||||
|
|
||||||
|
r, _ := config.Decrypt(in)
|
||||||
|
got, err := io.ReadAll(r)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
assert.Equal(t, configData, string(got))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -77,8 +77,9 @@ func Decrypt(b io.ReadSeeker) (io.Reader, error) {
|
||||||
if strings.HasPrefix(l, "RCLONE_ENCRYPT_V") {
|
if strings.HasPrefix(l, "RCLONE_ENCRYPT_V") {
|
||||||
return nil, errors.New("unsupported configuration encryption - update rclone for support")
|
return nil, errors.New("unsupported configuration encryption - update rclone for support")
|
||||||
}
|
}
|
||||||
|
// Restore non-seekable plain-text stream to its original state
|
||||||
if _, err := b.Seek(0, io.SeekStart); err != nil {
|
if _, err := b.Seek(0, io.SeekStart); err != nil {
|
||||||
return nil, err
|
return io.MultiReader(strings.NewReader(l+"\n"), r), nil
|
||||||
}
|
}
|
||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue