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

Remove body from Unclaim request #6381

Merged
merged 6 commits into from
Jul 12, 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
2 changes: 1 addition & 1 deletion api/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` | `*` |
Expand Down
51 changes: 22 additions & 29 deletions api/api.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
1 change: 0 additions & 1 deletion api/deviceclaimingserver.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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: "*"
};
};

Expand Down
6 changes: 4 additions & 2 deletions cypress/e2e/console/devices/unclaim.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
152 changes: 76 additions & 76 deletions pkg/ttnpb/deviceclaimingserver.pb.go

Large diffs are not rendered by default.

34 changes: 18 additions & 16 deletions pkg/ttnpb/deviceclaimingserver.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion pkg/webui/console/views/device/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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 (
<RequireRequest requestAction={loadDeviceData}>
<Device {...props} />
{hasDevice && <Device {...props} />}
</RequireRequest>
)
}
Expand Down
1 change: 0 additions & 1 deletion sdk/js/generated/api-definition.json
Original file line number Diff line number Diff line change
Expand Up @@ -2281,7 +2281,6 @@
{
"method": "delete",
"pattern": "/edcs/claim/{application_ids.application_id}/devices/{device_id}",
"body": "*",
"parameters": [
"application_ids.application_id",
"device_id"
Expand Down
3 changes: 1 addition & 2 deletions sdk/js/generated/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}
]
}
Expand Down
5 changes: 3 additions & 2 deletions sdk/js/src/service/claim.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import autoBind from 'auto-bind'

import Bytes from '../util/bytes'
import Marshaler from '../util/marshaler'

class DeviceClaim {
Expand Down Expand Up @@ -62,8 +63,8 @@ class DeviceClaim {
}

const response = await this._api.EndDeviceClaimingServer.Unclaim(params, {
dev_eui: devEui,
join_eui: joinEui,
dev_eui: Bytes.hexToBase64(devEui),
join_eui: Bytes.hexToBase64(joinEui),
})

return Marshaler.payloadSingleResponse(response)
Expand Down
51 changes: 51 additions & 0 deletions sdk/js/src/util/bytes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// 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.

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(' '),
),
)
}

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('')
}
}

export default Bytes
3 changes: 1 addition & 2 deletions tools/mage/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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),
Expand Down
Loading