diff --git a/fly/lib/common.sh b/fly/lib/common.sh index e35f59532..c416c59d0 100644 --- a/fly/lib/common.sh +++ b/fly/lib/common.sh @@ -138,28 +138,7 @@ get_fly_org() { # Get server name from env var or prompt get_server_name() { - if [[ -n "${FLY_APP_NAME:-}" ]]; then - log_info "Using app name from environment: $FLY_APP_NAME" - if ! validate_server_name "$FLY_APP_NAME"; then - return 1 - fi - echo "$FLY_APP_NAME" - return 0 - fi - - local server_name=$(safe_read "Enter app name: ") - if [[ -z "$server_name" ]]; then - log_error "App name is required" - log_warn "Set FLY_APP_NAME environment variable for non-interactive usage:" - log_warn " FLY_APP_NAME=dev-mk1 curl ... | bash" - return 1 - fi - - if ! validate_server_name "$server_name"; then - return 1 - fi - - echo "$server_name" + get_validated_server_name "FLY_APP_NAME" "Enter app name: " } # Create Fly.io app, returning 0 on success or if app already exists diff --git a/oracle/lib/common.sh b/oracle/lib/common.sh index 30f9963dd..f3ca77a3e 100644 --- a/oracle/lib/common.sh +++ b/oracle/lib/common.sh @@ -182,22 +182,25 @@ _create_vcn() { echo "${vcn_id}" } -_setup_vcn_networking() { +_create_internet_gateway() { local compartment="${1}" local vcn_id="${2}" - # Create internet gateway - local igw_id - igw_id=$(oci network internet-gateway create \ + oci network internet-gateway create \ --compartment-id "${compartment}" \ --vcn-id "${vcn_id}" \ --display-name "spawn-igw" \ --is-enabled true \ --wait-for-state AVAILABLE \ --query 'data.id' \ - --raw-output 2>/dev/null) + --raw-output 2>/dev/null +} + +_add_default_route() { + local compartment="${1}" + local vcn_id="${2}" + local igw_id="${3}" - # Add default route to internet gateway local rt_id rt_id=$(oci network route-table list \ --compartment-id "${compartment}" \ @@ -205,15 +208,19 @@ _setup_vcn_networking() { --query 'data[0].id' \ --raw-output 2>/dev/null) - if [[ -n "${rt_id}" && "${rt_id}" != "null" && -n "${igw_id}" && "${igw_id}" != "null" ]]; then + if [[ -n "${rt_id}" && "${rt_id}" != "null" ]]; then oci network route-table update \ --rt-id "${rt_id}" \ --route-rules "[{\"destination\":\"0.0.0.0/0\",\"networkEntityId\":\"${igw_id}\",\"destinationType\":\"CIDR_BLOCK\"}]" \ --force \ --wait-for-state AVAILABLE >/dev/null 2>&1 || true fi +} + +_add_ssh_security_rules() { + local compartment="${1}" + local vcn_id="${2}" - # Add SSH ingress rule to default security list local sl_id sl_id=$(oci network security-list list \ --compartment-id "${compartment}" \ @@ -231,6 +238,20 @@ _setup_vcn_networking() { fi } +_setup_vcn_networking() { + local compartment="${1}" + local vcn_id="${2}" + + local igw_id + igw_id=$(_create_internet_gateway "${compartment}" "${vcn_id}") + + if [[ -n "${igw_id}" && "${igw_id}" != "null" ]]; then + _add_default_route "${compartment}" "${vcn_id}" "${igw_id}" + fi + + _add_ssh_security_rules "${compartment}" "${vcn_id}" +} + _create_subnet() { local compartment="${1}" local vcn_id="${2}"