-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Add WebSocket handler for WebUI database sessions #49749
Merged
Merged
Changes from 11 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
0e2468e
feat(web): add websocket handler for database webui sessions
gabrielcorado 1a70cc5
refactor: move common structs into a separate package
gabrielcorado add121d
refactor(web): use ALPN local proxy to dial databases
gabrielcorado 25f7e6e
Merge branch 'master' into gabrielcorado/pg-webui-handler
gabrielcorado 7a6fd3b
feat(repl): add default registry
gabrielcorado bbb6b38
refactor(web): code review suggestions
gabrielcorado 6ef2712
refactor: update repl config parameters
gabrielcorado 0db0613
refactor: move default getter implementation
gabrielcorado b76c6f7
Merge branch 'master' into gabrielcorado/pg-webui-handler
gabrielcorado 6237ed0
feat(web): add supports_interactive field on dbs
gabrielcorado 46df432
Merge branch 'master' into gabrielcorado/pg-webui-handler
gabrielcorado 010445e
refactor: code review suggestions
gabrielcorado 9cb2b71
refactor: update database REPL interfaces
gabrielcorado 4c67214
Merge branch 'master' into gabrielcorado/pg-webui-handler
gabrielcorado e773a87
chore(web): remove debug print
gabrielcorado b344080
Merge branch 'master' into gabrielcorado/pg-webui-handler
gabrielcorado df26468
feat: register postgres repl
gabrielcorado 0e094b9
refactor(web): update MakeDatabase to receive access checker and inte…
gabrielcorado c05b558
Merge branch 'master' into gabrielcorado/pg-webui-handler
gabrielcorado a53effd
chore(web): remove unused function
gabrielcorado 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 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 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,72 @@ | ||
// Teleport | ||
// Copyright (C) 2024 Gravitational, Inc. | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package repl | ||
|
||
import ( | ||
"context" | ||
"io" | ||
"net" | ||
|
||
"github.com/gravitational/trace" | ||
|
||
clientproto "github.com/gravitational/teleport/api/client/proto" | ||
) | ||
|
||
// NewREPLConfig represents the database REPL constructor config. | ||
type NewREPLConfig struct { | ||
// Client is the user terminal client. | ||
Client io.ReadWriteCloser | ||
// ServerConn is the database server connection. | ||
ServerConn net.Conn | ||
// Route is the session routing information. | ||
Route clientproto.RouteToDatabase | ||
} | ||
|
||
// REPLNewFunc defines the constructor function for database REPL | ||
// sessions. | ||
type REPLNewFunc func(context.Context, *NewREPLConfig) (REPLInstance, error) | ||
|
||
// REPLInstance represents a REPL instance. | ||
type REPLInstance interface { | ||
// Run executes the REPL. This is a blocking operation. | ||
Run(context.Context) error | ||
} | ||
|
||
// REPLGetter is an interface for retrieving REPL constructor functions given | ||
// the database protocol. | ||
type REPLGetter interface { | ||
// GetREPL returns a start function for the specified protocol. | ||
GetREPL(protocol string) (REPLNewFunc, error) | ||
} | ||
|
||
// NewREPLGetter creates a new REPL getter given the list of supported REPLs. | ||
func NewREPLGetter(replNewFuncs map[string]REPLNewFunc) REPLGetter { | ||
return &replGetter{m: replNewFuncs} | ||
} | ||
|
||
type replGetter struct { | ||
m map[string]REPLNewFunc | ||
} | ||
|
||
// GetREPL implements REPLGetter. | ||
func (r *replGetter) GetREPL(dbProtocol string) (REPLNewFunc, error) { | ||
if f, ok := r.m[dbProtocol]; ok { | ||
return f, nil | ||
} | ||
|
||
return nil, trace.NotImplemented("REPL not supported for protocol %q", dbProtocol) | ||
} |
This file contains 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 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 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 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.