diff --git a/server/handler/vmModify.go b/server/handler/vmModify.go index d52f44b..41ba0bc 100644 --- a/server/handler/vmModify.go +++ b/server/handler/vmModify.go @@ -24,7 +24,7 @@ func (h *Handler) VmModify(w http.ResponseWriter, r *http.Request) { params := queries.CreateUpdateParams{} var unixTimestamp int64 - //re := regexp.MustCompile(`/([^/]+)/[^/]+\.vmdk$`) + re := regexp.MustCompile(`/([^/]+)/[^/]+\.vmdk$`) reqBody, err := io.ReadAll(r.Body) if err != nil { @@ -102,6 +102,21 @@ func (h *Handler) VmModify(w http.ResponseWriter, r *http.Request) { for i := range testConfig.DeviceChange { if testConfig.DeviceChange[i].Device.Backing != nil { h.Logger.Debug("Found backing in configspec", "backing", testConfig.DeviceChange[i].Device.Backing) + + // Find the match + backingFile := testConfig.DeviceChange[i].Device.Backing.FileName + matches := re.FindStringSubmatch(backingFile) + if len(matches) < 2 { + h.Logger.Warn("unable to match regex", "backing_filename", backingFile, "match_count", len(matches)) + } else { + h.Logger.Debug("Matched regex", "disk_owner", matches[1]) + + if strings.ToLower(matches[1]) == strings.ToLower(event.CloudEvent.Data.VM.Name) { + h.Logger.Debug("This disk belongs to this VM") + } else { + h.Logger.Debug("This disk belongs to a different VM, don't record this config change") + } + } } } }