-
Notifications
You must be signed in to change notification settings - Fork 84
Add VSCode+MSSQL extension and SSMS support to replace deprecated ADS #685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
162fa57
Initial plan
Copilot c3bc585
Add VSCode support to replace deprecated ADS
Copilot 88988bb
Remove binary artifact and update .gitignore
Copilot 9601624
Address code review feedback
Copilot d89b2f1
Add SSMS (SQL Server Management Studio) support
Copilot d596ea5
Address code review feedback - use ReplaceAll
Copilot 7ef3526
Fix golangci-lint issues and improve localization
Copilot d89a3b5
Fix remaining staticcheck QF1008 warnings
Copilot 85089c9
Update cmd/modern/root/open/vscode_windows.go
dlevy-msft-sql File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| package open | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "runtime" | ||
| "strings" | ||
|
|
||
| "github.com/microsoft/go-sqlcmd/cmd/modern/sqlconfig" | ||
| "github.com/microsoft/go-sqlcmd/internal/cmdparser" | ||
| "github.com/microsoft/go-sqlcmd/internal/config" | ||
| "github.com/microsoft/go-sqlcmd/internal/container" | ||
| "github.com/microsoft/go-sqlcmd/internal/localizer" | ||
| "github.com/microsoft/go-sqlcmd/internal/tools" | ||
| ) | ||
|
|
||
| // Ssms implements the `sqlcmd open ssms` command. It opens | ||
| // SQL Server Management Studio and connects to the current context using the | ||
| // credentials specified in the context. | ||
| func (c *Ssms) DefineCommand(...cmdparser.CommandOptions) { | ||
| options := cmdparser.CommandOptions{ | ||
| Use: "ssms", | ||
| Short: "Open SQL Server Management Studio and connect to current context", | ||
| Examples: []cmdparser.ExampleOptions{{ | ||
| Description: "Open SSMS and connect using the current context", | ||
| Steps: []string{"sqlcmd open ssms"}}}, | ||
| Run: c.run, | ||
| } | ||
|
|
||
| c.Cmd.DefineCommand(options) | ||
| } | ||
|
|
||
| // Launch SSMS and connect to the current context | ||
| func (c *Ssms) run() { | ||
| endpoint, user := config.CurrentContext() | ||
|
|
||
| // If the context has a local container, ensure it is running, otherwise bail out | ||
| if endpoint.AssetDetails != nil && endpoint.AssetDetails.ContainerDetails != nil { | ||
| c.ensureContainerIsRunning(endpoint) | ||
| } | ||
|
|
||
| // Launch SSMS with connection parameters | ||
| c.launchSsms(endpoint.EndpointDetails.Address, endpoint.EndpointDetails.Port, user) | ||
| } | ||
|
|
||
| func (c *Ssms) ensureContainerIsRunning(endpoint sqlconfig.Endpoint) { | ||
| output := c.Output() | ||
| controller := container.NewController() | ||
| if !controller.ContainerRunning(endpoint.AssetDetails.ContainerDetails.Id) { | ||
| output.FatalWithHintExamples([][]string{ | ||
| {localizer.Sprintf("To start the container"), localizer.Sprintf("sqlcmd start")}, | ||
| }, localizer.Sprintf("Container is not running")) | ||
| } | ||
| } | ||
|
|
||
| // launchSsms launches SQL Server Management Studio using the specified server and user credentials. | ||
| func (c *Ssms) launchSsms(host string, port int, user *sqlconfig.User) { | ||
| output := c.Output() | ||
|
|
||
| // Build server connection string | ||
| serverArg := fmt.Sprintf("%s,%d", host, port) | ||
|
|
||
| args := []string{ | ||
| "-S", serverArg, | ||
| "-nosplash", | ||
| } | ||
|
|
||
| // Add authentication parameters | ||
| if user != nil && user.AuthenticationType == "basic" { | ||
| // SQL Server authentication | ||
| // Escape double quotes in username (SQL Server allows " in login names) | ||
| username := strings.ReplaceAll(user.BasicAuth.Username, `"`, `\"`) | ||
| args = append(args, "-U", username) | ||
| // Note: -P parameter was removed in SSMS 18+ for security reasons | ||
| // User will need to enter password in the login dialog | ||
| output.Info(localizer.Sprintf("Note: You will need to enter the password in the SSMS login dialog")) | ||
| } else { | ||
| // Windows integrated authentication | ||
| if runtime.GOOS == "windows" { | ||
| args = append(args, "-E") | ||
| } | ||
| } | ||
|
|
||
| tool := tools.NewTool("ssms") | ||
| if !tool.IsInstalled() { | ||
| output.Fatal(tool.HowToInstall()) | ||
| } | ||
|
|
||
| c.displayPreLaunchInfo() | ||
|
|
||
| _, err := tool.Run(args) | ||
| c.CheckErr(err) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| package open | ||
|
|
||
| import ( | ||
| "github.com/microsoft/go-sqlcmd/internal/cmdparser" | ||
| "github.com/microsoft/go-sqlcmd/internal/localizer" | ||
| ) | ||
|
|
||
| // Type Ssms is used to implement the "open ssms" which launches SQL Server | ||
| // Management Studio and establishes a connection to the SQL Server for the current | ||
| // context | ||
| type Ssms struct { | ||
| cmdparser.Cmd | ||
| } | ||
|
|
||
| func (c *Ssms) displayPreLaunchInfo() { | ||
| output := c.Output() | ||
| output.Info(localizer.Sprintf("SSMS is only available on Windows")) | ||
| output.Info(localizer.Sprintf("Please use 'sqlcmd open vscode' or 'sqlcmd open ads' instead")) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| package open | ||
|
|
||
| import ( | ||
| "github.com/microsoft/go-sqlcmd/internal/cmdparser" | ||
| "github.com/microsoft/go-sqlcmd/internal/localizer" | ||
| ) | ||
|
|
||
| // Type Ssms is used to implement the "open ssms" which launches SQL Server | ||
| // Management Studio and establishes a connection to the SQL Server for the current | ||
| // context | ||
| type Ssms struct { | ||
| cmdparser.Cmd | ||
| } | ||
|
|
||
| func (c *Ssms) displayPreLaunchInfo() { | ||
| output := c.Output() | ||
| output.Info(localizer.Sprintf("SSMS is only available on Windows")) | ||
| output.Info(localizer.Sprintf("Please use 'sqlcmd open vscode' or 'sqlcmd open ads' instead")) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| package open | ||
|
|
||
| import ( | ||
| "github.com/microsoft/go-sqlcmd/cmd/modern/sqlconfig" | ||
| "github.com/microsoft/go-sqlcmd/internal/cmdparser" | ||
| "github.com/microsoft/go-sqlcmd/internal/config" | ||
| "runtime" | ||
| "testing" | ||
| ) | ||
|
|
||
| // TestSsms runs a sanity test of `sqlcmd open ssms` | ||
| func TestSsms(t *testing.T) { | ||
| if runtime.GOOS != "windows" { | ||
| t.Skip("SSMS is only available on Windows") | ||
| } | ||
|
|
||
| cmdparser.TestSetup(t) | ||
| config.AddEndpoint(sqlconfig.Endpoint{ | ||
| AssetDetails: nil, | ||
| EndpointDetails: sqlconfig.EndpointDetails{}, | ||
| Name: "endpoint", | ||
| }) | ||
| config.AddContext(sqlconfig.Context{ | ||
| ContextDetails: sqlconfig.ContextDetails{ | ||
| Endpoint: "endpoint", | ||
| User: nil, | ||
| }, | ||
| Name: "context", | ||
| }) | ||
| config.SetCurrentContextName("context") | ||
|
|
||
| cmdparser.TestCmd[*Ssms]() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| package open | ||
|
|
||
| import ( | ||
| "github.com/microsoft/go-sqlcmd/internal/cmdparser" | ||
| "github.com/microsoft/go-sqlcmd/internal/localizer" | ||
| ) | ||
|
|
||
| // Type Ssms is used to implement the "open ssms" which launches SQL Server | ||
| // Management Studio and establishes a connection to the SQL Server for the current | ||
| // context | ||
| type Ssms struct { | ||
| cmdparser.Cmd | ||
| } | ||
|
|
||
| // On Windows, display info before launching | ||
| func (c *Ssms) displayPreLaunchInfo() { | ||
| output := c.Output() | ||
| output.Info(localizer.Sprintf("Launching SQL Server Management Studio...")) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.