diff --git a/backend/embed/migrations/20201013035318_initial_schema.sql b/backend/embed/migrations/20201013035318_initial_schema.sql index 4d5cb1e..490769b 100644 --- a/backend/embed/migrations/20201013035318_initial_schema.sql +++ b/backend/embed/migrations/20201013035318_initial_schema.sql @@ -205,6 +205,9 @@ CREATE TABLE IF NOT EXISTS `host` listen_interface TEXT NOT NULL DEFAULT "", domain_names TEXT NOT NULL, upstream_id INTEGER NOT NULL DEFAULT 0, + proxy_scheme TEXT NOT NULL DEFAULT "", + proxy_host TEXT NOT NULL DEFAULT "", + proxy_port INTEGER NOT NULL DEFAULT 0, certificate_id INTEGER NOT NULL DEFAULT 0, access_list_id INTEGER NOT NULL DEFAULT 0, ssl_forced INTEGER NOT NULL DEFAULT 0, diff --git a/backend/embed/migrations/20201013035839_initial_data.sql b/backend/embed/migrations/20201013035839_initial_data.sql index 55eb59f..f166259 100644 --- a/backend/embed/migrations/20201013035839_initial_data.sql +++ b/backend/embed/migrations/20201013035839_initial_data.sql @@ -151,10 +151,6 @@ INSERT INTO `nginx_template` ( # ------------------------------------------------------------ server { - set $forward_scheme {{Host.ForwardScheme}} http; # todo - set $server ""{{Host.ForwardHost}}""; # todo - set $port {{Host.ForwardPort}} 80; # todo - {{#if Config.Ipv4}} listen 80; {{/if}} @@ -255,10 +251,10 @@ server { {{#if Upstream.ID}} # upstream - proxy_pass $forward_scheme://npm_upstream_{{Upstream.ID}}; + proxy_pass {{Host.ProxyScheme}}://npm_upstream_{{Upstream.ID}}; {{else}} - # proxy - proxy_pass $forward_scheme://$server:$port; + # proxy a single host + proxy_pass {{Host.ProxyScheme}}://{{Host.ProxyHost}}:{{Host.ProxyPort}}; {{/if}} } diff --git a/backend/internal/api/schema/create_host.go b/backend/internal/api/schema/create_host.go index 18347bb..819d976 100644 --- a/backend/internal/api/schema/create_host.go +++ b/backend/internal/api/schema/create_host.go @@ -17,7 +17,8 @@ func CreateHost() string { "required": [ "type", "domain_names", - "nginx_template_id" + "nginx_template_id", + "proxy_scheme" ], "properties": { "type": { @@ -33,6 +34,16 @@ func CreateHost() string { "upstream_id": { "type": "integer" }, + "proxy_scheme": { + "type": "string", + "pattern": "^https?$" + }, + "proxy_host": { + "type": "string" + }, + "proxy_port": { + "type": "integer" + }, "certificate_id": { "type": "integer" }, diff --git a/backend/internal/entity/host/model.go b/backend/internal/entity/host/model.go index e449cb0..83d6cee 100644 --- a/backend/internal/entity/host/model.go +++ b/backend/internal/entity/host/model.go @@ -36,6 +36,9 @@ type Model struct { ListenInterface string `json:"listen_interface" db:"listen_interface" filter:"listen_interface,string"` DomainNames types.JSONB `json:"domain_names" db:"domain_names" filter:"domain_names,string"` UpstreamID int `json:"upstream_id" db:"upstream_id" filter:"upstream_id,integer"` + ProxyScheme string `json:"proxy_scheme" db:"proxy_scheme" filter:"proxy_scheme,string"` + ProxyHost string `json:"proxy_host" db:"proxy_host" filter:"proxy_host,string"` + ProxyPort int `json:"proxy_port" db:"proxy_port" filter:"proxy_port,integer"` CertificateID int `json:"certificate_id" db:"certificate_id" filter:"certificate_id,integer"` AccessListID int `json:"access_list_id" db:"access_list_id" filter:"access_list_id,integer"` SSLForced bool `json:"ssl_forced" db:"ssl_forced" filter:"ssl_forced,boolean"` diff --git a/backend/internal/validator/hosts.go b/backend/internal/validator/hosts.go index 7a7ca2e..3bdf69a 100644 --- a/backend/internal/validator/hosts.go +++ b/backend/internal/validator/hosts.go @@ -6,6 +6,7 @@ import ( "npm/internal/entity/certificate" "npm/internal/entity/host" "npm/internal/entity/nginxtemplate" + "npm/internal/entity/upstream" ) // ValidateHost will check if associated objects exist and other checks @@ -20,6 +21,21 @@ func ValidateHost(h host.Model) error { } } + if h.UpstreamID > 0 { + // Check upstream exists + if _, uErr := upstream.GetByID(h.UpstreamID); uErr != nil { + return fmt.Errorf("Upstream #%d does not exist", h.UpstreamID) + } + } + + // Ensure either UpstreamID is set or appropriate proxy host params are set + if h.UpstreamID > 0 && (h.ProxyHost != "" || h.ProxyPort > 0) { + return fmt.Errorf("Proxy Host or Port cannot be set when using an Upstream") + } + if h.UpstreamID == 0 && (h.ProxyHost == "" || h.ProxyPort < 1) { + return fmt.Errorf("Proxy Host and Port must be specified, unless using an Upstream") + } + // Check the nginx template exists and has the same type. nginxTemplate, tErr := nginxtemplate.GetByID(h.NginxTemplateID) if tErr != nil { diff --git a/scripts/ci/fulltest-cypress b/scripts/ci/fulltest-cypress index 4b2d338..0ee2e8c 100755 --- a/scripts/ci/fulltest-cypress +++ b/scripts/ci/fulltest-cypress @@ -72,34 +72,3 @@ docker cp -L "$(docker-compose ps -q cypress):/test/results" "$DIR/../../test/" docker cp -L "$(docker-compose ps -q fullstack):/data/logs" "$DIR/../../test/results/" echo -e "${BLUE}❯ ${GREEN}Fullstack cypress testing complete${RESET}" - -# ----------------- Debug Report ---------------------- -# echo ip address of every docker container in stack -# echo the hostnames and aliases of them -# dns lookups from main container -echo -e "${BLUE}============================================${RESET}" - -FULLSTACK_IP=$(get_container_ip "fullstack") -FULLSTACK_ALIASES=$(get_container_aliases "fullstack") -echo -e "${YELLOW}fullstack IP: ${GREEN}${FULLSTACK_IP}${RESET}" -echo -e "${YELLOW}fullstack Aliases: ${CYAN}${FULLSTACK_ALIASES}${RESET}" - -STEPCA_IP=$(get_container_ip "stepca") -STEPCA_ALIASES=$(get_container_aliases "stepca") -echo -e "${YELLOW}stepca IP: ${GREEN}${STEPCA_IP}${RESET}" -echo -e "${YELLOW}stepca Aliases: ${CYAN}${STEPCA_ALIASES}${RESET}" - -PDNS_IP=$(get_container_ip "pdns") -STEPCA_ALIASES=$(get_container_aliases "stepca") -echo -e "${YELLOW}pdns IP: ${GREEN}${PDNS_IP}${RESET}" -echo -e "${YELLOW}pdns Aliases: ${CYAN}${PDNS_ALIASES}${RESET}" - -PDNSDB_IP=$(get_container_ip "pdns-db") -PDNSDB_ALIASES=$(get_container_aliases "pdns-db") -echo -e "${YELLOW}pdns-db IP: ${GREEN}${PDNSDB_IP}${RESET}" -echo -e "${YELLOW}pdns-db Aliases: ${CYAN}${PDNSDB_ALIASES}${RESET}" - -DNSROUTER_IP=$(get_container_ip "dnsrouter") -DNSROUTER_ALIASES=$(get_container_aliases "dnsrouter") -echo -e "${YELLOW}dnsrouter IP: ${GREEN}${DNSROUTER_IP}${RESET}" -echo -e "${YELLOW}dnsrouter Aliases: ${CYAN}${DNSROUTER_ALIASES}${RESET}"