Skip to content

Commit f6b2197

Browse files
committed
Adds proxy host vars
1 parent ad848a6 commit f6b2197

File tree

6 files changed

+37
-39
lines changed

6 files changed

+37
-39
lines changed

backend/embed/migrations/20201013035318_initial_schema.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ CREATE TABLE IF NOT EXISTS `host`
205205
listen_interface TEXT NOT NULL DEFAULT "",
206206
domain_names TEXT NOT NULL,
207207
upstream_id INTEGER NOT NULL DEFAULT 0,
208+
proxy_scheme TEXT NOT NULL DEFAULT "",
209+
proxy_host TEXT NOT NULL DEFAULT "",
210+
proxy_port INTEGER NOT NULL DEFAULT 0,
208211
certificate_id INTEGER NOT NULL DEFAULT 0,
209212
access_list_id INTEGER NOT NULL DEFAULT 0,
210213
ssl_forced INTEGER NOT NULL DEFAULT 0,

backend/embed/migrations/20201013035839_initial_data.sql

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,6 @@ INSERT INTO `nginx_template` (
151151
# ------------------------------------------------------------
152152
153153
server {
154-
set $forward_scheme {{Host.ForwardScheme}} http; # todo
155-
set $server ""{{Host.ForwardHost}}""; # todo
156-
set $port {{Host.ForwardPort}} 80; # todo
157-
158154
{{#if Config.Ipv4}}
159155
listen 80;
160156
{{/if}}
@@ -255,10 +251,10 @@ server {
255251
256252
{{#if Upstream.ID}}
257253
# upstream
258-
proxy_pass $forward_scheme://npm_upstream_{{Upstream.ID}};
254+
proxy_pass {{Host.ProxyScheme}}://npm_upstream_{{Upstream.ID}};
259255
{{else}}
260-
# proxy
261-
proxy_pass $forward_scheme://$server:$port;
256+
# proxy a single host
257+
proxy_pass {{Host.ProxyScheme}}://{{Host.ProxyHost}}:{{Host.ProxyPort}};
262258
{{/if}}
263259
}
264260

backend/internal/api/schema/create_host.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ func CreateHost() string {
1717
"required": [
1818
"type",
1919
"domain_names",
20-
"nginx_template_id"
20+
"nginx_template_id",
21+
"proxy_scheme"
2122
],
2223
"properties": {
2324
"type": {
@@ -33,6 +34,16 @@ func CreateHost() string {
3334
"upstream_id": {
3435
"type": "integer"
3536
},
37+
"proxy_scheme": {
38+
"type": "string",
39+
"pattern": "^https?$"
40+
},
41+
"proxy_host": {
42+
"type": "string"
43+
},
44+
"proxy_port": {
45+
"type": "integer"
46+
},
3647
"certificate_id": {
3748
"type": "integer"
3849
},

backend/internal/entity/host/model.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ type Model struct {
3636
ListenInterface string `json:"listen_interface" db:"listen_interface" filter:"listen_interface,string"`
3737
DomainNames types.JSONB `json:"domain_names" db:"domain_names" filter:"domain_names,string"`
3838
UpstreamID int `json:"upstream_id" db:"upstream_id" filter:"upstream_id,integer"`
39+
ProxyScheme string `json:"proxy_scheme" db:"proxy_scheme" filter:"proxy_scheme,string"`
40+
ProxyHost string `json:"proxy_host" db:"proxy_host" filter:"proxy_host,string"`
41+
ProxyPort int `json:"proxy_port" db:"proxy_port" filter:"proxy_port,integer"`
3942
CertificateID int `json:"certificate_id" db:"certificate_id" filter:"certificate_id,integer"`
4043
AccessListID int `json:"access_list_id" db:"access_list_id" filter:"access_list_id,integer"`
4144
SSLForced bool `json:"ssl_forced" db:"ssl_forced" filter:"ssl_forced,boolean"`

backend/internal/validator/hosts.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"npm/internal/entity/certificate"
77
"npm/internal/entity/host"
88
"npm/internal/entity/nginxtemplate"
9+
"npm/internal/entity/upstream"
910
)
1011

1112
// ValidateHost will check if associated objects exist and other checks
@@ -20,6 +21,21 @@ func ValidateHost(h host.Model) error {
2021
}
2122
}
2223

24+
if h.UpstreamID > 0 {
25+
// Check upstream exists
26+
if _, uErr := upstream.GetByID(h.UpstreamID); uErr != nil {
27+
return fmt.Errorf("Upstream #%d does not exist", h.UpstreamID)
28+
}
29+
}
30+
31+
// Ensure either UpstreamID is set or appropriate proxy host params are set
32+
if h.UpstreamID > 0 && (h.ProxyHost != "" || h.ProxyPort > 0) {
33+
return fmt.Errorf("Proxy Host or Port cannot be set when using an Upstream")
34+
}
35+
if h.UpstreamID == 0 && (h.ProxyHost == "" || h.ProxyPort < 1) {
36+
return fmt.Errorf("Proxy Host and Port must be specified, unless using an Upstream")
37+
}
38+
2339
// Check the nginx template exists and has the same type.
2440
nginxTemplate, tErr := nginxtemplate.GetByID(h.NginxTemplateID)
2541
if tErr != nil {

scripts/ci/fulltest-cypress

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -72,34 +72,3 @@ docker cp -L "$(docker-compose ps -q cypress):/test/results" "$DIR/../../test/"
7272
docker cp -L "$(docker-compose ps -q fullstack):/data/logs" "$DIR/../../test/results/"
7373

7474
echo -e "${BLUE}${GREEN}Fullstack cypress testing complete${RESET}"
75-
76-
# ----------------- Debug Report ----------------------
77-
# echo ip address of every docker container in stack
78-
# echo the hostnames and aliases of them
79-
# dns lookups from main container
80-
echo -e "${BLUE}============================================${RESET}"
81-
82-
FULLSTACK_IP=$(get_container_ip "fullstack")
83-
FULLSTACK_ALIASES=$(get_container_aliases "fullstack")
84-
echo -e "${YELLOW}fullstack IP: ${GREEN}${FULLSTACK_IP}${RESET}"
85-
echo -e "${YELLOW}fullstack Aliases: ${CYAN}${FULLSTACK_ALIASES}${RESET}"
86-
87-
STEPCA_IP=$(get_container_ip "stepca")
88-
STEPCA_ALIASES=$(get_container_aliases "stepca")
89-
echo -e "${YELLOW}stepca IP: ${GREEN}${STEPCA_IP}${RESET}"
90-
echo -e "${YELLOW}stepca Aliases: ${CYAN}${STEPCA_ALIASES}${RESET}"
91-
92-
PDNS_IP=$(get_container_ip "pdns")
93-
STEPCA_ALIASES=$(get_container_aliases "stepca")
94-
echo -e "${YELLOW}pdns IP: ${GREEN}${PDNS_IP}${RESET}"
95-
echo -e "${YELLOW}pdns Aliases: ${CYAN}${PDNS_ALIASES}${RESET}"
96-
97-
PDNSDB_IP=$(get_container_ip "pdns-db")
98-
PDNSDB_ALIASES=$(get_container_aliases "pdns-db")
99-
echo -e "${YELLOW}pdns-db IP: ${GREEN}${PDNSDB_IP}${RESET}"
100-
echo -e "${YELLOW}pdns-db Aliases: ${CYAN}${PDNSDB_ALIASES}${RESET}"
101-
102-
DNSROUTER_IP=$(get_container_ip "dnsrouter")
103-
DNSROUTER_ALIASES=$(get_container_aliases "dnsrouter")
104-
echo -e "${YELLOW}dnsrouter IP: ${GREEN}${DNSROUTER_IP}${RESET}"
105-
echo -e "${YELLOW}dnsrouter Aliases: ${CYAN}${DNSROUTER_ALIASES}${RESET}"

0 commit comments

Comments
 (0)