go-sigsci icon indicating copy to clipboard operation
go-sigsci copied to clipboard

Handle blank AgentLastRuleUpdate

Open jeremy-cxf opened this issue 5 months ago • 0 comments

Ran into some issues today running a debug util that uses ListAgents failed each time when the site contained an EdgeWAF. This is because the agents endpoint is returning:

      "agent.last_rule_update": "",

In the JSON response, which we try to unmarshal via:

AgentLastRuleUpdate         time.Time  `json:"agent.last_rule_update"`

Which results in:

2024/09/04 19:17:12 parsing time "" as "2006-01-02T15:04:05Z07:00": cannot parse "" as "2006"

Could probably handle this from the API, but easier to just implement a custom Unmarshal() to handle the empty "" value in this scenario. I don't believe any other keys need to be changed, as AgentLastSeen is always updated.

	agents, err := sc.ListAgents("xxxx", "xxxxx")
	if err != nil {
		log.Fatal(err)
	}

	for _, agent := range agents {
		fmt.Println(agent.AgentName)
		fmt.Println(agent.AgentLastRuleUpdate)
	}

Now returns:

Site ID:  xxxxx
EdgeSecurity
0001-01-01 00:00:00 +0000 UTC
waf-lab-demo-cf9fcf48-gd6zt
2024-09-04 10:58:05 +0000 UTC

jeremy-cxf avatar Sep 04 '24 18:09 jeremy-cxf