forked from TrueCloudLab/rclone
config: remove log.Fatal and replace with error passing where possible
This commit is contained in:
parent
bb0b6432ae
commit
3cf6ea848b
3 changed files with 17 additions and 17 deletions
|
@ -29,8 +29,8 @@ rclone config.
|
||||||
|
|
||||||
Use the --auth-no-open-browser to prevent rclone to open auth
|
Use the --auth-no-open-browser to prevent rclone to open auth
|
||||||
link in default browser automatically.`,
|
link in default browser automatically.`,
|
||||||
Run: func(command *cobra.Command, args []string) {
|
RunE: func(command *cobra.Command, args []string) error {
|
||||||
cmd.CheckArgs(1, 3, command, args)
|
cmd.CheckArgs(1, 3, command, args)
|
||||||
config.Authorize(context.Background(), args, noAutoBrowser)
|
return config.Authorize(context.Background(), args, noAutoBrowser)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,8 @@ package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"log"
|
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/rclone/rclone/fs"
|
"github.com/rclone/rclone/fs"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -13,17 +13,17 @@ import (
|
||||||
//
|
//
|
||||||
// rclone authorize "fs name"
|
// rclone authorize "fs name"
|
||||||
// rclone authorize "fs name" "client id" "client secret"
|
// rclone authorize "fs name" "client id" "client secret"
|
||||||
func Authorize(ctx context.Context, args []string, noAutoBrowser bool) {
|
func Authorize(ctx context.Context, args []string, noAutoBrowser bool) error {
|
||||||
ctx = suppressConfirm(ctx)
|
ctx = suppressConfirm(ctx)
|
||||||
switch len(args) {
|
switch len(args) {
|
||||||
case 1, 3:
|
case 1, 3:
|
||||||
default:
|
default:
|
||||||
log.Fatalf("Invalid number of arguments: %d", len(args))
|
return errors.Errorf("invalid number of arguments: %d", len(args))
|
||||||
}
|
}
|
||||||
newType := args[0]
|
newType := args[0]
|
||||||
f := fs.MustFind(newType)
|
f := fs.MustFind(newType)
|
||||||
if f.Config == nil {
|
if f.Config == nil {
|
||||||
log.Fatalf("Can't authorize fs %q", newType)
|
return errors.Errorf("can't authorize fs %q", newType)
|
||||||
}
|
}
|
||||||
// Name used for temporary fs
|
// Name used for temporary fs
|
||||||
name := "**temp-fs**"
|
name := "**temp-fs**"
|
||||||
|
@ -44,4 +44,5 @@ func Authorize(ctx context.Context, args []string, noAutoBrowser bool) {
|
||||||
|
|
||||||
m := fs.ConfigMap(f, name)
|
m := fs.ConfigMap(f, name)
|
||||||
f.Config(ctx, name, m)
|
f.Config(ctx, name, m)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -145,13 +144,13 @@ func Decrypt(b io.ReadSeeker) (io.Reader, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errRemove := os.Remove(envKeyFile)
|
errRemove := os.Remove(envKeyFile)
|
||||||
if errRemove != nil {
|
if errRemove != nil {
|
||||||
log.Fatalf("unable to read obscured config key and unable to delete the temp file: %v", err)
|
return nil, errors.Wrap(err, "unable to read obscured config key and unable to delete the temp file")
|
||||||
}
|
}
|
||||||
log.Fatalf("unable to read obscured config key: %v", err)
|
return nil, errors.Wrap(err, "unable to read obscured config key")
|
||||||
}
|
}
|
||||||
errRemove := os.Remove(envKeyFile)
|
errRemove := os.Remove(envKeyFile)
|
||||||
if errRemove != nil {
|
if errRemove != nil {
|
||||||
log.Fatalf("unable to delete temp file with configKey: %v", err)
|
return nil, errors.Wrap(errRemove, "unable to delete temp file with configKey")
|
||||||
}
|
}
|
||||||
configKey = []byte(obscure.MustReveal(string(obscuredKey)))
|
configKey = []byte(obscure.MustReveal(string(obscuredKey)))
|
||||||
fs.Debugf(nil, "using _RCLONE_CONFIG_KEY_FILE for configKey")
|
fs.Debugf(nil, "using _RCLONE_CONFIG_KEY_FILE for configKey")
|
||||||
|
@ -259,32 +258,32 @@ func SetConfigPassword(password string) error {
|
||||||
if PassConfigKeyForDaemonization {
|
if PassConfigKeyForDaemonization {
|
||||||
tempFile, err := ioutil.TempFile("", "rclone")
|
tempFile, err := ioutil.TempFile("", "rclone")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("cannot create temp file to store configKey: %v", err)
|
return errors.Wrap(err, "cannot create temp file to store configKey")
|
||||||
}
|
}
|
||||||
_, err = tempFile.WriteString(obscure.MustObscure(string(configKey)))
|
_, err = tempFile.WriteString(obscure.MustObscure(string(configKey)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errRemove := os.Remove(tempFile.Name())
|
errRemove := os.Remove(tempFile.Name())
|
||||||
if errRemove != nil {
|
if errRemove != nil {
|
||||||
log.Fatalf("error writing configKey to temp file and also error deleting it: %v", err)
|
return errors.Wrap(err, "error writing configKey to temp file and also error deleting it")
|
||||||
}
|
}
|
||||||
log.Fatalf("error writing configKey to temp file: %v", err)
|
return errors.Wrap(err, "error writing configKey to temp file")
|
||||||
}
|
}
|
||||||
err = tempFile.Close()
|
err = tempFile.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errRemove := os.Remove(tempFile.Name())
|
errRemove := os.Remove(tempFile.Name())
|
||||||
if errRemove != nil {
|
if errRemove != nil {
|
||||||
log.Fatalf("error closing temp file with configKey and also error deleting it: %v", err)
|
return errors.Wrap(err, "error closing temp file with configKey and also error deleting it")
|
||||||
}
|
}
|
||||||
log.Fatalf("error closing temp file with configKey: %v", err)
|
return errors.Wrap(err, "error closing temp file with configKey")
|
||||||
}
|
}
|
||||||
fs.Debugf(nil, "saving configKey to temp file")
|
fs.Debugf(nil, "saving configKey to temp file")
|
||||||
err = os.Setenv("_RCLONE_CONFIG_KEY_FILE", tempFile.Name())
|
err = os.Setenv("_RCLONE_CONFIG_KEY_FILE", tempFile.Name())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errRemove := os.Remove(tempFile.Name())
|
errRemove := os.Remove(tempFile.Name())
|
||||||
if errRemove != nil {
|
if errRemove != nil {
|
||||||
log.Fatalf("unable to set environment variable _RCLONE_CONFIG_KEY_FILE and unable to delete the temp file: %v", err)
|
return errors.Wrap(err, "unable to set environment variable _RCLONE_CONFIG_KEY_FILE and unable to delete the temp file")
|
||||||
}
|
}
|
||||||
log.Fatalf("unable to set environment variable _RCLONE_CONFIG_KEY_FILE: %v", err)
|
return errors.Wrap(err, "unable to set environment variable _RCLONE_CONFIG_KEY_FILE")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in a new issue