-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2156 from fermyon/sockets
Basic Socket Support
- Loading branch information
Showing
28 changed files
with
1,182 additions
and
22 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pub mod cli; | ||
pub mod loader; | ||
mod network; | ||
mod runtime_config; | ||
mod stdio; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use crate::TriggerHooks; | ||
|
||
pub struct Network; | ||
|
||
impl TriggerHooks for Network { | ||
fn component_store_builder( | ||
&self, | ||
component: &spin_app::AppComponent, | ||
store_builder: &mut spin_core::StoreBuilder, | ||
) -> anyhow::Result<()> { | ||
let hosts = component | ||
.get_metadata(spin_outbound_networking::ALLOWED_HOSTS_KEY)? | ||
.unwrap_or_default(); | ||
let allowed_hosts = spin_outbound_networking::AllowedHostsConfig::parse(&hosts)?; | ||
match allowed_hosts { | ||
spin_outbound_networking::AllowedHostsConfig::All => { | ||
store_builder.inherit_limited_network() | ||
} | ||
spin_outbound_networking::AllowedHostsConfig::SpecificHosts(configs) => { | ||
for config in configs { | ||
if config.scheme().allows_any() { | ||
match config.host() { | ||
spin_outbound_networking::HostConfig::Any => { | ||
store_builder.inherit_limited_network() | ||
} | ||
spin_outbound_networking::HostConfig::ToSelf => {} | ||
spin_outbound_networking::HostConfig::List(hosts) => { | ||
for host in hosts { | ||
let Ok(ip_net) = | ||
// Parse the host as an `IpNet` cidr block and if it fails | ||
// then try parsing again with `/32` appended to the end. | ||
host.parse().or_else(|_| format!("{host}/32").parse()) | ||
else { | ||
continue; | ||
}; | ||
match config.port() { | ||
spin_outbound_networking::PortConfig::Any => { | ||
store_builder.insert_ip_net_port_range(ip_net, 0, None); | ||
} | ||
spin_outbound_networking::PortConfig::List(ports) => { | ||
for port in ports { | ||
match port { | ||
spin_outbound_networking::IndividualPortConfig::Port(p) => { | ||
store_builder.insert_ip_net_port_range(ip_net, *p, p.checked_add(1)); | ||
} | ||
spin_outbound_networking::IndividualPortConfig::Range(r) => { | ||
store_builder.insert_ip_net_port_range(ip_net, r.start, Some(r.end)) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.