rework protobuf messages
Some checks failed
/ build_macos (push) Has been cancelled
/ build_windows (push) Has been cancelled
/ build_ubuntu (push) Has been cancelled

PubSub allows us to do schema validation, however it only allows one top level message at a time.  Move other sub-message declarations under the main message declaration so that we can enable schema validation in the pubsub stream directly
This commit is contained in:
Grant Limberg 2025-08-25 15:09:10 -07:00
parent 2833d0e4f4
commit f8a4a5d6af
7 changed files with 100 additions and 97 deletions

View file

@ -12,7 +12,6 @@ fn main() {
.type_attribute(".", "#[derive(serde::Serialize, serde::Deserialize)]")
.compile_protos(
&[
"src/pubsub/metadata.proto",
"src/pubsub/network.proto",
"src/pubsub/member.proto",
"src/pubsub/member_status.proto",

View file

@ -1,37 +1,39 @@
syntax = "proto3";
import "metadata.proto";
package pbmessages;
message Member {
string device_id = 1;
string network_id = 2;
string identity = 3; // Identity of the member
bool authorized = 4; // Whether the member is authorized
repeated string ip_assignments = 5; // List of IP assignments
bool active_bridge = 6; // Whether the member is an active bridge
string tags = 7; // JSON string of tags
string capabilities = 8; // JSON string of capabilities
uint64 creation_time = 9; // Unix timestamp in milliseconds
bool no_auto_assign_ips = 10; // Whether auto IP assignment is disabled
uint64 revision = 11; // Revision number
uint64 last_authorized_time = 12; // Last time the member was authorized
uint64 last_deauthorized_time = 13; // Last time the member was deauthorized
optional string last_authorized_credential_type = 14; // Type of credential used for last authorization
optional string last_authorized_credential = 15; // Credential used for last authorization
int32 version_major = 16; // Major version of the member
int32 version_minor = 17; // Minor version of the member
int32 version_rev = 18; // Patch version of the member
int32 version_protocol = 19; // Protocol version of the member
int32 remote_trace_level = 20; // Remote trace level
optional string remote_trace_target = 21; // Remote trace target
bool sso_exepmt = 22; // Whether SSO is exempt
uint64 auth_expiry_time = 23; // Authorization expiry time in milliseconds
}
message MemberChange {
message Member {
string device_id = 1;
string network_id = 2;
string identity = 3; // Identity of the member
bool authorized = 4; // Whether the member is authorized
repeated string ip_assignments = 5; // List of IP assignments
bool active_bridge = 6; // Whether the member is an active bridge
string tags = 7; // JSON string of tags
string capabilities = 8; // JSON string of capabilities
uint64 creation_time = 9; // Unix timestamp in milliseconds
bool no_auto_assign_ips = 10; // Whether auto IP assignment is disabled
uint64 revision = 11; // Revision number
uint64 last_authorized_time = 12; // Last time the member was authorized
uint64 last_deauthorized_time = 13; // Last time the member was deauthorized
optional string last_authorized_credential_type = 14; // Type of credential used for last authorization
optional string last_authorized_credential = 15; // Credential used for last authorization
int32 version_major = 16; // Major version of the member
int32 version_minor = 17; // Minor version of the member
int32 version_rev = 18; // Patch version of the member
int32 version_protocol = 19; // Protocol version of the member
int32 remote_trace_level = 20; // Remote trace level
optional string remote_trace_target = 21; // Remote trace target
bool sso_exepmt = 22; // Whether SSO is exempt
uint64 auth_expiry_time = 23; // Authorization expiry time in milliseconds
}
message MemberChangeMetadata {
string trace_id = 1;
string controller_id = 2;
}
optional Member old = 1;
optional Member new = 2;
optional Metadata metadata = 3;
optional MemberChangeMetadata metadata = 3;
}

View file

@ -87,7 +87,8 @@ impl MemberListener {
mod tests {
use super::*;
use crate::pubsub::change_listener::tests::setup_pubsub_emulator;
use crate::pubsub::protobuf::pbmessages::{Member, MemberChange};
use crate::pubsub::protobuf::pbmessages::member_change::Member;
use crate::pubsub::protobuf::pbmessages::MemberChange;
use gcloud_googleapis::pubsub::v1::PubsubMessage;
use gcloud_pubsub::client::{Client, ClientConfig};

View file

@ -2,10 +2,15 @@ syntax = "proto3";
package pbmessages;
import "metadata.proto";
message MemberStatus {
Metadata metadata = 1;
message MemberStatusMetadata {
string trace_id = 1;
string controller_id = 2;
}
MemberStatusMetadata metadata = 1;
string network_id = 2;
string member_id = 3;
uint64 timestamp = 4; // Unix timestamp in milliseconds
@ -13,4 +18,4 @@ message MemberStatus {
optional string os = 6;
optional string arch = 7;
optional string version = 8;
}
}

View file

@ -1,8 +0,0 @@
syntax = "proto3";
package pbmessages;
message Metadata {
string trace_id = 1;
string controller_id = 2;
}

View file

@ -1,62 +1,65 @@
syntax = "proto3";
import "metadata.proto";
package pbmessages;
message IPRange {
string start_ip = 1; // Start of the IP range
string end_ip = 2; // End of the IP range
}
message Route {
string target = 1; // Target IP or network
optional string via = 2; // Optional next hop IP
}
message DNS {
string domain = 1; // Search domain
repeated string nameservers = 2; // List of nameservers
}
message IPV4AssignMode {
bool zt = 1; // Whether ZeroTier is used for IPv4 assignment
}
message IPv6AssignMode {
bool six_plane = 1; // Whether 6plane is used for IPv6 assignment
bool rfc4193 = 2; // Whether RFC 4193 is used for IPv6 assignment
bool zt = 3; // Whether ZeroTier is used for IPv6 assignment
}
message Network {
string network_id = 1;
string capabilities = 2; // JSON string of capabilities
uint64 creation_time = 3; // Unix timestamp in milliseconds
bool enable_broadcast = 4; // Whether broadcast is enabled
repeated IPRange assignment_pools = 5; // List of IP ranges for assignment
uint32 mtu = 6; // Maximum Transmission Unit
uint32 multicast_limit = 7; // Limit for multicast messages
optional string name = 8; // Name of the network
bool is_private = 9; // Whether the network is private
uint32 remote_trace_level = 10; // Remote trace level
optional string remote_trace_target = 11; // Remote trace target
uint64 revision = 12; // Revision number
repeated Route routes = 13; // List of routes
string rules = 14; // JSON string of rules
optional string tags = 15; // JSON string of tags
IPV4AssignMode ipv4_assign_mode = 16; // IPv4 assignment mode
IPv6AssignMode ipv6_assign_mode = 17; // IPv6 assignment mode
optional DNS dns = 18; // DNS configuration
bool sso_enabled = 19; // Whether Single Sign-On is enabled
optional string sso_client_id = 20; // SSO client ID
optional string sso_authorization_endpoint = 21; // SSO authorization endpoint
optional string sso_issuer = 22; // SSO issuer
optional string sso_provider = 23; // SSO provider
}
message NetworkChange {
message NetworkChangeMetadata {
string trace_id = 1;
string controller_id = 2;
}
message IPRange {
string start_ip = 1; // Start of the IP range
string end_ip = 2; // End of the IP range
}
message Route {
string target = 1; // Target IP or network
optional string via = 2; // Optional next hop IP
}
message DNS {
string domain = 1; // Search domain
repeated string nameservers = 2; // List of nameservers
}
message IPV4AssignMode {
bool zt = 1; // Whether ZeroTier is used for IPv4 assignment
}
message IPv6AssignMode {
bool six_plane = 1; // Whether 6plane is used for IPv6 assignment
bool rfc4193 = 2; // Whether RFC 4193 is used for IPv6 assignment
bool zt = 3; // Whether ZeroTier is used for IPv6 assignment
}
message Network {
string network_id = 1;
string capabilities = 2; // JSON string of capabilities
uint64 creation_time = 3; // Unix timestamp in milliseconds
bool enable_broadcast = 4; // Whether broadcast is enabled
repeated IPRange assignment_pools = 5; // List of IP ranges for assignment
uint32 mtu = 6; // Maximum Transmission Unit
uint32 multicast_limit = 7; // Limit for multicast messages
optional string name = 8; // Name of the network
bool is_private = 9; // Whether the network is private
uint32 remote_trace_level = 10; // Remote trace level
optional string remote_trace_target = 11; // Remote trace target
uint64 revision = 12; // Revision number
repeated Route routes = 13; // List of routes
string rules = 14; // JSON string of rules
optional string tags = 15; // JSON string of tags
IPV4AssignMode ipv4_assign_mode = 16; // IPv4 assignment mode
IPv6AssignMode ipv6_assign_mode = 17; // IPv6 assignment mode
optional DNS dns = 18; // DNS configuration
bool sso_enabled = 19; // Whether Single Sign-On is enabled
optional string sso_client_id = 20; // SSO client ID
optional string sso_authorization_endpoint = 21; // SSO authorization endpoint
optional string sso_issuer = 22; // SSO issuer
optional string sso_provider = 23; // SSO provider
}
optional Network old = 1;
optional Network new = 2;
optional Metadata metadata = 3;
optional NetworkChangeMetadata metadata = 3;
}

View file

@ -88,7 +88,8 @@ impl NetworkListener {
mod tests {
use super::*;
use crate::pubsub::change_listener::tests::setup_pubsub_emulator;
use crate::pubsub::protobuf::pbmessages::Network;
use crate::pubsub::protobuf::pbmessages::network_change::Network;
use crate::pubsub::protobuf::pbmessages::NetworkChange;
use gcloud_googleapis::pubsub::v1::PubsubMessage;
use gcloud_pubsub::client::{Client, ClientConfig};