Skip to content
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

update castle sdk remove deprecated fields #26

Merged
merged 9 commits into from
Nov 6, 2024
Merged
Changes from 1 commit
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
15 changes: 13 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"io"
"net/http"
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
Expand Down Expand Up @@ -75,6 +76,10 @@ func (c *Castle) Filter(ctx context.Context, req *Request) (RecommendedAction, e
Email: req.User.Email,
Username: req.User.Name,
Copy link

Choose a reason for hiding this comment

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

Is the name necessarily the username? I wonder if we're reusing the name field in our generic request type in a way that wasn't intended by the underlying API, or are they actually the same values?

Copy link
Author

@pansbro12 pansbro12 Nov 6, 2024

Choose a reason for hiding this comment

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

No so i actually was just thinking about this now, I remember us using either the account number or the email as username in a service somewhere but i can't think where.

Copy link
Author

Choose a reason for hiding this comment

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

Not really sure whether to include this now, looking at the code from the castle-processor the username is seems to be either the email or account number depending on what the user used to sign in. The username value is contained in the request properties so I've just set that as the username, might be that the username and the email are duplicates in some cases but I don't think that will be an issue.

}
createdAt := req.CreatedAt
if req.CreatedAt.IsZero() {
pansbro12 marked this conversation as resolved.
Show resolved Hide resolved
createdAt = time.Now()
}
r := &castleFilterAPIRequest{
Type: req.Event.EventType,
Name: req.Event.Name,
Expand All @@ -83,7 +88,7 @@ func (c *Castle) Filter(ctx context.Context, req *Request) (RecommendedAction, e
Params: params,
Context: req.Context,
Properties: req.Properties,
CreatedAt: req.CreatedAt,
CreatedAt: createdAt,
}
return c.sendCall(ctx, r, FilterEndpoint)
}
Expand All @@ -97,6 +102,10 @@ func (c *Castle) Risk(ctx context.Context, req *Request) (RecommendedAction, err
if req.Context == nil {
return RecommendedActionNone, errors.New("request.Context cannot be nil")
}
createdAt := req.CreatedAt
if req.CreatedAt.IsZero() {
pansbro12 marked this conversation as resolved.
Show resolved Hide resolved
createdAt = time.Now()
}
r := &castleRiskAPIRequest{
Type: req.Event.EventType,
Name: req.Event.Name,
Expand All @@ -105,7 +114,7 @@ func (c *Castle) Risk(ctx context.Context, req *Request) (RecommendedAction, err
User: req.User,
Context: req.Context,
Properties: req.Properties,
CreatedAt: req.CreatedAt,
CreatedAt: createdAt,
}
return c.sendCall(ctx, r, RiskEndpoint)
}
Expand All @@ -128,6 +137,8 @@ func (c *Castle) sendCall(ctx context.Context, r castleAPIRequest, url string) (
switch request := r.(type) {
case *castleFilterAPIRequest, *castleRiskAPIRequest:
err = json.NewEncoder(b).Encode(request)
default:
err = fmt.Errorf("incorrect request type passed as argument.")
}
if err != nil {
return RecommendedActionNone, err
Expand Down
Loading