Skip to content

Commit 03191b6

Browse files
committed
Changes:
- #87 Improve golang unit testing - auto generating OpenAPI definition from tests - OpenAPI definition
1 parent e6866d7 commit 03191b6

20 files changed

+6599
-1276
lines changed

.github/coverage/coverage.txt

+65-63
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ github.com/0xrawsec/whids/api/api_client.go:309: GetIoCs 75.0%
1515
github.com/0xrawsec/whids/api/api_client.go:338: GetIoCsSha256 68.8%
1616
github.com/0xrawsec/whids/api/api_client.go:367: GetRules 68.8%
1717
github.com/0xrawsec/whids/api/api_client.go:394: IsFileAboveUploadLimit 0.0%
18-
github.com/0xrawsec/whids/api/api_client.go:405: PostDump 0.0%
18+
github.com/0xrawsec/whids/api/api_client.go:405: PostDump 65.0%
1919
github.com/0xrawsec/whids/api/api_client.go:441: PostLogs 68.8%
20-
github.com/0xrawsec/whids/api/api_client.go:473: PostCommand 70.6%
21-
github.com/0xrawsec/whids/api/api_client.go:507: FetchCommand 64.7%
20+
github.com/0xrawsec/whids/api/api_client.go:473: PostCommand 76.5%
21+
github.com/0xrawsec/whids/api/api_client.go:507: FetchCommand 82.4%
2222
github.com/0xrawsec/whids/api/api_client.go:543: Close 100.0%
2323
github.com/0xrawsec/whids/api/command.go:48: NewCommand 100.0%
2424
github.com/0xrawsec/whids/api/command.go:59: SetCommandLine 87.5%
@@ -37,10 +37,10 @@ github.com/0xrawsec/whids/api/endpoint.go:32: Copy 100.0%
3737
github.com/0xrawsec/whids/api/endpoint.go:38: UpdateLastConnection 100.0%
3838
github.com/0xrawsec/whids/api/endpoint.go:53: NewEndpoints 100.0%
3939
github.com/0xrawsec/whids/api/endpoint.go:61: Add 100.0%
40-
github.com/0xrawsec/whids/api/endpoint.go:69: DelByUUID 0.0%
41-
github.com/0xrawsec/whids/api/endpoint.go:90: HasByUUID 0.0%
40+
github.com/0xrawsec/whids/api/endpoint.go:69: DelByUUID 70.0%
41+
github.com/0xrawsec/whids/api/endpoint.go:90: HasByUUID 100.0%
4242
github.com/0xrawsec/whids/api/endpoint.go:98: GetByUUID 80.0%
43-
github.com/0xrawsec/whids/api/endpoint.go:108: GetMutByUUID 80.0%
43+
github.com/0xrawsec/whids/api/endpoint.go:108: GetMutByUUID 100.0%
4444
github.com/0xrawsec/whids/api/endpoint.go:118: Len 100.0%
4545
github.com/0xrawsec/whids/api/endpoint.go:125: Endpoints 100.0%
4646
github.com/0xrawsec/whids/api/endpoint.go:136: MutEndpoints 100.0%
@@ -57,36 +57,38 @@ github.com/0xrawsec/whids/api/forwarder.go:227: ProcessQueue 79.4%
5757
github.com/0xrawsec/whids/api/forwarder.go:297: Reset 100.0%
5858
github.com/0xrawsec/whids/api/forwarder.go:304: Collect 72.7%
5959
github.com/0xrawsec/whids/api/forwarder.go:332: Run 100.0%
60-
github.com/0xrawsec/whids/api/forwarder.go:365: Close 87.5%
60+
github.com/0xrawsec/whids/api/forwarder.go:365: Close 100.0%
6161
github.com/0xrawsec/whids/api/log_streamer.go:18: Queue 75.0%
6262
github.com/0xrawsec/whids/api/log_streamer.go:26: Stream 100.0%
6363
github.com/0xrawsec/whids/api/log_streamer.go:40: Close 0.0%
6464
github.com/0xrawsec/whids/api/log_streamer.go:49: NewEventStreamer 100.0%
6565
github.com/0xrawsec/whids/api/log_streamer.go:55: NewStream 100.0%
6666
github.com/0xrawsec/whids/api/log_streamer.go:63: newId 100.0%
6767
github.com/0xrawsec/whids/api/log_streamer.go:73: Queue 83.3%
68-
github.com/0xrawsec/whids/api/manager.go:61: init 75.0%
69-
github.com/0xrawsec/whids/api/manager.go:74: IPFromRequest 0.0%
70-
github.com/0xrawsec/whids/api/manager.go:87: gunzipMiddleware 62.5%
71-
github.com/0xrawsec/whids/api/manager.go:110: Empty 100.0%
72-
github.com/0xrawsec/whids/api/manager.go:115: Verify 50.0%
73-
github.com/0xrawsec/whids/api/manager.go:128: UUIDGen 100.0%
74-
github.com/0xrawsec/whids/api/manager.go:137: KeyGen 100.0%
75-
github.com/0xrawsec/whids/api/manager.go:184: LoadManagerConfig 0.0%
76-
github.com/0xrawsec/whids/api/manager.go:196: SetPath 100.0%
77-
github.com/0xrawsec/whids/api/manager.go:201: Save 0.0%
78-
github.com/0xrawsec/whids/api/manager.go:239: NewManager 75.0%
79-
github.com/0xrawsec/whids/api/manager.go:308: initializeDB 66.7%
80-
github.com/0xrawsec/whids/api/manager.go:339: CreateNewAdminAPIUser 66.7%
81-
github.com/0xrawsec/whids/api/manager.go:352: LoadGeneEngine 85.7%
82-
github.com/0xrawsec/whids/api/manager.go:365: updateRules 100.0%
83-
github.com/0xrawsec/whids/api/manager.go:378: AddEndpoint 100.0%
84-
github.com/0xrawsec/whids/api/manager.go:383: UpdateReducer 100.0%
85-
github.com/0xrawsec/whids/api/manager.go:399: Wait 100.0%
86-
github.com/0xrawsec/whids/api/manager.go:404: IsDone 0.0%
87-
github.com/0xrawsec/whids/api/manager.go:409: Shutdown 86.7%
88-
github.com/0xrawsec/whids/api/manager.go:433: Run 100.0%
89-
github.com/0xrawsec/whids/api/manager_admin_api.go:34: admApiParseDuration 0.0%
68+
github.com/0xrawsec/whids/api/manager.go:62: init 75.0%
69+
github.com/0xrawsec/whids/api/manager.go:75: IPFromRequest 0.0%
70+
github.com/0xrawsec/whids/api/manager.go:88: gunzipMiddleware 62.5%
71+
github.com/0xrawsec/whids/api/manager.go:111: Empty 100.0%
72+
github.com/0xrawsec/whids/api/manager.go:116: Verify 50.0%
73+
github.com/0xrawsec/whids/api/manager.go:129: UUIDGen 100.0%
74+
github.com/0xrawsec/whids/api/manager.go:138: KeyGen 100.0%
75+
github.com/0xrawsec/whids/api/manager.go:185: LoadManagerConfig 0.0%
76+
github.com/0xrawsec/whids/api/manager.go:197: SetPath 100.0%
77+
github.com/0xrawsec/whids/api/manager.go:202: EndpointAPIUrl 0.0%
78+
github.com/0xrawsec/whids/api/manager.go:212: AdminAPIUrl 75.0%
79+
github.com/0xrawsec/whids/api/manager.go:222: Save 0.0%
80+
github.com/0xrawsec/whids/api/manager.go:260: NewManager 77.8%
81+
github.com/0xrawsec/whids/api/manager.go:329: initializeDB 66.7%
82+
github.com/0xrawsec/whids/api/manager.go:360: CreateNewAdminAPIUser 50.0%
83+
github.com/0xrawsec/whids/api/manager.go:373: LoadGeneEngine 85.7%
84+
github.com/0xrawsec/whids/api/manager.go:386: updateRules 100.0%
85+
github.com/0xrawsec/whids/api/manager.go:399: AddEndpoint 100.0%
86+
github.com/0xrawsec/whids/api/manager.go:404: UpdateReducer 100.0%
87+
github.com/0xrawsec/whids/api/manager.go:420: Wait 100.0%
88+
github.com/0xrawsec/whids/api/manager.go:425: IsDone 0.0%
89+
github.com/0xrawsec/whids/api/manager.go:430: Shutdown 86.7%
90+
github.com/0xrawsec/whids/api/manager.go:454: Run 100.0%
91+
github.com/0xrawsec/whids/api/manager_admin_api.go:34: admApiParseDuration 71.4%
9092
github.com/0xrawsec/whids/api/manager_admin_api.go:47: admApiParseTime 66.7%
9193
github.com/0xrawsec/whids/api/manager_admin_api.go:54: muxGetVar 75.0%
9294
github.com/0xrawsec/whids/api/manager_admin_api.go:62: format 100.0%
@@ -98,37 +100,37 @@ github.com/0xrawsec/whids/api/manager_admin_api.go:108: UnmarshalData 75.0%
98100
github.com/0xrawsec/whids/api/manager_admin_api.go:117: ToJSON 50.0%
99101
github.com/0xrawsec/whids/api/manager_admin_api.go:127: admErr 0.0%
100102
github.com/0xrawsec/whids/api/manager_admin_api.go:131: admJSONResp 100.0%
101-
github.com/0xrawsec/whids/api/manager_admin_api.go:135: admMsgStr 0.0%
103+
github.com/0xrawsec/whids/api/manager_admin_api.go:135: admMsgStr 100.0%
102104
github.com/0xrawsec/whids/api/manager_admin_api.go:146: adminAuthorizationMiddleware 66.7%
103105
github.com/0xrawsec/whids/api/manager_admin_api.go:162: admLogHTTPMiddleware 100.0%
104106
github.com/0xrawsec/whids/api/manager_admin_api.go:170: adminRespHeaderMiddleware 100.0%
105-
github.com/0xrawsec/whids/api/manager_admin_api.go:180: admAPIUsers 0.0%
106-
github.com/0xrawsec/whids/api/manager_admin_api.go:228: admAPIUser 0.0%
107-
github.com/0xrawsec/whids/api/manager_admin_api.go:289: admAPIEndpoints 83.3%
108-
github.com/0xrawsec/whids/api/manager_admin_api.go:334: admAPIEndpoint 0.0%
109-
github.com/0xrawsec/whids/api/manager_admin_api.go:413: ToCommand 77.8%
110-
github.com/0xrawsec/whids/api/manager_admin_api.go:435: admAPIEndpointCommand 70.8%
111-
github.com/0xrawsec/whids/api/manager_admin_api.go:480: admAPIEndpointCommandField 52.9%
112-
github.com/0xrawsec/whids/api/manager_admin_api.go:517: admAPIEndpointLogs 57.9%
113-
github.com/0xrawsec/whids/api/manager_admin_api.go:658: admAPIEndpointReport 73.7%
114-
github.com/0xrawsec/whids/api/manager_admin_api.go:698: admAPIEndpointReportArchive 0.0%
115-
github.com/0xrawsec/whids/api/manager_admin_api.go:773: admAPIEndpointsReports 100.0%
116-
github.com/0xrawsec/whids/api/manager_admin_api.go:796: listEndpointDumps 0.0%
117-
github.com/0xrawsec/whids/api/manager_admin_api.go:863: admAPIArtifacts 0.0%
118-
github.com/0xrawsec/whids/api/manager_admin_api.go:894: admAPIEndpointArtifacts 0.0%
119-
github.com/0xrawsec/whids/api/manager_admin_api.go:925: admAPIEndpointArtifact 0.0%
120-
github.com/0xrawsec/whids/api/manager_admin_api.go:996: admAPIStats 0.0%
121-
github.com/0xrawsec/whids/api/manager_admin_api.go:1004: admAPIIocs 54.3%
122-
github.com/0xrawsec/whids/api/manager_admin_api.go:1077: admAPIRules 0.0%
123-
github.com/0xrawsec/whids/api/manager_admin_api.go:1238: admAPIRulesReload 0.0%
124-
github.com/0xrawsec/whids/api/manager_admin_api.go:1251: admAPIRulesSave 0.0%
125-
github.com/0xrawsec/whids/api/manager_admin_api.go:1294: wsHandleControlMessage 100.0%
126-
github.com/0xrawsec/whids/api/manager_admin_api.go:1304: admAPIStreamEvents 71.4%
127-
github.com/0xrawsec/whids/api/manager_admin_api.go:1327: admAPIStreamDetections 0.0%
128-
github.com/0xrawsec/whids/api/manager_admin_api.go:1352: runAdminAPI 87.2%
129-
github.com/0xrawsec/whids/api/manager_endpoint_api.go:27: endpointFromRequest 0.0%
107+
github.com/0xrawsec/whids/api/manager_admin_api.go:180: admAPIUsers 54.8%
108+
github.com/0xrawsec/whids/api/manager_admin_api.go:248: admAPIUser 59.4%
109+
github.com/0xrawsec/whids/api/manager_admin_api.go:309: admAPIEndpoints 83.3%
110+
github.com/0xrawsec/whids/api/manager_admin_api.go:354: admAPIEndpoint 73.5%
111+
github.com/0xrawsec/whids/api/manager_admin_api.go:433: ToCommand 77.8%
112+
github.com/0xrawsec/whids/api/manager_admin_api.go:455: admAPIEndpointCommand 75.0%
113+
github.com/0xrawsec/whids/api/manager_admin_api.go:500: admAPIEndpointCommandField 52.9%
114+
github.com/0xrawsec/whids/api/manager_admin_api.go:537: admAPIEndpointLogs 69.7%
115+
github.com/0xrawsec/whids/api/manager_admin_api.go:678: admAPIEndpointReport 78.9%
116+
github.com/0xrawsec/whids/api/manager_admin_api.go:718: admAPIEndpointReportArchive 67.4%
117+
github.com/0xrawsec/whids/api/manager_admin_api.go:793: admAPIEndpointsReports 100.0%
118+
github.com/0xrawsec/whids/api/manager_admin_api.go:816: listEndpointDumps 80.6%
119+
github.com/0xrawsec/whids/api/manager_admin_api.go:883: admAPIArtifacts 61.1%
120+
github.com/0xrawsec/whids/api/manager_admin_api.go:914: admAPIEndpointArtifacts 61.1%
121+
github.com/0xrawsec/whids/api/manager_admin_api.go:945: admAPIEndpointArtifact 62.9%
122+
github.com/0xrawsec/whids/api/manager_admin_api.go:1016: admAPIStats 100.0%
123+
github.com/0xrawsec/whids/api/manager_admin_api.go:1024: admAPIIocs 68.6%
124+
github.com/0xrawsec/whids/api/manager_admin_api.go:1097: admAPIRules 68.8%
125+
github.com/0xrawsec/whids/api/manager_admin_api.go:1260: admAPIRulesReload 83.3%
126+
github.com/0xrawsec/whids/api/manager_admin_api.go:1273: admAPIRulesSave 65.2%
127+
github.com/0xrawsec/whids/api/manager_admin_api.go:1316: wsHandleControlMessage 100.0%
128+
github.com/0xrawsec/whids/api/manager_admin_api.go:1326: admAPIStreamEvents 71.4%
129+
github.com/0xrawsec/whids/api/manager_admin_api.go:1349: admAPIStreamDetections 0.0%
130+
github.com/0xrawsec/whids/api/manager_admin_api.go:1374: runAdminAPI 87.2%
131+
github.com/0xrawsec/whids/api/manager_endpoint_api.go:27: endpointFromRequest 75.0%
130132
github.com/0xrawsec/whids/api/manager_endpoint_api.go:35: mutEndpointFromRequest 75.0%
131-
github.com/0xrawsec/whids/api/manager_endpoint_api.go:45: endpointAuthorizationMiddleware 66.7%
133+
github.com/0xrawsec/whids/api/manager_endpoint_api.go:45: endpointAuthorizationMiddleware 76.2%
132134
github.com/0xrawsec/whids/api/manager_endpoint_api.go:85: isVerboseURL 100.0%
133135
github.com/0xrawsec/whids/api/manager_endpoint_api.go:94: endptLogHTTPMiddleware 0.0%
134136
github.com/0xrawsec/whids/api/manager_endpoint_api.go:102: endptQuietLogHTTPMiddleware 100.0%
@@ -138,21 +140,21 @@ github.com/0xrawsec/whids/api/manager_endpoint_api.go:182: Rules 100.0%
138140
github.com/0xrawsec/whids/api/manager_endpoint_api.go:189: RulesSha256 100.0%
139141
github.com/0xrawsec/whids/api/manager_endpoint_api.go:195: IoCs 50.0%
140142
github.com/0xrawsec/whids/api/manager_endpoint_api.go:204: IoCsSha256 100.0%
141-
github.com/0xrawsec/whids/api/manager_endpoint_api.go:209: UploadDump 0.0%
143+
github.com/0xrawsec/whids/api/manager_endpoint_api.go:209: UploadDump 44.4%
142144
github.com/0xrawsec/whids/api/manager_endpoint_api.go:242: Collect 84.6%
143145
github.com/0xrawsec/whids/api/manager_endpoint_api.go:315: AddCommand 75.0%
144146
github.com/0xrawsec/whids/api/manager_endpoint_api.go:324: GetCommand 66.7%
145-
github.com/0xrawsec/whids/api/manager_endpoint_api.go:334: Command 80.8%
147+
github.com/0xrawsec/whids/api/manager_endpoint_api.go:334: Command 84.6%
146148
github.com/0xrawsec/whids/api/upload.go:31: NewUploadShrinker 0.0%
147149
github.com/0xrawsec/whids/api/upload.go:65: Size 0.0%
148150
github.com/0xrawsec/whids/api/upload.go:70: Next 0.0%
149151
github.com/0xrawsec/whids/api/upload.go:91: Done 0.0%
150152
github.com/0xrawsec/whids/api/upload.go:96: Err 0.0%
151153
github.com/0xrawsec/whids/api/upload.go:101: Close 0.0%
152-
github.com/0xrawsec/whids/api/upload.go:118: Validate 0.0%
153-
github.com/0xrawsec/whids/api/upload.go:132: Implode 0.0%
154-
github.com/0xrawsec/whids/api/upload.go:137: Dump 0.0%
155-
github.com/0xrawsec/whids/api/upload.go:155: write 0.0%
154+
github.com/0xrawsec/whids/api/upload.go:118: Validate 57.1%
155+
github.com/0xrawsec/whids/api/upload.go:132: Implode 100.0%
156+
github.com/0xrawsec/whids/api/upload.go:137: Dump 71.4%
157+
github.com/0xrawsec/whids/api/upload.go:155: write 31.6%
156158
github.com/0xrawsec/whids/event/event.go:42: NewEdrEvent 100.0%
157159
github.com/0xrawsec/whids/event/event.go:46: InitEdrData 0.0%
158160
github.com/0xrawsec/whids/event/event.go:50: Hash 100.0%
@@ -231,4 +233,4 @@ github.com/0xrawsec/whids/logger/search.go:187: Events 89.7%
231233
github.com/0xrawsec/whids/logger/search.go:254: Err 100.0%
232234
github.com/0xrawsec/whids/logger/search.go:258: close 80.0%
233235
github.com/0xrawsec/whids/logger/search.go:269: Close 100.0%
234-
total: (statements) 54.3%
236+
total: (statements) 70.4%

