Version 3 starter

This commit is contained in:
Jamie Curnow
2021-06-14 19:29:35 +10:00
parent 60fc57431a
commit 6205434140
642 changed files with 25817 additions and 32319 deletions

View File

@@ -0,0 +1,191 @@
package schema
import (
"fmt"
"npm/internal/entity/certificate"
)
// This validation is strictly for Custom certificates
// and the combination of values that must be defined
func createCertificateCustom() string {
return fmt.Sprintf(`
{
"type": "object",
"required": [
"type",
"name",
"domain_names"
],
"properties": {
"type": %s,
"name": %s,
"domain_names": %s,
"meta": {
"type": "object"
}
}
}`, strictString("custom"), stringMinMax(1, 100), domainNames())
}
// This validation is strictly for HTTP certificates
// and the combination of values that must be defined
func createCertificateHTTP() string {
return fmt.Sprintf(`
{
"type": "object",
"required": [
"type",
"certificate_authority_id",
"name",
"domain_names"
],
"properties": {
"type": %s,
"certificate_authority_id": %s,
"name": %s,
"domain_names": %s,
"meta": {
"type": "object"
}
}
}`, strictString("http"), intMinOne, stringMinMax(1, 100), domainNames())
}
// This validation is strictly for DNS certificates
// and the combination of values that must be defined
func createCertificateDNS() string {
return fmt.Sprintf(`
{
"type": "object",
"required": [
"type",
"certificate_authority_id",
"dns_provider_id",
"name",
"domain_names"
],
"properties": {
"type": %s,
"certificate_authority_id": %s,
"dns_provider_id": %s,
"name": %s,
"domain_names": %s,
"meta": {
"type": "object"
}
}
}`, strictString("dns"), intMinOne, intMinOne, stringMinMax(1, 100), domainNames())
}
// This validation is strictly for MKCERT certificates
// and the combination of values that must be defined
func createCertificateMkcert() string {
return fmt.Sprintf(`
{
"type": "object",
"required": [
"type",
"name",
"domain_names"
],
"properties": {
"type": %s,
"name": %s,
"domain_names": %s,
"meta": {
"type": "object"
}
}
}`, strictString("mkcert"), stringMinMax(1, 100), domainNames())
}
func updateCertificateHTTP() string {
return fmt.Sprintf(`
{
"type": "object",
"minProperties": 1,
"properties": {
"certificate_authority_id": %s,
"name": %s,
"domain_names": %s,
"meta": {
"type": "object"
}
}
}`, intMinOne, stringMinMax(1, 100), domainNames())
}
func updateCertificateDNS() string {
return fmt.Sprintf(`
{
"type": "object",
"minProperties": 1,
"properties": {
"certificate_authority_id": %s,
"dns_provider_id": %s,
"name": %s,
"domain_names": %s,
"meta": {
"type": "object"
}
}
}`, intMinOne, intMinOne, stringMinMax(1, 100), domainNames())
}
func updateCertificateCustom() string {
return fmt.Sprintf(`
{
"type": "object",
"minProperties": 1,
"properties": {
"name": %s,
"domain_names": %s,
"meta": {
"type": "object"
}
}
}`, stringMinMax(1, 100), domainNames())
}
func updateCertificateMkcert() string {
return fmt.Sprintf(`
{
"type": "object",
"minProperties": 1,
"properties": {
"name": %s,
"domain_names": %s,
"meta": {
"type": "object"
}
}
}`, stringMinMax(1, 100), domainNames())
}
// CreateCertificate is the schema for incoming data validation
func CreateCertificate() string {
return fmt.Sprintf(`
{
"oneOf": [%s, %s, %s, %s]
}`, createCertificateHTTP(), createCertificateDNS(), createCertificateCustom(), createCertificateMkcert())
}
// UpdateCertificate is the schema for incoming data validation
func UpdateCertificate(certificateType string) string {
switch certificateType {
case certificate.TypeHTTP:
return updateCertificateHTTP()
case certificate.TypeDNS:
return updateCertificateDNS()
case certificate.TypeCustom:
return updateCertificateCustom()
case certificate.TypeMkcert:
return updateCertificateMkcert()
default:
return fmt.Sprintf(`
{
"oneOf": [%s, %s, %s, %s]
}`, updateCertificateHTTP(), updateCertificateDNS(), updateCertificateCustom(), updateCertificateMkcert())
}
}

View File

@@ -0,0 +1,61 @@
package schema
import "fmt"
func strictString(value string) string {
return fmt.Sprintf(`{
"type": "string",
"pattern": "^%s$"
}`, value)
}
const intMinOne = `
{
"type": "integer",
"minimum": 1
}
`
func stringMinMax(minLength, maxLength int) string {
return fmt.Sprintf(`{
"type": "string",
"minLength": %d,
"maxLength": %d
}`, minLength, maxLength)
}
func userRoles() string {
return fmt.Sprintf(`
{
"type": "array",
"items": %s
}`, stringMinMax(2, 50))
}
func domainNames() string {
return fmt.Sprintf(`
{
"type": "array",
"minItems": 1,
"items": %s
}`, stringMinMax(4, 255))
}
const anyType = `
{
"anyOf": [
{
"type": "array"
},
{
"type": "boolean"
},
{
"type": "object"
},
{
"type": "integer"
}
]
}
`

View File

@@ -0,0 +1,21 @@
package schema
import "fmt"
// CreateCertificateAuthority is the schema for incoming data validation
func CreateCertificateAuthority() string {
return fmt.Sprintf(`
{
"type": "object",
"additionalProperties": false,
"required": [
"name",
"acme2_url"
],
"properties": {
"name": %s,
"acme2_url": %s
}
}
`, stringMinMax(1, 100), stringMinMax(8, 255))
}

View File

@@ -0,0 +1,25 @@
package schema
import "fmt"
// CreateDNSProvider is the schema for incoming data validation
func CreateDNSProvider() string {
return fmt.Sprintf(`
{
"type": "object",
"additionalProperties": false,
"required": [
"provider_key",
"name",
"meta"
],
"properties": {
"provider_key": %s,
"name": %s,
"meta": {
"type": "object"
}
}
}
`, stringMinMax(2, 100), stringMinMax(1, 100))
}

View File

@@ -0,0 +1,75 @@
package schema
import "fmt"
// CreateHost is the schema for incoming data validation
// This schema supports 3 possible types with different data combinations:
// - proxy
// - redirection
// - dead
func CreateHost() string {
return fmt.Sprintf(`
{
"oneOf": [
{
"type": "object",
"additionalProperties": false,
"required": [
"type",
"domain_names"
],
"properties": {
"type": {
"type": "string",
"pattern": "^proxy$"
},
"listen_interface": %s,
"domain_names": %s,
"upstream_id": {
"type": "integer"
},
"certificate_id": {
"type": "integer"
},
"access_list_id": {
"type": "integer"
},
"ssl_forced": {
"type": "boolean"
},
"caching_enabled": {
"type": "boolean"
},
"block_exploits": {
"type": "boolean"
},
"allow_websocket_upgrade": {
"type": "boolean"
},
"http2_support": {
"type": "boolean"
},
"hsts_enabled": {
"type": "boolean"
},
"hsts_subdomains": {
"type": "boolean"
},
"paths": {
"type": "string"
},
"upstream_options": {
"type": "string"
},
"advanced_config": {
"type": "string"
},
"is_disabled": {
"type": "boolean"
}
}
}
]
}
`, stringMinMax(0, 255), domainNames())
}

View File

@@ -0,0 +1,21 @@
package schema
import "fmt"
// CreateSetting is the schema for incoming data validation
func CreateSetting() string {
return fmt.Sprintf(`
{
"type": "object",
"additionalProperties": false,
"required": [
"name",
"value"
],
"properties": {
"name": %s,
"value": %s
}
}
`, stringMinMax(2, 100), anyType)
}

View File

@@ -0,0 +1,27 @@
package schema
import "fmt"
// CreateStream is the schema for incoming data validation
func CreateStream() string {
return fmt.Sprintf(`
{
"type": "object",
"additionalProperties": false,
"required": [
"provider",
"name",
"domain_names"
],
"properties": {
"provider": %s,
"name": %s,
"domain_names": %s,
"expires_on": %s,
"meta": {
"type": "object"
}
}
}
`, stringMinMax(2, 100), stringMinMax(1, 100), domainNames(), intMinOne)
}

