Skip to content

Commit

Permalink
dcs: Update method input types
Browse files Browse the repository at this point in the history
  • Loading branch information
KrishnaIyer committed Apr 26, 2022
1 parent f13ac29 commit f06edc0
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion config/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions pkg/deviceclaimingserver/enddevices/enddevices.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/deviceclaimingserver/enddevices/enddevices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion pkg/deviceclaimingserver/enddevices/ttjs/ttjs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
30 changes: 15 additions & 15 deletions pkg/deviceclaimingserver/enddevices/ttjs/ttjs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -195,17 +195,17 @@ 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)
},
},
{
Name: "NotProvisoned",
DevEUI: &types.EUI64{},
JoinEUI: &supportedJoinEUI,
DevEUI: types.EUI64{},
JoinEUI: supportedJoinEUI,
AuthenticationCode: claimAuthenticationCode,
HNSAddress: nsAddress,
ErrorAssertion: func(err error) bool {
Expand All @@ -214,8 +214,8 @@ func TestTTJS(t *testing.T) {
},
{
Name: "SuccessfulClaim",
DevEUI: &devEUI,
JoinEUI: &supportedJoinEUI,
DevEUI: devEUI,
JoinEUI: supportedJoinEUI,
AuthenticationCode: claimAuthenticationCode,
HNSAddress: nsAddress,
},
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions pkg/deviceclaimingserver/grpc_end_devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand All @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/qrcodegenerator/qrcode/enddevices/enddevices.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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()
}

0 comments on commit f06edc0

Please sign in to comment.