api/adminapi_test.go

+19-15
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,8 @@ func TestAdminAPIGetEndpointLogs(t *testing.T) {
403403

404404
// test pivoting
405405
v := url.Values{}
406-
v.Set("pivot", time.Now().Format(time.RFC3339))
407-
v.Set("delta", "1m")
406+
v.Set(qpPivot, time.Now().Format(time.RFC3339))
407+
v.Set(qpDelta, "1m")
408408
r = get(AdmAPIEndpointsPath + "/" + euuid + "/logs?" + v.Encode())
409409
failOnAdminAPIError(t, r)
410410
data := make([]event.EdrEvent, 0)
@@ -416,8 +416,8 @@ func TestAdminAPIGetEndpointLogs(t *testing.T) {
416416

417417
// test pivoting with delta
418418
v = url.Values{}
419-
v.Set("pivot", time.Now().Format(time.RFC3339))
420-
v.Set("delta", "3h")
419+
v.Set(qpPivot, time.Now().Format(time.RFC3339))
420+
v.Set(qpDelta, "3h")
421421
r = get(AdmAPIEndpointsPath + "/" + euuid + "/logs?" + v.Encode())
422422
failOnAdminAPIError(t, r)
423423
data = make([]event.EdrEvent, 0)
@@ -429,8 +429,8 @@ func TestAdminAPIGetEndpointLogs(t *testing.T) {
429429

430430
// test with start and stop
431431
v = url.Values{}
432-
v.Set("start", time.Now().Add(-3*time.Hour).Format(time.RFC3339))
433-
v.Set("stop", time.Now().Add(3*time.Hour).Format(time.RFC3339))
432+
v.Set(qpSince, time.Now().Add(-3*time.Hour).Format(time.RFC3339))
433+
v.Set(qpUntil, time.Now().Add(3*time.Hour).Format(time.RFC3339))
434434
r = get(AdmAPIEndpointsPath + "/" + euuid + "/logs?" + v.Encode())
435435
failOnAdminAPIError(t, r)
436436
data = make([]event.EdrEvent, 0)
@@ -486,8 +486,8 @@ func TestAdminAPIGetEndpointAlerts(t *testing.T) {
486486

487487
// test pivoting
488488
v := url.Values{}
489-
v.Set("pivot", time.Now().Format(time.RFC3339))
490-
r = get(AdmAPIEndpointsPath + "/" + euuid + AdmAPIDetectionPart + "?" + v.Encode())
489+
v.Set(qpPivot, time.Now().Format(time.RFC3339))
490+
r = get(AdmAPIEndpointsPath + "/" + euuid + AdmAPIDetectionSuffix + "?" + v.Encode())
491491
failOnAdminAPIError(t, r)
492492
data := make([]evtx.GoEvtxMap, 0)
493493
r.UnmarshalData(&data)
@@ -498,9 +498,9 @@ func TestAdminAPIGetEndpointAlerts(t *testing.T) {
498498

499499
// test pivoting with delta
500500
v = url.Values{}
501-
v.Set("pivot", time.Now().Format(time.RFC3339))
502-
v.Set("delta", "3h")
503-
r = get(AdmAPIEndpointsPath + "/" + euuid + AdmAPIDetectionPart + "?" + v.Encode())
501+
v.Set(qpPivot, time.Now().Format(time.RFC3339))
502+
v.Set(qpDelta, "3h")
503+
r = get(AdmAPIEndpointsPath + "/" + euuid + AdmAPIDetectionSuffix + "?" + v.Encode())
504504
failOnAdminAPIError(t, r)
505505
data = make([]evtx.GoEvtxMap, 0)
506506
r.UnmarshalData(&data)
@@ -511,9 +511,9 @@ func TestAdminAPIGetEndpointAlerts(t *testing.T) {
511511

512512
// test with start and stop
513513
v = url.Values{}
514-
v.Set("start", time.Now().Add(-3*time.Hour).Format(time.RFC3339))
515-
v.Set("stop", time.Now().Add(3*time.Hour).Format(time.RFC3339))
516-
r = get(AdmAPIEndpointsPath + "/" + euuid + AdmAPIDetectionPart + "?" + v.Encode())
514+
v.Set(qpSince, time.Now().Add(-3*time.Hour).Format(time.RFC3339))
515+
v.Set(qpUntil, time.Now().Add(3*time.Hour).Format(time.RFC3339))
516+
r = get(AdmAPIEndpointsPath + "/" + euuid + AdmAPIDetectionSuffix + "?" + v.Encode())
517517
failOnAdminAPIError(t, r)
518518
data = make([]evtx.GoEvtxMap, 0)
519519
r.UnmarshalData(&data)
@@ -541,7 +541,11 @@ func TestEventStream(t *testing.T) {
541541
wg := sync.WaitGroup{}
542542

543543
for i := float64(0); i < nclients; i++ {
544-
u := url.URL{Scheme: "wss", Host: format("localhost:%d", 8001), Path: AdmAPIStreamEvents}
544+
545+
u := url.URL{
546+
Scheme: "wss",
547+
Host: format("%s:%d", mconf.AdminAPI.Host, mconf.AdminAPI.Port),
548+
Path: AdmAPIStreamEvents}
545549
key := testAdminUser.Key
546550
dialer := *websocket.DefaultDialer
547551
dialer.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}

api/api_client_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var (
1919
cconf = ClientConfig{
2020
Proto: "https",
2121
Host: "localhost",
22-
Port: 8000,
22+
Port: mconf.EndpointAPI.Port,
2323
UUID: "5a92baeb-9384-47d3-92b4-a0db6f9b8c6d",
2424
Key: "don'tcomplain",
2525
ServerFingerprint: "511dc40cb2363974a97dfd47437feb8307cbd9d938645e1442775aa97ec14227",

api/forwarder_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ var (
3636
mconf = ManagerConfig{
3737
AdminAPI: AdminAPIConfig{
3838
Host: "localhost",
39-
Port: 8001,
39+
Port: AdmAPIDefaultPort,
4040
},
4141
EndpointAPI: EndpointAPIConfig{
4242
Host: "",
43-
Port: 8000,
43+
Port: EptAPIDefaultPort,
4444
},
4545
Logging: ManagerLogConfig{
4646
Root: "./data/logs",

api/manager.go

+24-3
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ const (
5353
)
5454

5555
var (
56-
guidRe = regexp.MustCompile(`(?i:\{[a-f0-9]{8}-([a-f0-9]{4}-){3}[a-f0-9]{12}\})`)
57-
eventHashRe = regexp.MustCompile(`(?i:[a-f0-9]{32,})`) // at least md5
58-
filenameRe = regexp.MustCompile(`[\w\s\.-]+`)
56+
noBracketGuidRe = regexp.MustCompile(`(?i:[a-f0-9]{8}-([a-f0-9]{4}-){3}[a-f0-9]{12})`)
57+
guidRe = regexp.MustCompile(`(?i:\{[a-f0-9]{8}-([a-f0-9]{4}-){3}[a-f0-9]{12}\})`)
58+
eventHashRe = regexp.MustCompile(`(?i:[a-f0-9]{32,})`) // at least md5
59+
filenameRe = regexp.MustCompile(`[\w\s\.-]+`)
5960
)
6061

6162
func init() {
@@ -197,6 +198,26 @@ func (mc *ManagerConfig) SetPath(path string) {
197198
mc.path = path
198199
}
199200

201+
// EndpointAPIUrl returns the URL of the Endpoint API
202+
func (mc *ManagerConfig) EndpointAPIUrl() string {
203+
proto := "https"
204+
if mc.TLS.Empty() {
205+
proto = "http"
206+
}
207+
208+
return fmt.Sprintf("%s://%s:%d", proto, mc.EndpointAPI.Host, mc.EndpointAPI.Port)
209+
}
210+
211+
// EndpointAPIUrl returns the URL of the Admin API
212+
func (mc *ManagerConfig) AdminAPIUrl() string {
213+
proto := "https"
214+
if mc.TLS.Empty() {
215+
proto = "http"
216+
}
217+
218+
return fmt.Sprintf("%s://%s:%d", proto, mc.AdminAPI.Host, mc.AdminAPI.Port)
219+
}
220+
200221
// Save saves the configuration to a path specified by the path member of the structure
201222
func (mc *ManagerConfig) Save() error {
202223
b, err := toml.Marshal(mc)

0 commit comments

Comments
 (0)