Skip to content

Commit 653cd5e

Browse files
authored
chore(core): remove v1 config (#1484)
1 parent e8a9a8e commit 653cd5e

File tree

7 files changed

+3
-300
lines changed

7 files changed

+3
-300
lines changed

scw/README.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ The function [`GetConfigPath`](https://godoc.org/github.com/scaleway/scaleway-sd
2323
3. Unix home directory: `$HOME/.config/scw/config.yaml`
2424
4. Windows home directory: `%USERPROFILE%/.config/scw/config.yaml`
2525

26-
## V1 config (DEPRECATED)
27-
28-
The V1 config (AKA legacy config) `.scwrc` is deprecated.
29-
To migrate the V1 config to the new format use the function [`MigrateLegacyConfig`](https://godoc.org/github.com/scaleway/scaleway-sdk-go/scw#MigrateLegacyConfig), this will create a [proper config file](#tl-dr) the new [config file path](#config-file-path).
30-
3126
## Reading config order
3227

3328
[ClientOption](https://godoc.org/github.com/scaleway/scaleway-sdk-go/scw#ClientOption) ordering will decide the order in which the config should apply:

scw/config.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,6 @@ func LoadConfigFromPath(path string) (*Config, error) {
223223
return nil, errors.Wrap(err, "cannot read config file")
224224
}
225225

226-
_, err = unmarshalConfV1(file)
227-
if err == nil {
228-
// reject V1 config
229-
return nil, errors.New("found legacy config in %s: legacy config is not allowed, please switch to the new config file format: %s", path, documentationLink)
230-
}
231-
232226
confV2, err := unmarshalConfV2(file)
233227
if err != nil {
234228
return nil, errors.Wrap(err, "content of config file %s is invalid", path)

scw/config_legacy.go

Lines changed: 0 additions & 92 deletions
This file was deleted.

scw/config_legacy_test.go

Lines changed: 0 additions & 103 deletions
This file was deleted.

scw/config_test.go

Lines changed: 3 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,6 @@ default_region: ` + v2ValidDefaultRegion + `
126126

127127
v2SimpleInvalidConfigFile = `insecure: "bool""`
128128
v2SimpleConfigFileWithInvalidProfile = `active_profile: flantier`
129-
130-
v2FromV1ConfigFile = `secret_key: ` + v1ValidToken + `
131-
default_organization_id: ` + v1ValidOrganizationID + `
132-
default_project_id: ` + v1ValidOrganizationID + `
133-
`
134129
)
135130

136131
// TestSaveConfig tests config write the correct values in the config file
@@ -261,10 +256,9 @@ func TestSaveConfig(t *testing.T) {
261256
// TestLoadConfig tests config getters return correct values
262257
func TestLoadProfileAndActiveProfile(t *testing.T) {
263258
tests := []struct {
264-
name string
265-
env map[string]string
266-
files map[string]string
267-
isMigrated bool
259+
name string
260+
env map[string]string
261+
files map[string]string
268262

269263
expectedError string
270264
expectedAccessKey *string
@@ -326,34 +320,6 @@ func TestLoadProfileAndActiveProfile(t *testing.T) {
326320
expectedDefaultProjectID: s(v2ValidDefaultProjectID),
327321
expectedDefaultRegion: s(v2ValidDefaultRegion),
328322
},
329-
{
330-
name: "Simple config with valid V1",
331-
env: map[string]string{
332-
"HOME": "{HOME}",
333-
},
334-
files: map[string]string{
335-
".scwrc": v1ValidConfigFile,
336-
},
337-
isMigrated: true,
338-
expectedSecretKey: s(v1ValidToken),
339-
expectedDefaultOrganizationID: s(v1ValidOrganizationID),
340-
expectedDefaultProjectID: s(v1ValidOrganizationID),
341-
},
342-
{
343-
name: "Simple config with valid V2 and valid V1",
344-
env: map[string]string{
345-
"HOME": "{HOME}",
346-
},
347-
files: map[string]string{
348-
".config/scw/config.yaml": v2SimpleValidConfigFile,
349-
".scwrc": v1ValidConfigFile,
350-
},
351-
expectedAccessKey: s(v2ValidAccessKey),
352-
expectedSecretKey: s(v2ValidSecretKey),
353-
expectedDefaultOrganizationID: s(v2ValidDefaultOrganizationID),
354-
expectedDefaultProjectID: s(v2ValidDefaultProjectID),
355-
expectedDefaultRegion: s(v2ValidDefaultRegion),
356-
},
357323
{
358324
name: "Complete config",
359325
env: map[string]string{
@@ -426,28 +392,6 @@ func TestLoadProfileAndActiveProfile(t *testing.T) {
426392
expectedDefaultZone: s(v2ValidDefaultZone2),
427393
},
428394

429-
// Valid V1 is not allowed
430-
{
431-
name: "Err: custom-path config with valid V1",
432-
env: map[string]string{
433-
ScwConfigPathEnv: "{HOME}/valid2/test.conf",
434-
},
435-
files: map[string]string{
436-
"valid2/test.conf": v1ValidConfigFile,
437-
},
438-
expectedError: "scaleway-sdk-go: found legacy config in {HOME}/valid2/test.conf: legacy config is not allowed, please switch to the new config file format: " + documentationLink,
439-
},
440-
{
441-
name: "Err: default config with invalid V1",
442-
env: map[string]string{
443-
"HOME": "{HOME}",
444-
},
445-
files: map[string]string{
446-
".scwrc": v1InvalidConfigFile,
447-
},
448-
expectedError: "scaleway-sdk-go: content of config file {HOME}/.scwrc is invalid json: invalid character ':' after top-level value",
449-
},
450-
451395
// Config file config.yaml and config.yml
452396
{
453397
name: "Read config.yml",
@@ -480,16 +424,6 @@ func TestLoadProfileAndActiveProfile(t *testing.T) {
480424
// remove config file(s)
481425
defer cleanEnv(t, test.files, dir)
482426

483-
// load config
484-
isMigrated, err := MigrateLegacyConfig()
485-
486-
if test.expectedError != "" && err != nil {
487-
testhelpers.Equals(t, test.expectedError, err.Error())
488-
return
489-
}
490-
testhelpers.AssertNoError(t, err)
491-
492-
testhelpers.Equals(t, test.isMigrated, isMigrated)
493427
config, err := LoadConfig()
494428
if test.expectedError == "" {
495429
testhelpers.AssertNoError(t, err)

scw/load_config_test.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ import (
1212

1313
// TestLoad tests all valid configuration files:
1414
// - v2 config
15-
// - v1 to v2 config migration
1615
// - custom-path with v2 config
17-
// - custom-path with v1 config
1816
// - XDG config path with v2 config
1917
func TestLoad(t *testing.T) {
2018
tests := []struct {
@@ -59,20 +57,6 @@ func TestLoad(t *testing.T) {
5957
".config/scw/config.yaml": v2SimpleValidConfigFile,
6058
},
6159
},
62-
{
63-
name: "Default config with valid V2 and valid V1",
64-
env: map[string]string{
65-
"HOME": "{HOME}",
66-
},
67-
files: map[string]string{
68-
".config/scw/config.yaml": v2SimpleValidConfigFile,
69-
".scwrc": v1ValidConfigFile,
70-
},
71-
expected: v2SimpleValidConfig,
72-
expectedFiles: map[string]string{
73-
".config/scw/config.yaml": v2SimpleValidConfigFile,
74-
},
75-
},
7660
{
7761
name: "XDG config with valid V2",
7862
env: map[string]string{

scw/path.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,6 @@ func getConfigV2FilePath() (string, bool) {
7070
return filepath.Clean(filepath.Join(configDir, defaultConfigFileName)), true
7171
}
7272

73-
// getConfigV1FilePath returns the path to the v1 config file
74-
func getConfigV1FilePath() (string, bool) {
75-
path, err := os.UserHomeDir()
76-
if err != nil {
77-
return "", false
78-
}
79-
return filepath.Clean(filepath.Join(path, ".scwrc")), true
80-
}
81-
8273
// GetScwConfigDir returns the path to scw config folder
8374
func GetScwConfigDir() (string, error) {
8475
if xdgPath := os.Getenv(xdgConfigDirEnv); xdgPath != "" {

0 commit comments

Comments
 (0)