mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 18:18:55 +00:00
fix(connlib): prevent panic on internet resource for apps (#6381)
[Refs](https://github.com/firezone/firezone/pull/6299#discussion_r1724108733) The problem right now, after #6325 we send the internet resource up to the clients. The clients expect a certain format for the resources and panic if it isn't followed. Particularly, in the case of no `address` or no `name`. To fix this, we add a name and an address for the internet resource when it is converted to the callback type. Setting the `name` at that point actually makes a lot of sense since it homogenizes the name across all platforms. But the internet resource having an address makes no sense. So in a next PR, when I do the last UI changes I plan to make `address` optional for all resources on the clients and specialize the display of the internet resource. For now I wanted to get this in so that we don't ever panic on the internet resource existing. (This was tested on all platforms and it works)
This commit is contained in:
@@ -29,6 +29,9 @@ enum class TypeEnum {
|
||||
|
||||
@Json(name = "cidr")
|
||||
CIDR,
|
||||
|
||||
@Json(name = "internet")
|
||||
Internet,
|
||||
}
|
||||
|
||||
enum class StatusEnum {
|
||||
|
||||
@@ -34,7 +34,7 @@ impl ResourceDescription {
|
||||
match self {
|
||||
ResourceDescription::Dns(r) => &r.name,
|
||||
ResourceDescription::Cidr(r) => &r.name,
|
||||
ResourceDescription::Internet(_) => "Internet",
|
||||
ResourceDescription::Internet(r) => &r.name,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,8 +120,15 @@ pub struct ResourceDescriptionCidr {
|
||||
/// Description of an Internet resource
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct ResourceDescriptionInternet {
|
||||
/// Name for display always set to "Internet Resource"
|
||||
pub name: String,
|
||||
|
||||
/// Address for display always set to "All internet addresses"
|
||||
pub address: String,
|
||||
|
||||
pub id: ResourceId,
|
||||
pub sites: Vec<Site>,
|
||||
|
||||
pub status: Status,
|
||||
pub can_be_disabled: bool,
|
||||
}
|
||||
|
||||
@@ -86,6 +86,8 @@ pub struct ResourceDescriptionInternet {
|
||||
impl ResourceDescriptionInternet {
|
||||
pub fn with_status(self, status: Status) -> crate::callbacks::ResourceDescriptionInternet {
|
||||
crate::callbacks::ResourceDescriptionInternet {
|
||||
name: "Internet Resource".to_string(),
|
||||
address: "All internet addresses".to_string(),
|
||||
id: self.id,
|
||||
sites: self.sites,
|
||||
can_be_disabled: false,
|
||||
|
||||
@@ -338,9 +338,8 @@ mod tests {
|
||||
{
|
||||
"id": "1106047c-cd5d-4151-b679-96b93da7383b",
|
||||
"type": "internet",
|
||||
"name": "internet",
|
||||
"address": "0.0.0.0/0",
|
||||
"address_description": "The whole entire Internet",
|
||||
"name": "Internet Resource",
|
||||
"address": "All internet addresses",
|
||||
"sites": [{"name": "test", "id": "eb94482a-94f4-47cb-8127-14fb3afa5516"}],
|
||||
"status": "Offline",
|
||||
"can_be_disabled": false
|
||||
@@ -448,12 +447,12 @@ mod tests {
|
||||
.copyable(GATEWAY_CONNECTED),
|
||||
)
|
||||
.add_submenu(
|
||||
"Internet",
|
||||
"Internet Resource",
|
||||
Menu::default()
|
||||
.copyable("")
|
||||
.separator()
|
||||
.disabled("Resource")
|
||||
.copyable("Internet")
|
||||
.copyable("Internet Resource")
|
||||
.copyable("")
|
||||
.item(
|
||||
Event::AddFavorite(
|
||||
@@ -535,12 +534,12 @@ mod tests {
|
||||
.copyable(NO_ACTIVITY),
|
||||
)
|
||||
.add_submenu(
|
||||
"Internet",
|
||||
"Internet Resource",
|
||||
Menu::default()
|
||||
.copyable("")
|
||||
.separator()
|
||||
.disabled("Resource")
|
||||
.copyable("Internet")
|
||||
.copyable("Internet Resource")
|
||||
.copyable("")
|
||||
.item(
|
||||
Event::AddFavorite(ResourceId::from_str(
|
||||
@@ -622,12 +621,12 @@ mod tests {
|
||||
.copyable(GATEWAY_CONNECTED),
|
||||
)
|
||||
.add_submenu(
|
||||
"Internet",
|
||||
"Internet Resource",
|
||||
Menu::default()
|
||||
.copyable("")
|
||||
.separator()
|
||||
.disabled("Resource")
|
||||
.copyable("Internet")
|
||||
.copyable("Internet Resource")
|
||||
.copyable("")
|
||||
.item(
|
||||
Event::AddFavorite(ResourceId::from_str(
|
||||
|
||||
@@ -77,4 +77,5 @@ public enum ResourceType: String, Decodable {
|
||||
case dns = "dns"
|
||||
case cidr = "cidr"
|
||||
case ip = "ip"
|
||||
case internet = "internet"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user