mirror of
https://github.com/dragonheim/gagent.git
synced 2025-01-18 09:36:28 -08:00
fix: changed db destination to programatic instead of hardcoded.
fix: minor cleanup. feat: cleaned up agent hint collection.
This commit is contained in:
parent
13d18d7714
commit
2b0975b30a
3 changed files with 16 additions and 9 deletions
|
@ -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)
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -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<Hints>.+)"\s*\,\s*\]`)
|
||||
|
||||
// Use named capture groups to extract the hints
|
||||
re := regexp.MustCompile(`^*set\s+GHINT\s*\[\s*split\s*"(?P<Hints>[^"]+)"\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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue