@@ -34,28 +34,13 @@ func (a *AuditAPI) ReportConnection(ctx context.Context, req *agentproto.ReportC
34
34
return nil ,xerrors .Errorf ("connection id from bytes: %w" ,err )
35
35
}
36
36
37
- var action database.AuditAction
38
- switch req .GetConnection ().GetAction () {
39
- case agentproto .Connection_CONNECT :
40
- action = database .AuditActionConnect
41
- case agentproto .Connection_DISCONNECT :
42
- action = database .AuditActionDisconnect
43
- default :
44
- return nil ,xerrors .Errorf ("unknown agent connection action %q" ,req .GetConnection ().GetAction ())
37
+ action ,err := AgentProtoConnectionActionToAuditAction (req .GetConnection ().GetAction ())
38
+ if err != nil {
39
+ return nil ,err
45
40
}
46
-
47
- var connectionType agentsdk.ConnectionType
48
- switch req .GetConnection ().GetType () {
49
- case agentproto .Connection_SSH :
50
- connectionType = agentsdk .ConnectionTypeSSH
51
- case agentproto .Connection_VSCODE :
52
- connectionType = agentsdk .ConnectionTypeVSCode
53
- case agentproto .Connection_JETBRAINS :
54
- connectionType = agentsdk .ConnectionTypeJetBrains
55
- case agentproto .Connection_RECONNECTING_PTY :
56
- connectionType = agentsdk .ConnectionTypeReconnectingPTY
57
- default :
58
- return nil ,xerrors .Errorf ("unknown agent connection type %q" ,req .GetConnection ().GetType ())
41
+ connectionType ,err := AgentProtoConnectionTypeToAgentConnectionType (req .GetConnection ().GetType ())
42
+ if err != nil {
43
+ return nil ,err
59
44
}
60
45
61
46
// Fetch contextual data for this audit event.
@@ -115,3 +100,29 @@ func (a *AuditAPI) ReportConnection(ctx context.Context, req *agentproto.ReportC
115
100
116
101
return & emptypb.Empty {},nil
117
102
}
103
+
104
+ func AgentProtoConnectionActionToAuditAction (action agentproto.Connection_Action ) (database.AuditAction ,error ) {
105
+ switch action {
106
+ case agentproto .Connection_CONNECT :
107
+ return database .AuditActionConnect ,nil
108
+ case agentproto .Connection_DISCONNECT :
109
+ return database .AuditActionDisconnect ,nil
110
+ default :
111
+ return "" ,xerrors .Errorf ("unknown agent connection action %q" ,action )
112
+ }
113
+ }
114
+
115
+ func AgentProtoConnectionTypeToAgentConnectionType (typ agentproto.Connection_Type ) (agentsdk.ConnectionType ,error ) {
116
+ switch typ {
117
+ case agentproto .Connection_SSH :
118
+ return agentsdk .ConnectionTypeSSH ,nil
119
+ case agentproto .Connection_VSCODE :
120
+ return agentsdk .ConnectionTypeVSCode ,nil
121
+ case agentproto .Connection_JETBRAINS :
122
+ return agentsdk .ConnectionTypeJetBrains ,nil
123
+ case agentproto .Connection_RECONNECTING_PTY :
124
+ return agentsdk .ConnectionTypeReconnectingPTY ,nil
125
+ default :
126
+ return "" ,xerrors .Errorf ("unknown agent connection type %q" ,typ )
127
+ }
128
+ }