Skip to content

Commit

Permalink
all: Migrate to new validation plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman Volosatovs committed Mar 6, 2019
1 parent 45ac2ea commit 4453468
Show file tree
Hide file tree
Showing 160 changed files with 32,917 additions and 11,048 deletions.
5 changes: 2 additions & 3 deletions .make/protos/go.make
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
GO_PROTO_TYPES := any duration empty field_mask struct timestamp wrappers
GO_PROTO_TYPE_CONVERSIONS = $(subst $(SPACE),$(COMMA),$(foreach type,$(GO_PROTO_TYPES),Mgoogle/protobuf/$(type).proto=github.com/gogo/protobuf/types))
GO_PROTOC_FLAGS ?= \
--fieldmask_out=$(PROTOC_OUT) \
--fieldmask_out=lang=gogo,$(GO_PROTO_TYPE_CONVERSIONS):$(PROTOC_OUT) \
--gogottn_out=plugins=grpc,$(GO_PROTO_TYPE_CONVERSIONS):$(PROTOC_OUT) \
--grpc-gateway_out=$(GO_PROTO_TYPE_CONVERSIONS):$(PROTOC_OUT) \
--govalidators_out=gogoimport=true:$(PROTOC_OUT)
--grpc-gateway_out=$(GO_PROTO_TYPE_CONVERSIONS):$(PROTOC_OUT)

