#!/bin/bash

# Get public ports only (for UFW/firewall) with protocol
portGetPublicPorts()
{
    local app_name="$1"
    local service_name="$2"
    
    portGetServicePorts "$app_name" "$service_name"
    local ports_result="$service_ports"
    
    if [[ -n "$ports_result" ]]; then
        local public_ports=""
        for port_entry in ${ports_result//,/ }; do
            local access_type_protocol="${port_entry#*:}"
            local access_type="${access_type_protocol%%:*}"
            if [[ "$access_type" == "public" ]]; then
                local port="${port_entry%%:*}"
                local protocol="${access_type_protocol#*:}"
                local port_protocol="$port/$protocol"
                if [[ -z "$public_ports" ]]; then
                    public_ports="$port_protocol"
                else
                    public_ports="$public_ports,$port_protocol"
                fi
            fi
        done
        public_ports_result="$public_ports"
    fi
}
