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

Backport contextualizing TTJS claim request #6705

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
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
23 changes: 23 additions & 0 deletions pkg/deviceclaimingserver/enddevices/ttjsv2/messages.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2022 The Things Network Foundation, The Things Industries B.V.

Check warning on line 1 in pkg/deviceclaimingserver/enddevices/ttjsv2/messages.go

View workflow job for this annotation

GitHub Actions / Check Mergeability

pkg/deviceclaimingserver/enddevices/ttjsv2/messages.go has a conflict when merging TheThingsIndustries/lorawan-stack:v3.28.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -14,6 +14,10 @@

package ttjsv2

import (
"context"
)

// ClaimData contains information about the claim.
type ClaimData struct {
HomeNetID string `json:"homeNetID"`
Expand All @@ -38,6 +42,25 @@
KEK *KEK `json:"kek,omitempty"`
}

// Apply applies the context to the request.
func (req ClaimRequest) Apply(ctx context.Context, c Component) (ClaimRequest, error) {

Check warning on line 46 in pkg/deviceclaimingserver/enddevices/ttjsv2/messages.go

View workflow job for this annotation

GitHub Actions / Code Quality

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
deriv := req
if req.HomeNSID != nil {
deriv.HomeNSID = stringValue(*req.HomeNSID)
}
if req.RegenerateOwnerToken != nil {
deriv.RegenerateOwnerToken = boolValue(*req.RegenerateOwnerToken)
}
if req.Lock != nil {
deriv.Lock = boolValue(*req.Lock)
}
if req.KEK != nil {
kek := *req.KEK
deriv.KEK = &kek
}
return deriv, nil
}

// ErrorResponse is a message that may be returned by The Things Join Server in case of an error.
type ErrorResponse struct {
Message string `json:"message"`
Expand Down
6 changes: 5 additions & 1 deletion pkg/deviceclaimingserver/enddevices/ttjsv2/ttjs.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (c *TTJS) Claim(ctx context.Context, joinEUI, devEUI types.EUI64, claimAuth
"url", reqURL,
))

claimReq := &ClaimRequest{
claimReq := ClaimRequest{
OwnerToken: claimAuthenticationCode,
Lock: boolValue(true),
HomeNetID: c.config.NetID.String(),
Expand All @@ -132,6 +132,10 @@ func (c *TTJS) Claim(ctx context.Context, joinEUI, devEUI types.EUI64, claimAuth
if c.config.NSID != nil {
claimReq.HomeNSID = stringValue(c.config.NSID.String())
}
claimReq, err := claimReq.Apply(ctx, c)
if err != nil {
return err
}
buf, err := json.Marshal(claimReq)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions pkg/deviceclaimingserver/enddevices/ttjsv2/ttjs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestTTJS(t *testing.T) { //nolint:paralleltest
client1 := ttjsv2.NewClient(c, fetcher, ttjsv2.Config{
NetID: test.DefaultNetID,
NSID: &homeNSID,
ASID: "localhost",
ASID: client1ASID,
JoinEUIPrefixes: []types.EUI64Prefix{
supportedJoinEUIPrefix,
},
Expand Down Expand Up @@ -176,7 +176,7 @@ func TestTTJS(t *testing.T) { //nolint:paralleltest
client2 := ttjsv2.NewClient(c, fetcher, ttjsv2.Config{
NetID: test.DefaultNetID,
NSID: &homeNSID,
ASID: "localhost",
ASID: client2ASID,
JoinEUIPrefixes: []types.EUI64Prefix{
supportedJoinEUIPrefix,
},
Expand Down
Loading