Skip to content

Support both cases for resource holder id #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion pkg/brood/data.go
Original file line number Diff line number Diff line change
@@ -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"`
2 changes: 1 addition & 1 deletion pkg/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package bugout

const Version string = "0.4.5"
const Version string = "0.4.6"