Skip to content

Commit

Permalink
dcs: Adapt parse QR code
Browse files Browse the repository at this point in the history
  • Loading branch information
KrishnaIyer committed Jan 24, 2022
1 parent 744d675 commit 33e0f66
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions pkg/deviceclaimingserver/grpc_end_devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (

pbtypes "github.com/gogo/protobuf/types"
"go.thethings.network/lorawan-stack/v3/pkg/errors"
"go.thethings.network/lorawan-stack/v3/pkg/qrcode"
"go.thethings.network/lorawan-stack/v3/pkg/ttnpb"
"go.thethings.network/lorawan-stack/v3/pkg/types"
"go.thethings.network/lorawan-stack/v3/pkg/web"
Expand Down Expand Up @@ -67,21 +66,28 @@ var (
)

// Claim implements EndDeviceClaimingServer.
func (edcs *endDeviceClaimingServer) Claim(ctx context.Context, req *ttnpb.ClaimEndDeviceRequest) (ids *ttnpb.EndDeviceIdentifiers, err error) {
for _, edcs := range edcs.DCS.endDeviceClaimingUpstreams {
func (srv *endDeviceClaimingServer) Claim(ctx context.Context, req *ttnpb.ClaimEndDeviceRequest) (ids *ttnpb.EndDeviceIdentifiers, err error) {
for _, edcs := range srv.DCS.endDeviceClaimingUpstreams {
var joinEUI types.EUI64
if authenticatedIDs := req.GetAuthenticatedIdentifiers(); authenticatedIDs != nil {
joinEUI = req.GetAuthenticatedIdentifiers().JoinEui
} else if qrCode := req.GetQrCode(); qrCode != nil {
data, err := qrcode.Parse(qrCode)
conn, err := srv.DCS.GetPeerConn(ctx, ttnpb.ClusterRole_QR_CODE_GENERATOR, nil)
if err != nil {
return nil, err
}
client := ttnpb.NewQRCodeParserClient(conn)
data, err := client.Parse(ctx, &ttnpb.ParseQRCodeRequest{
QrCode: qrCode,
})
if err != nil {
return nil, errParseQRCode.WithCause(err)
}
authIDs, ok := data.(qrcode.AuthenticatedEndDeviceIdentifiers)
if !ok {
if onboardingData := data.EntityOnboardingData.GetEndDeviceOnboardingData(); onboardingData != nil && onboardingData.JoinEui != nil {
joinEUI = *onboardingData.JoinEui
} else {
return nil, errQRCodeData.New()
}
joinEUI, _, _ = authIDs.AuthenticatedEndDeviceIdentifiers()
} else {
return nil, errNoJoinEUI.New()
}
Expand All @@ -91,15 +97,15 @@ func (edcs *endDeviceClaimingServer) Claim(ctx context.Context, req *ttnpb.Claim
}
// Use default if no EDCS supports this EUI.
// TODO: Remove this option and return JoinEUI not provisioned error (https://github.com/TheThingsIndustries/lorawan-stack/issues/3036).
return edcs.DCS.endDeviceClaimingUpstreams[defaultType].Claim(ctx, req)
return srv.DCS.endDeviceClaimingUpstreams[defaultType].Claim(ctx, req)
}

// AuthorizeApplication implements EndDeviceClaimingServer.
func (edcs *endDeviceClaimingServer) AuthorizeApplication(ctx context.Context, req *ttnpb.AuthorizeApplicationRequest) (*pbtypes.Empty, error) {
return edcs.DCS.endDeviceClaimingUpstreams[defaultType].AuthorizeApplication(ctx, req)
func (srv *endDeviceClaimingServer) AuthorizeApplication(ctx context.Context, req *ttnpb.AuthorizeApplicationRequest) (*pbtypes.Empty, error) {
return srv.DCS.endDeviceClaimingUpstreams[defaultType].AuthorizeApplication(ctx, req)
}

// UnauthorizeApplication implements EndDeviceClaimingServer.
func (edcs *endDeviceClaimingServer) UnauthorizeApplication(ctx context.Context, ids *ttnpb.ApplicationIdentifiers) (*pbtypes.Empty, error) {
return edcs.DCS.endDeviceClaimingUpstreams[defaultType].UnauthorizeApplication(ctx, ids)
func (srv *endDeviceClaimingServer) UnauthorizeApplication(ctx context.Context, ids *ttnpb.ApplicationIdentifiers) (*pbtypes.Empty, error) {
return srv.DCS.endDeviceClaimingUpstreams[defaultType].UnauthorizeApplication(ctx, ids)
}

0 comments on commit 33e0f66

Please sign in to comment.