diff --git a/pkg/brood/data.go b/pkg/brood/data.go index 3adc140..11c482e 100644 --- a/pkg/brood/data.go +++ b/pkg/brood/data.go @@ -1,5 +1,9 @@ package brood +import ( + "encoding/json" +) + type User struct { Id string `json:"id"` Username string `json:"username"` @@ -83,11 +87,37 @@ type resourceUpdateRequest struct { } type ResourceHolder struct { - Id string `json:"id"` + Id string `json:"holder_id"` HolderType string `json:"holder_type"` Permissions []string `json:"permissions"` } +func (r *ResourceHolder) UnmarshalJSON(data []byte) error { + // Define an alias to avoid recursion in custom unmarshaling + type Alias ResourceHolder + aux := &struct { + Id string `json:"id"` + HolderId string `json:"holder_id"` + *Alias + }{ + Alias: (*Alias)(r), + } + + // Unmarshal into the auxiliary struct + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + + // Populate the Id field based on available data + if aux.Id != "" { + r.Id = aux.Id + } else { + r.Id = aux.HolderId + } + + return nil +} + type ResourceHolders struct { ResourceId string `json:"resource_id"` Holders []ResourceHolder `json:"holders"` diff --git a/pkg/version.go b/pkg/version.go index d535f73..0053fd2 100644 --- a/pkg/version.go +++ b/pkg/version.go @@ -1,3 +1,3 @@ package bugout -const Version string = "0.4.5" +const Version string = "0.4.6"