Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
remyleone committed Apr 23, 2020
1 parent 160c770 commit 76c05ff
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
11 changes: 10 additions & 1 deletion internal/namespaces/object/v1/custom_config_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"reflect"

"github.com/scaleway/scaleway-cli/internal/core"
Expand Down Expand Up @@ -76,7 +77,7 @@ func configInstallCommand() *core.Command {
if err != nil {
return "", err
}
configPath, err := config.getPath(args.Type)
configPath, err := config.getPath(args.Type, ctx)
if err != nil {
return "", err
}
Expand All @@ -94,6 +95,14 @@ func configInstallCommand() *core.Command {
return "Installation aborted by user", nil
}
}

// Ensure the subfolders for the configuration files are all created
err = os.MkdirAll(filepath.Dir(configPath), 755)
if err != nil {
return "", err
}

// Write the configuration file
err = ioutil.WriteFile(configPath, []byte(newConfig), 0600)
if err != nil {
return "", err
Expand Down
12 changes: 9 additions & 3 deletions internal/namespaces/object/v1/custom_config_install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ func Test_ConfigInstall(t *testing.T) {
Cmd: "scw object config install type=rclone",
Check: core.TestCheckCombine(
func(t *testing.T, ctx *core.CheckFuncCtx) {
_, err := os.Stat(path.Join(tmpDir, ".config", "rclone", "rclone.conf"))
filePath := path.Join(tmpDir, ".config", "rclone", "rclone.conf")
_, err := os.Stat(filePath)
if err != nil {
t.Logf("No file at %s", filePath)
t.Fail()
}
},
Expand All @@ -34,8 +36,10 @@ func Test_ConfigInstall(t *testing.T) {
Cmd: "scw object config install type=mc",
Check: core.TestCheckCombine(
func(t *testing.T, ctx *core.CheckFuncCtx) {
_, err := os.Stat(path.Join(tmpDir, ".mc", "config.json"))
filePath := path.Join(tmpDir, ".mc", "config.json")
_, err := os.Stat(filePath)
if err != nil {
t.Logf("No file at %s", filePath)
t.Fail()
}
},
Expand All @@ -51,8 +55,10 @@ func Test_ConfigInstall(t *testing.T) {
Cmd: "scw object config install type=s3cmd",
Check: core.TestCheckCombine(
func(t *testing.T, ctx *core.CheckFuncCtx) {
_, err := os.Stat(path.Join(tmpDir, ".s3cfg"))
filePath := path.Join(tmpDir, ".s3cfg")
_, err := os.Stat(filePath)
if err != nil {
t.Logf("No file at %s", filePath)
t.Fail()
}
},
Expand Down
9 changes: 3 additions & 6 deletions internal/namespaces/object/v1/s3configfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"encoding/json"
"fmt"
"os"
"path"
"text/template"

Expand Down Expand Up @@ -98,11 +97,9 @@ func newS3Config(ctx context.Context, region scw.Region, name string) (s3config,
return config, nil
}

func (c s3config) getPath(tool s3tool) (string, error) {
homeDir, err := os.UserHomeDir()
if err != nil {
return "", err
}
func (c s3config) getPath(tool s3tool, ctx context.Context) (string, error) {
homeDir := core.ExtractUserHomeDir(ctx)

switch tool {
case s3cmd:
return path.Join(homeDir, ".s3cfg"), nil
Expand Down

0 comments on commit 76c05ff

Please sign in to comment.