Skip to content

Commit a63d168

Browse files
authored
feat: Add -A switch (#361)
1 parent 17426d6 commit a63d168

File tree

9 files changed

+62
-64
lines changed

9 files changed

+62
-64
lines changed

NOTICE.md

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ SOFTWARE
3737
## github.com/Azure/azure-sdk-for-go/sdk/azidentity
3838

3939
* Name: github.com/Azure/azure-sdk-for-go/sdk/azidentity
40-
* Version: v1.1.0
41-
* License: [MIT](https://github.com/Azure/azure-sdk-for-go/blob/sdk/azidentity/v1.1.0/sdk/azidentity/LICENSE.txt)
40+
* Version: v1.2.1
41+
* License: [MIT](https://github.com/Azure/azure-sdk-for-go/blob/sdk/azidentity/v1.2.1/sdk/azidentity/LICENSE.txt)
4242

4343
```
4444
MIT License
@@ -99,8 +99,8 @@ SOFTWARE
9999
## github.com/AzureAD/microsoft-authentication-library-for-go/apps
100100

101101
* Name: github.com/AzureAD/microsoft-authentication-library-for-go/apps
102-
* Version: v0.5.1
103-
* License: [MIT](https://github.com/AzureAD/microsoft-authentication-library-for-go/blob/v0.5.1/LICENSE)
102+
* Version: v0.8.1
103+
* License: [MIT](https://github.com/AzureAD/microsoft-authentication-library-for-go/blob/v0.8.1/LICENSE)
104104

105105
```
106106
MIT License
@@ -188,35 +188,6 @@ SOFTWARE.
188188
189189
```
190190

191-
## github.com/alecthomas/kong
192-
193-
* Name: github.com/alecthomas/kong
194-
* Version: v0.6.2-0.20220922001058-c62bf25854a0
195-
* License: [MIT](https://github.com/alecthomas/kong/blob/c62bf25854a0/COPYING)
196-
197-
```
198-
Copyright (C) 2018 Alec Thomas
199-
200-
Permission is hereby granted, free of charge, to any person obtaining a copy of
201-
this software and associated documentation files (the "Software"), to deal in
202-
the Software without restriction, including without limitation the rights to
203-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
204-
of the Software, and to permit persons to whom the Software is furnished to do
205-
so, subject to the following conditions:
206-
207-
The above copyright notice and this permission notice shall be included in all
208-
copies or substantial portions of the Software.
209-
210-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
211-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
212-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
213-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
214-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
215-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
216-
SOFTWARE.
217-
218-
```
219-
220191
## github.com/beorn7/perks/quantile
221192

222193
* Name: github.com/beorn7/perks/quantile
@@ -344,8 +315,8 @@ SOFTWARE.
344315
## github.com/docker/distribution
345316

346317
* Name: github.com/docker/distribution
347-
* Version: v2.8.1
348-
* License: [Apache-2.0](https://github.com/docker/distribution/blob/v2.8.1/LICENSE)
318+
* Version: v2.8.2
319+
* License: [Apache-2.0](https://github.com/docker/distribution/blob/v2.8.2/LICENSE)
349320

350321
```
351322
Apache License
@@ -1437,11 +1408,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14371408
14381409
```
14391410

1440-
## github.com/golang-jwt/jwt
1411+
## github.com/golang-jwt/jwt/v4
14411412

1442-
* Name: github.com/golang-jwt/jwt
1443-
* Version: v3.2.2
1444-
* License: [MIT](https://github.com/golang-jwt/jwt/blob/v3.2.2/LICENSE)
1413+
* Name: github.com/golang-jwt/jwt/v4
1414+
* Version: v4.4.2
1415+
* License: [MIT](https://github.com/golang-jwt/jwt/blob/v4.4.2/LICENSE)
14451416

14461417
```
14471418
Copyright (c) 2012 Dave Grijalva

cmd/sqlcmd/sqlcmd.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ type SQLCmdArguments struct {
6363
TrimSpaces bool
6464
MultiSubnetFailover bool
6565
Password string
66+
DedicatedAdminConnection bool
6667
// Keep Help at the end of the list
6768
Help bool
6869
}
@@ -232,10 +233,10 @@ func setFlags(rootCmd *cobra.Command, args *SQLCmdArguments) {
232233

233234
// Using PersistentFlags() for ErrorSeverityLevel due to data type uint8 , which is not supported in Flags()
234235
rootCmd.PersistentFlags().Uint8VarP(&args.ErrorSeverityLevel, "error-severity-level", "V", 0, "Controls the severity level that is used to set the ERRORLEVEL variable on exit.")
235-
236236
var screenWidth int
237237
screenWidthPtr := &screenWidth
238238
rootCmd.Flags().IntVarP(screenWidthPtr, "screen-width", "w", 0, localizer.Sprintf("Specifies the screen width for output"))
239+
rootCmd.Flags().BoolVarP(&args.DedicatedAdminConnection, "dedicated-admin-connection", "A", false, localizer.Sprintf("Dedicated administrator connection"))
239240
}
240241

241242
func normalizeFlags(rootCmd *cobra.Command) error {
@@ -388,6 +389,7 @@ func setConnect(connect *sqlcmd.ConnectSettings, args *SQLCmdArguments, vars *sq
388389
connect.LogLevel = args.DriverLoggingLevel
389390
connect.ExitOnError = args.ExitOnError
390391
connect.ErrorSeverityLevel = args.ErrorSeverityLevel
392+
connect.DedicatedAdminConnection = args.DedicatedAdminConnection
391393
}
392394

393395
func isConsoleInitializationRequired(connect *sqlcmd.ConnectSettings, args *SQLCmdArguments) bool {

cmd/sqlcmd/sqlcmd_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package sqlcmd
55

66
import (
7+
"bytes"
78
"os"
89
"path/filepath"
910
"runtime"
@@ -68,8 +69,8 @@ func TestValidCommandLineToArgsConversion(t *testing.T) {
6869
{[]string{"-h", "2", "-?"}, func(args SQLCmdArguments) bool {
6970
return args.Help && args.Headers == 2
7071
}},
71-
{[]string{"-u"}, func(args SQLCmdArguments) bool {
72-
return args.UnicodeOutputFile
72+
{[]string{"-u", "-A"}, func(args SQLCmdArguments) bool {
73+
return args.UnicodeOutputFile && args.DedicatedAdminConnection
7374
}},
7475
{[]string{"--version"}, func(args SQLCmdArguments) bool {
7576
return args.Version
@@ -98,7 +99,10 @@ func TestValidCommandLineToArgsConversion(t *testing.T) {
9899
Run: func(cmd *cobra.Command, argss []string) {
99100
// Command logic goes here
100101
},
102+
SilenceErrors: true,
103+
SilenceUsage: true,
101104
}
105+
cmd.SetOut(new(bytes.Buffer))
102106
setFlags(cmd, arguments)
103107
cmd.SetArgs(test.commandLine)
104108
err := cmd.Execute()
@@ -136,6 +140,8 @@ func TestInvalidCommandLine(t *testing.T) {
136140
},
137141
Run: func(cmd *cobra.Command, argss []string) {
138142
},
143+
SilenceErrors: true,
144+
SilenceUsage: true,
139145
}
140146
setFlags(cmd, arguments)
141147
cmd.SetArgs(test.commandLine)
@@ -169,6 +175,8 @@ func TestValidateFlags(t *testing.T) {
169175
},
170176
Run: func(cmd *cobra.Command, argss []string) {
171177
},
178+
SilenceErrors: true,
179+
SilenceUsage: true,
172180
}
173181

174182
setFlags(cmd, arguments)

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/docker/go-connections v0.4.0
1111
github.com/golang-sql/sqlexp v0.1.0
1212
github.com/google/uuid v1.3.0
13-
github.com/microsoft/go-mssqldb v0.20.0
13+
github.com/microsoft/go-mssqldb v1.0.0
1414
github.com/opencontainers/image-spec v1.0.2
1515
github.com/peterh/liner v1.2.2
1616
github.com/pkg/errors v0.9.1
@@ -26,9 +26,9 @@ require (
2626

2727
require (
2828
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.1.2 // indirect
29-
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.1.0 // indirect
29+
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.1 // indirect
3030
github.com/Azure/azure-sdk-for-go/sdk/internal v1.0.0 // indirect
31-
github.com/AzureAD/microsoft-authentication-library-for-go v0.5.1 // indirect
31+
github.com/AzureAD/microsoft-authentication-library-for-go v0.8.1 // indirect
3232
github.com/Microsoft/go-winio v0.6.0 // indirect
3333
github.com/beorn7/perks v1.0.1 // indirect
3434
github.com/cespare/xxhash/v2 v2.1.1 // indirect
@@ -39,7 +39,7 @@ require (
3939
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 // indirect
4040
github.com/fsnotify/fsnotify v1.6.0 // indirect
4141
github.com/gogo/protobuf v1.3.2 // indirect
42-
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
42+
github.com/golang-jwt/jwt/v4 v4.4.2 // indirect
4343
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe // indirect
4444
github.com/golang/protobuf v1.5.2 // indirect
4545
github.com/gorilla/mux v1.8.0 // indirect

go.sum

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7
3939
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.0.0/go.mod h1:uGG2W01BaETf0Ozp+QxxKJdMBNRWPdstHG0Fmdwn1/U=
4040
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.1.2 h1:lneMk5qtUMulXa/eVxjVd+/bDYMEDIqYpLzLa2/EsNI=
4141
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.1.2/go.mod h1:uGG2W01BaETf0Ozp+QxxKJdMBNRWPdstHG0Fmdwn1/U=
42-
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.1.0 h1:QkAcEIAKbNL4KoFr4SathZPhDhF4mVwpBMFlYjyAqy8=
43-
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.1.0/go.mod h1:bhXu1AjYL+wutSL/kpSq6s7733q2Rb0yuot9Zgfqa/0=
42+
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.1 h1:T8quHYlUGyb/oqtSTwqlCr1ilJHrDv+ZtpSfo+hm1BU=
43+
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.1/go.mod h1:gLa1CL2RNE4s7M3yopJ/p0iq5DdY6Yv5ZUt9MTRZOQM=
4444
github.com/Azure/azure-sdk-for-go/sdk/internal v1.0.0 h1:jp0dGvZ7ZK0mgqnTSClMxa5xuRL7NZgHameVYF6BurY=
4545
github.com/Azure/azure-sdk-for-go/sdk/internal v1.0.0/go.mod h1:eWRD7oawr1Mu1sLCawqVc0CUiF43ia3qQMxLscsKQ9w=
4646
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
47-
github.com/AzureAD/microsoft-authentication-library-for-go v0.5.1 h1:BWe8a+f/t+7KY7zH2mqygeUD0t8hNFXe08p1Pb3/jKE=
48-
github.com/AzureAD/microsoft-authentication-library-for-go v0.5.1/go.mod h1:Vt9sXTKwMyGcOxSmLDMnGPgqsUg7m8pe215qMLrDXw4=
47+
github.com/AzureAD/microsoft-authentication-library-for-go v0.8.1 h1:oPdPEZFSbl7oSPEAIPMPBMUmiL+mqgzBJwM/9qYcwNg=
48+
github.com/AzureAD/microsoft-authentication-library-for-go v0.8.1/go.mod h1:4qFor3D/HDsvBME35Xy9rwW9DecL+M2sNw1ybjPtwA0=
4949
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
5050
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
5151
github.com/Microsoft/go-winio v0.6.0 h1:slsWYD/zyx7lCXoZVlvQrj0hPTM1HI4+v1sIda2yDvg=
@@ -119,11 +119,8 @@ github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/me
119119
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
120120
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
121121
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
122-
github.com/golang-jwt/jwt v3.2.1+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
123-
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
124-
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
125-
github.com/golang-jwt/jwt/v4 v4.2.0 h1:besgBTC8w8HjP6NzQdxwKH9Z5oQMZ24ThTrHp3cZ8eU=
126-
github.com/golang-jwt/jwt/v4 v4.2.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg=
122+
github.com/golang-jwt/jwt/v4 v4.4.2 h1:rcc4lwaZgFMCZ5jxF9ABolDcIHdBytAFgqFPbSJQAYs=
123+
github.com/golang-jwt/jwt/v4 v4.4.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
127124
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY=
128125
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
129126
github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A=
@@ -239,8 +236,8 @@ github.com/mattn/go-runewidth v0.0.3 h1:a+kO+98RDGEfo6asOGMmpodZq4FNtnGP54yps8Bz
239236
github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
240237
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
241238
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
242-
github.com/microsoft/go-mssqldb v0.20.0 h1:jAfvs5TIR311fEuNgohFzMtUO0IcCHyI1kWAVws4ES8=
243-
github.com/microsoft/go-mssqldb v0.20.0/go.mod h1:ukJCBnnzLzpVF0qYRT+eg1e+eSwjeQ7IvenUv8QPook=
239+
github.com/microsoft/go-mssqldb v1.0.0 h1:k2p2uuG8T5T/7Hp7/e3vMGTnnR0sU4h8d1CcC71iLHU=
240+
github.com/microsoft/go-mssqldb v1.0.0/go.mod h1:+4wZTUnz/SV6nffv+RRRB/ss8jPng5Sho2SmM1l2ts4=
244241
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
245242
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
246243
github.com/moby/term v0.0.0-20221120202655-abb19827d345 h1:J9c53/kxIH+2nTKBEfZYFMlhghtHpIHSXpm5VRGHSnU=

pkg/sqlcmd-linter/imports.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var AllowedImports = map[string][]string{
2727
`"github.com/microsoft/go-mssqldb`: {},
2828
`"github.com/microsoft/go-sqlcmd`: {},
2929
`"github.com/spf13/cobra`: {`cmd/sqlcmd`, `cmd/modern`},
30+
`"github.com/spf13/pflag`: {`cmd/sqlcmd`, `cmd/modern`},
3031
`"github.com/spf13/viper`: {`cmd/sqlcmd`, `cmd/modern`},
3132
`"github.com/stretchr/testify`: {},
3233
}

pkg/sqlcmd/connect.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ type ConnectSettings struct {
5151
Database string
5252
// ApplicationName is the name of the application to be included in the connection string
5353
ApplicationName string
54+
// DedicatedAdminConnection forces the connection to occur over tcp on the dedicated admin port. Requires Browser service access
55+
DedicatedAdminConnection bool
5456
}
5557

5658
func (c ConnectSettings) authenticationMethod() string {
@@ -147,6 +149,9 @@ func (connect ConnectSettings) ConnectionString() (connectionString string, err
147149
if connect.ApplicationName != "" {
148150
query.Add(`app name`, connect.ApplicationName)
149151
}
152+
if connect.DedicatedAdminConnection {
153+
query.Set("protocol", "admin")
154+
}
150155
connectionURL.RawQuery = query.Encode()
151156
return connectionURL.String(), nil
152157
}

pkg/sqlcmd/sqlcmd_test.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ func TestConnectionStringFromSqlCmd(t *testing.T) {
6262
&ConnectSettings{ServerName: `\\someserver\pipe\sql\query`},
6363
"sqlserver://someserver?pipe=sql%5Cquery&protocol=np",
6464
},
65+
{
66+
&ConnectSettings{DedicatedAdminConnection: true},
67+
"sqlserver://.?protocol=admin",
68+
},
69+
{
70+
&ConnectSettings{ServerName: `tcp:someserver`, DedicatedAdminConnection: true},
71+
"sqlserver://someserver?protocol=admin",
72+
},
73+
{
74+
&ConnectSettings{ServerName: `admin:someserver`, DedicatedAdminConnection: true},
75+
"sqlserver://someserver?protocol=admin",
76+
},
6577
}
6678

6779
for i, test := range commands {
@@ -633,7 +645,8 @@ func TestSqlcmdPrefersSharedMemoryProtocol(t *testing.T) {
633645
t.Skip("Only valid on Windows amd64")
634646
}
635647
assert.EqualValuesf(t, "lpc", msdsn.ProtocolParsers[0].Protocol(), "lpc should be first protocol")
636-
assert.EqualValuesf(t, "tcp", msdsn.ProtocolParsers[1].Protocol(), "tcp should be second protocol")
637-
assert.EqualValuesf(t, "np", msdsn.ProtocolParsers[2].Protocol(), "np should be third protocol")
648+
assert.Truef(t, msdsn.ProtocolParsers[1].Hidden(), "Protocol %s should be hidden", msdsn.ProtocolParsers[1].Protocol())
649+
assert.EqualValuesf(t, "tcp", msdsn.ProtocolParsers[2].Protocol(), "tcp should be second protocol")
650+
assert.EqualValuesf(t, "np", msdsn.ProtocolParsers[3].Protocol(), "np should be third protocol")
638651

639652
}

pkg/sqlcmd/sqlcmd_windows_amd64.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ import (
77
)
88

99
func init() {
10-
if len(msdsn.ProtocolParsers) == 3 {
11-
// reorder the protocol parsers to lpc->tcp->np
10+
if len(msdsn.ProtocolParsers) == 4 {
11+
// reorder the protocol parsers to lpc->admin->tcp->np
1212
// ODBC follows this same order.
13+
// Named pipes/shared memory package doesn't support ARM
1314
var tcp = msdsn.ProtocolParsers[0]
14-
msdsn.ProtocolParsers[0] = msdsn.ProtocolParsers[2]
15-
msdsn.ProtocolParsers[2] = msdsn.ProtocolParsers[1]
16-
msdsn.ProtocolParsers[1] = tcp
15+
msdsn.ProtocolParsers[0] = msdsn.ProtocolParsers[3]
16+
msdsn.ProtocolParsers[3] = msdsn.ProtocolParsers[2]
17+
msdsn.ProtocolParsers[2] = tcp
1718
}
1819
}

0 commit comments

Comments
 (0)