Skip to content

Commit

Permalink
qrg: Update parse gateway qr response
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlad Vitan committed Sep 9, 2024
1 parent c1bd09a commit 281d218
Show file tree
Hide file tree
Showing 11 changed files with 313 additions and 256 deletions.
10 changes: 9 additions & 1 deletion api/ttn/lorawan/v3/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -10564,7 +10564,15 @@ The Pba service allows clients to manage peering through Packet Broker.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `format_id` | [`string`](#string) | | Identifier of the format used to successfully parse the QR code data. |
| `claim_gateway_request` | [`ClaimGatewayRequest`](#ttn.lorawan.v3.ClaimGatewayRequest) | | |
| `gateway_eui` | [`bytes`](#bytes) | | |
| `owner_token` | [`string`](#string) | | |

#### Field Rules

| Field | Validations |
| ----- | ----------- |
| `gateway_eui` | <p>`bytes.len`: `8`</p> |
| `owner_token` | <p>`string.pattern`: `^[A-Z0-9]{1,32}$`</p> |

### <a name="ttn.lorawan.v3.QRCodeFormat">Message `QRCodeFormat`</a>

Expand Down
9 changes: 7 additions & 2 deletions api/ttn/lorawan/v3/api.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -28060,8 +28060,13 @@
"type": "string",
"description": "Identifier of the format used to successfully parse the QR code data."
},
"claim_gateway_request": {
"$ref": "#/definitions/v3ClaimGatewayRequest"
"gateway_eui": {
"type": "string",
"format": "string",
"example": "70B3D57ED000ABCD"
},
"owner_token": {
"type": "string"
}
}
},
Expand Down
19 changes: 17 additions & 2 deletions api/ttn/lorawan/v3/qrcodegenerator.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import "google/api/annotations.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/field_mask.proto";
import "protoc-gen-openapiv2/options/annotations.proto";
import "ttn/lorawan/v3/deviceclaimingserver.proto";
import "thethings/json/annotations.proto";
import "ttn/lorawan/v3/end_device.proto";
import "ttn/lorawan/v3/picture.proto";
import "validate/validate.proto";
Expand Down Expand Up @@ -149,7 +149,22 @@ message ParseGatewayQRCodeRequest {
message ParseGatewayQRCodeResponse {
// Identifier of the format used to successfully parse the QR code data.
string format_id = 1;
ClaimGatewayRequest claim_gateway_request = 2;
bytes gateway_eui = 2 [
(validate.rules).bytes = {
len: 8,
ignore_empty: true
},
(thethings.json.field) = {
marshaler_func: "go.thethings.network/lorawan-stack/v3/pkg/types.MarshalHEXBytes",
unmarshaler_func: "go.thethings.network/lorawan-stack/v3/pkg/types.Unmarshal8Bytes"
},
(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {
type: STRING,
format: "string",
example: "\"70B3D57ED000ABCD\""
}
];
string owner_token = 3 [(validate.rules).string.pattern = "^[A-Z0-9]{1,32}$"];
}

// The GatewayQRCodeGenerator service provides functionality to generate and parse QR codes for gateways.
Expand Down
12 changes: 3 additions & 9 deletions pkg/qrcodegenerator/grpc_gateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,8 @@ func (s *gatewayQRCodeGeneratorServer) Parse(
}

return &ttnpb.ParseGatewayQRCodeResponse{
FormatId: data.FormatID(),
ClaimGatewayRequest: &ttnpb.ClaimGatewayRequest{
SourceGateway: &ttnpb.ClaimGatewayRequest_AuthenticatedIdentifiers_{
AuthenticatedIdentifiers: &ttnpb.ClaimGatewayRequest_AuthenticatedIdentifiers{
GatewayEui: data.GatewayEUI().Bytes(),
AuthenticationCode: []byte(data.OwnerToken()),
},
},
},
FormatId: data.FormatID(),
GatewayEui: data.GatewayEUI().Bytes(),
OwnerToken: data.OwnerToken(),
}, nil
}
2 changes: 2 additions & 0 deletions pkg/qrcodegenerator/grpc_gateways_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ func TestGatewayQRCodeParsing(t *testing.T) {
return false
}
a.So(resp.FormatId, should.Equal, ttigpro1.ID())
a.So(resp.GatewayEui, should.Resemble, []uint8{0xec, 0x65, 0x6e, 0xff, 0xfe, 0x00, 0x01, 0x28})
a.So(resp.OwnerToken, should.Equal, "abcdef123456")

return true
},
Expand Down
361 changes: 189 additions & 172 deletions pkg/ttnpb/qrcodegenerator.pb.go

Large diffs are not rendered by default.

31 changes: 4 additions & 27 deletions pkg/ttnpb/qrcodegenerator.pb.paths.fm.go

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

38 changes: 16 additions & 22 deletions pkg/ttnpb/qrcodegenerator.pb.setters.fm.go

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

24 changes: 18 additions & 6 deletions pkg/ttnpb/qrcodegenerator.pb.validate.go

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

25 changes: 15 additions & 10 deletions pkg/ttnpb/qrcodegenerator_json.pb.go

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

38 changes: 33 additions & 5 deletions sdk/js/generated/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -48337,16 +48337,44 @@
"defaultValue": ""
},
{
"name": "claim_gateway_request",
"name": "gateway_eui",
"description": "",
"label": "",
"type": "ClaimGatewayRequest",
"longType": "ClaimGatewayRequest",
"fullType": "ttn.lorawan.v3.ClaimGatewayRequest",
"type": "bytes",
"longType": "bytes",
"fullType": "bytes",
"ismap": false,
"isoneof": false,
"oneofdecl": "",
"defaultValue": ""
"defaultValue": "",
"options": {
"validate.rules": [
{
"name": "bytes.len",
"value": 8
}
]
}
},
{
"name": "owner_token",
"description": "",
"label": "",
"type": "string",
"longType": "string",
"fullType": "string",
"ismap": false,
"isoneof": false,
"oneofdecl": "",
"defaultValue": "",
"options": {
"validate.rules": [
{
"name": "string.pattern",
"value": "^[A-Z0-9]{1,32}$"
}
]
}
}
]
},
Expand Down

0 comments on commit 281d218

Please sign in to comment.