- Added upstream objects
- Renamed host templates to nginx templates - Generate upstream templates - Better nginx error reporting when reloading - Use tparse for golang test reporting
This commit is contained in:
@ -34,7 +34,7 @@ func create(host *Model) (int, error) {
|
||||
modified_on,
|
||||
user_id,
|
||||
type,
|
||||
host_template_id,
|
||||
nginx_template_id,
|
||||
listen_interface,
|
||||
domain_names,
|
||||
upstream_id,
|
||||
@ -48,7 +48,6 @@ func create(host *Model) (int, error) {
|
||||
hsts_enabled,
|
||||
hsts_subdomains,
|
||||
paths,
|
||||
upstream_options,
|
||||
advanced_config,
|
||||
status,
|
||||
error_message,
|
||||
@ -59,7 +58,7 @@ func create(host *Model) (int, error) {
|
||||
:modified_on,
|
||||
:user_id,
|
||||
:type,
|
||||
:host_template_id,
|
||||
:nginx_template_id,
|
||||
:listen_interface,
|
||||
:domain_names,
|
||||
:upstream_id,
|
||||
@ -73,7 +72,6 @@ func create(host *Model) (int, error) {
|
||||
:hsts_enabled,
|
||||
:hsts_subdomains,
|
||||
:paths,
|
||||
:upstream_options,
|
||||
:advanced_config,
|
||||
:status,
|
||||
:error_message,
|
||||
@ -110,7 +108,7 @@ func update(host *Model) error {
|
||||
modified_on = :modified_on,
|
||||
user_id = :user_id,
|
||||
type = :type,
|
||||
host_template_id = :host_template_id,
|
||||
nginx_template_id = :nginx_template_id,
|
||||
listen_interface = :listen_interface,
|
||||
domain_names = :domain_names,
|
||||
upstream_id = :upstream_id,
|
||||
@ -124,7 +122,6 @@ func update(host *Model) error {
|
||||
hsts_enabled = :hsts_enabled,
|
||||
hsts_subdomains = :hsts_subdomains,
|
||||
paths = :paths,
|
||||
upstream_options = :upstream_options,
|
||||
advanced_config = :advanced_config,
|
||||
status = :status,
|
||||
error_message = :error_message,
|
||||
@ -163,7 +160,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter, expand []string) (Lis
|
||||
}
|
||||
|
||||
// Get rows
|
||||
var items []Model
|
||||
items := make([]Model, 0)
|
||||
query, params = entity.ListQueryBuilder(exampleModel, tableName, &pageInfo, defaultSort, filters, getFilterMapFunctions(), false)
|
||||
err := db.Select(&items, query, params...)
|
||||
if err != nil {
|
||||
|
@ -6,8 +6,10 @@ import (
|
||||
|
||||
"npm/internal/database"
|
||||
"npm/internal/entity/certificate"
|
||||
"npm/internal/entity/hosttemplate"
|
||||
"npm/internal/entity/nginxtemplate"
|
||||
"npm/internal/entity/upstream"
|
||||
"npm/internal/entity/user"
|
||||
"npm/internal/status"
|
||||
"npm/internal/types"
|
||||
"npm/internal/util"
|
||||
)
|
||||
@ -21,12 +23,6 @@ const (
|
||||
RedirectionHostType = "redirection"
|
||||
// DeadHostType is self explanatory
|
||||
DeadHostType = "dead"
|
||||
// StatusReady means a host is ready to configure
|
||||
StatusReady = "ready"
|
||||
// StatusOK means a host is configured within Nginx
|
||||
StatusOK = "ok"
|
||||
// StatusError is self explanatory
|
||||
StatusError = "error"
|
||||
)
|
||||
|
||||
// Model is the user model
|
||||
@ -36,7 +32,7 @@ type Model struct {
|
||||
ModifiedOn types.DBDate `json:"modified_on" db:"modified_on" filter:"modified_on,integer"`
|
||||
UserID int `json:"user_id" db:"user_id" filter:"user_id,integer"`
|
||||
Type string `json:"type" db:"type" filter:"type,string"`
|
||||
HostTemplateID int `json:"host_template_id" db:"host_template_id" filter:"host_template_id,integer"`
|
||||
NginxTemplateID int `json:"nginx_template_id" db:"nginx_template_id" filter:"nginx_template_id,integer"`
|
||||
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"`
|
||||
@ -50,16 +46,16 @@ type Model struct {
|
||||
HSTSEnabled bool `json:"hsts_enabled" db:"hsts_enabled" filter:"hsts_enabled,boolean"`
|
||||
HSTSSubdomains bool `json:"hsts_subdomains" db:"hsts_subdomains" filter:"hsts_subdomains,boolean"`
|
||||
Paths string `json:"paths" db:"paths" filter:"paths,string"`
|
||||
UpstreamOptions string `json:"upstream_options" db:"upstream_options" filter:"upstream_options,string"`
|
||||
AdvancedConfig string `json:"advanced_config" db:"advanced_config" filter:"advanced_config,string"`
|
||||
Status string `json:"status" db:"status" filter:"status,string"`
|
||||
ErrorMessage string `json:"error_message" db:"error_message" filter:"error_message,string"`
|
||||
IsDisabled bool `json:"is_disabled" db:"is_disabled" filter:"is_disabled,boolean"`
|
||||
IsDeleted bool `json:"is_deleted,omitempty" db:"is_deleted"`
|
||||
// Expansions
|
||||
Certificate *certificate.Model `json:"certificate,omitempty"`
|
||||
HostTemplate *hosttemplate.Model `json:"host_template,omitempty"`
|
||||
User *user.Model `json:"user,omitempty"`
|
||||
Certificate *certificate.Model `json:"certificate,omitempty"`
|
||||
NginxTemplate *nginxtemplate.Model `json:"nginx_template,omitempty"`
|
||||
User *user.Model `json:"user,omitempty"`
|
||||
Upstream *upstream.Model `json:"upstream,omitempty"`
|
||||
}
|
||||
|
||||
func (m *Model) getByQuery(query string, params []interface{}) error {
|
||||
@ -93,7 +89,7 @@ func (m *Model) Save(skipConfiguration bool) error {
|
||||
|
||||
if !skipConfiguration {
|
||||
// Set this host as requiring reconfiguration
|
||||
m.Status = StatusReady
|
||||
m.Status = status.StatusReady
|
||||
}
|
||||
|
||||
if m.ID == 0 {
|
||||
@ -119,6 +115,13 @@ func (m *Model) Delete() bool {
|
||||
func (m *Model) Expand(items []string) error {
|
||||
var err error
|
||||
|
||||
// Always expand the upstream
|
||||
if m.UpstreamID > 0 {
|
||||
var u upstream.Model
|
||||
u, err = upstream.GetByID(m.UpstreamID)
|
||||
m.Upstream = &u
|
||||
}
|
||||
|
||||
if util.SliceContainsItem(items, "user") && m.ID > 0 {
|
||||
var usr user.Model
|
||||
usr, err = user.GetByID(m.UserID)
|
||||
@ -131,10 +134,10 @@ func (m *Model) Expand(items []string) error {
|
||||
m.Certificate = &cert
|
||||
}
|
||||
|
||||
if util.SliceContainsItem(items, "hosttemplate") && m.HostTemplateID > 0 {
|
||||
var templ hosttemplate.Model
|
||||
templ, err = hosttemplate.GetByID(m.HostTemplateID)
|
||||
m.HostTemplate = &templ
|
||||
if util.SliceContainsItem(items, "nginxtemplate") && m.NginxTemplateID > 0 {
|
||||
var templ nginxtemplate.Model
|
||||
templ, err = nginxtemplate.GetByID(m.NginxTemplateID)
|
||||
m.NginxTemplate = &templ
|
||||
}
|
||||
|
||||
return err
|
||||
@ -150,7 +153,7 @@ func (m *Model) GetTemplate() Template {
|
||||
ModifiedOn: m.ModifiedOn.Time.String(),
|
||||
UserID: m.UserID,
|
||||
Type: m.Type,
|
||||
HostTemplateID: m.HostTemplateID,
|
||||
NginxTemplateID: m.NginxTemplateID,
|
||||
ListenInterface: m.ListenInterface,
|
||||
DomainNames: domainNames,
|
||||
UpstreamID: m.UpstreamID,
|
||||
@ -164,7 +167,6 @@ func (m *Model) GetTemplate() Template {
|
||||
HSTSEnabled: m.HSTSEnabled,
|
||||
HSTSSubdomains: m.HSTSSubdomains,
|
||||
Paths: m.Paths,
|
||||
UpstreamOptions: m.UpstreamOptions,
|
||||
AdvancedConfig: m.AdvancedConfig,
|
||||
Status: m.Status,
|
||||
ErrorMessage: m.ErrorMessage,
|
||||
|
@ -1,5 +1,14 @@
|
||||
package host
|
||||
|
||||
type TemplateUpstream struct {
|
||||
Hostname string
|
||||
Port int
|
||||
BalanceMethod string
|
||||
MaxFails int
|
||||
FailTimeout int
|
||||
AdvancedConfig string
|
||||
}
|
||||
|
||||
// Template is the model given to the template parser, converted from the Model
|
||||
type Template struct {
|
||||
ID int
|
||||
@ -7,7 +16,7 @@ type Template struct {
|
||||
ModifiedOn string
|
||||
UserID int
|
||||
Type string
|
||||
HostTemplateID int
|
||||
NginxTemplateID int
|
||||
ListenInterface string
|
||||
DomainNames []string
|
||||
UpstreamID int
|
||||
@ -22,8 +31,8 @@ type Template struct {
|
||||
HSTSSubdomains bool
|
||||
IsDisabled bool
|
||||
Paths string
|
||||
UpstreamOptions string
|
||||
AdvancedConfig string
|
||||
Status string
|
||||
ErrorMessage string
|
||||
Upstreams []TemplateUpstream
|
||||
}
|
||||
|
Reference in New Issue
Block a user