View File

@@ -0,0 +1,42 @@
package schema
import "fmt"
// CreateUser is the schema for incoming data validation
func CreateUser() string {
return fmt.Sprintf(`
{
"type": "object",
"additionalProperties": false,
"required": [
"name",
"email",
"roles",
"is_disabled"
],
"properties": {
"name": %s,
"nickname": %s,
"email": %s,
"roles": %s,
"is_disabled": {
"type": "boolean"
},
"auth": {
"type": "object",
"required": [
"type",
"secret"
],
"properties": {
"type": {
"type": "string",
"pattern": "^password$"
},
"secret": %s
}
}
}
}
`, stringMinMax(2, 100), stringMinMax(2, 100), stringMinMax(5, 150), userRoles(), stringMinMax(8, 255))
}

View File

@@ -0,0 +1,28 @@
package schema
import "fmt"
// GetToken is the schema for incoming data validation
// nolint: gosec
func GetToken() string {
stdField := stringMinMax(1, 255)
return fmt.Sprintf(`
{
"type": "object",
"additionalProperties": false,
"required": [
"type",
"identity",
"secret"
],
"properties": {
"type": {
"type": "string",
"pattern": "^password$"
},
"identity": %s,
"secret": %s
}
}
`, stdField, stdField)
}

View File

@@ -0,0 +1,21 @@
package schema
import "fmt"
// SetAuth is the schema for incoming data validation
func SetAuth() string {
return fmt.Sprintf(`
{
"type": "object",
"additionalProperties": false,
"required": [
"name",
"value"
],
"properties": {
"name": %s,
"value": %s
}
}
`, stringMinMax(2, 100), anyType)
}

View File

@@ -0,0 +1,17 @@
package schema
import "fmt"
// UpdateCertificateAuthority is the schema for incoming data validation
func UpdateCertificateAuthority() string {
return fmt.Sprintf(`
{
"type": "object",
"additionalProperties": false,
"properties": {
"name": %s,
"acme2_url": %s
}
}
`, stringMinMax(1, 100), stringMinMax(8, 255))
}

View File

@@ -0,0 +1,19 @@
package schema
import "fmt"
// UpdateDNSProvider is the schema for incoming data validation
func UpdateDNSProvider() string {
return fmt.Sprintf(`
{
"type": "object",
"additionalProperties": false,
"properties": {
"name": %s,
"meta": {
"type": "object"
}
}
}
`, stringMinMax(1, 100))
}

View File

@@ -0,0 +1,22 @@
package schema
import "fmt"
// UpdateHost is the schema for incoming data validation
func UpdateHost() string {
return fmt.Sprintf(`
{
"type": "object",
"additionalProperties": false,
"properties": {
"provider": %s,
"name": %s,
"domain_names": %s,
"expires_on": %s,
"meta": {
"type": "object"
}
}
}
`, stringMinMax(2, 100), stringMinMax(1, 100), domainNames(), intMinOne)
}

View File

@@ -0,0 +1,16 @@
package schema
import "fmt"
// UpdateSetting is the schema for incoming data validation
func UpdateSetting() string {
return fmt.Sprintf(`
{
"type": "object",
"additionalProperties": false,
"properties": {
"value": %s
}
}
`, anyType)
}

View File

@@ -0,0 +1,22 @@
package schema
import "fmt"
// UpdateStream is the schema for incoming data validation
func UpdateStream() string {
return fmt.Sprintf(`
{
"type": "object",
"additionalProperties": false,
"properties": {
"provider": %s,
"name": %s,
"domain_names": %s,
"expires_on": %s,
"meta": {
"type": "object"
}
}
}
`, stringMinMax(2, 100), stringMinMax(1, 100), domainNames(), intMinOne)
}

View File

@@ -0,0 +1,22 @@
package schema
import "fmt"
// UpdateUser is the schema for incoming data validation
func UpdateUser() string {
return fmt.Sprintf(`
{
"type": "object",
"additionalProperties": false,
"properties": {
"name": %s,
"nickname": %s,
"email": %s,
"roles": %s,
"is_disabled": {
"type": "boolean"
}
}
}
`, stringMinMax(2, 100), stringMinMax(2, 100), stringMinMax(5, 150), userRoles())
}