Skip to content
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
7 changes: 4 additions & 3 deletions api/types/accesslist/accesslist.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package accesslist

import (
"encoding/json"
"fmt"
"time"

"github.com/gravitational/trace"
Expand Down Expand Up @@ -235,17 +236,17 @@ func (a *AccessList) MatchSearch(values []string) bool {
}

func (a *Audit) UnmarshalJSON(data []byte) error {
var audit map[string]string
var audit map[string]interface{}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's already merged but why don't you just use a temp struct to unmarshal these values. The unmarshal to map[string]any is not good when we know the types and fields.
Extending to other fields isn't trivial and the current form is quite difficult to understand

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to look into that as a follow on PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with this ^

if err := json.Unmarshal(data, &audit); err != nil {
return trace.Wrap(err)
}

var err error
a.Frequency, err = time.ParseDuration(audit["frequency"])
a.Frequency, err = time.ParseDuration(fmt.Sprintf("%v", audit["frequency"]))
if err != nil {
return trace.Wrap(err)
}
a.NextAuditDate, err = time.Parse(time.RFC3339Nano, audit["next_audit_date"])
a.NextAuditDate, err = time.Parse(time.RFC3339Nano, fmt.Sprintf("%v", audit["next_audit_date"]))
if err != nil {
return trace.Wrap(err)
}
Expand Down