mirror of
https://github.com/rclone/rclone
synced 2024-12-26 18:23:45 +01:00
rc: implement core/obscure
This commit is contained in:
parent
1916410316
commit
bc17ca7ed9
@ -7,6 +7,7 @@ import (
|
||||
"runtime"
|
||||
|
||||
"github.com/ncw/rclone/fs"
|
||||
"github.com/ncw/rclone/fs/config/obscure"
|
||||
"github.com/ncw/rclone/fs/version"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
@ -191,3 +192,34 @@ func rcVersion(in Params) (out Params, err error) {
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
Add(Call{
|
||||
Path: "core/obscure",
|
||||
Fn: rcObscure,
|
||||
Title: "Obscures a string passed in.",
|
||||
Help: `
|
||||
Pass a clear string and rclone will obscure it for the config file:
|
||||
- clear - string
|
||||
|
||||
Returns
|
||||
- obscured - string
|
||||
`,
|
||||
})
|
||||
}
|
||||
|
||||
// Return obscured string
|
||||
func rcObscure(in Params) (out Params, err error) {
|
||||
clear, err := in.GetString("clear")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
obscured, err := obscure.Obscure(clear)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out = Params{
|
||||
"obscured": obscured,
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/ncw/rclone/fs"
|
||||
"github.com/ncw/rclone/fs/config/obscure"
|
||||
"github.com/ncw/rclone/fs/version"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@ -93,3 +94,15 @@ func TestCoreVersion(t *testing.T) {
|
||||
v := out["decomposed"].(version.Version)
|
||||
assert.True(t, len(v) >= 2)
|
||||
}
|
||||
|
||||
func TestCoreObscure(t *testing.T) {
|
||||
call := Calls.Get("core/obscure")
|
||||
assert.NotNil(t, call)
|
||||
in := Params{
|
||||
"clear": "potato",
|
||||
}
|
||||
out, err := call.Fn(in)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, out)
|
||||
assert.Equal(t, in["clear"], obscure.MustReveal(out["obscured"].(string)))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user