diff --git a/config/messages.json b/config/messages.json index 95e489dde71..bbbba4d365a 100644 --- a/config/messages.json +++ b/config/messages.json @@ -8056,7 +8056,7 @@ }, "error:pkg/qrcodegenerator/qrcode/enddevices:unknown_format": { "translations": { - "en": "format `{format_id}` unknown" + "en": "format unknown" }, "description": { "package": "pkg/qrcodegenerator/qrcode/enddevices", diff --git a/pkg/deviceclaimingserver/enddevices/enddevices.go b/pkg/deviceclaimingserver/enddevices/enddevices.go index 6cf2bd5c110..cbb04c360f2 100644 --- a/pkg/deviceclaimingserver/enddevices/enddevices.go +++ b/pkg/deviceclaimingserver/enddevices/enddevices.go @@ -41,7 +41,7 @@ type EndDeviceClaimer interface { // SupportsJoinEUI returns whether the Join Server supports this JoinEUI. SupportsJoinEUI(joinEUI types.EUI64) bool // Claim claims an End Device. - Claim(ctx context.Context, joinEUI *types.EUI64, devEUI *types.EUI64, claimAuthenticationCode string, networkServerAddress string) error + Claim(ctx context.Context, joinEUI, devEUI types.EUI64, claimAuthenticationCode, networkServerAddress string) error // GetClaimStatus returns the claim status an End Device. GetClaimStatus(ctx context.Context, ids *ttnpb.EndDeviceIdentifiers) (*ttnpb.GetClaimStatusResponse, error) // Unclaim releases the claim on an End Device. @@ -161,8 +161,8 @@ func (upstream *Upstream) joinEUIClaimer(ctx context.Context, joinEUI types.EUI6 } // Claim implements EndDeviceClaimingServer. -func (upstream *Upstream) Claim(ctx context.Context, joinEUI *types.EUI64, devEUI *types.EUI64, claimAuthenticationCode string, networkServerAddress string) error { - claimer := upstream.joinEUIClaimer(ctx, *joinEUI) +func (upstream *Upstream) Claim(ctx context.Context, joinEUI, devEUI types.EUI64, claimAuthenticationCode, networkServerAddress string) error { + claimer := upstream.joinEUIClaimer(ctx, joinEUI) if claimer == nil { return errClaimingNotSupported.WithAttributes("eui", joinEUI) } diff --git a/pkg/deviceclaimingserver/enddevices/enddevices_test.go b/pkg/deviceclaimingserver/enddevices/enddevices_test.go index a7fc816f951..9969b0a66b0 100644 --- a/pkg/deviceclaimingserver/enddevices/enddevices_test.go +++ b/pkg/deviceclaimingserver/enddevices/enddevices_test.go @@ -55,7 +55,7 @@ func TestUpstream(t *testing.T) { ctx = rights.NewContextWithFetcher(ctx, mock) // Invalid JoinEUI. - err = upstream.Claim(ctx, unsupportedJoinEUI, &types.EUI64{0x00, 0x04, 0xA3, 0x0B, 0x00, 0x1C, 0x05, 0x30}, "secret", "") + err = upstream.Claim(ctx, *unsupportedJoinEUI, types.EUI64{0x00, 0x04, 0xA3, 0x0B, 0x00, 0x1C, 0x05, 0x30}, "secret", "") a.So(errors.IsAborted(err), should.BeTrue) _, err = upstream.Unclaim(ctx, &ttnpb.EndDeviceIdentifiers{ @@ -82,7 +82,7 @@ func TestUpstream(t *testing.T) { a.So(inf.JoinEui, should.Resemble, supportedJoinEUI) a.So(inf.SupportsClaiming, should.BeTrue) - err = upstream.Claim(ctx, supportedJoinEUI, &types.EUI64{0x00, 0x04, 0xA3, 0x0B, 0x00, 0x1C, 0x05, 0x30}, "secret", "") + err = upstream.Claim(ctx, *supportedJoinEUI, types.EUI64{0x00, 0x04, 0xA3, 0x0B, 0x00, 0x1C, 0x05, 0x30}, "secret", "") a.So(!errors.IsUnimplemented(err), should.BeTrue) _, err = upstream.Unclaim(ctx, &ttnpb.EndDeviceIdentifiers{ diff --git a/pkg/deviceclaimingserver/enddevices/ttjs/ttjs.go b/pkg/deviceclaimingserver/enddevices/ttjs/ttjs.go index 2001561ee1c..61f146e146b 100644 --- a/pkg/deviceclaimingserver/enddevices/ttjs/ttjs.go +++ b/pkg/deviceclaimingserver/enddevices/ttjs/ttjs.go @@ -121,7 +121,7 @@ var ( ) // Claim implements EndDeviceClaimer. -func (client *TTJS) Claim(ctx context.Context, joinEUI *types.EUI64, devEUI *types.EUI64, claimAuthenticationCode string, networkServerAddress string) error { +func (client *TTJS) Claim(ctx context.Context, joinEUI, devEUI types.EUI64, claimAuthenticationCode, networkServerAddress string) error { htenantID := client.config.TenantID hNSID, ok := client.hsNSIDs[networkServerAddress] diff --git a/pkg/deviceclaimingserver/enddevices/ttjs/ttjs_test.go b/pkg/deviceclaimingserver/enddevices/ttjs/ttjs_test.go index cf574d5a9e2..f9d657aa47a 100644 --- a/pkg/deviceclaimingserver/enddevices/ttjs/ttjs_test.go +++ b/pkg/deviceclaimingserver/enddevices/ttjs/ttjs_test.go @@ -141,7 +141,7 @@ func TestTTJS(t *testing.T) { // Invalid client API key. unauthenticatedClient, err := ttJSConfig.NewClient(ctx, c) test.Must(unauthenticatedClient, err) - err = unauthenticatedClient.Claim(ctx, &supportedJoinEUI, &devEUI, claimAuthenticationCode, nsAddress) + err = unauthenticatedClient.Claim(ctx, supportedJoinEUI, devEUI, claimAuthenticationCode, nsAddress) a.So(errors.IsUnauthenticated(err), should.BeTrue) err = unauthenticatedClient.Unclaim(ctx, &ttnpb.EndDeviceIdentifiers{ DevEui: &devEUI, @@ -167,16 +167,16 @@ func TestTTJS(t *testing.T) { // Test Claiming for _, tc := range []struct { Name string - DevEUI *types.EUI64 - JoinEUI *types.EUI64 + DevEUI types.EUI64 + JoinEUI types.EUI64 AuthenticationCode string HNSAddress string ErrorAssertion func(err error) bool }{ { Name: "EmptyCAC", - DevEUI: &devEUI, - JoinEUI: &supportedJoinEUI, + DevEUI: devEUI, + JoinEUI: supportedJoinEUI, AuthenticationCode: "", HNSAddress: nsAddress, ErrorAssertion: func(err error) bool { @@ -185,8 +185,8 @@ func TestTTJS(t *testing.T) { }, { Name: "InvalidCAC", - DevEUI: &devEUI, - JoinEUI: &supportedJoinEUI, + DevEUI: devEUI, + JoinEUI: supportedJoinEUI, AuthenticationCode: "invalid", HNSAddress: nsAddress, ErrorAssertion: func(err error) bool { @@ -195,8 +195,8 @@ func TestTTJS(t *testing.T) { }, { Name: "NoTargetNSID", - DevEUI: &devEUI, - JoinEUI: &supportedJoinEUI, + DevEUI: devEUI, + JoinEUI: supportedJoinEUI, AuthenticationCode: claimAuthenticationCode, ErrorAssertion: func(err error) bool { return errors.IsInvalidArgument(err) @@ -204,8 +204,8 @@ func TestTTJS(t *testing.T) { }, { Name: "NotProvisoned", - DevEUI: &types.EUI64{}, - JoinEUI: &supportedJoinEUI, + DevEUI: types.EUI64{}, + JoinEUI: supportedJoinEUI, AuthenticationCode: claimAuthenticationCode, HNSAddress: nsAddress, ErrorAssertion: func(err error) bool { @@ -214,8 +214,8 @@ func TestTTJS(t *testing.T) { }, { Name: "SuccessfulClaim", - DevEUI: &devEUI, - JoinEUI: &supportedJoinEUI, + DevEUI: devEUI, + JoinEUI: supportedJoinEUI, AuthenticationCode: claimAuthenticationCode, HNSAddress: nsAddress, }, @@ -250,7 +250,7 @@ func TestTTJS(t *testing.T) { } otherClient, err := otherClientConfig.NewClient(ctx, c) test.Must(otherClient, err) - err = otherClient.Claim(ctx, &supportedJoinEUI, &devEUI, claimAuthenticationCode, nsAddress) + err = otherClient.Claim(ctx, supportedJoinEUI, devEUI, claimAuthenticationCode, nsAddress) a.So(errors.IsPermissionDenied(err), should.BeTrue) ret, err = otherClient.GetClaimStatus(ctx, &ttnpb.EndDeviceIdentifiers{ DevEui: &devEUI, @@ -284,7 +284,7 @@ func TestTTJS(t *testing.T) { a.So(errors.IsNotFound(err), should.BeTrue) // Try to claim - err = client.Claim(ctx, &supportedJoinEUI, &devEUI, claimAuthenticationCode, nsAddress) + err = client.Claim(ctx, supportedJoinEUI, devEUI, claimAuthenticationCode, nsAddress) a.So(err, should.BeNil) // Get valid status diff --git a/pkg/deviceclaimingserver/grpc_end_devices.go b/pkg/deviceclaimingserver/grpc_end_devices.go index db64850f030..aaddcad1572 100644 --- a/pkg/deviceclaimingserver/grpc_end_devices.go +++ b/pkg/deviceclaimingserver/grpc_end_devices.go @@ -103,13 +103,12 @@ func (edcs *endDeviceClaimingServer) Claim(ctx context.Context, req *ttnpb.Claim } var ( - joinEUI *types.EUI64 - devEUI *types.EUI64 + joinEUI, devEUI types.EUI64 claimAuthenticationCode string ) if authenticatedIDs := req.GetAuthenticatedIdentifiers(); authenticatedIDs != nil { - joinEUI = &req.GetAuthenticatedIdentifiers().JoinEui - devEUI = &req.GetAuthenticatedIdentifiers().DevEui + joinEUI = req.GetAuthenticatedIdentifiers().JoinEui + devEUI = req.GetAuthenticatedIdentifiers().DevEui claimAuthenticationCode = req.GetAuthenticatedIdentifiers().AuthenticationCode } else if qrCode := req.GetQrCode(); qrCode != nil { conn, err := edcs.DCS.GetPeerConn(ctx, ttnpb.ClusterRole_QR_CODE_GENERATOR, nil) @@ -124,13 +123,14 @@ func (edcs *endDeviceClaimingServer) Claim(ctx context.Context, req *ttnpb.Claim if dev == nil { return nil, errParseQRCode.New() } - joinEUI = dev.GetIds().JoinEui - devEUI = dev.GetIds().DevEui + joinEUI = *dev.GetIds().JoinEui + devEUI = *dev.GetIds().DevEui claimAuthenticationCode = dev.ClaimAuthenticationCode.Value } else { return nil, errNoJoinEUI.New() } + // External services, including Join Servers, typically identify Network Servers by host instead of by host and port. networkServerAddress, _, err := net.SplitHostPort(req.TargetNetworkServerAddress) if err != nil { // TargetNetworkServerAddress is already validated by the API. @@ -151,8 +151,8 @@ func (edcs *endDeviceClaimingServer) Claim(ctx context.Context, req *ttnpb.Claim return &ttnpb.EndDeviceIdentifiers{ DeviceId: req.TargetDeviceId, ApplicationIds: req.TargetApplicationIds, - DevEui: devEUI, - JoinEui: joinEUI, + DevEui: &devEUI, + JoinEui: &joinEUI, }, nil } diff --git a/pkg/qrcodegenerator/qrcode/enddevices/enddevices.go b/pkg/qrcodegenerator/qrcode/enddevices/enddevices.go index 314f445983c..c8287f34351 100644 --- a/pkg/qrcodegenerator/qrcode/enddevices/enddevices.go +++ b/pkg/qrcodegenerator/qrcode/enddevices/enddevices.go @@ -107,7 +107,7 @@ func (s *Server) RegisterEndDeviceFormat(id string, f Format) { } var ( - errUnknownFormat = errors.DefineInvalidArgument("unknown_format", "format `{format_id}` unknown") + errUnknownFormat = errors.DefineInvalidArgument("unknown_format", "format unknown") ) // Parse attempts to parse the given QR code data. @@ -125,5 +125,5 @@ func (s *Server) Parse(formatID string, data []byte) (ret Data, err error) { return nil, err } } - return nil, errUnknownFormat.WithAttributes("format_id", formatID) + return nil, errUnknownFormat.New() }