use crate::codec::support::{from_wire_duration, from_wire_timestamp, to_wire_struct};
use crate::generated::v1;
use crate::remote::{
CreateRemoteRequest, DeleteRemoteRequest, ListRemotesRequest, ListRemotesResponse, ProviderRef,
RegistrationCheckRequest, RegistrationCheckResponse, Remote, RemoteProviderDefinition,
RemoteProviderSummary, RemoteReachability, ServerIdentity, TunnelBootstrap, TunnelEndpoint,
};
pub(crate) fn to_wire_create_remote_request(value: CreateRemoteRequest) -> v1::CreateRemoteRequest {
v1::CreateRemoteRequest {
tunnel: value.tunnel.map(to_wire_tunnel_endpoint),
providers: value
.providers
.into_iter()
.map(to_wire_remote_provider_definition)
.collect(),
expected_generation: value.expected_generation,
}
}
pub(crate) fn to_wire_delete_remote_request(value: DeleteRemoteRequest) -> v1::DeleteRemoteRequest {
v1::DeleteRemoteRequest {
id: value.id,
expected_generation: value.expected_generation,
}
}
pub(crate) fn to_wire_list_remotes_request(_value: ListRemotesRequest) -> v1::ListRemotesRequest {
v1::ListRemotesRequest {}
}
pub(crate) fn from_wire_list_remotes_response(
value: v1::ListRemotesResponse,
) -> ListRemotesResponse {
ListRemotesResponse {
remotes: value.remotes.into_iter().map(from_wire_remote).collect(),
server_identity: value.server_identity.map(from_wire_server_identity),
tunnel: value.tunnel.map(from_wire_tunnel_bootstrap),
lease_duration: value.lease_duration.map(from_wire_duration),
}
}
pub(crate) fn to_wire_provider_ref(value: ProviderRef) -> v1::ProviderRef {
v1::ProviderRef {
kind: value.kind,
name: value.name,
}
}
pub(crate) fn to_wire_registration_check_request(
value: RegistrationCheckRequest,
) -> v1::RegistrationCheckRequest {
v1::RegistrationCheckRequest {
registration_id: value.registration_id,
generation: value.generation,
providers: value
.providers
.into_iter()
.map(to_wire_provider_ref)
.collect(),
}
}
pub(crate) fn from_wire_registration_check_response(
value: v1::RegistrationCheckResponse,
) -> RegistrationCheckResponse {
RegistrationCheckResponse {
ready: value.ready,
message: value.message,
}
}
pub(crate) fn from_wire_remote(value: v1::Remote) -> Remote {
Remote {
id: value.id,
owner_subject_id: value.owner_subject_id,
generation: value.generation,
providers: value
.providers
.into_iter()
.map(from_wire_remote_provider_summary)
.collect(),
reachability: value.reachability.map(from_wire_remote_reachability),
server_spki_sha256: value.server_spki_sha256,
created_at: value.created_at.map(from_wire_timestamp),
updated_at: value.updated_at.map(from_wire_timestamp),
last_checked_at: value.last_checked_at.map(from_wire_timestamp),
last_successful_heartbeat_at: value.last_successful_heartbeat_at.map(from_wire_timestamp),
last_error: value.last_error,
lease_expires_at: value.lease_expires_at.map(from_wire_timestamp),
}
}
pub(crate) fn to_wire_remote_provider_definition(
value: RemoteProviderDefinition,
) -> v1::RemoteProviderDefinition {
v1::RemoteProviderDefinition {
kind: value.kind,
name: value.name,
definition: value.definition.map(to_wire_struct),
}
}
pub(crate) fn from_wire_remote_provider_summary(
value: v1::RemoteProviderSummary,
) -> RemoteProviderSummary {
RemoteProviderSummary {
kind: value.kind,
name: value.name,
}
}
pub(crate) fn from_wire_remote_reachability(value: v1::RemoteReachability) -> RemoteReachability {
RemoteReachability {
reachable: value.reachable,
message: value.message,
}
}
pub(crate) fn from_wire_server_identity(value: v1::ServerIdentity) -> ServerIdentity {
ServerIdentity {
client_spki_sha256: value.client_spki_sha256,
}
}
pub(crate) fn from_wire_tunnel_bootstrap(value: v1::TunnelBootstrap) -> TunnelBootstrap {
TunnelBootstrap {
frps_address: value.frps_address,
lease_duration: value.lease_duration.map(from_wire_duration),
}
}
pub(crate) fn to_wire_tunnel_endpoint(value: TunnelEndpoint) -> v1::TunnelEndpoint {
v1::TunnelEndpoint {
host: value.host,
certificate: value.certificate,
server_spki_sha256: value.server_spki_sha256,
}
}