Skip to content

Commit

Permalink
refactor: get spans from context instead of passing as arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
rmrt1n committed Dec 11, 2024
1 parent c4cb253 commit 54557af
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
6 changes: 4 additions & 2 deletions relay/nakama/auth/argus_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ func authWithArgusID(
logger runtime.Logger,
_ runtime.NakamaModule,
in *api.AuthenticateCustomRequest,
span trace.Span,
) (*api.AuthenticateCustomRequest, error) {
span := trace.SpanFromContext(ctx)

jwtHash := in.GetAccount().GetId()
jwt := in.GetAccount().GetVars()["jwt"]
claims, err := validateAndParseJWT(ctx, jwtHash, jwt, GlobalJWTSecret)
Expand Down Expand Up @@ -129,8 +130,9 @@ func linkWithArgusID(
logger runtime.Logger,
_ runtime.NakamaModule,
in *api.AccountCustom,
span trace.Span,
) (*api.AccountCustom, error) {
span := trace.SpanFromContext(ctx)

jwtHash := in.GetId()
jwt := in.GetVars()["jwt"]
claims, err := validateAndParseJWT(ctx, jwtHash, jwt, GlobalJWTSecret)
Expand Down
8 changes: 4 additions & 4 deletions relay/nakama/auth/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func handleCustomAuthentication(
// In the future, other authentication methods can be added here (e.g. Twitter)
if authType == signInWithEthereumType {
span.AddEvent("Handling custom auth with SIWE")
in, err := authWithSIWE(ctx, logger, nk, in, span)
in, err := authWithSIWE(ctx, logger, nk, in)
if err != nil {
span.RecordError(err)
span.SetStatus(otelcode.Error, "Failed to authenticate with SIWE")
Expand All @@ -78,7 +78,7 @@ func handleCustomAuthentication(
}
if authType == signInWithArgusIDType && GlobalJWTSecret != "" {
span.AddEvent("Handling custom auth with Argus ID")
in, err := authWithArgusID(ctx, logger, nk, in, span)
in, err := authWithArgusID(ctx, logger, nk, in)
if err != nil {
span.RecordError(err)
span.SetStatus(otelcode.Error, "Failed to authenticate with Argus ID")
Expand Down Expand Up @@ -114,7 +114,7 @@ func handleCustomLink(
defer span.End()
// In the future, other authentication methods can be added here (e.g. Twitter)
if authType == signInWithEthereumType {
in, err := linkWithSIWE(ctx, logger, nk, in, span)
in, err := linkWithSIWE(ctx, logger, nk, in)
if err != nil {
span.RecordError(err)
span.SetStatus(otelcode.Error, "Failed to link with SIWE")
Expand All @@ -124,7 +124,7 @@ func handleCustomLink(
return in, nil
}
if authType == signInWithArgusIDType && GlobalJWTSecret != "" {
in, err := linkWithArgusID(ctx, logger, nk, in, span)
in, err := linkWithArgusID(ctx, logger, nk, in)
if err != nil {
span.RecordError(err)
span.SetStatus(otelcode.Error, "Failed to link with Argus ID")
Expand Down
8 changes: 3 additions & 5 deletions relay/nakama/auth/siwe.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func processSIWE(
logger runtime.Logger,
nk runtime.NakamaModule,
signerAddress, signature, message string,
span trace.Span,
) error {
span := trace.SpanFromContext(ctx)
span.AddEvent("Validating SIWE request")
isValidationRequest, err := validateSIWE(signerAddress, message, signature)
if err != nil {
Expand Down Expand Up @@ -86,13 +86,12 @@ func authWithSIWE(
logger runtime.Logger,
nk runtime.NakamaModule,
in *api.AuthenticateCustomRequest,
span trace.Span,
) (*api.AuthenticateCustomRequest, error) {
signerAddress := in.GetAccount().GetId()
signature := in.GetAccount().GetVars()["signature"]
message := in.GetAccount().GetVars()["message"]

err := processSIWE(ctx, logger, nk, signerAddress, signature, message, span)
err := processSIWE(ctx, logger, nk, signerAddress, signature, message)
if err != nil {
return nil, err
}
Expand All @@ -106,13 +105,12 @@ func linkWithSIWE(
logger runtime.Logger,
nk runtime.NakamaModule,
in *api.AccountCustom,
span trace.Span,
) (*api.AccountCustom, error) {
signerAddress := in.GetId()
signature := in.GetVars()["signature"]
message := in.GetVars()["message"]

err := processSIWE(ctx, logger, nk, signerAddress, signature, message, span)
err := processSIWE(ctx, logger, nk, signerAddress, signature, message)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 54557af

Please sign in to comment.