mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add agentapi endpoint to report connections for audit (#16507)
This change adds a new `ReportConnection` endpoint to the `agentapi`. The protocol version was bumped previously, so it has been omitted here. This allows the agent to report connection events, for example when the user connects to the workspace via SSH or VS Code. Updates #15139
This commit is contained in:
@@ -34,6 +34,18 @@ import (
|
||||
// log-source. This should be removed in the future.
|
||||
var ExternalLogSourceID = uuid.MustParse("3b579bf4-1ed8-4b99-87a8-e9a1e3410410")
|
||||
|
||||
// ConnectionType is the type of connection that the agent is receiving.
|
||||
type ConnectionType string
|
||||
|
||||
// Connection type enums.
|
||||
const (
|
||||
ConnectionTypeUnspecified ConnectionType = "Unspecified"
|
||||
ConnectionTypeSSH ConnectionType = "SSH"
|
||||
ConnectionTypeVSCode ConnectionType = "VS Code"
|
||||
ConnectionTypeJetBrains ConnectionType = "JetBrains"
|
||||
ConnectionTypeReconnectingPTY ConnectionType = "Web Terminal"
|
||||
)
|
||||
|
||||
// New returns a client that is used to interact with the
|
||||
// Coder API from a workspace agent.
|
||||
func New(serverURL *url.URL) *Client {
|
||||
|
||||
@@ -390,3 +390,37 @@ func ProtoFromLifecycleState(s codersdk.WorkspaceAgentLifecycle) (proto.Lifecycl
|
||||
}
|
||||
return proto.Lifecycle_State(caps), nil
|
||||
}
|
||||
|
||||
func ConnectionTypeFromProto(typ proto.Connection_Type) (ConnectionType, error) {
|
||||
switch typ {
|
||||
case proto.Connection_TYPE_UNSPECIFIED:
|
||||
return ConnectionTypeUnspecified, nil
|
||||
case proto.Connection_SSH:
|
||||
return ConnectionTypeSSH, nil
|
||||
case proto.Connection_VSCODE:
|
||||
return ConnectionTypeVSCode, nil
|
||||
case proto.Connection_JETBRAINS:
|
||||
return ConnectionTypeJetBrains, nil
|
||||
case proto.Connection_RECONNECTING_PTY:
|
||||
return ConnectionTypeReconnectingPTY, nil
|
||||
default:
|
||||
return "", xerrors.Errorf("unknown connection type %q", typ)
|
||||
}
|
||||
}
|
||||
|
||||
func ProtoFromConnectionType(typ ConnectionType) (proto.Connection_Type, error) {
|
||||
switch typ {
|
||||
case ConnectionTypeUnspecified:
|
||||
return proto.Connection_TYPE_UNSPECIFIED, nil
|
||||
case ConnectionTypeSSH:
|
||||
return proto.Connection_SSH, nil
|
||||
case ConnectionTypeVSCode:
|
||||
return proto.Connection_VSCODE, nil
|
||||
case ConnectionTypeJetBrains:
|
||||
return proto.Connection_JETBRAINS, nil
|
||||
case ConnectionTypeReconnectingPTY:
|
||||
return proto.Connection_RECONNECTING_PTY, nil
|
||||
default:
|
||||
return 0, xerrors.Errorf("unknown connection type %q", typ)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user