Skip to content

Commit 32948a1

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

16 files changed

Lines changed: 3647 additions & 3639 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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
package config
55

66
import (
7+
"fmt"
78
. "github.com/microsoft/go-sqlcmd/cmd/modern/sqlconfig"
89
"github.com/microsoft/go-sqlcmd/internal/io/file"
910
"github.com/microsoft/go-sqlcmd/internal/io/folder"
1011
"github.com/microsoft/go-sqlcmd/internal/pal"
1112
"os"
1213
"path/filepath"
14+
"strings"
1315
"testing"
1416
)
1517

@@ -24,6 +26,13 @@ func SetFileName(name string) {
2426
panic("name is empty")
2527
}
2628

29+
ext := strings.ToLower(filepath.Ext(name))
30+
if ext != "" && ext != ".yaml" && ext != ".yml" {
31+
panic(fmt.Sprintf(
32+
"configuration file %q has unsupported extension %q (must be .yaml or .yml)",
33+
name, ext))
34+
}
35+
2736
filename = name
2837

2938
file.CreateEmptyIfNotExists(filename)

internal/config/config_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,17 @@ func TestNegConfig_SetFileName(t *testing.T) {
392392
})
393393
}
394394

395+
func TestNegConfig_SetFileNameBadExtension(t *testing.T) {
396+
assert.PanicsWithValue(t,
397+
`configuration file "foo.json" has unsupported extension ".json" (must be .yaml or .yml)`,
398+
func() { SetFileName("foo.json") })
399+
assert.PanicsWithValue(t,
400+
`configuration file "config.toml" has unsupported extension ".toml" (must be .yaml or .yml)`,
401+
func() { SetFileName("config.toml") })
402+
assert.NotPanics(t, func() { SetFileName(pal.FilenameInUserHomeDotDirectory(".sqlcmd", "sqlconfig-test-yaml.yaml")) })
403+
assert.NotPanics(t, func() { SetFileName(pal.FilenameInUserHomeDotDirectory(".sqlcmd", "sqlconfig-test-yml.yml")) })
404+
}
405+
395406
func TestNegConfig_SetCurrentContextName(t *testing.T) {
396407
assert.Panics(t, func() {
397408
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)