Skip to content

Commit

Permalink
fix conversion error for empty zone
Browse files Browse the repository at this point in the history
Signed-off-by: Lorenzo Merici <[email protected]>
  • Loading branch information
lorenzo-merici authored and poiana committed Sep 21, 2023
1 parent 69618af commit 2fd8cf9
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions plugins/gcpaudit/pkg/gcpaudit/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,16 @@ func (p *Plugin) Extract(req sdk.ExtractRequest, evt sdk.EventReader) error {
return nil
}
// if region is not present, check for zone
zone := p.jdata.Get("resource").Get("labels").Get("zone").String()
if zone != "" && len(zone) > 2 {
// if in format: "us-central1-a", remove last two chars
formattedZone := zone[:len(zone)-2]
req.SetValue(formattedZone)
} else if zone != "" {
req.SetValue(zone)
val := p.jdata.Get("resource").Get("labels").Get("zone").GetStringBytes()
if val != nil {
zone := string(val)
if len(zone) > 2 {
// if in format: "us-central1-a", remove last two chars
formattedZone := zone[:len(zone)-2]
req.SetValue(formattedZone)
} else if zone != "" {
req.SetValue(zone)
}
}

case "gcp.logging.sink":
Expand Down

0 comments on commit 2fd8cf9

Please sign in to comment.