Skip to content

Commit 3d689dd

Browse files
fix: reject non-YAML extensions for --sqlconfig flag
1 parent fb4625f commit 3d689dd

16 files changed

Lines changed: 3653 additions & 3646 deletions

File tree

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@ sqlcmd config connection-strings
8484
sqlcmd config view
8585
```
8686

87+
#### Custom Configuration Files
88+
89+
The `--sqlconfig` flag specifies a custom configuration file. Files must be **YAML format** with a `.yaml` or `.yml` extension:
90+
91+
```
92+
sqlcmd config --sqlconfig ./myproject.yaml add-endpoint --name ep1434 --address localhost --port 1434
93+
sqlcmd config --sqlconfig ./myproject.yaml view
94+
```
95+
96+
The default file (`~/.sqlcmd/sqlconfig`) has no extension but is also YAML.
97+
8798
### Versions
8899

89100
To see all version tags to choose from (2017, 2019, 2022 etc.), and install a specific version, run:

cmd/modern/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (c *Root) addGlobalFlags() {
121121
String: &c.configFilename,
122122
DefaultString: config.DefaultFileName(),
123123
Name: "sqlconfig",
124-
Usage: localizer.Sprintf("configuration file"),
124+
Usage: localizer.Sprintf("YAML configuration file (.yaml or .yml extension)"),
125125
})
126126

127127
/* BUG(stuartpa): - At the moment this is a top level flag, but it doesn't

internal/config/config.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
package config
55

66
import (
7+
"fmt"
8+
"os"
9+
"path/filepath"
10+
"strings"
11+
"testing"
12+
713
. "github.com/microsoft/go-sqlcmd/cmd/modern/sqlconfig"
814
"github.com/microsoft/go-sqlcmd/internal/io/file"
915
"github.com/microsoft/go-sqlcmd/internal/io/folder"
1016
"github.com/microsoft/go-sqlcmd/internal/pal"
11-
"os"
12-
"path/filepath"
13-
"testing"
1417
)
1518

1619
var config Sqlconfig
@@ -24,6 +27,14 @@ func SetFileName(name string) {
2427
panic("name is empty")
2528
}
2629

30+
ext := strings.ToLower(filepath.Ext(name))
31+
if ext != "" && ext != ".yaml" && ext != ".yml" {
32+
checkErr(fmt.Errorf(
33+
"configuration file %q has unsupported extension %q (must be .yaml or .yml)",
34+
name, ext))
35+
return
36+
}
37+
2738
filename = name
2839

2940
file.CreateEmptyIfNotExists(filename)

internal/config/config_test.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
package config
55

66
import (
7+
"os"
8+
"reflect"
9+
"strings"
10+
"testing"
11+
712
. "github.com/microsoft/go-sqlcmd/cmd/modern/sqlconfig"
813
"github.com/microsoft/go-sqlcmd/internal/output"
914
"github.com/microsoft/go-sqlcmd/internal/pal"
1015
"github.com/microsoft/go-sqlcmd/internal/secret"
1116
"github.com/stretchr/testify/assert"
12-
"os"
13-
"reflect"
14-
"strings"
15-
"testing"
1617
)
1718

1819
func TestConfig(t *testing.T) {
@@ -392,6 +393,13 @@ func TestNegConfig_SetFileName(t *testing.T) {
392393
})
393394
}
394395

396+
func TestNegConfig_SetFileNameBadExtension(t *testing.T) {
397+
assert.Panics(t, func() { SetFileName("foo.json") })
398+
assert.Panics(t, func() { SetFileName("config.toml") })
399+
assert.NotPanics(t, func() { SetFileName(pal.FilenameInUserHomeDotDirectory(".sqlcmd", "sqlconfig-test-yaml.yaml")) })
400+
assert.NotPanics(t, func() { SetFileName(pal.FilenameInUserHomeDotDirectory(".sqlcmd", "sqlconfig-test-yml.yml")) })
401+
}
402+
395403
func TestNegConfig_SetCurrentContextName(t *testing.T) {
396404
assert.Panics(t, func() {
397405
SetCurrentContextName("does not exist")

internal/translations/catalog.go

Lines changed: 3582 additions & 3585 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/translations/locales/de-DE/out.gotext.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,9 @@
4747
"fuzzy": true
4848
},
4949
{
50-
"id": "configuration file",
51-
"message": "configuration file",
52-
"translation": "Konfigurationsdatei",
53-
"translatorComment": "Copied from source.",
54-
"fuzzy": true
50+
"id": "YAML configuration file (.yaml or .yml extension)",
51+
"message": "YAML configuration file (.yaml or .yml extension)",
52+
"translation": ""
5553
},
5654
{
5755
"id": "log level, error=0, warn=1, info=2, debug=3, trace=4",

internal/translations/locales/en-US/out.gotext.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@
4747
"fuzzy": true
4848
},
4949
{
50-
"id": "configuration file",
51-
"message": "configuration file",
52-
"translation": "configuration file",
50+
"id": "YAML configuration file (.yaml or .yml extension)",
51+
"message": "YAML configuration file (.yaml or .yml extension)",
52+
"translation": "YAML configuration file (.yaml or .yml extension)",
5353
"translatorComment": "Copied from source.",
5454
"fuzzy": true
5555
},

internal/translations/locales/es-ES/out.gotext.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,9 @@
4747
"fuzzy": true
4848
},
4949
{
50-
"id": "configuration file",
51-
"message": "configuration file",
52-
"translation": "archivo de configuración",
53-
"translatorComment": "Copied from source.",
54-
"fuzzy": true
50+
"id": "YAML configuration file (.yaml or .yml extension)",
51+
"message": "YAML configuration file (.yaml or .yml extension)",
52+
"translation": ""
5553
},
5654
{
5755
"id": "log level, error=0, warn=1, info=2, debug=3, trace=4",

internal/translations/locales/fr-FR/out.gotext.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,9 @@
4747
"fuzzy": true
4848
},
4949
{
50-
"id": "configuration file",
51-
"message": "configuration file",
52-
"translation": "fichier de configuration",
53-
"translatorComment": "Copied from source.",
54-
"fuzzy": true
50+
"id": "YAML configuration file (.yaml or .yml extension)",
51+
"message": "YAML configuration file (.yaml or .yml extension)",
52+
"translation": ""
5553
},
5654
{
5755
"id": "log level, error=0, warn=1, info=2, debug=3, trace=4",

internal/translations/locales/it-IT/out.gotext.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,9 @@
4747
"fuzzy": true
4848
},
4949
{
50-
"id": "configuration file",
51-
"message": "configuration file",
52-
"translation": "file di configurazione",
53-
"translatorComment": "Copied from source.",
54-
"fuzzy": true
50+
"id": "YAML configuration file (.yaml or .yml extension)",
51+
"message": "YAML configuration file (.yaml or .yml extension)",
52+
"translation": ""
5553
},
5654
{
5755
"id": "log level, error=0, warn=1, info=2, debug=3, trace=4",

0 commit comments

Comments
 (0)