Skip to content

Commit 12785a3

Browse files
committed
Fix
1 parent 494f939 commit 12785a3

3 files changed

Lines changed: 22 additions & 10 deletions

File tree

internal/namespaces/object/v1/custom_config_install.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"io/ioutil"
77
"os"
8+
"path/filepath"
89
"reflect"
910

1011
"github.com/scaleway/scaleway-cli/internal/core"
@@ -76,7 +77,7 @@ func configInstallCommand() *core.Command {
7677
if err != nil {
7778
return "", err
7879
}
79-
configPath, err := config.getPath(args.Type)
80+
configPath, err := config.getPath(args.Type, ctx)
8081
if err != nil {
8182
return "", err
8283
}
@@ -94,6 +95,14 @@ func configInstallCommand() *core.Command {
9495
return "Installation aborted by user", nil
9596
}
9697
}
98+
99+
// Ensure the subfolders for the configuration files are all created
100+
err = os.MkdirAll(filepath.Dir(configPath), 755)
101+
if err != nil {
102+
return "", err
103+
}
104+
105+
// Write the configuration file
97106
err = ioutil.WriteFile(configPath, []byte(newConfig), 0600)
98107
if err != nil {
99108
return "", err

internal/namespaces/object/v1/custom_config_install_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ func Test_ConfigInstall(t *testing.T) {
1717
Cmd: "scw object config install type=rclone",
1818
Check: core.TestCheckCombine(
1919
func(t *testing.T, ctx *core.CheckFuncCtx) {
20-
_, err := os.Stat(path.Join(tmpDir, ".config", "rclone", "rclone.conf"))
20+
filePath := path.Join(tmpDir, ".config", "rclone", "rclone.conf")
21+
_, err := os.Stat(filePath)
2122
if err != nil {
23+
t.Logf("No file at %s", filePath)
2224
t.Fail()
2325
}
2426
},
@@ -34,8 +36,10 @@ func Test_ConfigInstall(t *testing.T) {
3436
Cmd: "scw object config install type=mc",
3537
Check: core.TestCheckCombine(
3638
func(t *testing.T, ctx *core.CheckFuncCtx) {
37-
_, err := os.Stat(path.Join(tmpDir, ".mc", "config.json"))
39+
filePath := path.Join(tmpDir, ".mc", "config.json")
40+
_, err := os.Stat(filePath)
3841
if err != nil {
42+
t.Logf("No file at %s", filePath)
3943
t.Fail()
4044
}
4145
},
@@ -51,8 +55,10 @@ func Test_ConfigInstall(t *testing.T) {
5155
Cmd: "scw object config install type=s3cmd",
5256
Check: core.TestCheckCombine(
5357
func(t *testing.T, ctx *core.CheckFuncCtx) {
54-
_, err := os.Stat(path.Join(tmpDir, ".s3cfg"))
58+
filePath := path.Join(tmpDir, ".s3cfg")
59+
_, err := os.Stat(filePath)
5560
if err != nil {
61+
t.Logf("No file at %s", filePath)
5662
t.Fail()
5763
}
5864
},

internal/namespaces/object/v1/s3configfile.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"context"
66
"encoding/json"
77
"fmt"
8-
"os"
98
"path"
109
"text/template"
1110

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

101-
func (c s3config) getPath(tool s3tool) (string, error) {
102-
homeDir, err := os.UserHomeDir()
103-
if err != nil {
104-
return "", err
105-
}
100+
func (c s3config) getPath(tool s3tool, ctx context.Context) (string, error) {
101+
homeDir := core.ExtractUserHomeDir(ctx)
102+
106103
switch tool {
107104
case s3cmd:
108105
return path.Join(homeDir, ".s3cfg"), nil

0 commit comments

Comments
 (0)