MCPcopy Create free account
hub / github.com/PowerShell/DSC / invoke

Method invoke

lib/dsc-lib/src/functions/cidr_host.rs:33–59  ·  view source on GitHub ↗
(&self, args: &[Value], _context: &Context)

Source from the content-addressed store, hash-verified

31 }
32
33 fn invoke(&self, args: &[Value], _context: &Context) -> Result<Value, DscError> {
34 debug!("{}", t!("functions.cidrHost.invoked"));
35
36 let cidr_string = args[0].as_str().unwrap();
37 let host_index = args[1].as_i64().unwrap();
38
39 if host_index < 0 {
40 return Err(DscError::FunctionArg(
41 "cidrHost".to_string(),
42 t!("functions.cidrHost.negativeHostIndex").to_string(),
43 ));
44 }
45
46 let network = cidr_string.parse::<IpNetwork>().map_err(|_| {
47 DscError::FunctionArg(
48 "cidrHost".to_string(),
49 t!("functions.cidrHost.invalidCidr", cidr = cidr_string).to_string(),
50 )
51 })?;
52
53 let result = match network {
54 IpNetwork::V4(net) => calculate_ipv4_host(&net, host_index as u32)?,
55 IpNetwork::V6(net) => calculate_ipv6_host(&net, host_index as u128)?,
56 };
57
58 Ok(Value::String(result))
59 }
60}
61
62fn calculate_ipv4_host(net: &Ipv4Network, host_index: u32) -> Result<String, DscError> {

Callers

nothing calls this directly

Calls 4

FunctionArgEnum · 0.85
calculate_ipv4_hostFunction · 0.85
calculate_ipv6_hostFunction · 0.85
as_strMethod · 0.80

Tested by

no test coverage detected