list-cidr-secgps.sh 898 B

1234567891011121314151617181920212223242526272829303132
  1. #! /bin/bash
  2. usage() {
  3. cat << EOF
  4. Usage: ${0##*/} [-h] <cidr>
  5. List security groups matching cidr
  6. -h Print this help
  7. EOF
  8. }
  9. while getopts h opt; do
  10. case $opt in
  11. h) usage; exit 0 ;;
  12. esac
  13. done
  14. shift $(( OPTIND - 1 ))
  15. . ~/.os_helpers
  16. endpoint="$(get_service_endpoint network)"
  17. get_rules() {
  18. curl -s \
  19. -H "X-Auth-Token: $CURL_OS_TOKEN" \
  20. "${endpoint}/security-group-rules?remote_ip_prefix=${1}&direction=ingress&sort_key=project_id&sort_dir=asc&sort_key=security_group_id&sort_dir=asc&sort_key=port_range_min&sort_dir=asc"
  21. }
  22. get_rules "$1" \
  23. | jq -r '.security_group_rules[] | [.id, .security_group_id, .project_id, .protocol, .port_range_min, .port_range_max, .created_at, .updated_at] | @tsv' \
  24. | column -s$'\t' -t --table-columns id,security_group_id,project_id,protocol,p_min,p_max,created_at,updated_at