From efaa73f90f06c99412b7d367ccfad6bfc6e5bec8 Mon Sep 17 00:00:00 2001 From: Krishna Iyer Easwaran Date: Wed, 5 Jul 2023 17:12:10 +0200 Subject: [PATCH 1/6] api: Remove body from Unclaim request --- api/api.md | 2 +- api/api.swagger.json | 51 ++++---- api/deviceclaimingserver.proto | 1 - pkg/ttnpb/deviceclaimingserver.pb.go | 152 ++++++++++++------------ pkg/ttnpb/deviceclaimingserver.pb.gw.go | 34 +++--- sdk/js/generated/api-definition.json | 1 - sdk/js/generated/api.json | 3 +- tools/mage/proto.go | 3 +- 8 files changed, 119 insertions(+), 128 deletions(-) diff --git a/api/api.md b/api/api.md index 63c63b4172..ff308f2ee6 100644 --- a/api/api.md +++ b/api/api.md @@ -2885,7 +2885,7 @@ and allows clients to claim end devices. | Method Name | Method | Pattern | Body | | ----------- | ------ | ------- | ---- | | `Claim` | `POST` | `/api/v3/edcs/claim` | `*` | -| `Unclaim` | `DELETE` | `/api/v3/edcs/claim/{application_ids.application_id}/devices/{device_id}` | `*` | +| `Unclaim` | `DELETE` | `/api/v3/edcs/claim/{application_ids.application_id}/devices/{device_id}` | | | `GetInfoByJoinEUI` | `POST` | `/api/v3/edcs/claim/info` | `*` | | `GetClaimStatus` | `GET` | `/api/v3/edcs/claim/{application_ids.application_id}/devices/{device_id}` | | | `AuthorizeApplication` | `POST` | `/api/v3/edcs/applications/{application_ids.application_id}/authorize` | `*` | diff --git a/api/api.swagger.json b/api/api.swagger.json index 43b097b5ff..97de233984 100644 --- a/api/api.swagger.json +++ b/api/api.swagger.json @@ -8117,35 +8117,28 @@ "type": "string" }, { - "name": "body", - "in": "body", - "required": true, - "schema": { - "type": "object", - "properties": { - "application_ids": { - "type": "object" - }, - "dev_eui": { - "type": "string", - "format": "string", - "example": "70B3D57ED000ABCD", - "description": "The LoRaWAN DevEUI." - }, - "join_eui": { - "type": "string", - "format": "string", - "example": "70B3D57ED000ABCD", - "description": "The LoRaWAN JoinEUI (AppEUI until LoRaWAN 1.0.3 end devices)." - }, - "dev_addr": { - "type": "string", - "format": "string", - "example": "2600ABCD", - "description": "The LoRaWAN DevAddr." - } - } - } + "name": "dev_eui", + "description": "The LoRaWAN DevEUI.", + "in": "query", + "required": false, + "type": "string", + "format": "string" + }, + { + "name": "join_eui", + "description": "The LoRaWAN JoinEUI (AppEUI until LoRaWAN 1.0.3 end devices).", + "in": "query", + "required": false, + "type": "string", + "format": "string" + }, + { + "name": "dev_addr", + "description": "The LoRaWAN DevAddr.", + "in": "query", + "required": false, + "type": "string", + "format": "string" } ], "tags": [ diff --git a/api/deviceclaimingserver.proto b/api/deviceclaimingserver.proto index 633c1945a5..e2bec36c06 100644 --- a/api/deviceclaimingserver.proto +++ b/api/deviceclaimingserver.proto @@ -162,7 +162,6 @@ service EndDeviceClaimingServer { rpc Unclaim(EndDeviceIdentifiers) returns (google.protobuf.Empty) { option (google.api.http) = { delete: "/edcs/claim/{application_ids.application_id}/devices/{device_id}", - body: "*" }; }; diff --git a/pkg/ttnpb/deviceclaimingserver.pb.go b/pkg/ttnpb/deviceclaimingserver.pb.go index fcf1891243..644270f673 100644 --- a/pkg/ttnpb/deviceclaimingserver.pb.go +++ b/pkg/ttnpb/deviceclaimingserver.pb.go @@ -1176,7 +1176,7 @@ var file_lorawan_stack_api_deviceclaimingserver_proto_rawDesc = []byte{ 0x42, 0x05, 0x8a, 0x01, 0x02, 0x10, 0x01, 0x52, 0x0a, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x49, 0x64, 0x73, 0x12, 0x20, 0x0a, 0x07, 0x61, 0x70, 0x69, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x42, 0x07, 0xfa, 0x42, 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, 0x06, 0x61, - 0x70, 0x69, 0x4b, 0x65, 0x79, 0x32, 0x88, 0x07, 0x0a, 0x17, 0x45, 0x6e, 0x64, 0x44, 0x65, 0x76, + 0x70, 0x69, 0x4b, 0x65, 0x79, 0x32, 0x85, 0x07, 0x0a, 0x17, 0x45, 0x6e, 0x64, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x69, 0x6e, 0x67, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x6c, 0x0a, 0x05, 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x12, 0x25, 0x2e, 0x74, 0x74, 0x6e, 0x2e, 0x6c, 0x6f, 0x72, 0x61, 0x77, 0x61, 0x6e, 0x2e, 0x76, 0x33, 0x2e, 0x43, 0x6c, 0x61, 0x69, @@ -1185,84 +1185,84 @@ var file_lorawan_stack_api_deviceclaimingserver_proto_rawDesc = []byte{ 0x76, 0x33, 0x2e, 0x45, 0x6e, 0x64, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x73, 0x22, 0x16, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x10, 0x3a, 0x01, 0x2a, 0x22, 0x0b, 0x2f, 0x65, 0x64, 0x63, 0x73, 0x2f, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x12, - 0x94, 0x01, 0x0a, 0x07, 0x55, 0x6e, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x12, 0x24, 0x2e, 0x74, 0x74, + 0x91, 0x01, 0x0a, 0x07, 0x55, 0x6e, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x12, 0x24, 0x2e, 0x74, 0x74, 0x6e, 0x2e, 0x6c, 0x6f, 0x72, 0x61, 0x77, 0x61, 0x6e, 0x2e, 0x76, 0x33, 0x2e, 0x45, 0x6e, 0x64, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x73, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x4b, 0x82, 0xd3, 0xe4, 0x93, 0x02, - 0x45, 0x3a, 0x01, 0x2a, 0x2a, 0x40, 0x2f, 0x65, 0x64, 0x63, 0x73, 0x2f, 0x63, 0x6c, 0x61, 0x69, - 0x6d, 0x2f, 0x7b, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, - 0x64, 0x73, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, - 0x64, 0x7d, 0x2f, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2f, 0x7b, 0x64, 0x65, 0x76, 0x69, - 0x63, 0x65, 0x5f, 0x69, 0x64, 0x7d, 0x12, 0x82, 0x01, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x49, 0x6e, - 0x66, 0x6f, 0x42, 0x79, 0x4a, 0x6f, 0x69, 0x6e, 0x45, 0x55, 0x49, 0x12, 0x27, 0x2e, 0x74, 0x74, - 0x6e, 0x2e, 0x6c, 0x6f, 0x72, 0x61, 0x77, 0x61, 0x6e, 0x2e, 0x76, 0x33, 0x2e, 0x47, 0x65, 0x74, - 0x49, 0x6e, 0x66, 0x6f, 0x42, 0x79, 0x4a, 0x6f, 0x69, 0x6e, 0x45, 0x55, 0x49, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x28, 0x2e, 0x74, 0x74, 0x6e, 0x2e, 0x6c, 0x6f, 0x72, 0x61, 0x77, - 0x61, 0x6e, 0x2e, 0x76, 0x33, 0x2e, 0x47, 0x65, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x42, 0x79, 0x4a, - 0x6f, 0x69, 0x6e, 0x45, 0x55, 0x49, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1b, - 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x15, 0x3a, 0x01, 0x2a, 0x22, 0x10, 0x2f, 0x65, 0x64, 0x63, 0x73, - 0x2f, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x2f, 0x69, 0x6e, 0x66, 0x6f, 0x12, 0xa8, 0x01, 0x0a, 0x0e, - 0x47, 0x65, 0x74, 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x24, - 0x2e, 0x74, 0x74, 0x6e, 0x2e, 0x6c, 0x6f, 0x72, 0x61, 0x77, 0x61, 0x6e, 0x2e, 0x76, 0x33, 0x2e, - 0x45, 0x6e, 0x64, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, - 0x69, 0x65, 0x72, 0x73, 0x1a, 0x26, 0x2e, 0x74, 0x74, 0x6e, 0x2e, 0x6c, 0x6f, 0x72, 0x61, 0x77, - 0x61, 0x6e, 0x2e, 0x76, 0x33, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x53, 0x74, - 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x48, 0x82, 0xd3, - 0xe4, 0x93, 0x02, 0x42, 0x12, 0x40, 0x2f, 0x65, 0x64, 0x63, 0x73, 0x2f, 0x63, 0x6c, 0x61, 0x69, - 0x6d, 0x2f, 0x7b, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, - 0x64, 0x73, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, - 0x64, 0x7d, 0x2f, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2f, 0x7b, 0x64, 0x65, 0x76, 0x69, - 0x63, 0x65, 0x5f, 0x69, 0x64, 0x7d, 0x12, 0xa5, 0x01, 0x0a, 0x14, 0x41, 0x75, 0x74, 0x68, 0x6f, - 0x72, 0x69, 0x7a, 0x65, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, - 0x2b, 0x2e, 0x74, 0x74, 0x6e, 0x2e, 0x6c, 0x6f, 0x72, 0x61, 0x77, 0x61, 0x6e, 0x2e, 0x76, 0x33, - 0x2e, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, 0x65, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, - 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, - 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, - 0x6d, 0x70, 0x74, 0x79, 0x22, 0x48, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x42, 0x3a, 0x01, 0x2a, 0x22, - 0x3d, 0x2f, 0x65, 0x64, 0x63, 0x73, 0x2f, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, - 0x6f, 0x6e, 0x73, 0x2f, 0x7b, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x5f, 0x69, 0x64, 0x73, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x5f, 0x69, 0x64, 0x7d, 0x2f, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, 0x65, 0x12, 0x8f, - 0x01, 0x0a, 0x16, 0x55, 0x6e, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, 0x65, 0x41, 0x70, - 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x26, 0x2e, 0x74, 0x74, 0x6e, 0x2e, - 0x6c, 0x6f, 0x72, 0x61, 0x77, 0x61, 0x6e, 0x2e, 0x76, 0x33, 0x2e, 0x41, 0x70, 0x70, 0x6c, 0x69, - 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, - 0x73, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x35, 0x82, 0xd3, 0xe4, 0x93, 0x02, - 0x2f, 0x2a, 0x2d, 0x2f, 0x65, 0x64, 0x63, 0x73, 0x2f, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x7b, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, - 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x7d, 0x2f, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, 0x65, - 0x32, 0x96, 0x03, 0x0a, 0x15, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x43, 0x6c, 0x61, 0x69, - 0x6d, 0x69, 0x6e, 0x67, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x68, 0x0a, 0x05, 0x43, 0x6c, - 0x61, 0x69, 0x6d, 0x12, 0x23, 0x2e, 0x74, 0x74, 0x6e, 0x2e, 0x6c, 0x6f, 0x72, 0x61, 0x77, 0x61, - 0x6e, 0x2e, 0x76, 0x33, 0x2e, 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, - 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x22, 0x2e, 0x74, 0x74, 0x6e, 0x2e, 0x6c, - 0x6f, 0x72, 0x61, 0x77, 0x61, 0x6e, 0x2e, 0x76, 0x33, 0x2e, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, - 0x79, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x73, 0x22, 0x16, 0x82, 0xd3, - 0xe4, 0x93, 0x02, 0x10, 0x3a, 0x01, 0x2a, 0x22, 0x0b, 0x2f, 0x67, 0x63, 0x6c, 0x73, 0x2f, 0x63, - 0x6c, 0x61, 0x69, 0x6d, 0x12, 0x91, 0x01, 0x0a, 0x10, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, - 0x7a, 0x65, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x12, 0x27, 0x2e, 0x74, 0x74, 0x6e, 0x2e, - 0x6c, 0x6f, 0x72, 0x61, 0x77, 0x61, 0x6e, 0x2e, 0x76, 0x33, 0x2e, 0x41, 0x75, 0x74, 0x68, 0x6f, - 0x72, 0x69, 0x7a, 0x65, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x3c, 0x82, 0xd3, 0xe4, 0x93, - 0x02, 0x36, 0x3a, 0x01, 0x2a, 0x22, 0x31, 0x2f, 0x67, 0x63, 0x6c, 0x73, 0x2f, 0x67, 0x61, 0x74, - 0x65, 0x77, 0x61, 0x79, 0x73, 0x2f, 0x7b, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x5f, 0x69, - 0x64, 0x73, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x5f, 0x69, 0x64, 0x7d, 0x2f, 0x61, - 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, 0x65, 0x12, 0x7f, 0x0a, 0x12, 0x55, 0x6e, 0x61, 0x75, - 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, 0x65, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x12, 0x22, - 0x2e, 0x74, 0x74, 0x6e, 0x2e, 0x6c, 0x6f, 0x72, 0x61, 0x77, 0x61, 0x6e, 0x2e, 0x76, 0x33, 0x2e, - 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, - 0x72, 0x73, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x2d, 0x82, 0xd3, 0xe4, 0x93, - 0x02, 0x27, 0x2a, 0x25, 0x2f, 0x67, 0x63, 0x6c, 0x73, 0x2f, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, - 0x79, 0x73, 0x2f, 0x7b, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x5f, 0x69, 0x64, 0x7d, 0x2f, - 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, 0x65, 0x42, 0x31, 0x5a, 0x2f, 0x67, 0x6f, 0x2e, - 0x74, 0x68, 0x65, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x73, 0x2e, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, - 0x6b, 0x2f, 0x6c, 0x6f, 0x72, 0x61, 0x77, 0x61, 0x6e, 0x2d, 0x73, 0x74, 0x61, 0x63, 0x6b, 0x2f, - 0x76, 0x33, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x74, 0x74, 0x6e, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x33, + 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x48, 0x82, 0xd3, 0xe4, 0x93, 0x02, + 0x42, 0x2a, 0x40, 0x2f, 0x65, 0x64, 0x63, 0x73, 0x2f, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x2f, 0x7b, + 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x73, 0x2e, + 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x7d, 0x2f, + 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2f, 0x7b, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x5f, + 0x69, 0x64, 0x7d, 0x12, 0x82, 0x01, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x42, + 0x79, 0x4a, 0x6f, 0x69, 0x6e, 0x45, 0x55, 0x49, 0x12, 0x27, 0x2e, 0x74, 0x74, 0x6e, 0x2e, 0x6c, + 0x6f, 0x72, 0x61, 0x77, 0x61, 0x6e, 0x2e, 0x76, 0x33, 0x2e, 0x47, 0x65, 0x74, 0x49, 0x6e, 0x66, + 0x6f, 0x42, 0x79, 0x4a, 0x6f, 0x69, 0x6e, 0x45, 0x55, 0x49, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x28, 0x2e, 0x74, 0x74, 0x6e, 0x2e, 0x6c, 0x6f, 0x72, 0x61, 0x77, 0x61, 0x6e, 0x2e, + 0x76, 0x33, 0x2e, 0x47, 0x65, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x42, 0x79, 0x4a, 0x6f, 0x69, 0x6e, + 0x45, 0x55, 0x49, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1b, 0x82, 0xd3, 0xe4, + 0x93, 0x02, 0x15, 0x3a, 0x01, 0x2a, 0x22, 0x10, 0x2f, 0x65, 0x64, 0x63, 0x73, 0x2f, 0x63, 0x6c, + 0x61, 0x69, 0x6d, 0x2f, 0x69, 0x6e, 0x66, 0x6f, 0x12, 0xa8, 0x01, 0x0a, 0x0e, 0x47, 0x65, 0x74, + 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x24, 0x2e, 0x74, 0x74, + 0x6e, 0x2e, 0x6c, 0x6f, 0x72, 0x61, 0x77, 0x61, 0x6e, 0x2e, 0x76, 0x33, 0x2e, 0x45, 0x6e, 0x64, + 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, + 0x73, 0x1a, 0x26, 0x2e, 0x74, 0x74, 0x6e, 0x2e, 0x6c, 0x6f, 0x72, 0x61, 0x77, 0x61, 0x6e, 0x2e, + 0x76, 0x33, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x53, 0x74, 0x61, 0x74, 0x75, + 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x48, 0x82, 0xd3, 0xe4, 0x93, 0x02, + 0x42, 0x12, 0x40, 0x2f, 0x65, 0x64, 0x63, 0x73, 0x2f, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x2f, 0x7b, + 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x73, 0x2e, + 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x7d, 0x2f, + 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2f, 0x7b, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x5f, + 0x69, 0x64, 0x7d, 0x12, 0xa5, 0x01, 0x0a, 0x14, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, + 0x65, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x2b, 0x2e, 0x74, + 0x74, 0x6e, 0x2e, 0x6c, 0x6f, 0x72, 0x61, 0x77, 0x61, 0x6e, 0x2e, 0x76, 0x33, 0x2e, 0x41, 0x75, + 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, 0x65, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, + 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, + 0x79, 0x22, 0x48, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x42, 0x3a, 0x01, 0x2a, 0x22, 0x3d, 0x2f, 0x65, + 0x64, 0x63, 0x73, 0x2f, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, + 0x2f, 0x7b, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, + 0x73, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, + 0x7d, 0x2f, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, 0x65, 0x12, 0x8f, 0x01, 0x0a, 0x16, + 0x55, 0x6e, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, 0x65, 0x41, 0x70, 0x70, 0x6c, 0x69, + 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x26, 0x2e, 0x74, 0x74, 0x6e, 0x2e, 0x6c, 0x6f, 0x72, + 0x61, 0x77, 0x61, 0x6e, 0x2e, 0x76, 0x33, 0x2e, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x73, 0x1a, 0x16, + 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, + 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x35, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x2f, 0x2a, 0x2d, + 0x2f, 0x65, 0x64, 0x63, 0x73, 0x2f, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x73, 0x2f, 0x7b, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, + 0x69, 0x64, 0x7d, 0x2f, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, 0x65, 0x32, 0x96, 0x03, + 0x0a, 0x15, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x69, 0x6e, + 0x67, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x68, 0x0a, 0x05, 0x43, 0x6c, 0x61, 0x69, 0x6d, + 0x12, 0x23, 0x2e, 0x74, 0x74, 0x6e, 0x2e, 0x6c, 0x6f, 0x72, 0x61, 0x77, 0x61, 0x6e, 0x2e, 0x76, + 0x33, 0x2e, 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x22, 0x2e, 0x74, 0x74, 0x6e, 0x2e, 0x6c, 0x6f, 0x72, 0x61, + 0x77, 0x61, 0x6e, 0x2e, 0x76, 0x33, 0x2e, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x49, 0x64, + 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x73, 0x22, 0x16, 0x82, 0xd3, 0xe4, 0x93, 0x02, + 0x10, 0x3a, 0x01, 0x2a, 0x22, 0x0b, 0x2f, 0x67, 0x63, 0x6c, 0x73, 0x2f, 0x63, 0x6c, 0x61, 0x69, + 0x6d, 0x12, 0x91, 0x01, 0x0a, 0x10, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, 0x65, 0x47, + 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x12, 0x27, 0x2e, 0x74, 0x74, 0x6e, 0x2e, 0x6c, 0x6f, 0x72, + 0x61, 0x77, 0x61, 0x6e, 0x2e, 0x76, 0x33, 0x2e, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, + 0x65, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, + 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x3c, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x36, 0x3a, + 0x01, 0x2a, 0x22, 0x31, 0x2f, 0x67, 0x63, 0x6c, 0x73, 0x2f, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, + 0x79, 0x73, 0x2f, 0x7b, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x5f, 0x69, 0x64, 0x73, 0x2e, + 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x5f, 0x69, 0x64, 0x7d, 0x2f, 0x61, 0x75, 0x74, 0x68, + 0x6f, 0x72, 0x69, 0x7a, 0x65, 0x12, 0x7f, 0x0a, 0x12, 0x55, 0x6e, 0x61, 0x75, 0x74, 0x68, 0x6f, + 0x72, 0x69, 0x7a, 0x65, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x12, 0x22, 0x2e, 0x74, 0x74, + 0x6e, 0x2e, 0x6c, 0x6f, 0x72, 0x61, 0x77, 0x61, 0x6e, 0x2e, 0x76, 0x33, 0x2e, 0x47, 0x61, 0x74, + 0x65, 0x77, 0x61, 0x79, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x73, 0x1a, + 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, + 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x2d, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x27, 0x2a, + 0x25, 0x2f, 0x67, 0x63, 0x6c, 0x73, 0x2f, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x73, 0x2f, + 0x7b, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x5f, 0x69, 0x64, 0x7d, 0x2f, 0x61, 0x75, 0x74, + 0x68, 0x6f, 0x72, 0x69, 0x7a, 0x65, 0x42, 0x31, 0x5a, 0x2f, 0x67, 0x6f, 0x2e, 0x74, 0x68, 0x65, + 0x74, 0x68, 0x69, 0x6e, 0x67, 0x73, 0x2e, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2f, 0x6c, + 0x6f, 0x72, 0x61, 0x77, 0x61, 0x6e, 0x2d, 0x73, 0x74, 0x61, 0x63, 0x6b, 0x2f, 0x76, 0x33, 0x2f, + 0x70, 0x6b, 0x67, 0x2f, 0x74, 0x74, 0x6e, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, } var ( diff --git a/pkg/ttnpb/deviceclaimingserver.pb.gw.go b/pkg/ttnpb/deviceclaimingserver.pb.gw.go index 103a27f6ae..5fdc24d217 100644 --- a/pkg/ttnpb/deviceclaimingserver.pb.gw.go +++ b/pkg/ttnpb/deviceclaimingserver.pb.gw.go @@ -65,18 +65,14 @@ func local_request_EndDeviceClaimingServer_Claim_0(ctx context.Context, marshale } +var ( + filter_EndDeviceClaimingServer_Unclaim_0 = &utilities.DoubleArray{Encoding: map[string]int{"application_ids": 0, "application_id": 1, "applicationId": 2, "device_id": 3, "deviceId": 4}, Base: []int{1, 1, 1, 2, 3, 4, 0, 0, 0, 0}, Check: []int{0, 1, 2, 1, 1, 1, 3, 4, 5, 6}} +) + func request_EndDeviceClaimingServer_Unclaim_0(ctx context.Context, marshaler runtime.Marshaler, client EndDeviceClaimingServerClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq EndDeviceIdentifiers var metadata runtime.ServerMetadata - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - var ( val string ok bool @@ -104,6 +100,13 @@ func request_EndDeviceClaimingServer_Unclaim_0(ctx context.Context, marshaler ru return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "device_id", err) } + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_EndDeviceClaimingServer_Unclaim_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := client.Unclaim(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err @@ -113,14 +116,6 @@ func local_request_EndDeviceClaimingServer_Unclaim_0(ctx context.Context, marsha var protoReq EndDeviceIdentifiers var metadata runtime.ServerMetadata - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - var ( val string ok bool @@ -148,6 +143,13 @@ func local_request_EndDeviceClaimingServer_Unclaim_0(ctx context.Context, marsha return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "device_id", err) } + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_EndDeviceClaimingServer_Unclaim_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := server.Unclaim(ctx, &protoReq) return msg, metadata, err diff --git a/sdk/js/generated/api-definition.json b/sdk/js/generated/api-definition.json index 7b8963c1e2..65c59607f2 100644 --- a/sdk/js/generated/api-definition.json +++ b/sdk/js/generated/api-definition.json @@ -2281,7 +2281,6 @@ { "method": "delete", "pattern": "/edcs/claim/{application_ids.application_id}/devices/{device_id}", - "body": "*", "parameters": [ "application_ids.application_id", "device_id" diff --git a/sdk/js/generated/api.json b/sdk/js/generated/api.json index 9b00856d97..152d1e943b 100644 --- a/sdk/js/generated/api.json +++ b/sdk/js/generated/api.json @@ -11131,8 +11131,7 @@ "rules": [ { "method": "DELETE", - "pattern": "/edcs/claim/{application_ids.application_id}/devices/{device_id}", - "body": "*" + "pattern": "/edcs/claim/{application_ids.application_id}/devices/{device_id}" } ] } diff --git a/tools/mage/proto.go b/tools/mage/proto.go index e994e4a6c5..609e468be1 100644 --- a/tools/mage/proto.go +++ b/tools/mage/proto.go @@ -152,7 +152,7 @@ func (p Proto) fieldMask(context.Context) error { func (p Proto) grpcGateway(context.Context) error { return withProtoc(grpcGatewayProtoImage, func(pCtx *protocContext, protoc func(...string) error) error { if err := protoc( - fmt.Sprintf("--grpc-gateway_out=allow_delete_body=true:%s", protocOut), + fmt.Sprintf("--grpc-gateway_out=:%s", protocOut), fmt.Sprintf("%s/api/*.proto", pCtx.WorkingDirectory), ); err != nil { return fmt.Errorf("failed to generate protos: %w", err) @@ -204,7 +204,6 @@ func (p Proto) Swagger(context.Context) error { } return withProtoc(openAPIv2ProtoImage, func(pCtx *protocContext, protoc func(...string) error) error { if err := protoc( - "--openapiv2_opt allow_delete_body=true", "--openapiv2_opt=json_names_for_fields=false", fmt.Sprintf("--openapiv2_out=allow_merge,merge_file_name=api:%s/api", pCtx.WorkingDirectory), fmt.Sprintf("%s/api/*.proto", pCtx.WorkingDirectory), From 356f84fbcd7bccffcd4ad8fe849a0d197580850f Mon Sep 17 00:00:00 2001 From: Krishna Iyer Easwaran Date: Thu, 6 Jul 2023 13:29:00 +0200 Subject: [PATCH 2/6] console: Convert EUIs to Base64 before calling Unclaim request --- pkg/webui/console/views/device-general-settings/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/webui/console/views/device-general-settings/index.js b/pkg/webui/console/views/device-general-settings/index.js index 8e6c895c45..a34ed6d021 100644 --- a/pkg/webui/console/views/device-general-settings/index.js +++ b/pkg/webui/console/views/device-general-settings/index.js @@ -36,6 +36,7 @@ import { selectNsConfig, } from '@ttn-lw/lib/selectors/env' +import { hexToBase64 } from '@console/lib/bytes' import { mayEditApplicationDeviceKeys, mayReadApplicationDeviceKeys, @@ -100,7 +101,9 @@ const DeviceGeneralSettings = () => { const { ids: { dev_eui: devEui, join_eui: joinEui }, } = device - await dispatch(attachPromise(unclaimDevice(appId, devId, devEui, joinEui))) + await dispatch( + attachPromise(unclaimDevice(appId, devId, hexToBase64(devEui), hexToBase64(joinEui))), + ) }, [appId, devId, device, dispatch]) const handleUnclaimFailure = useCallback(async () => { From e87bfc3125897799201516c9d8870b9a85ad7aea Mon Sep 17 00:00:00 2001 From: Krishna Iyer Easwaran Date: Mon, 10 Jul 2023 14:46:42 +0200 Subject: [PATCH 3/6] console: Move EUI transformation to SDK --- .../views/device-general-settings/index.js | 5 +- sdk/js/src/service/claim.js | 5 +- sdk/js/src/util/bytes.js | 46 +++++++++++++++++++ 3 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 sdk/js/src/util/bytes.js diff --git a/pkg/webui/console/views/device-general-settings/index.js b/pkg/webui/console/views/device-general-settings/index.js index a34ed6d021..8e6c895c45 100644 --- a/pkg/webui/console/views/device-general-settings/index.js +++ b/pkg/webui/console/views/device-general-settings/index.js @@ -36,7 +36,6 @@ import { selectNsConfig, } from '@ttn-lw/lib/selectors/env' -import { hexToBase64 } from '@console/lib/bytes' import { mayEditApplicationDeviceKeys, mayReadApplicationDeviceKeys, @@ -101,9 +100,7 @@ const DeviceGeneralSettings = () => { const { ids: { dev_eui: devEui, join_eui: joinEui }, } = device - await dispatch( - attachPromise(unclaimDevice(appId, devId, hexToBase64(devEui), hexToBase64(joinEui))), - ) + await dispatch(attachPromise(unclaimDevice(appId, devId, devEui, joinEui))) }, [appId, devId, device, dispatch]) const handleUnclaimFailure = useCallback(async () => { diff --git a/sdk/js/src/service/claim.js b/sdk/js/src/service/claim.js index 2340ac9cd6..b1894cdb3e 100644 --- a/sdk/js/src/service/claim.js +++ b/sdk/js/src/service/claim.js @@ -14,6 +14,7 @@ import autoBind from 'auto-bind' +import hexToBase64 from '../util/bytes' import Marshaler from '../util/marshaler' class DeviceClaim { @@ -62,8 +63,8 @@ class DeviceClaim { } const response = await this._api.EndDeviceClaimingServer.Unclaim(params, { - dev_eui: devEui, - join_eui: joinEui, + dev_eui: hexToBase64(devEui), + join_eui: hexToBase64(joinEui), }) return Marshaler.payloadSingleResponse(response) diff --git a/sdk/js/src/util/bytes.js b/sdk/js/src/util/bytes.js new file mode 100644 index 0000000000..411c485400 --- /dev/null +++ b/sdk/js/src/util/bytes.js @@ -0,0 +1,46 @@ +// Copyright © 2023 The Things Network Foundation, The Things Industries B.V. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * Converts hex encoded string to base64. + * + * @param {string} str - Hex encoded string. + * @returns {string} - `str` base64 encoded. + */ +export const hexToBase64 = str => + btoa( + String.fromCharCode.apply( + null, + str + .replace(/\r|\n/g, '') + .replace(/([\da-fA-F]{2}) ?/g, '0x$1 ') + .replace(/ +$/, '') + .split(' '), + ), + ) + +/** + * Converts base64 encoded string to hex. + * + * @param {string} str - Base64 encoded string. + * @returns {string} - `str` hex encoded. + */ +export const base64ToHex = str => + Array.from(atob(str.replace(/[ \r\n]+$/, ''))) + .map(char => { + const tmp = char.charCodeAt(0).toString(16) + + return tmp.length > 1 ? tmp : `0${tmp}` + }) + .join('') From 6aa85aada0a0c4e7378bd912bd75ffecf0f1d3a4 Mon Sep 17 00:00:00 2001 From: Krishna Iyer Easwaran Date: Tue, 11 Jul 2023 12:53:28 +0200 Subject: [PATCH 4/6] console: Convert SDK util to class --- sdk/js/src/service/claim.js | 6 ++-- sdk/js/src/util/bytes.js | 65 ++++++++++++++++++++----------------- 2 files changed, 38 insertions(+), 33 deletions(-) diff --git a/sdk/js/src/service/claim.js b/sdk/js/src/service/claim.js index b1894cdb3e..2ec0ce1a91 100644 --- a/sdk/js/src/service/claim.js +++ b/sdk/js/src/service/claim.js @@ -14,7 +14,7 @@ import autoBind from 'auto-bind' -import hexToBase64 from '../util/bytes' +import Bytes from '../util/bytes' import Marshaler from '../util/marshaler' class DeviceClaim { @@ -63,8 +63,8 @@ class DeviceClaim { } const response = await this._api.EndDeviceClaimingServer.Unclaim(params, { - dev_eui: hexToBase64(devEui), - join_eui: hexToBase64(joinEui), + dev_eui: Bytes.hexToBase64(devEui), + join_eui: Bytes.hexToBase64(joinEui), }) return Marshaler.payloadSingleResponse(response) diff --git a/sdk/js/src/util/bytes.js b/sdk/js/src/util/bytes.js index 411c485400..005cf64b45 100644 --- a/sdk/js/src/util/bytes.js +++ b/sdk/js/src/util/bytes.js @@ -12,35 +12,40 @@ // See the License for the specific language governing permissions and // limitations under the License. -/** - * Converts hex encoded string to base64. - * - * @param {string} str - Hex encoded string. - * @returns {string} - `str` base64 encoded. - */ -export const hexToBase64 = str => - btoa( - String.fromCharCode.apply( - null, - str - .replace(/\r|\n/g, '') - .replace(/([\da-fA-F]{2}) ?/g, '0x$1 ') - .replace(/ +$/, '') - .split(' '), - ), - ) +class Bytes { + /** + * Converts hex encoded string to base64. + * + * @param {string} str - Hex encoded string. + * @returns {string} - `str` base64 encoded. + */ + static hexToBase64(str) { + return btoa( + String.fromCharCode.apply( + null, + str + .replace(/\r|\n/g, '') + .replace(/([\da-fA-F]{2}) ?/g, '0x$1 ') + .replace(/ +$/, '') + .split(' '), + ), + ) + } -/** - * Converts base64 encoded string to hex. - * - * @param {string} str - Base64 encoded string. - * @returns {string} - `str` hex encoded. - */ -export const base64ToHex = str => - Array.from(atob(str.replace(/[ \r\n]+$/, ''))) - .map(char => { - const tmp = char.charCodeAt(0).toString(16) + static base64ToHex(str) { + /** + * Converts base64 encoded string to hex. + * + * @param {string} str - Base64 encoded string. + * @returns {string} - `str` hex encoded. + */ + return Array.from(atob(str.replace(/[ \r\n]+$/, ''))) + .map(char => { + const tmp = char.charCodeAt(0).toString(16) + return tmp.length > 1 ? tmp : `0${tmp}` + }) + .join('') + } +} - return tmp.length > 1 ? tmp : `0${tmp}` - }) - .join('') +export default Bytes From 50723f175bb5553d1a77da722df5db80911aae02 Mon Sep 17 00:00:00 2001 From: Kevin Schiffer Date: Wed, 12 Jul 2023 11:09:37 +0200 Subject: [PATCH 5/6] console: Prevent device view from rendering after device was deleted --- pkg/webui/console/views/device/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/webui/console/views/device/index.js b/pkg/webui/console/views/device/index.js index 34cb5c51ce..5e2d08dda5 100644 --- a/pkg/webui/console/views/device/index.js +++ b/pkg/webui/console/views/device/index.js @@ -34,6 +34,7 @@ import { getNsFrequencyPlans } from '@console/store/actions/configuration' import { getInfoByJoinEUI } from '@console/store/actions/claim' import { selectSelectedApplicationId } from '@console/store/selectors/applications' +import { selectSelectedDevice } from '@console/store/selectors/devices' import Device from './device' @@ -105,9 +106,13 @@ const DeviceContainer = props => { [appId, devId, dispatch], ) + // Check whether the device still exists after it has been possibly deleted. + const device = useSelector(selectSelectedDevice) + const hasDevice = Boolean(device) + return ( - + {hasDevice && } ) } From dd2b02e76d3bc449662661812504ac1d2b3a0b82 Mon Sep 17 00:00:00 2001 From: Kevin Schiffer Date: Wed, 12 Jul 2023 12:29:17 +0200 Subject: [PATCH 6/6] dev: Update unclaiming test --- cypress/e2e/console/devices/unclaim.spec.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cypress/e2e/console/devices/unclaim.spec.js b/cypress/e2e/console/devices/unclaim.spec.js index bbd4a9403f..c8abf0ea08 100644 --- a/cypress/e2e/console/devices/unclaim.spec.js +++ b/cypress/e2e/console/devices/unclaim.spec.js @@ -90,9 +90,11 @@ describe('Device un-claiming', () => { .its('request.url') .then(url => { const params = new URLSearchParams(new URL(url).search) + const hexToBase64 = hex => + btoa(String.fromCharCode(...hex.match(/.{1,2}/g).map(byte => parseInt(byte, 16)))) - expect(params.get('dev_eui')).to.equal(ns.end_device.ids.dev_eui) - expect(params.get('join_eui')).to.equal('0000000000000000') + expect(params.get('dev_eui')).to.equal(hexToBase64(ns.end_device.ids.dev_eui)) + expect(params.get('join_eui')).to.equal(hexToBase64('0000000000000000')) }) cy.findByTestId('error-notification').should('not.exist')