Skip to content

Commit

Permalink
Changes:
Browse files Browse the repository at this point in the history
    - #87 Improve golang unit testing
    - auto generating OpenAPI definition from tests
    - OpenAPI definition
  • Loading branch information
qjerome committed Dec 7, 2021
1 parent e6866d7 commit 03191b6
Show file tree
Hide file tree
Showing 20 changed files with 6,599 additions and 1,276 deletions.
128 changes: 65 additions & 63 deletions .github/coverage/coverage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ github.com/0xrawsec/whids/api/api_client.go:309: GetIoCs 75.0%
github.com/0xrawsec/whids/api/api_client.go:338: GetIoCsSha256 68.8%
github.com/0xrawsec/whids/api/api_client.go:367: GetRules 68.8%
github.com/0xrawsec/whids/api/api_client.go:394: IsFileAboveUploadLimit 0.0%
github.com/0xrawsec/whids/api/api_client.go:405: PostDump 0.0%
github.com/0xrawsec/whids/api/api_client.go:405: PostDump 65.0%
github.com/0xrawsec/whids/api/api_client.go:441: PostLogs 68.8%
github.com/0xrawsec/whids/api/api_client.go:473: PostCommand 70.6%
github.com/0xrawsec/whids/api/api_client.go:507: FetchCommand 64.7%
github.com/0xrawsec/whids/api/api_client.go:473: PostCommand 76.5%
github.com/0xrawsec/whids/api/api_client.go:507: FetchCommand 82.4%
github.com/0xrawsec/whids/api/api_client.go:543: Close 100.0%
github.com/0xrawsec/whids/api/command.go:48: NewCommand 100.0%
github.com/0xrawsec/whids/api/command.go:59: SetCommandLine 87.5%
Expand All @@ -37,10 +37,10 @@ github.com/0xrawsec/whids/api/endpoint.go:32: Copy 100.0%
github.com/0xrawsec/whids/api/endpoint.go:38: UpdateLastConnection 100.0%
github.com/0xrawsec/whids/api/endpoint.go:53: NewEndpoints 100.0%
github.com/0xrawsec/whids/api/endpoint.go:61: Add 100.0%
github.com/0xrawsec/whids/api/endpoint.go:69: DelByUUID 0.0%
github.com/0xrawsec/whids/api/endpoint.go:90: HasByUUID 0.0%
github.com/0xrawsec/whids/api/endpoint.go:69: DelByUUID 70.0%
github.com/0xrawsec/whids/api/endpoint.go:90: HasByUUID 100.0%
github.com/0xrawsec/whids/api/endpoint.go:98: GetByUUID 80.0%
github.com/0xrawsec/whids/api/endpoint.go:108: GetMutByUUID 80.0%
github.com/0xrawsec/whids/api/endpoint.go:108: GetMutByUUID 100.0%
github.com/0xrawsec/whids/api/endpoint.go:118: Len 100.0%
github.com/0xrawsec/whids/api/endpoint.go:125: Endpoints 100.0%
github.com/0xrawsec/whids/api/endpoint.go:136: MutEndpoints 100.0%
Expand All @@ -57,36 +57,38 @@ github.com/0xrawsec/whids/api/forwarder.go:227: ProcessQueue 79.4%
github.com/0xrawsec/whids/api/forwarder.go:297: Reset 100.0%
github.com/0xrawsec/whids/api/forwarder.go:304: Collect 72.7%
github.com/0xrawsec/whids/api/forwarder.go:332: Run 100.0%
github.com/0xrawsec/whids/api/forwarder.go:365: Close 87.5%
github.com/0xrawsec/whids/api/forwarder.go:365: Close 100.0%
github.com/0xrawsec/whids/api/log_streamer.go:18: Queue 75.0%
github.com/0xrawsec/whids/api/log_streamer.go:26: Stream 100.0%
github.com/0xrawsec/whids/api/log_streamer.go:40: Close 0.0%
github.com/0xrawsec/whids/api/log_streamer.go:49: NewEventStreamer 100.0%
github.com/0xrawsec/whids/api/log_streamer.go:55: NewStream 100.0%
github.com/0xrawsec/whids/api/log_streamer.go:63: newId 100.0%
github.com/0xrawsec/whids/api/log_streamer.go:73: Queue 83.3%
github.com/0xrawsec/whids/api/manager.go:61: init 75.0%
github.com/0xrawsec/whids/api/manager.go:74: IPFromRequest 0.0%
github.com/0xrawsec/whids/api/manager.go:87: gunzipMiddleware 62.5%
github.com/0xrawsec/whids/api/manager.go:110: Empty 100.0%
github.com/0xrawsec/whids/api/manager.go:115: Verify 50.0%
github.com/0xrawsec/whids/api/manager.go:128: UUIDGen 100.0%
github.com/0xrawsec/whids/api/manager.go:137: KeyGen 100.0%
github.com/0xrawsec/whids/api/manager.go:184: LoadManagerConfig 0.0%
github.com/0xrawsec/whids/api/manager.go:196: SetPath 100.0%
github.com/0xrawsec/whids/api/manager.go:201: Save 0.0%
github.com/0xrawsec/whids/api/manager.go:239: NewManager 75.0%
github.com/0xrawsec/whids/api/manager.go:308: initializeDB 66.7%
github.com/0xrawsec/whids/api/manager.go:339: CreateNewAdminAPIUser 66.7%
github.com/0xrawsec/whids/api/manager.go:352: LoadGeneEngine 85.7%
github.com/0xrawsec/whids/api/manager.go:365: updateRules 100.0%
github.com/0xrawsec/whids/api/manager.go:378: AddEndpoint 100.0%
github.com/0xrawsec/whids/api/manager.go:383: UpdateReducer 100.0%
github.com/0xrawsec/whids/api/manager.go:399: Wait 100.0%
github.com/0xrawsec/whids/api/manager.go:404: IsDone 0.0%
github.com/0xrawsec/whids/api/manager.go:409: Shutdown 86.7%
github.com/0xrawsec/whids/api/manager.go:433: Run 100.0%
github.com/0xrawsec/whids/api/manager_admin_api.go:34: admApiParseDuration 0.0%
github.com/0xrawsec/whids/api/manager.go:62: init 75.0%
github.com/0xrawsec/whids/api/manager.go:75: IPFromRequest 0.0%
github.com/0xrawsec/whids/api/manager.go:88: gunzipMiddleware 62.5%
github.com/0xrawsec/whids/api/manager.go:111: Empty 100.0%
github.com/0xrawsec/whids/api/manager.go:116: Verify 50.0%
github.com/0xrawsec/whids/api/manager.go:129: UUIDGen 100.0%
github.com/0xrawsec/whids/api/manager.go:138: KeyGen 100.0%
github.com/0xrawsec/whids/api/manager.go:185: LoadManagerConfig 0.0%
github.com/0xrawsec/whids/api/manager.go:197: SetPath 100.0%
github.com/0xrawsec/whids/api/manager.go:202: EndpointAPIUrl 0.0%
github.com/0xrawsec/whids/api/manager.go:212: AdminAPIUrl 75.0%
github.com/0xrawsec/whids/api/manager.go:222: Save 0.0%
github.com/0xrawsec/whids/api/manager.go:260: NewManager 77.8%
github.com/0xrawsec/whids/api/manager.go:329: initializeDB 66.7%
github.com/0xrawsec/whids/api/manager.go:360: CreateNewAdminAPIUser 50.0%
github.com/0xrawsec/whids/api/manager.go:373: LoadGeneEngine 85.7%
github.com/0xrawsec/whids/api/manager.go:386: updateRules 100.0%
github.com/0xrawsec/whids/api/manager.go:399: AddEndpoint 100.0%
github.com/0xrawsec/whids/api/manager.go:404: UpdateReducer 100.0%
github.com/0xrawsec/whids/api/manager.go:420: Wait 100.0%
github.com/0xrawsec/whids/api/manager.go:425: IsDone 0.0%
github.com/0xrawsec/whids/api/manager.go:430: Shutdown 86.7%
github.com/0xrawsec/whids/api/manager.go:454: Run 100.0%
github.com/0xrawsec/whids/api/manager_admin_api.go:34: admApiParseDuration 71.4%
github.com/0xrawsec/whids/api/manager_admin_api.go:47: admApiParseTime 66.7%
github.com/0xrawsec/whids/api/manager_admin_api.go:54: muxGetVar 75.0%
github.com/0xrawsec/whids/api/manager_admin_api.go:62: format 100.0%
Expand All @@ -98,37 +100,37 @@ github.com/0xrawsec/whids/api/manager_admin_api.go:108: UnmarshalData 75.0%
github.com/0xrawsec/whids/api/manager_admin_api.go:117: ToJSON 50.0%
github.com/0xrawsec/whids/api/manager_admin_api.go:127: admErr 0.0%
github.com/0xrawsec/whids/api/manager_admin_api.go:131: admJSONResp 100.0%
github.com/0xrawsec/whids/api/manager_admin_api.go:135: admMsgStr 0.0%
github.com/0xrawsec/whids/api/manager_admin_api.go:135: admMsgStr 100.0%
github.com/0xrawsec/whids/api/manager_admin_api.go:146: adminAuthorizationMiddleware 66.7%
github.com/0xrawsec/whids/api/manager_admin_api.go:162: admLogHTTPMiddleware 100.0%
github.com/0xrawsec/whids/api/manager_admin_api.go:170: adminRespHeaderMiddleware 100.0%
github.com/0xrawsec/whids/api/manager_admin_api.go:180: admAPIUsers 0.0%
github.com/0xrawsec/whids/api/manager_admin_api.go:228: admAPIUser 0.0%
github.com/0xrawsec/whids/api/manager_admin_api.go:289: admAPIEndpoints 83.3%
github.com/0xrawsec/whids/api/manager_admin_api.go:334: admAPIEndpoint 0.0%
github.com/0xrawsec/whids/api/manager_admin_api.go:413: ToCommand 77.8%
github.com/0xrawsec/whids/api/manager_admin_api.go:435: admAPIEndpointCommand 70.8%
github.com/0xrawsec/whids/api/manager_admin_api.go:480: admAPIEndpointCommandField 52.9%
github.com/0xrawsec/whids/api/manager_admin_api.go:517: admAPIEndpointLogs 57.9%
github.com/0xrawsec/whids/api/manager_admin_api.go:658: admAPIEndpointReport 73.7%
github.com/0xrawsec/whids/api/manager_admin_api.go:698: admAPIEndpointReportArchive 0.0%
github.com/0xrawsec/whids/api/manager_admin_api.go:773: admAPIEndpointsReports 100.0%
github.com/0xrawsec/whids/api/manager_admin_api.go:796: listEndpointDumps 0.0%
github.com/0xrawsec/whids/api/manager_admin_api.go:863: admAPIArtifacts 0.0%
github.com/0xrawsec/whids/api/manager_admin_api.go:894: admAPIEndpointArtifacts 0.0%
github.com/0xrawsec/whids/api/manager_admin_api.go:925: admAPIEndpointArtifact 0.0%
github.com/0xrawsec/whids/api/manager_admin_api.go:996: admAPIStats 0.0%
github.com/0xrawsec/whids/api/manager_admin_api.go:1004: admAPIIocs 54.3%
github.com/0xrawsec/whids/api/manager_admin_api.go:1077: admAPIRules 0.0%
github.com/0xrawsec/whids/api/manager_admin_api.go:1238: admAPIRulesReload 0.0%
github.com/0xrawsec/whids/api/manager_admin_api.go:1251: admAPIRulesSave 0.0%
github.com/0xrawsec/whids/api/manager_admin_api.go:1294: wsHandleControlMessage 100.0%
github.com/0xrawsec/whids/api/manager_admin_api.go:1304: admAPIStreamEvents 71.4%
github.com/0xrawsec/whids/api/manager_admin_api.go:1327: admAPIStreamDetections 0.0%
github.com/0xrawsec/whids/api/manager_admin_api.go:1352: runAdminAPI 87.2%
github.com/0xrawsec/whids/api/manager_endpoint_api.go:27: endpointFromRequest 0.0%
github.com/0xrawsec/whids/api/manager_admin_api.go:180: admAPIUsers 54.8%
github.com/0xrawsec/whids/api/manager_admin_api.go:248: admAPIUser 59.4%
github.com/0xrawsec/whids/api/manager_admin_api.go:309: admAPIEndpoints 83.3%
github.com/0xrawsec/whids/api/manager_admin_api.go:354: admAPIEndpoint 73.5%
github.com/0xrawsec/whids/api/manager_admin_api.go:433: ToCommand 77.8%
github.com/0xrawsec/whids/api/manager_admin_api.go:455: admAPIEndpointCommand 75.0%
github.com/0xrawsec/whids/api/manager_admin_api.go:500: admAPIEndpointCommandField 52.9%
github.com/0xrawsec/whids/api/manager_admin_api.go:537: admAPIEndpointLogs 69.7%
github.com/0xrawsec/whids/api/manager_admin_api.go:678: admAPIEndpointReport 78.9%
github.com/0xrawsec/whids/api/manager_admin_api.go:718: admAPIEndpointReportArchive 67.4%
github.com/0xrawsec/whids/api/manager_admin_api.go:793: admAPIEndpointsReports 100.0%
github.com/0xrawsec/whids/api/manager_admin_api.go:816: listEndpointDumps 80.6%
github.com/0xrawsec/whids/api/manager_admin_api.go:883: admAPIArtifacts 61.1%
github.com/0xrawsec/whids/api/manager_admin_api.go:914: admAPIEndpointArtifacts 61.1%
github.com/0xrawsec/whids/api/manager_admin_api.go:945: admAPIEndpointArtifact 62.9%
github.com/0xrawsec/whids/api/manager_admin_api.go:1016: admAPIStats 100.0%
github.com/0xrawsec/whids/api/manager_admin_api.go:1024: admAPIIocs 68.6%
github.com/0xrawsec/whids/api/manager_admin_api.go:1097: admAPIRules 68.8%
github.com/0xrawsec/whids/api/manager_admin_api.go:1260: admAPIRulesReload 83.3%
github.com/0xrawsec/whids/api/manager_admin_api.go:1273: admAPIRulesSave 65.2%
github.com/0xrawsec/whids/api/manager_admin_api.go:1316: wsHandleControlMessage 100.0%
github.com/0xrawsec/whids/api/manager_admin_api.go:1326: admAPIStreamEvents 71.4%
github.com/0xrawsec/whids/api/manager_admin_api.go:1349: admAPIStreamDetections 0.0%
github.com/0xrawsec/whids/api/manager_admin_api.go:1374: runAdminAPI 87.2%
github.com/0xrawsec/whids/api/manager_endpoint_api.go:27: endpointFromRequest 75.0%
github.com/0xrawsec/whids/api/manager_endpoint_api.go:35: mutEndpointFromRequest 75.0%
github.com/0xrawsec/whids/api/manager_endpoint_api.go:45: endpointAuthorizationMiddleware 66.7%
github.com/0xrawsec/whids/api/manager_endpoint_api.go:45: endpointAuthorizationMiddleware 76.2%
github.com/0xrawsec/whids/api/manager_endpoint_api.go:85: isVerboseURL 100.0%
github.com/0xrawsec/whids/api/manager_endpoint_api.go:94: endptLogHTTPMiddleware 0.0%
github.com/0xrawsec/whids/api/manager_endpoint_api.go:102: endptQuietLogHTTPMiddleware 100.0%
Expand All @@ -138,21 +140,21 @@ github.com/0xrawsec/whids/api/manager_endpoint_api.go:182: Rules 100.0%
github.com/0xrawsec/whids/api/manager_endpoint_api.go:189: RulesSha256 100.0%
github.com/0xrawsec/whids/api/manager_endpoint_api.go:195: IoCs 50.0%
github.com/0xrawsec/whids/api/manager_endpoint_api.go:204: IoCsSha256 100.0%
github.com/0xrawsec/whids/api/manager_endpoint_api.go:209: UploadDump 0.0%
github.com/0xrawsec/whids/api/manager_endpoint_api.go:209: UploadDump 44.4%
github.com/0xrawsec/whids/api/manager_endpoint_api.go:242: Collect 84.6%
github.com/0xrawsec/whids/api/manager_endpoint_api.go:315: AddCommand 75.0%
github.com/0xrawsec/whids/api/manager_endpoint_api.go:324: GetCommand 66.7%
github.com/0xrawsec/whids/api/manager_endpoint_api.go:334: Command 80.8%
github.com/0xrawsec/whids/api/manager_endpoint_api.go:334: Command 84.6%
github.com/0xrawsec/whids/api/upload.go:31: NewUploadShrinker 0.0%
github.com/0xrawsec/whids/api/upload.go:65: Size 0.0%
github.com/0xrawsec/whids/api/upload.go:70: Next 0.0%
github.com/0xrawsec/whids/api/upload.go:91: Done 0.0%
github.com/0xrawsec/whids/api/upload.go:96: Err 0.0%
github.com/0xrawsec/whids/api/upload.go:101: Close 0.0%
github.com/0xrawsec/whids/api/upload.go:118: Validate 0.0%
github.com/0xrawsec/whids/api/upload.go:132: Implode 0.0%
github.com/0xrawsec/whids/api/upload.go:137: Dump 0.0%
github.com/0xrawsec/whids/api/upload.go:155: write 0.0%
github.com/0xrawsec/whids/api/upload.go:118: Validate 57.1%
github.com/0xrawsec/whids/api/upload.go:132: Implode 100.0%
github.com/0xrawsec/whids/api/upload.go:137: Dump 71.4%
github.com/0xrawsec/whids/api/upload.go:155: write 31.6%
github.com/0xrawsec/whids/event/event.go:42: NewEdrEvent 100.0%
github.com/0xrawsec/whids/event/event.go:46: InitEdrData 0.0%
github.com/0xrawsec/whids/event/event.go:50: Hash 100.0%
Expand Down Expand Up @@ -231,4 +233,4 @@ github.com/0xrawsec/whids/logger/search.go:187: Events 89.7%
github.com/0xrawsec/whids/logger/search.go:254: Err 100.0%
github.com/0xrawsec/whids/logger/search.go:258: close 80.0%
github.com/0xrawsec/whids/logger/search.go:269: Close 100.0%
total: (statements) 54.3%
total: (statements) 70.4%
34 changes: 19 additions & 15 deletions api/adminapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,8 @@ func TestAdminAPIGetEndpointLogs(t *testing.T) {

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

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

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

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

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

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

for i := float64(0); i < nclients; i++ {
u := url.URL{Scheme: "wss", Host: format("localhost:%d", 8001), Path: AdmAPIStreamEvents}

u := url.URL{
Scheme: "wss",
Host: format("%s:%d", mconf.AdminAPI.Host, mconf.AdminAPI.Port),
Path: AdmAPIStreamEvents}
key := testAdminUser.Key
dialer := *websocket.DefaultDialer
dialer.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
Expand Down
2 changes: 1 addition & 1 deletion api/api_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var (
cconf = ClientConfig{
Proto: "https",
Host: "localhost",
Port: 8000,
Port: mconf.EndpointAPI.Port,
UUID: "5a92baeb-9384-47d3-92b4-a0db6f9b8c6d",
Key: "don'tcomplain",
ServerFingerprint: "511dc40cb2363974a97dfd47437feb8307cbd9d938645e1442775aa97ec14227",
Expand Down
4 changes: 2 additions & 2 deletions api/forwarder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ var (
mconf = ManagerConfig{
AdminAPI: AdminAPIConfig{
Host: "localhost",
Port: 8001,
Port: AdmAPIDefaultPort,
},
EndpointAPI: EndpointAPIConfig{
Host: "",
Port: 8000,
Port: EptAPIDefaultPort,
},
Logging: ManagerLogConfig{
Root: "./data/logs",
Expand Down
27 changes: 24 additions & 3 deletions api/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ const (
)

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

func init() {
Expand Down Expand Up @@ -197,6 +198,26 @@ func (mc *ManagerConfig) SetPath(path string) {
mc.path = path
}

// EndpointAPIUrl returns the URL of the Endpoint API
func (mc *ManagerConfig) EndpointAPIUrl() string {
proto := "https"
if mc.TLS.Empty() {
proto = "http"
}

return fmt.Sprintf("%s://%s:%d", proto, mc.EndpointAPI.Host, mc.EndpointAPI.Port)
}

// EndpointAPIUrl returns the URL of the Admin API
func (mc *ManagerConfig) AdminAPIUrl() string {
proto := "https"
if mc.TLS.Empty() {
proto = "http"
}

return fmt.Sprintf("%s://%s:%d", proto, mc.AdminAPI.Host, mc.AdminAPI.Port)
}

// Save saves the configuration to a path specified by the path member of the structure
func (mc *ManagerConfig) Save() error {
b, err := toml.Marshal(mc)
Expand Down
Loading

0 comments on commit 03191b6

Please sign in to comment.