go.protos: $(wildcard api/*.proto)
$(PROTOC) $(GO_PROTOC_FLAGS) $(API_PROTO_FILES) 2>&1 | grep -vE ' protoc-gen-gogo: WARNING: failed finding publicly imported dependency for \.ttn\.lorawan\.v3\..* used in' || true
Expand Down
2 changes: 1 addition & 1 deletion .make/protos/main.make
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ API_PROTO_FILES = $(PWD)/api/'*.proto'

PROTOC_OUT ?= /out

PROTOC_DOCKER_IMAGE ?= thethingsindustries/protoc:3.0.26
PROTOC_DOCKER_IMAGE ?= thethingsindustries/protoc:3.1.0
PROTOC_DOCKER_ARGS = run --user `id -u` --rm \
--mount type=bind,src=$(PWD)/api,dst=$(PWD)/api \
--mount type=bind,src=$(PWD)/pkg/ttnpb,dst=$(PROTOC_OUT)/go.thethings.network/lorawan-stack/pkg/ttnpb \
Expand Down
4 changes: 2 additions & 2 deletions api/applicationserver.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
syntax = "proto3";

import "github.com/gogo/protobuf/gogoproto/gogo.proto";
import "github.com/mwitkow/go-proto-validators/validator.proto";
import "github.com/lyft/protoc-gen-validate/validate/validate.proto";
import "google/api/annotations.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/field_mask.proto";
Expand All @@ -34,7 +34,7 @@ message ApplicationLink {
// the normal port inference (with DNS lookup, otherwise defaults) is used.
// Leave empty when linking to a cluster Network Server.
string network_server_address = 1;
string api_key = 2 [(gogoproto.customname) = "APIKey", (validator.field) = {string_not_empty: true}];
string api_key = 2 [(gogoproto.customname) = "APIKey", (validate.rules).string.min_len = 1];
MessagePayloadFormatters default_formatters = 3;
}

Expand Down
4 changes: 2 additions & 2 deletions api/applicationserver_web.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
syntax = "proto3";

import "github.com/gogo/protobuf/gogoproto/gogo.proto";
import "github.com/mwitkow/go-proto-validators/validator.proto";
import "github.com/lyft/protoc-gen-validate/validate/validate.proto";
import "google/api/annotations.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/field_mask.proto";
Expand All @@ -28,7 +28,7 @@ option go_package = "go.thethings.network/lorawan-stack/pkg/ttnpb";

message ApplicationWebhookIdentifiers {
ApplicationIdentifiers application_ids = 1 [(gogoproto.embed) = true, (gogoproto.nullable) = false];
string webhook_id = 2 [(gogoproto.customname) = "WebhookID", (validator.field) = {regex: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$" , length_lt: 37}];
string webhook_id = 2 [(gogoproto.customname) = "WebhookID", (validate.rules).string = {pattern: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$" , max_len: 36}];
}

message ApplicationWebhook {
Expand Down
10 changes: 5 additions & 5 deletions api/end_device.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
syntax = "proto3";

import "github.com/gogo/protobuf/gogoproto/gogo.proto";
import "github.com/mwitkow/go-proto-validators/validator.proto";
import "github.com/lyft/protoc-gen-validate/validate/validate.proto";
import "google/api/annotations.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/field_mask.proto";
Expand Down Expand Up @@ -128,8 +128,8 @@ message EndDeviceModel {

// Identifies an end device model with version information.
message EndDeviceVersionIdentifiers {
string brand_id = 1 [(gogoproto.customname) = "BrandID", (validator.field) = {regex: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$|^$", length_lt: 37}];
string model_id = 2 [(gogoproto.customname) = "ModelID", (validator.field) = {regex: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$|^$", length_lt: 37}];
string brand_id = 1 [(gogoproto.customname) = "BrandID", (validate.rules).string = {pattern: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$|^$", max_len: 36}];
string model_id = 2 [(gogoproto.customname) = "ModelID", (validate.rules).string = {pattern: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$|^$", max_len: 36}];
string hardware_version = 3;
string firmware_version = 4;
}
Expand Down Expand Up @@ -290,7 +290,7 @@ message MACState {

message JoinAccept {
// Payload of the join-accept received from Join Server.
bytes payload = 1 [(validator.field) = { length_gt: 11, length_lt: 29 }];
bytes payload = 1 [(validate.rules).bytes = { min_len: 12, max_len: 28 }];
// JoinRequest sent to Join Server.
JoinRequest request = 2 [(gogoproto.nullable) = false];
// Network session keys associated with the join.
Expand Down Expand Up @@ -458,7 +458,7 @@ message EndDevice {
MessagePayloadFormatters formatters = 41;

// ID of the provisioner. Stored in Join Server.
string provisioner_id = 42 [(gogoproto.customname) = "ProvisionerID", (validator.field) = {regex: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$|^$", length_lt: 37}];
string provisioner_id = 42 [(gogoproto.customname) = "ProvisionerID", (validate.rules).string = {pattern: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$|^$", max_len: 36}];
// Vendor-specific provisioning data. Stored in Join Server.
google.protobuf.Struct provisioning_data = 43;
}
Expand Down
14 changes: 7 additions & 7 deletions api/identifiers.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
syntax = "proto3";

import "github.com/gogo/protobuf/gogoproto/gogo.proto";
import "github.com/mwitkow/go-proto-validators/validator.proto";
import "github.com/lyft/protoc-gen-validate/validate/validate.proto";

package ttn.lorawan.v3;

Expand All @@ -25,19 +25,19 @@ option go_package = "go.thethings.network/lorawan-stack/pkg/ttnpb";
message ApplicationIdentifiers {
option (gogoproto.populate) = false;

string application_id = 1 [(gogoproto.customname) = "ApplicationID", (validator.field) = {regex: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$" , length_lt: 37}];
string application_id = 1 [(gogoproto.customname) = "ApplicationID", (validate.rules).string = {pattern: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$" , max_len: 36}];
}

message ClientIdentifiers {
option (gogoproto.populate) = false;

string client_id = 1 [(gogoproto.customname) = "ClientID", (validator.field) = {regex: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$" , length_lt: 37}];
string client_id = 1 [(gogoproto.customname) = "ClientID", (validate.rules).string = {pattern: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$" , max_len: 36}];
}

message EndDeviceIdentifiers {
option (gogoproto.populate) = false;

string device_id = 1 [(gogoproto.customname) = "DeviceID", (validator.field) = {regex: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$" , length_lt: 37}];
string device_id = 1 [(gogoproto.customname) = "DeviceID", (validate.rules).string = {pattern: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$" , max_len: 36}];
ApplicationIdentifiers application_ids = 2 [(gogoproto.embed) = true, (gogoproto.nullable) = false];
// The LoRaWAN DevEUI.
bytes dev_eui = 4 [(gogoproto.customtype) = "go.thethings.network/lorawan-stack/pkg/types.EUI64", (gogoproto.customname) = "DevEUI"];
Expand All @@ -50,7 +50,7 @@ message EndDeviceIdentifiers {
message GatewayIdentifiers {
option (gogoproto.populate) = false;

string gateway_id = 1 [(gogoproto.customname) = "GatewayID", (validator.field) = {regex: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$" , length_lt: 37}];
string gateway_id = 1 [(gogoproto.customname) = "GatewayID", (validate.rules).string = {pattern: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$" , max_len: 36}];

// Secondary identifier, which can only be used in specific requests.
bytes eui = 2 [(gogoproto.customtype) = "go.thethings.network/lorawan-stack/pkg/types.EUI64", (gogoproto.customname) = "EUI"];
Expand All @@ -60,14 +60,14 @@ message OrganizationIdentifiers {
option (gogoproto.populate) = false;

// This ID shares namespace with user IDs.
string organization_id = 1 [(gogoproto.customname) = "OrganizationID", (validator.field) = {regex: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$" , length_lt: 37}];
string organization_id = 1 [(gogoproto.customname) = "OrganizationID", (validate.rules).string = {pattern: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$" , max_len: 36}];
}

message UserIdentifiers {
option (gogoproto.populate) = false;

// This ID shares namespace with organization IDs.
string user_id = 1 [(gogoproto.customname) = "UserID", (validator.field) = {regex: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$" , length_lt: 37}];
string user_id = 1 [(gogoproto.customname) = "UserID", (validate.rules).string = {pattern: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$" , max_len: 36}];

// Secondary identifier, which can only be used in specific requests.
string email = 2;
Expand Down
6 changes: 3 additions & 3 deletions api/join.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
syntax = "proto3";

import "github.com/gogo/protobuf/gogoproto/gogo.proto";
import "github.com/mwitkow/go-proto-validators/validator.proto";
import "github.com/lyft/protoc-gen-validate/validate/validate.proto";
import "google/protobuf/duration.proto";
import "lorawan-stack/api/keys.proto";
import "lorawan-stack/api/lorawan.proto";
Expand All @@ -27,7 +27,7 @@ option go_package = "go.thethings.network/lorawan-stack/pkg/ttnpb";
message JoinRequest {
option (gogoproto.populate) = false;

bytes raw_payload = 1 [(validator.field) = { length_eq: 23 }];
bytes raw_payload = 1 [(validate.rules).bytes = {len: 23}];
Message payload = 2;
bytes dev_addr = 3 [(gogoproto.nullable) = false, (gogoproto.customtype) = "go.thethings.network/lorawan-stack/pkg/types.DevAddr"];
MACVersion selected_mac_version = 4 [(gogoproto.customname) = "SelectedMACVersion"];
Expand All @@ -41,7 +41,7 @@ message JoinRequest {
}

message JoinResponse {
bytes raw_payload = 1 [(validator.field) = { length_gt:16, length_lt: 34 }];
bytes raw_payload = 1 [(validate.rules).bytes = {min_len:17, max_len: 33}];
SessionKeys session_keys = 2 [(gogoproto.embed) = true, (gogoproto.nullable) = false];
google.protobuf.Duration lifetime = 3 [(gogoproto.nullable) = false, (gogoproto.stdduration) = true];
repeated string correlation_ids = 4 [(gogoproto.customname) = "CorrelationIDs"];
Expand Down
10 changes: 5 additions & 5 deletions api/joinserver.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
syntax = "proto3";

import "github.com/gogo/protobuf/gogoproto/gogo.proto";
import "github.com/mwitkow/go-proto-validators/validator.proto";
import "github.com/lyft/protoc-gen-validate/validate/validate.proto";
import "google/api/annotations.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/struct.proto";
Expand Down Expand Up @@ -65,7 +65,7 @@ message CryptoServicePayloadRequest {
EndDeviceIdentifiers ids = 1 [(gogoproto.nullable) = false, (gogoproto.embed) = true];
MACVersion lorawan_version = 2 [(gogoproto.customname) = "LoRaWANVersion"];
bytes payload = 3;
string provisioner_id = 4 [(gogoproto.customname) = "ProvisionerID", (validator.field) = {regex: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$|^$", length_lt: 37}];
string provisioner_id = 4 [(gogoproto.customname) = "ProvisionerID", (validate.rules).string = {pattern: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$|^$", max_len: 36}];
google.protobuf.Struct provisioning_data = 5;
}

Expand All @@ -85,13 +85,13 @@ message DeriveSessionKeysRequest {
bytes join_nonce = 3 [(gogoproto.nullable) = false, (gogoproto.customtype) = "go.thethings.network/lorawan-stack/pkg/types.JoinNonce"];
bytes dev_nonce = 4 [(gogoproto.nullable) = false, (gogoproto.customtype) = "go.thethings.network/lorawan-stack/pkg/types.DevNonce"];
bytes net_id = 5 [(gogoproto.nullable) = false, (gogoproto.customname) = "NetID", (gogoproto.customtype) = "go.thethings.network/lorawan-stack/pkg/types.NetID"];
string provisioner_id = 6 [(gogoproto.customname) = "ProvisionerID", (validator.field) = {regex: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$|^$", length_lt: 37}];
string provisioner_id = 6 [(gogoproto.customname) = "ProvisionerID", (validate.rules).string = {pattern: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$|^$", max_len: 36}];
google.protobuf.Struct provisioning_data = 7;
}

message GetRootKeysRequest {
EndDeviceIdentifiers ids = 1 [(gogoproto.nullable) = false, (gogoproto.embed) = true];
string provisioner_id = 2 [(gogoproto.customname) = "ProvisionerID", (validator.field) = {regex: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$|^$", length_lt: 37}];
string provisioner_id = 2 [(gogoproto.customname) = "ProvisionerID", (validate.rules).string = {pattern: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$|^$", max_len: 36}];
google.protobuf.Struct provisioning_data = 3;
}

Expand All @@ -116,7 +116,7 @@ service ApplicationCryptoService {
message ProvisionEndDevicesRequest {
ApplicationIdentifiers application_ids = 1 [(gogoproto.nullable) = false, (gogoproto.embed) = true];
// ID of the provisioner service as configured in the Join Server.
string provisioner_id = 2 [(gogoproto.customname) = "ProvisionerID", (validator.field) = {regex: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$", length_lt: 37}];
string provisioner_id = 2 [(gogoproto.customname) = "ProvisionerID", (validate.rules).string = {pattern: "^[a-z0-9](?:[-]?[a-z0-9]){2,}$", max_len: 36}];
// Vendor-specific provisioning data.
bytes provisioning_data = 3;

Expand Down
1 change: 0 additions & 1 deletion api/keys.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
syntax = "proto3";

import "github.com/gogo/protobuf/gogoproto/gogo.proto";
import "github.com/mwitkow/go-proto-validators/validator.proto";

package ttn.lorawan.v3;

Expand Down
10 changes: 5 additions & 5 deletions api/lorawan.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
syntax = "proto3";

import "github.com/gogo/protobuf/gogoproto/gogo.proto";
import "github.com/mwitkow/go-proto-validators/validator.proto";
import "github.com/lyft/protoc-gen-validate/validate/validate.proto";
import "google/protobuf/struct.proto";
import "google/protobuf/timestamp.proto";
import "lorawan-stack/api/identifiers.proto";
Expand Down Expand Up @@ -115,7 +115,7 @@ message MACPayload {
option (gogoproto.populate) = false;

FHDR f_hdr = 1 [(gogoproto.embed) = true, (gogoproto.nullable) = false];
uint32 f_port = 2 [(validator.field) = {int_lt: 256}];
uint32 f_port = 2 [(validate.rules).uint32 = {lt: 256}];
bytes frm_payload = 3 [(gogoproto.customname) = "FRMPayload"];
google.protobuf.Struct decoded_payload = 4;
}
Expand All @@ -125,7 +125,7 @@ message FHDR {

bytes dev_addr = 1 [(gogoproto.nullable) = false, (gogoproto.customtype) = "go.thethings.network/lorawan-stack/pkg/types.DevAddr"];
FCtrl f_ctrl = 2 [(gogoproto.embed) = true, (gogoproto.nullable) = false];
uint32 f_cnt = 3 [(validator.field) = {int_lt: 65536}];
uint32 f_cnt = 3 [(validate.rules).uint32 = {lt: 65536}];
bytes f_opts = 4;
}

Expand Down Expand Up @@ -256,10 +256,10 @@ message TxSettings {
bool invert_polarization = 6;
// Index of the gateway channel that received the message.
// Set by Gateway Server.
uint32 gateway_channel_index = 7 [(validator.field) = {int_lt: 256}];
uint32 gateway_channel_index = 7 [(validate.rules).uint32 = {lt: 256}];
// Index of the device channel that received the message.
// Set by Network Server.
uint32 device_channel_index = 8 [(validator.field) = {int_lt: 256}];
uint32 device_channel_index = 8 [(validate.rules).uint32 = {lt: 256}];
// Send a CRC in the packet; only on uplink; on downlink, CRC should not be enabled.
bool enable_crc = 9 [(gogoproto.customname) = "EnableCRC"];
// Timestamp of the gateway concentrator when the uplink message was received, or when the downlink message should be transmitted (microseconds).
Expand Down
1 change: 0 additions & 1 deletion api/messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
syntax = "proto3";

import "github.com/gogo/protobuf/gogoproto/gogo.proto";
import "github.com/mwitkow/go-proto-validators/validator.proto";
import "google/protobuf/struct.proto";
import "google/protobuf/timestamp.proto";
import "lorawan-stack/api/error.proto";
Expand Down
6 changes: 3 additions & 3 deletions api/user.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
syntax = "proto3";

import "github.com/gogo/protobuf/gogoproto/gogo.proto";
import "github.com/mwitkow/go-proto-validators/validator.proto";
import "github.com/lyft/protoc-gen-validate/validate/validate.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/field_mask.proto";
import "google/protobuf/timestamp.proto";
Expand Down Expand Up @@ -139,11 +139,11 @@ message Invitations {
}

message SendInvitationRequest {
string email = 1 [(validator.field) = {string_not_empty: true}];
string email = 1 [(validate.rules).string = {min_len: 1}];
}

message DeleteInvitationRequest {
string email = 1 [(validator.field) = {string_not_empty: true}];
string email = 1 [(validate.rules).string = {min_len: 1}];
}

message UserSessionIdentifiers {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ require (
github.com/labstack/echo v3.3.10+incompatible
github.com/labstack/gommon v0.2.8
github.com/lib/pq v1.0.0
github.com/lyft/protoc-gen-validate v0.0.13
github.com/magefile/mage v1.8.0
github.com/mattn/go-colorable v0.1.0 // indirect
github.com/mattn/go-isatty v0.0.4
Expand All @@ -76,7 +77,6 @@ require (
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.1.2
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
github.com/mwitkow/go-proto-validators v0.0.0-20190212092829-1f388280e944
github.com/nicksnyder/go-i18n v1.10.0 // indirect
github.com/oklog/ulid v1.3.1
github.com/olekukonko/tablewriter v0.0.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ github.com/labstack/gommon v0.2.8 h1:JvRqmeZcfrHC5u6uVleB4NxxNbzx6gpbJiQknDbKQu0
github.com/labstack/gommon v0.2.8/go.mod h1:/tj9csK2iPSBvn+3NLM9e52usepMtrd5ilFYA+wQNJ4=
github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lyft/protoc-gen-validate v0.0.13 h1:KNt/RhmQTOLr7Aj8PsJ7mTronaFyx80mRTT9qF261dA=
github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
github.com/magefile/mage v1.8.0 h1:mzL+xIopvPURVBwHG9A50JcjBO+xV3b5iZ7khFRI+5E=
github.com/magefile/mage v1.8.0/go.mod h1:IUDi13rsHje59lecXokTfGX0QIzO45uVPlXnJYsXepA=
github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY=
Expand Down Expand Up @@ -271,8 +273,6 @@ github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mwitkow/go-proto-validators v0.0.0-20190212092829-1f388280e944 h1:RY9I2vt95pyT12MKfJo1Ck3O+NPQqlukBahURwDtJBc=
github.com/mwitkow/go-proto-validators v0.0.0-20190212092829-1f388280e944/go.mod h1:m2XC9Qq0AlmmVksL6FktJCdTYyLk7V3fKyp0sl1yWQo=
github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJEU3ofeGjhHklVoIGuVj85JJwZ6kWPaJwCIxgnFmo=
github.com/neelance/sourcemap v0.0.0-20151028013722-8c68805598ab/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM=
github.com/nicksnyder/go-i18n v1.10.0 h1:5AzlPKvXBH4qBzmZ09Ua9Gipyruv6uApMcrNZdo96+Q=
Expand Down
10 changes: 9 additions & 1 deletion pkg/applicationserver/io/web/redis/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,18 @@ var (
)

func applyWebhookFieldMask(dst, src *ttnpb.ApplicationWebhook, paths ...string) (*ttnpb.ApplicationWebhook, error) {
paths = append(paths, "ids")

if dst == nil {
dst = &ttnpb.ApplicationWebhook{}
}
return dst, dst.SetFields(src, append(paths, "ids")...)
if err := dst.SetFields(src, paths...); err != nil {
return nil, err
}
if err := dst.ValidateFields(paths...); err != nil {
return nil, err
}
return dst, nil
}

// WebhookRegistry is a Redis webhook registry.
Expand Down
2 changes: 1 addition & 1 deletion pkg/applicationserver/io/web/webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func (w *webhooks) validateAndFillIDs() echo.MiddlewareFunc {
ApplicationIdentifiers: appID,
WebhookID: c.Param(webhookIDKey),
}
if err := hookID.Validate(); err != nil {
if err := hookID.ValidateFields(); err != nil {
return err
}
c.Set(webhookIDKey, hookID)
Expand Down
6 changes: 4 additions & 2 deletions pkg/applicationserver/redis/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ var (
)

func applyDeviceFieldMask(dst, src *ttnpb.EndDevice, paths ...string) (*ttnpb.EndDevice, error) {
paths = append(paths, "ids")

if dst == nil {
dst = &ttnpb.EndDevice{}
}
if err := dst.SetFields(src, append(paths, "ids")...); err != nil {
if err := dst.SetFields(src, paths...); err != nil {
return nil, err
}
if err := dst.EndDeviceIdentifiers.Validate(); err != nil {
if err := dst.ValidateFields(paths...); err != nil {
return nil, err
}
return dst, nil
Expand Down
Loading

0 comments on commit 4453468

Please sign in to comment.