Render an endpoint as `host:port [layer, …allows…, …denies…]` so a reader can tell L4-only access apart from a method/path-scoped L7 grant. The L7 fields (`protocol: rest`, `rules`, `access`) materially change what gets allowed; surfacing them in the default text output is what makes `openshell rule get` useful for approval review.
(endpoint: &openshell_core::proto::NetworkEndpoint)
| 7779 | /// allowed; surfacing them in the default text output is what makes |
| 7780 | /// `openshell rule get` useful for approval review. |
| 7781 | fn format_endpoint(endpoint: &openshell_core::proto::NetworkEndpoint) -> String { |
| 7782 | let host_port = if endpoint.port > 0 { |
| 7783 | format!("{}:{}", endpoint.host, endpoint.port) |
| 7784 | } else { |
| 7785 | endpoint.host.clone() |
| 7786 | }; |
| 7787 | |
| 7788 | let mut tags: Vec<String> = Vec::new(); |
| 7789 | let layer_tag = if endpoint.protocol.eq_ignore_ascii_case("rest") { |
| 7790 | "L7 rest" |
| 7791 | } else if endpoint.protocol.is_empty() { |
| 7792 | "L4" |
| 7793 | } else { |
| 7794 | endpoint.protocol.as_str() |
| 7795 | }; |
| 7796 | tags.push(layer_tag.to_string()); |
| 7797 | |
| 7798 | if !endpoint.access.is_empty() { |
| 7799 | tags.push(format!("access={}", endpoint.access)); |
| 7800 | } |
| 7801 | |
| 7802 | for r in &endpoint.rules { |
| 7803 | if let Some(allow) = &r.allow { |
| 7804 | let method = non_empty_or(&allow.method, "*"); |
| 7805 | let path = non_empty_or(&allow.path, "*"); |
| 7806 | tags.push(format!("allow {method} {path}")); |
| 7807 | } |
| 7808 | } |
| 7809 | for r in &endpoint.deny_rules { |
| 7810 | let method = non_empty_or(&r.method, "*"); |
| 7811 | let path = non_empty_or(&r.path, "*"); |
| 7812 | tags.push(format!("deny {method} {path}")); |
| 7813 | } |
| 7814 | |
| 7815 | format!("{host_port} [{}]", tags.join(", ")) |
| 7816 | } |
| 7817 | |
| 7818 | fn non_empty_or<'a>(value: &'a str, fallback: &'a str) -> &'a str { |
| 7819 | if value.is_empty() { fallback } else { value } |
nothing calls this directly
no test coverage detected