diff --git a/internal/chaindb/chaindb.go b/internal/chaindb/chaindb.go index 3cb3721..1782c79 100644 --- a/internal/chaindb/chaindb.go +++ b/internal/chaindb/chaindb.go @@ -50,7 +50,7 @@ func (db *GagentDb) LoadHCL(ChainDBPath string) error { /* * Write the database to an HCL file */ -func (db *GagentDb) WriteHCL() error { +func (db *GagentDb) WriteHCL(ChainDBPath string) error { f := hclwrite.NewEmptyFile() rootBody := f.Body() @@ -69,7 +69,7 @@ func (db *GagentDb) WriteHCL() error { agentBody.SetAttributeValue("version", cty.StringVal(row.Agent.Shasum)) } - return ioutil.WriteFile("chaindb_out.hcl", f.Bytes(), 0600) + return ioutil.WriteFile(ChainDBPath, f.Bytes(), 0600) } /* diff --git a/internal/client/client.go b/internal/client/client.go index 3f894ca..3985de6 100644 --- a/internal/client/client.go +++ b/internal/client/client.go @@ -69,13 +69,21 @@ func Main(wg *sync.WaitGroup, config gstructs.GagentConfig) { */ func getTagsFromHints(agent gstructs.AgentDetails) []string { var tags []string - re := regexp.MustCompile(`\s*set\s+GHINT\s*\[\s*split\s*"(?P.+)"\s*\,\s*\]`) + + // Use named capture groups to extract the hints + re := regexp.MustCompile(`^*set\s+GHINT\s*\[\s*split\s*"(?P[^"]+)"\s*,\s*\]`) res := re.FindStringSubmatch(string(agent.ScriptCode)) - if len(res) < 1 { + + // If we don't have at least 2 matches, we have no hints + if len(res) < 2 { log.Printf("[ERROR] Agent is missing GHINT tags") os.Exit(4) } - tags = strings.Split(res[1], ",") + + // Use named capturing group index + hintsIndex := re.SubexpIndex("Hints") + tags = strings.Split(res[hintsIndex], ",") + log.Printf("[DEBUG] G'Agent hints: %v\n", tags) return tags diff --git a/internal/router/router.go b/internal/router/router.go index b2eca6c..80f2a30 100644 --- a/internal/router/router.go +++ b/internal/router/router.go @@ -122,7 +122,6 @@ func createClientListener(wg *sync.WaitGroup, config gstructs.GagentConfig) { } log.Printf("[DEBUG] Client message received: %s", msg) } - } func unwrap(msg []string) (head string, tail []string) { @@ -137,9 +136,6 @@ func unwrap(msg []string) (head string, tail []string) { func answerClient(w http.ResponseWriter, r *http.Request) { if r.URL.Path != "/" { - /* - * fmt.Fprintf(w, "%v\n", r) - */ http.NotFound(w, r) return } @@ -152,18 +148,21 @@ func answerClient(w http.ResponseWriter, r *http.Request) { * Handle GET requests */ case http.MethodGet: + log.Println("[DEBUG] GET method received") fmt.Fprintf(w, "%v\n", r) /* * Handle POST requests */ case http.MethodPost: + log.Println("[DEBUG] POST method received") fmt.Fprintf(w, "%v\n", r) /* * Handle PUT requests */ case http.MethodOptions: + log.Println("[DEBUG] PUT method received") w.Header().Set("Allow", "GET, POST, OPTIONS") w.WriteHeader(http.StatusNoContent)