Refactor acme.sh dns providers

- updated chakra and typescript
- added locales for dns provider configs
This commit is contained in:
Jamie Curnow 2023-01-12 16:25:43 +10:00
parent 1d5d3ecd7a
commit 5d3bc0fabd
57 changed files with 2204 additions and 2161 deletions

View File

@ -133,8 +133,7 @@ func DeleteDNSProvider() func(http.ResponseWriter, *http.Request) {
// Route: GET /dns-providers/acmesh // Route: GET /dns-providers/acmesh
func GetAcmeshProviders() func(http.ResponseWriter, *http.Request) { func GetAcmeshProviders() func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
items := dnsproviders.List() h.ResultResponseJSON(w, r, http.StatusOK, dnsproviders.List())
h.ResultResponseJSON(w, r, http.StatusOK, items)
} }
} }

View File

@ -5,6 +5,7 @@ import (
"strings" "strings"
"npm/internal/dnsproviders" "npm/internal/dnsproviders"
"npm/internal/logger"
"npm/internal/util" "npm/internal/util"
) )
@ -15,7 +16,12 @@ func CreateDNSProvider() string {
allSchemasWrapped := make([]string, 0) allSchemasWrapped := make([]string, 0)
for providerName, provider := range allProviders { for providerName, provider := range allProviders {
allSchemasWrapped = append(allSchemasWrapped, createDNSProviderType(providerName, provider.Schema)) schema, err := provider.GetJsonSchema()
if err != nil {
logger.Error("ProviderSchemaError", fmt.Errorf("Invalid Provider Schema for %s: %v", provider.Title, err))
} else {
allSchemasWrapped = append(allSchemasWrapped, createDNSProviderType(providerName, schema))
}
} }
return fmt.Sprintf(fmtStr, util.ConvertStringSliceToInterface(allSchemasWrapped)...) return fmt.Sprintf(fmtStr, util.ConvertStringSliceToInterface(allSchemasWrapped)...)

View File

@ -1,36 +1,47 @@
package dnsproviders package dnsproviders
import ( import (
"encoding/json"
"errors" "errors"
"npm/internal/util"
) )
// providerField should mimick jsonschema, so that
// the ui can render a field and validate it
// before we do.
// See: https://json-schema.org/draft/2020-12/json-schema-validation.html
type providerField struct { type providerField struct {
Name string `json:"name"` Title string `json:"title"`
Type string `json:"type"` Type string `json:"type"`
IsRequired bool `json:"is_required"` AdditionalProperties bool `json:"additionalProperties"`
IsSecret bool `json:"is_secret"` Minimum int `json:"minimum,omitempty"`
MetaKey string `json:"meta_key"` Maximum int `json:"maximum,omitempty"`
EnvKey string `json:"-"` // not exposed in api MinLength int `json:"minLength,omitempty"`
MaxLength int `json:"maxLength,omitempty"`
Pattern string `json:"pattern,omitempty"`
IsSecret bool `json:"isSecret"` // Not valid jsonschema
} }
// Provider is a simple struct // Provider is a simple struct
type Provider struct { type Provider struct {
AcmeshName string `json:"acmesh_name"` Title string `json:"title"`
Schema string `json:"-"` Type string `json:"type"` // Should always be "object"
Fields []providerField `json:"fields"` AdditionalProperties bool `json:"additionalProperties"`
MinProperties int `json:"minProperties,omitempty"`
Required []string `json:"required,omitempty"`
Properties map[string]providerField `json:"properties"`
} }
// GetAcmeEnvVars will map the meta given to the env var required for // GetJsonSchema encodes this object as JSON string
// acme.sh to use this dns provider func (p *Provider) GetJsonSchema() (string, error) {
func (p *Provider) GetAcmeEnvVars(meta interface{}) map[string]string { b, err := json.Marshal(p)
res := make(map[string]string) return string(b), err
for _, field := range p.Fields { }
if acmeShEnvValue, found := util.FindItemInInterface(field.MetaKey, meta); found {
res[field.EnvKey] = acmeShEnvValue.(string) // ConvertToUpdatable will manipulate this object so that it returns
} // an updatable json schema
} func (p *Provider) ConvertToUpdatable() {
return res p.MinProperties = 1
p.Required = nil
} }
// List returns an array of providers // List returns an array of providers
@ -89,7 +100,7 @@ func GetAll() map[string]Provider {
mp := make(map[string]Provider) mp := make(map[string]Provider)
items := List() items := List()
for _, item := range items { for _, item := range items {
mp[item.AcmeshName] = item mp[item.Title] = item
} }
return mp return mp
} }
@ -102,51 +113,3 @@ func Get(provider string) (Provider, error) {
} }
return Provider{}, errors.New("provider_not_found") return Provider{}, errors.New("provider_not_found")
} }
// GetAllSchemas returns a flat array with just the schemas
func GetAllSchemas() []string {
items := List()
mp := make([]string, 0)
for _, item := range items {
mp = append(mp, item.Schema)
}
return mp
}
const commonKeySchema = `
{
"type": "object",
"required": [
"api_key"
],
"additionalProperties": false,
"properties": {
"api_key": {
"type": "string",
"minLength": 1
}
}
}
`
// nolint: gosec
const commonKeySecretSchema = `
{
"type": "object",
"required": [
"api_key",
"secret"
],
"additionalProperties": false,
"properties": {
"api_key": {
"type": "string",
"minLength": 1
},
"secret": {
"type": "string",
"minLength": 1
}
}
}
`

View File

@ -1,67 +1,32 @@
package dnsproviders package dnsproviders
const acmeDNSchema = `
{
"type": "object",
"required": [
"api_url",
"user",
"password"
],
"additionalProperties": false,
"properties": {
"api_url": {
"type": "string",
"minLength": 4
},
"subdomain": {
"type": "string",
"minLength": 1
},
"user": {
"type": "string",
"minLength": 1
},
"password": {
"type": "string",
"minLength": 1
}
}
}
`
func getDNSAcmeDNS() Provider { func getDNSAcmeDNS() Provider {
return Provider{ return Provider{
AcmeshName: "dns_acmedns", Title: "dns_acmedns",
Schema: acmeDNSchema, Type: "object",
Fields: []providerField{ AdditionalProperties: false,
{ Required: []string{
Name: "Base URL", "ACMEDNS_BASE_URL",
Type: "text", "ACMEDNS_SUBDOMAIN",
MetaKey: "api_url", "ACMEDNS_USERNAME",
EnvKey: "ACMEDNS_BASE_URL", "ACMEDNS_PASSWORD",
IsRequired: true,
}, },
{ Properties: map[string]providerField{
Name: "Subdomain", "ACMEDNS_BASE_URL": {
Type: "text", Title: "base-url",
MetaKey: "subdomain", Type: "string",
EnvKey: "ACMEDNS_SUBDOMAIN",
IsRequired: true,
}, },
{ "ACMEDNS_SUBDOMAIN": {
Name: "User", Title: "subdomain",
Type: "text", Type: "string",
MetaKey: "user",
EnvKey: "ACMEDNS_USERNAME",
IsRequired: true,
}, },
{ "ACMEDNS_USERNAME": {
Name: "Password", Title: "username",
Type: "password", Type: "string",
MetaKey: "password", },
EnvKey: "ACMEDNS_PASSWORD", "ACMEDNS_PASSWORD": {
IsRequired: true, Title: "password",
Type: "string",
IsSecret: true, IsSecret: true,
}, },
}, },

View File

@ -2,15 +2,17 @@ package dnsproviders
func getDNSAd() Provider { func getDNSAd() Provider {
return Provider{ return Provider{
AcmeshName: "dns_ad", Title: "dns_ad",
Schema: commonKeySchema, Type: "object",
Fields: []providerField{ AdditionalProperties: false,
{ Required: []string{
Name: "API Key", "AD_API_KEY",
Type: "password", },
MetaKey: "api_key", Properties: map[string]providerField{
EnvKey: "AD_API_KEY", "AD_API_KEY": {
IsRequired: true, Title: "api-key",
Type: "string",
MinLength: 1,
}, },
}, },
} }

View File

@ -2,22 +2,23 @@ package dnsproviders
func getDNSAli() Provider { func getDNSAli() Provider {
return Provider{ return Provider{
AcmeshName: "dns_ali", Title: "dns_ali",
Schema: commonKeySecretSchema, Type: "object",
Fields: []providerField{ AdditionalProperties: false,
{ Required: []string{
Name: "Key", "Ali_Key",
Type: "text", "Ali_Secret",
MetaKey: "api_key",
EnvKey: "Ali_Key",
IsRequired: true,
}, },
{ Properties: map[string]providerField{
Name: "Secret", "Ali_Key": {
Type: "password", Title: "api-key",
MetaKey: "secret", Type: "string",
EnvKey: "Ali_Secret", MinLength: 1,
IsRequired: true, },
"Ali_Secret": {
Title: "secret",
Type: "string",
MinLength: 1,
IsSecret: true, IsSecret: true,
}, },
}, },

View File

@ -1,57 +1,31 @@
package dnsproviders package dnsproviders
const autoDNSSchema = `
{
"type": "object",
"required": [
"user",
"password",
"context"
],
"additionalProperties": false,
"properties": {
"user": {
"type": "string",
"minLength": 1
},
"password": {
"type": "string",
"minLength": 1
},
"context": {
"type": "string",
"minLength": 1
}
}
}
`
func getDNSAutoDNS() Provider { func getDNSAutoDNS() Provider {
return Provider{ return Provider{
AcmeshName: "dns_autodns", Title: "dns_autodns",
Schema: autoDNSSchema, Type: "object",
Fields: []providerField{ AdditionalProperties: false,
{ Required: []string{
Name: "User", "AUTODNS_USER",
Type: "text", "AUTODNS_PASSWORD",
MetaKey: "user", "AUTODNS_CONTEXT",
EnvKey: "AUTODNS_USER",
IsRequired: true,
}, },
{ Properties: map[string]providerField{
Name: "Password", "AUTODNS_USER": {
Type: "password", Title: "user",
MetaKey: "password", Type: "string",
EnvKey: "AUTODNS_PASSWORD", MinLength: 1,
IsRequired: true, },
"AUTODNS_PASSWORD": {
Title: "password",
Type: "string",
MinLength: 1,
IsSecret: true, IsSecret: true,
}, },
{ "AUTODNS_CONTEXT": {
Name: "Context", Title: "context",
Type: "text", Type: "string",
MetaKey: "context", MinLength: 1,
EnvKey: "AUTODNS_CONTEXT",
IsRequired: true,
}, },
}, },
} }

View File

@ -1,55 +1,29 @@
package dnsproviders package dnsproviders
const route53Schema = `
{
"type": "object",
"required": [
"access_key_id",
"access_key"
],
"additionalProperties": false,
"properties": {
"access_key_id": {
"type": "string",
"minLength": 10
},
"access_key": {
"type": "string",
"minLength": 10
},
"slow_rate": {
"type": "string",
"minLength": 1
}
}
}
`
func getDNSAws() Provider { func getDNSAws() Provider {
return Provider{ return Provider{
AcmeshName: "dns_aws", Title: "dns_aws",
Schema: route53Schema, Type: "object",
Fields: []providerField{ AdditionalProperties: false,
{ Required: []string{
Name: "Access Key ID", "AWS_ACCESS_KEY_ID",
Type: "text", "AWS_SECRET_ACCESS_KEY",
MetaKey: "access_key_id",
EnvKey: "AWS_ACCESS_KEY_ID",
IsRequired: true,
}, },
{ Properties: map[string]providerField{
Name: "Secret Access Key", "AWS_ACCESS_KEY_ID": {
Type: "password", Title: "access-key-id",
MetaKey: "access_key", Type: "string",
EnvKey: "AWS_SECRET_ACCESS_KEY", MinLength: 10,
IsRequired: true, },
"AWS_SECRET_ACCESS_KEY": {
Title: "secret-access-key",
Type: "string",
MinLength: 10,
IsSecret: true, IsSecret: true,
}, },
{ "AWS_DNS_SLOWRATE": {
Name: "Slow Rate", Title: "slow-rate",
Type: "number", Type: "integer",
MetaKey: "slow_rate",
EnvKey: "AWS_DNS_SLOWRATE",
}, },
}, },
} }

View File

@ -1,68 +1,36 @@
package dnsproviders package dnsproviders
const azureSchema = `
{
"type": "object",
"required": [
"subscription_id",
"tenant_id",
"app_id",
"client_secret"
],
"additionalProperties": false,
"properties": {
"subscription_id": {
"type": "string",
"minLength": 1
},
"tenant_id": {
"type": "string",
"minLength": 1
},
"app_id": {
"type": "string",
"minLength": 1
},
"client_secret": {
"type": "string",
"minLength": 1
}
}
}
`
func getDNSAzure() Provider { func getDNSAzure() Provider {
return Provider{ return Provider{
AcmeshName: "dns_azure", Title: "dns_azure",
Schema: azureSchema, Type: "object",
Fields: []providerField{ AdditionalProperties: false,
{ Required: []string{
Name: "Subscription ID", "AZUREDNS_SUBSCRIPTIONID",
Type: "text", "AZUREDNS_TENANTID",
MetaKey: "subscription_id", "AZUREDNS_APPID",
EnvKey: "AZUREDNS_SUBSCRIPTIONID", "AZUREDNS_CLIENTSECRET",
IsRequired: true,
}, },
{ Properties: map[string]providerField{
Name: "Tenant ID", "AZUREDNS_SUBSCRIPTIONID": {
Type: "text", Title: "subscription-id",
MetaKey: "tenant_id", Type: "string",
EnvKey: "AZUREDNS_TENANTID", MinLength: 1,
IsRequired: true,
}, },
{ "AZUREDNS_TENANTID": {
Name: "APP ID", Title: "tenant-id",
Type: "text", Type: "string",
MetaKey: "app_id", MinLength: 1,
EnvKey: "AZUREDNS_APPID",
IsRequired: true,
}, },
{ "AZUREDNS_APPID": {
Name: "Client Secret", Title: "app-id",
Type: "password", Type: "string",
MetaKey: "client_secret", MinLength: 1,
EnvKey: "AZUREDNS_CLIENTSECRET", },
IsRequired: true, "AZUREDNS_CLIENTSECRET": {
Title: "client-secret",
Type: "string",
MinLength: 1,
IsSecret: true, IsSecret: true,
}, },
}, },

View File

@ -1,79 +1,42 @@
package dnsproviders package dnsproviders
const cloudflareSchema = `
{
"type": "object",
"required": [
"api_key",
"email",
"token",
"account_id"
],
"additionalProperties": false,
"properties": {
"api_key": {
"type": "string",
"minLength": 1
},
"email": {
"type": "string",
"minLength": 5
},
"token": {
"type": "string",
"minLength": 5
},
"account_id": {
"type": "string",
"minLength": 1
},
"zone_id": {
"type": "string",
"minLength": 1
}
}
}
`
func getDNSCf() Provider { func getDNSCf() Provider {
return Provider{ return Provider{
AcmeshName: "dns_cf", Title: "dns_cf",
Schema: cloudflareSchema, Type: "object",
Fields: []providerField{ AdditionalProperties: false,
{ Required: []string{
Name: "API Key", "CF_Key",
Type: "password", "CF_Email",
MetaKey: "api_key", "CF_Token",
EnvKey: "CF_Key", "CF_Account_ID",
IsRequired: true,
}, },
{ Properties: map[string]providerField{
Name: "Email", "CF_Key": {
Type: "text", Title: "api-key",
MetaKey: "email", Type: "string",
EnvKey: "CF_Email", MinLength: 1,
IsRequired: true,
}, },
{ "CF_Email": {
Name: "Token", Title: "email",
Type: "text", Type: "string",
MetaKey: "token", MinLength: 5,
EnvKey: "CF_Token", },
IsRequired: true, "CF_Token": {
Title: "token",
Type: "string",
MinLength: 5,
IsSecret: true, IsSecret: true,
}, },
{ "CF_Account_ID": {
Name: "Account ID", Title: "account-id",
Type: "text",
MetaKey: "account_id",
EnvKey: "CF_Account_ID",
IsRequired: true,
},
{
Name: "Zone ID",
Type: "string", Type: "string",
MetaKey: "zone_id", MinLength: 1,
EnvKey: "CF_Zone_ID", },
"CF_Zone_ID": {
Title: "zone-id",
Type: "string",
MinLength: 1,
}, },
}, },
} }

View File

@ -1,52 +1,30 @@
package dnsproviders package dnsproviders
const clouDNSNetSchema = `
{
"type": "object",
"required": [
"password"
],
"additionalProperties": false,
"properties": {
"auth_id": {
"type": "string",
"minLength": 1
},
"sub_auth_id": {
"type": "string",
"minLength": 1
},
"password": {
"type": "string",
"minLength": 1
}
}
}
`
func getDNSCloudns() Provider { func getDNSCloudns() Provider {
return Provider{ return Provider{
AcmeshName: "dns_cloudns", Title: "dns_cloudns",
Schema: clouDNSNetSchema, Type: "object",
Fields: []providerField{ AdditionalProperties: false,
{ Required: []string{
Name: "Auth ID", "CLOUDNS_AUTH_ID",
Type: "text", "CLOUDNS_SUB_AUTH_ID",
MetaKey: "auth_id", "CLOUDNS_AUTH_PASSWORD",
EnvKey: "CLOUDNS_AUTH_ID",
}, },
{ Properties: map[string]providerField{
Name: "Sub Auth ID", "CLOUDNS_AUTH_ID": {
Type: "text", Title: "auth-id",
MetaKey: "sub_auth_id", Type: "string",
EnvKey: "CLOUDNS_SUB_AUTH_ID", MinLength: 1,
}, },
{ "CLOUDNS_SUB_AUTH_ID": {
Name: "Password", Title: "sub-auth-id",
Type: "password", Type: "string",
MetaKey: "password", MinLength: 1,
EnvKey: "CLOUDNS_AUTH_PASSWORD", },
IsRequired: true, "CLOUDNS_AUTH_PASSWORD": {
Title: "password",
Type: "string",
MinLength: 1,
IsSecret: true, IsSecret: true,
}, },
}, },

View File

@ -1,69 +1,37 @@
package dnsproviders package dnsproviders
const conohaSchema = `
{
"type": "object",
"required": [
"subscription_id",
"tenant_id",
"app_id",
"client_secret"
],
"additionalProperties": false,
"properties": {
"api_url": {
"type": "string",
"minLength": 4
},
"user": {
"type": "string",
"minLength": 1
},
"pass": {
"type": "string",
"minLength": 1
},
"tenant_id": {
"type": "string",
"minLength": 1
}
}
}
`
func getDNSConoha() Provider { func getDNSConoha() Provider {
return Provider{ return Provider{
AcmeshName: "dns_conoha", Title: "dns_conoha",
Schema: conohaSchema, Type: "object",
Fields: []providerField{ AdditionalProperties: false,
{ Required: []string{
Name: "API URL", "CONOHA_IdentityServiceApi",
Type: "text", "CONOHA_Username",
MetaKey: "api_url", "CONOHA_Password",
EnvKey: "CONOHA_IdentityServiceApi", "CONOHA_TenantId",
IsRequired: true,
}, },
{ Properties: map[string]providerField{
Name: "Username", "CONOHA_IdentityServiceApi": {
Type: "text", Title: "api-url",
MetaKey: "user", Type: "string",
EnvKey: "CONOHA_Username", MinLength: 4,
IsRequired: true,
}, },
{ "CONOHA_Username": {
Name: "Password", Title: "username",
Type: "password", Type: "string",
MetaKey: "password", MinLength: 1,
EnvKey: "CONOHA_Password", },
IsRequired: true, "CONOHA_Password": {
Title: "password",
Type: "string",
MinLength: 1,
IsSecret: true, IsSecret: true,
}, },
{ "CONOHA_TenantId": {
Name: "Tenant ID", Title: "tenant-id",
Type: "text", Type: "string",
MetaKey: "tenant_id", MinLength: 1,
EnvKey: "CONOHA_TenantId",
IsRequired: true,
}, },
}, },
} }

View File

@ -2,22 +2,21 @@ package dnsproviders
func getDNSCx() Provider { func getDNSCx() Provider {
return Provider{ return Provider{
AcmeshName: "dns_cx", Title: "dns_cx",
Schema: commonKeySecretSchema, Type: "object",
Fields: []providerField{ AdditionalProperties: false,
{ Required: []string{
Name: "Key", "CX_Key",
Type: "text", "CX_Secret",
MetaKey: "api_key",
EnvKey: "CX_Key",
IsRequired: true,
}, },
{ Properties: map[string]providerField{
Name: "Secret", "CX_Key": {
Type: "password", Title: "key",
MetaKey: "secret", Type: "string",
EnvKey: "CX_Secret", },
IsRequired: true, "CX_Secret": {
Title: "secret",
Type: "string",
IsSecret: true, IsSecret: true,
}, },
}, },

View File

@ -1,55 +1,31 @@
package dnsproviders package dnsproviders
const cyonChSchema = `
{
"type": "object",
"required": [
"user",
"password"
],
"additionalProperties": false,
"properties": {
"user": {
"type": "string",
"minLength": 1
},
"password": {
"type": "string",
"minLength": 1
},
"otp_secret": {
"type": "string",
"minLength": 1
}
}
}
`
func getDNSCyon() Provider { func getDNSCyon() Provider {
return Provider{ return Provider{
AcmeshName: "dns_cyon", Title: "dns_cyon",
Schema: cyonChSchema, Type: "object",
Fields: []providerField{ AdditionalProperties: false,
{ Required: []string{
Name: "User", "CY_Username",
Type: "text", "CY_Password",
MetaKey: "user", "CY_OTP_Secret",
EnvKey: "CY_Username",
IsRequired: true,
}, },
{ Properties: map[string]providerField{
Name: "Password", "CY_Username": {
Type: "password", Title: "user",
MetaKey: "password", Type: "string",
EnvKey: "CY_Password", MinLength: 1,
IsRequired: true, },
"CY_Password": {
Title: "password",
Type: "string",
MinLength: 1,
IsSecret: true, IsSecret: true,
}, },
{ "CY_OTP_Secret": {
Name: "OTP Secret", Title: "otp-secret",
Type: "password", Type: "string",
MetaKey: "otp_secret", MinLength: 1,
EnvKey: "CY_OTP_Secret",
IsSecret: true, IsSecret: true,
}, },
}, },

View File

@ -1,41 +1,22 @@
package dnsproviders package dnsproviders
const daSchema = `
{
"type": "object",
"required": [
"api_url"
],
"additionalProperties": false,
"properties": {
"api_url": {
"type": "string",
"minLength": 4
},
"insecure": {
"type": "boolean"
}
}
}
`
func getDNSDa() Provider { func getDNSDa() Provider {
return Provider{ return Provider{
AcmeshName: "dns_da", Title: "dns_da",
Schema: daSchema, Type: "object",
Fields: []providerField{ AdditionalProperties: false,
{ Required: []string{
Name: "API URL", "DA_Api",
Type: "text",
MetaKey: "api_url",
EnvKey: "DA_Api",
IsRequired: true,
}, },
{ Properties: map[string]providerField{
Name: "Insecure", "DA_Api": {
Type: "bool", Title: "api-url",
MetaKey: "insecure", Type: "string",
EnvKey: "DA_Api_Insecure", MinLength: 4,
},
"DA_Api_Insecure": {
Title: "insecure",
Type: "boolean",
}, },
}, },
} }

View File

@ -2,15 +2,16 @@ package dnsproviders
func getDNSDgon() Provider { func getDNSDgon() Provider {
return Provider{ return Provider{
AcmeshName: "dns_dgon", Title: "dns_dgon",
Schema: commonKeySchema, Type: "object",
Fields: []providerField{ AdditionalProperties: false,
{ Required: []string{
Name: "API Key", "DO_API_KEY",
Type: "password", },
MetaKey: "api_key", Properties: map[string]providerField{
EnvKey: "DO_API_KEY", "DO_API_KEY": {
IsRequired: true, Title: "api-key",
Type: "string",
IsSecret: true, IsSecret: true,
}, },
}, },

View File

@ -2,15 +2,17 @@ package dnsproviders
func getDNSDNSimple() Provider { func getDNSDNSimple() Provider {
return Provider{ return Provider{
AcmeshName: "dns_dnsimple", Title: "dns_dnsimple",
Schema: commonKeySchema, Type: "object",
Fields: []providerField{ AdditionalProperties: false,
{ Required: []string{
Name: "OAuth Token", "DNSimple_OAUTH_TOKEN",
Type: "text", },
MetaKey: "api_key", Properties: map[string]providerField{
EnvKey: "DNSimple_OAUTH_TOKEN", "DNSimple_OAUTH_TOKEN": {
IsRequired: true, Title: "oauth-token",
Type: "string",
MinLength: 1,
IsSecret: true, IsSecret: true,
}, },
}, },

View File

@ -1,44 +1,24 @@
package dnsproviders package dnsproviders
const dnsPodCnSchema = `
{
"type": "object",
"required": [
"id",
"api_key"
],
"additionalProperties": false,
"properties": {
"id": {
"type": "string",
"minLength": 1
},
"api_key": {
"type": "string",
"minLength": 1
}
}
}
`
func getDNSDp() Provider { func getDNSDp() Provider {
return Provider{ return Provider{
AcmeshName: "dns_dp", Title: "dns_dp",
Schema: dnsPodCnSchema, Type: "object",
Fields: []providerField{ AdditionalProperties: false,
{ Required: []string{
Name: "ID", "DP_Id",
Type: "text", "DP_Key",
MetaKey: "id",
EnvKey: "DP_Id",
IsRequired: true,
}, },
{ Properties: map[string]providerField{
Name: "Key", "DP_Id": {
Type: "password", Title: "id",
MetaKey: "api_key", Type: "string",
EnvKey: "DP_Key", MinLength: 1,
IsRequired: true, },
"DP_Key": {
Title: "key",
Type: "string",
MinLength: 1,
IsSecret: true, IsSecret: true,
}, },
}, },

View File

@ -1,44 +1,24 @@
package dnsproviders package dnsproviders
const dnsPodComSchema = `
{
"type": "object",
"required": [
"id",
"api_key"
],
"additionalProperties": false,
"properties": {
"id": {
"type": "string",
"minLength": 1
},
"api_key": {
"type": "string",
"minLength": 1
}
}
}
`
func getDNSDpi() Provider { func getDNSDpi() Provider {
return Provider{ return Provider{
AcmeshName: "dns_dpi", Title: "dns_dpi",
Schema: dnsPodComSchema, Type: "object",
Fields: []providerField{ AdditionalProperties: false,
{ Required: []string{
Name: "ID", "DPI_Id",
Type: "text", "DPI_Key",
MetaKey: "id",
EnvKey: "DPI_Id",
IsRequired: true,
}, },
{ Properties: map[string]providerField{
Name: "Key", "DPI_Id": {
Type: "password", Title: "id",
MetaKey: "api_key", Type: "string",
EnvKey: "DPI_Key", MinLength: 1,
IsRequired: true, },
"DPI_Key": {
Title: "key",
Type: "string",
MinLength: 1,
IsSecret: true, IsSecret: true,
}, },
}, },

View File

@ -2,15 +2,17 @@ package dnsproviders
func getDNSDreamhost() Provider { func getDNSDreamhost() Provider {
return Provider{ return Provider{
AcmeshName: "dns_dreamhost", Title: "dns_dreamhost",
Schema: commonKeySchema, Type: "object",
Fields: []providerField{ AdditionalProperties: false,
{ Required: []string{
Name: "API Key", "DH_API_KEY",
Type: "password", },
MetaKey: "api_key", Properties: map[string]providerField{
EnvKey: "DH_API_KEY", "DH_API_KEY": {
IsRequired: true, Title: "api-key",
Type: "string",
MinLength: 1,
IsSecret: true, IsSecret: true,
}, },
}, },

View File

@ -2,15 +2,17 @@ package dnsproviders
func getDNSDuckDNS() Provider { func getDNSDuckDNS() Provider {
return Provider{ return Provider{
AcmeshName: "dns_duckdns", Title: "dns_duckdns",
Schema: commonKeySchema, Type: "object",
Fields: []providerField{ AdditionalProperties: false,
{ Required: []string{
Name: "Token", "DuckDNS_Token",
Type: "password", },
MetaKey: "api_key", Properties: map[string]providerField{
EnvKey: "DuckDNS_Token", "DuckDNS_Token": {
IsRequired: true, Title: "token",
Type: "string",
MinLength: 1,
IsSecret: true, IsSecret: true,
}, },
}, },

View File

@ -1,56 +1,30 @@
package dnsproviders package dnsproviders
const dynSchema = `
{
"type": "object",
"required": [
"customer",
"username",
"password"
],
"additionalProperties": false,
"properties": {
"customer": {
"type": "string",
"minLength": 1
},
"username": {
"type": "string",
"minLength": 1
},
"password": {
"type": "string",
"minLength": 1
}
}
}
`
func getDNSDyn() Provider { func getDNSDyn() Provider {
return Provider{ return Provider{
AcmeshName: "dns_dyn", Title: "dns_dyn",
Schema: dynSchema, Type: "object",
Fields: []providerField{ AdditionalProperties: false,
{ Required: []string{
Name: "Customer", "DYN_Customer",
Type: "text", "DYN_Username",
MetaKey: "customer", "DYN_Password",
EnvKey: "DYN_Customer",
IsRequired: true,
}, },
{ Properties: map[string]providerField{
Name: "Username", "DYN_Customer": {
Type: "text", Title: "customer",
MetaKey: "username", Type: "string",
EnvKey: "DYN_Username", MinLength: 1,
IsRequired: true,
}, },
{ "DYN_Username": {
Name: "Password", Title: "username",
Type: "password", Type: "string",
MetaKey: "password", MinLength: 1,
EnvKey: "DYN_Password", },
IsRequired: true, "DYN_Password": {
Title: "password",
Type: "string",
MinLength: 1,
IsSecret: true, IsSecret: true,
}, },
}, },

View File

@ -2,22 +2,22 @@ package dnsproviders
func getDNSDynu() Provider { func getDNSDynu() Provider {
return Provider{ return Provider{
AcmeshName: "dns_dynu", Title: "dns_dynu",
Schema: commonKeySecretSchema, Type: "object",
Fields: []providerField{ AdditionalProperties: false,
{ Required: []string{
Name: "Client ID", "Dynu_ClientId",
Type: "text",
MetaKey: "api_key",
EnvKey: "Dynu_ClientId",
IsRequired: true,
}, },
{ Properties: map[string]providerField{
Name: "Secret", "Dynu_ClientId": {
Type: "password", Title: "client-id",
MetaKey: "secret", Type: "string",
EnvKey: "Dynu_Secret", MinLength: 1,
IsRequired: true, },
"Dynu_Secret": {
Title: "secret",
Type: "string",
MinLength: 1,
IsSecret: true, IsSecret: true,
}, },
}, },

View File

@ -1,48 +1,24 @@
package dnsproviders package dnsproviders
const euservSchema = `
{
"type": "object",
"required": [
"user",
"password"
],
"additionalProperties": false,
"properties": {
"user": {
"type": "string",
"minLength": 1
},
"password": {
"type": "string",
"minLength": 1
},
"otp_secret": {
"type": "string",
"minLength": 1
}
}
}
`
func getDNSEuserv() Provider { func getDNSEuserv() Provider {
return Provider{ return Provider{
AcmeshName: "dns_euserv", Title: "dns_euserv",
Schema: euservSchema, Type: "object",
Fields: []providerField{ AdditionalProperties: false,
{ Required: []string{
Name: "User", "EUSERV_Username",
Type: "text", "EUSERV_Password",
MetaKey: "user",
EnvKey: "EUSERV_Username",
IsRequired: true,
}, },
{ Properties: map[string]providerField{
Name: "Password", "EUSERV_Username": {
Type: "password", Title: "user",
MetaKey: "password", Type: "string",
EnvKey: "EUSERV_Password", MinLength: 1,
IsRequired: true, },
"EUSERV_Password": {
Title: "password",
Type: "string",
MinLength: 1,
IsSecret: true, IsSecret: true,
}, },
}, },

View File

@ -1,44 +1,24 @@
package dnsproviders package dnsproviders
const freeDNSSchema = `
{
"type": "object",
"required": [
"user",
"password"
],
"additionalProperties": false,
"properties": {
"user": {
"type": "string",
"minLength": 1
},
"password": {
"type": "string",
"minLength": 1
}
}
}
`
func getDNSFreeDNS() Provider { func getDNSFreeDNS() Provider {
return Provider{ return Provider{
AcmeshName: "dns_freedns", Title: "dns_freedns",
Schema: freeDNSSchema, Type: "object",
Fields: []providerField{ AdditionalProperties: false,
{ Required: []string{
Name: "User", "FREEDNS_User",
Type: "text", "FREEDNS_Password",
MetaKey: "user",
EnvKey: "FREEDNS_User",
IsRequired: true,
}, },
{ Properties: map[string]providerField{
Name: "Password", "FREEDNS_User": {
Type: "password", Title: "user",
MetaKey: "password", Type: "string",
EnvKey: "FREEDNS_Password", MinLength: 1,
IsRequired: true, },
"FREEDNS_Password": {
Title: "password",
Type: "string",
MinLength: 1,
IsSecret: true, IsSecret: true,
}, },
}, },

View File

@ -2,15 +2,17 @@ package dnsproviders
func getDNSGandiLiveDNS() Provider { func getDNSGandiLiveDNS() Provider {
return Provider{ return Provider{
AcmeshName: "dns_gandi_livedns", Title: "dns_gandi_livedns",
Schema: commonKeySchema, Type: "object",
Fields: []providerField{ AdditionalProperties: false,
{ Required: []string{
Name: "Key", "GANDI_LIVEDNS_KEY",
Type: "password", },
MetaKey: "api_key", Properties: map[string]providerField{
EnvKey: "GANDI_LIVEDNS_KEY", "GANDI_LIVEDNS_KEY": {
IsRequired: true, Title: "key",
Type: "string",
MinLength: 1,
}, },
}, },
} }

View File

@ -2,22 +2,23 @@ package dnsproviders
func getDNSGd() Provider { func getDNSGd() Provider {
return Provider{ return Provider{
AcmeshName: "dns_gd", Title: "dns_gd",
Schema: commonKeySecretSchema, Type: "object",
Fields: []providerField{ AdditionalProperties: false,
{ Required: []string{
Name: "Key", "GD_Key",
Type: "text", "GD_Secret",
MetaKey: "api_key",
EnvKey: "GD_Key",
IsRequired: true,
}, },
{ Properties: map[string]providerField{
Name: "Secret", "GD_Key": {
Type: "password", Title: "key",
MetaKey: "secret", Type: "string",
EnvKey: "GD_Secret", MinLength: 1,
IsRequired: true, },
"GD_Secret": {
Title: "secret",
Type: "string",
MinLength: 1,
IsSecret: true, IsSecret: true,
}, },
}, },

View File

@ -1,45 +1,24 @@
package dnsproviders package dnsproviders
// nolint: gosec
const commonUserPassSchema = `
{
"type": "object",
"required": [
"username",
"password"
],
"additionalProperties": false,
"properties": {
"username": {
"type": "string",
"minLength": 1
},
"password": {
"type": "string",
"minLength": 1
}
}
}
`
func getDNSHe() Provider { func getDNSHe() Provider {
return Provider{ return Provider{
AcmeshName: "dns_he", Title: "dns_he",
Schema: commonUserPassSchema, Type: "object",
Fields: []providerField{ AdditionalProperties: false,
{ Required: []string{
Name: "Username", "HE_Username",
Type: "text", "HE_Password",
MetaKey: "username",
EnvKey: "HE_Username",
IsRequired: true,
}, },
{ Properties: map[string]providerField{
Name: "Password", "HE_Username": {
Type: "password", Title: "username",
MetaKey: "password", Type: "string",
EnvKey: "HE_Password", MinLength: 1,
IsRequired: true, },
"HE_Password": {
Title: "password",
Type: "string",
MinLength: 1,
IsSecret: true, IsSecret: true,
}, },
}, },

View File

@ -1,45 +1,25 @@
package dnsproviders package dnsproviders
const infobloxSchema = `
{
"type": "object",
"required": [
"credentials",
"server"
],
"additionalProperties": false,
"properties": {
"credentials": {
"type": "string",
"minLength": 1
},
"server": {
"type": "string",
"minLength": 1
}
}
}
`
func getDNSInfoblox() Provider { func getDNSInfoblox() Provider {
return Provider{ return Provider{
AcmeshName: "dns_infoblox", Title: "dns_infoblox",
Schema: infobloxSchema, Type: "object",
Fields: []providerField{ AdditionalProperties: false,
{ Required: []string{
Name: "Credentials", "Infoblox_Creds",
Type: "text", "Infoblox_Server",
MetaKey: "credentials", },
EnvKey: "Infoblox_Creds", Properties: map[string]providerField{
IsRequired: true, "Infoblox_Creds": {
Title: "credentials",
Type: "string",
MinLength: 1,
IsSecret: true, IsSecret: true,
}, },
{ "Infoblox_Server": {
Name: "Server", Title: "server",
Type: "text", Type: "string",
MetaKey: "server", MinLength: 1,
EnvKey: "Infoblox_Server",
IsRequired: true,
}, },
}, },
} }

View File

@ -1,44 +1,24 @@
package dnsproviders package dnsproviders
const inwxSchema = `
{
"type": "object",
"required": [
"user",
"password"
],
"additionalProperties": false,
"properties": {
"user": {
"type": "string",
"minLength": 1
},
"password": {
"type": "string",
"minLength": 1
}
}
}
`
func getDNSInwx() Provider { func getDNSInwx() Provider {
return Provider{ return Provider{
AcmeshName: "dns_inwx", Title: "dns_inwx",
Schema: inwxSchema, Type: "object",
Fields: []providerField{ AdditionalProperties: false,
{ Required: []string{
Name: "User", "INWX_User",
Type: "text", "INWX_Password",
MetaKey: "user",
EnvKey: "INWX_User",
IsRequired: true,
}, },
{ Properties: map[string]providerField{
Name: "Password", "INWX_User": {
Type: "password", Title: "user",
MetaKey: "password", Type: "string",
EnvKey: "INWX_Password", MinLength: 1,
IsRequired: true, },
"INWX_Password": {
Title: "password",
Type: "string",
MinLength: 1,
IsSecret: true, IsSecret: true,
}, },
}, },

View File

@ -1,66 +1,35 @@
package dnsproviders package dnsproviders
const ispConfigSchema = `
{
"type": "object",
"required": [
"user",
"password",
"api_url"
],
"additionalProperties": false,
"properties": {
"user": {
"type": "string",
"minLength": 1
},
"password": {
"type": "string",
"minLength": 1
},
"api_url": {
"type": "string",
"minLength": 1
},
"insecure": {
"type": "string"
}
}
}
`
func getDNSIspconfig() Provider { func getDNSIspconfig() Provider {
return Provider{ return Provider{
AcmeshName: "dns_ispconfig", Title: "dns_ispconfig",
Schema: ispConfigSchema, Type: "object",
Fields: []providerField{ AdditionalProperties: false,
{ Required: []string{
Name: "User", "ISPC_User",
Type: "text", "ISPC_Password",
MetaKey: "user", "ISPC_Api",
EnvKey: "ISPC_User",
IsRequired: true,
}, },
{ Properties: map[string]providerField{
Name: "Password", "ISPC_User": {
Type: "password", Title: "user",
MetaKey: "password", Type: "string",
EnvKey: "ISPC_Password", MinLength: 1,
IsRequired: true, },
"ISPC_Password": {
Title: "password",
Type: "string",
MinLength: 1,
IsSecret: true, IsSecret: true,
}, },
{ "ISPC_Api": {
Name: "API URL", Title: "api-url",
Type: "text", Type: "string",
MetaKey: "api_url", MinLength: 1,
EnvKey: "ISPC_Api",
IsRequired: true,
}, },
{ "ISPC_Api_Insecure": {
Name: "Insecure", Title: "insecure",
Type: "bool", Type: "boolean",
MetaKey: "insecure",
EnvKey: "ISPC_Api_Insecure",
}, },
}, },
} }

View File

@ -1,44 +1,24 @@
package dnsproviders package dnsproviders
const kinghostSchema = `
{
"type": "object",
"required": [
"user",
"password"
],
"additionalProperties": false,
"properties": {
"user": {
"type": "string",
"minLength": 1
},
"password": {
"type": "string",
"minLength": 1
}
}
}
`
func getDNSKinghost() Provider { func getDNSKinghost() Provider {
return Provider{ return Provider{
AcmeshName: "dns_kinghost", Title: "dns_kinghost",
Schema: kinghostSchema, Type: "object",
Fields: []providerField{ AdditionalProperties: false,
{ Required: []string{
Name: "User", "KINGHOST_Username",
Type: "text", "KINGHOST_Password",
MetaKey: "user",
EnvKey: "KINGHOST_Username",
IsRequired: true,
}, },
{ Properties: map[string]providerField{
Name: "Password", "KINGHOST_Username": {
Type: "password", Title: "user",
MetaKey: "password", Type: "string",
EnvKey: "KINGHOST_Password", MinLength: 1,
IsRequired: true, },
"KINGHOST_Password": {
Title: "password",
Type: "string",
MinLength: 1,
IsSecret: true, IsSecret: true,
}, },
}, },

View File

@ -4,15 +4,17 @@ package dnsproviders
// needs 15 minute sleep, not currently implemented // needs 15 minute sleep, not currently implemented
func getDNSLinodeV4() Provider { func getDNSLinodeV4() Provider {
return Provider{ return Provider{
AcmeshName: "dns_linode_v4", Title: "dns_linode_v4",
Schema: commonKeySchema, Type: "object",
Fields: []providerField{ AdditionalProperties: false,
{ Required: []string{
Name: "API Key", "LINODE_V4_API_KEY",
Type: "text", },
MetaKey: "api_key", Properties: map[string]providerField{
EnvKey: "LINODE_V4_API_KEY", "LINODE_V4_API_KEY": {
IsRequired: true, Title: "api-key",
Type: "string",
MinLength: 1,
IsSecret: true, IsSecret: true,
}, },
}, },

View File

@ -1,56 +1,30 @@
package dnsproviders package dnsproviders
const loopiaSchema = `
{
"type": "object",
"required": [
"api_url",
"user",
"password"
],
"additionalProperties": false,
"properties": {
"api_url": {
"type": "string",
"minLength": 4
},
"user": {
"type": "string",
"minLength": 1
},
"password": {
"type": "string",
"minLength": 1
}
}
}
`
func getDNSLoopia() Provider { func getDNSLoopia() Provider {
return Provider{ return Provider{
AcmeshName: "dns_loopia", Title: "dns_loopia",
Schema: loopiaSchema, Type: "object",
Fields: []providerField{ AdditionalProperties: false,
{ Required: []string{
Name: "API URL", "LOOPIA_Api",
Type: "text", "LOOPIA_User",
MetaKey: "api_url", "LOOPIA_Password",
EnvKey: "LOOPIA_Api",
IsRequired: true,
}, },
{ Properties: map[string]providerField{
Name: "User", "LOOPIA_Api": {
Type: "text", Title: "api-url",
MetaKey: "user", Type: "string",
EnvKey: "LOOPIA_User", MinLength: 4,
IsRequired: true,
}, },
{ "LOOPIA_User": {
Name: "Password", Title: "user",
Type: "password", Type: "string",
MetaKey: "password", MinLength: 1,
EnvKey: "LOOPIA_Password", },
IsRequired: true, "LOOPIA_Password": {
Title: "password",
Type: "string",
MinLength: 1,
IsSecret: true, IsSecret: true,
}, },
}, },

View File

@ -1,45 +1,25 @@
package dnsproviders package dnsproviders
const luaDNSSchema = `
{
"type": "object",
"required": [
"api_key",
"email"
],
"additionalProperties": false,
"properties": {
"api_key": {
"type": "string",
"minLength": 1
},
"email": {
"type": "string",
"minLength": 5
}
}
}
`
func getDNSLua() Provider { func getDNSLua() Provider {
return Provider{ return Provider{
AcmeshName: "dns_lua", Title: "dns_lua",
Schema: luaDNSSchema, Type: "object",
Fields: []providerField{ AdditionalProperties: false,
{ Required: []string{
Name: "Key", "LUA_Key",
Type: "text", "LUA_Email",
MetaKey: "api_key", },
EnvKey: "LUA_Key", Properties: map[string]providerField{
IsRequired: true, "LUA_Key": {
Title: "key",
Type: "string",
MinLength: 1,
IsSecret: true, IsSecret: true,
}, },
{ "LUA_Email": {
Name: "Email", Title: "email",
Type: "text", Type: "string",
MetaKey: "email", MinLength: 5,
EnvKey: "LUA_Email",
IsRequired: true,
}, },
}, },
} }

View File

@ -2,22 +2,23 @@ package dnsproviders
func getDNSMe() Provider { func getDNSMe() Provider {
return Provider{ return Provider{
AcmeshName: "dns_me", Title: "dns_me",
Schema: commonKeySecretSchema, Type: "object",
Fields: []providerField{ AdditionalProperties: false,
{ Required: []string{
Name: "Key", "ME_Key",
Type: "text", "ME_Secret",
MetaKey: "api_key",
EnvKey: "ME_Key",
IsRequired: true,
}, },
{ Properties: map[string]providerField{
Name: "Secret", "ME_Key": {
Type: "password", Title: "key",
MetaKey: "secret", Type: "string",
EnvKey: "ME_Secret", MinLength: 1,
IsRequired: true, },
"ME_Secret": {
Title: "secret",
Type: "string",
MinLength: 1,
IsSecret: true, IsSecret: true,
}, },
}, },

View File

@ -1,44 +1,24 @@
package dnsproviders package dnsproviders
const nameComSchema = `
{
"type": "object",
"required": [
"username",
"token"
],
"additionalProperties": false,
"properties": {
"username": {
"type": "string",
"minLength": 1
},
"token": {
"type": "string",
"minLength": 1
}
}
}
`
func getDNSNamecom() Provider { func getDNSNamecom() Provider {
return Provider{ return Provider{
AcmeshName: "dns_namecom", Title: "dns_namecom",
Schema: nameComSchema, Type: "object",
Fields: []providerField{ AdditionalProperties: false,
{ Required: []string{
Name: "Username", "Namecom_Username",
Type: "text", "Namecom_Token",
MetaKey: "username",
EnvKey: "Namecom_Username",
IsRequired: true,
}, },
{ Properties: map[string]providerField{
Name: "Token", "Namecom_Username": {
Type: "text", Title: "username",
MetaKey: "token", Type: "string",
EnvKey: "Namecom_Token", MinLength: 1,
IsRequired: true, },
"Namecom_Token": {
Title: "token",
Type: "string",
MinLength: 1,
IsSecret: true, IsSecret: true,
}, },
}, },

View File

@ -2,15 +2,16 @@ package dnsproviders
func getDNSNamesilo() Provider { func getDNSNamesilo() Provider {
return Provider{ return Provider{
AcmeshName: "dns_namesilo", Title: "dns_namesilo",
Schema: commonKeySchema, AdditionalProperties: false,
Fields: []providerField{ Required: []string{
{ "Namesilo_Key",
Name: "API Key", },
Type: "password", Properties: map[string]providerField{
MetaKey: "api_key", "Namesilo_Key": {
EnvKey: "Namesilo_Key", Title: "api-key",
IsRequired: true, Type: "string",
MinLength: 1,
IsSecret: true, IsSecret: true,
}, },
}, },

View File

@ -2,15 +2,16 @@ package dnsproviders
func getDNSOne() Provider { func getDNSOne() Provider {
return Provider{ return Provider{
AcmeshName: "dns_nsone", Title: "dns_nsone",
Schema: commonKeySchema, AdditionalProperties: false,
Fields: []providerField{ Required: []string{
{ "NS1_Key",
Name: "Key", },
Type: "password", Properties: map[string]providerField{
MetaKey: "api_key", "NS1_Key": {
EnvKey: "NS1_Key", Title: "key",
IsRequired: true, Type: "string",
MinLength: 1,
IsSecret: true, IsSecret: true,
}, },
}, },

View File

@ -1,68 +1,35 @@
package dnsproviders package dnsproviders
const powerDNSSchema = `
{
"type": "object",
"required": [
"url",
"server_id",
"token",
"ttl"
],
"additionalProperties": false,
"properties": {
"url": {
"type": "string",
"minLength": 1
},
"server_id": {
"type": "string",
"minLength": 1
},
"token": {
"type": "string",
"minLength": 1
},
"ttl": {
"type": "string",
"minLength": 1
}
}
}
`
func getDNSPDNS() Provider { func getDNSPDNS() Provider {
return Provider{ return Provider{
AcmeshName: "dns_pdns", Title: "dns_pdns",
Schema: powerDNSSchema, AdditionalProperties: false,
Fields: []providerField{ Required: []string{
{ "PDNS_Url",
Name: "URL", "PDNS_ServerId",
Type: "text", "PDNS_Token",
MetaKey: "url", "PDNS_Ttl",
EnvKey: "PDNS_Url",
IsRequired: true,
}, },
{ Properties: map[string]providerField{
Name: "Server ID", "PDNS_Url": {
Type: "text", Title: "url",
MetaKey: "server_id", Type: "string",
EnvKey: "PDNS_ServerId", MinLength: 1,
IsRequired: true,
}, },
{ "PDNS_ServerId": {
Name: "Token", Title: "server-id",
Type: "text", Type: "string",
MetaKey: "token", MinLength: 1,
EnvKey: "PDNS_Token",
IsRequired: true,
}, },
{ "PDNS_Token": {
Name: "TTL", Title: "token",
Type: "number", Type: "string",
MetaKey: "ttl", MinLength: 1,
EnvKey: "PDNS_Ttl", },
IsRequired: true, "PDNS_Ttl": {
Title: "ttl",
Type: "integer",
Minimum: 1,
}, },
}, },
} }

View File

@ -2,15 +2,16 @@ package dnsproviders
func getDNSSelectel() Provider { func getDNSSelectel() Provider {
return Provider{ return Provider{
AcmeshName: "dns_selectel", Title: "dns_selectel",
Schema: commonKeySchema, AdditionalProperties: false,
Fields: []providerField{ Required: []string{
{ "SL_Key",
Name: "API Key", },
Type: "password", Properties: map[string]providerField{
MetaKey: "api_key", "SL_Key": {
EnvKey: "SL_Key", Title: "api-key",
IsRequired: true, Type: "string",
MinLength: 1,
IsSecret: true, IsSecret: true,
}, },
}, },

View File

@ -1,44 +1,23 @@
package dnsproviders package dnsproviders
const servercowSchema = `
{
"type": "object",
"required": [
"user",
"password"
],
"additionalProperties": false,
"properties": {
"user": {
"type": "string",
"minLength": 1
},
"password": {
"type": "string",
"minLength": 1
}
}
}
`
func getDNSServercow() Provider { func getDNSServercow() Provider {
return Provider{ return Provider{
AcmeshName: "dns_servercow", Title: "dns_servercow",
Schema: servercowSchema, AdditionalProperties: false,
Fields: []providerField{ Required: []string{
{ "SERVERCOW_API_Username",
Name: "User", "SERVERCOW_API_Password",
Type: "text",
MetaKey: "user",
EnvKey: "SERVERCOW_API_Username",
IsRequired: true,
}, },
{ Properties: map[string]providerField{
Name: "Password", "SERVERCOW_API_Username": {
Type: "password", Title: "user",
MetaKey: "password", Type: "string",
EnvKey: "SERVERCOW_API_Password", MinLength: 1,
IsRequired: true, },
"SERVERCOW_API_Password": {
Title: "password",
Type: "string",
MinLength: 1,
IsSecret: true, IsSecret: true,
}, },
}, },

View File

@ -2,22 +2,22 @@ package dnsproviders
func getDNSTele3() Provider { func getDNSTele3() Provider {
return Provider{ return Provider{
AcmeshName: "dns_tele3", Title: "dns_tele3",
Schema: commonKeySecretSchema, AdditionalProperties: false,
Fields: []providerField{ Required: []string{
{ "TELE3_Key",
Name: "Key", "TELE3_Secret",
Type: "text",
MetaKey: "api_key",
EnvKey: "TELE3_Key",
IsRequired: true,
}, },
{ Properties: map[string]providerField{
Name: "Secret", "TELE3_Key": {
Type: "password", Title: "key",
MetaKey: "secret", Type: "string",
EnvKey: "TELE3_Secret", MinLength: 1,
IsRequired: true, },
"TELE3_Secret": {
Title: "secret",
Type: "string",
MinLength: 1,
IsSecret: true, IsSecret: true,
}, },
}, },

View File

@ -1,45 +1,24 @@
package dnsproviders package dnsproviders
const unoEuroSchema = `
{
"type": "object",
"required": [
"api_key",
"user"
],
"additionalProperties": false,
"properties": {
"api_key": {
"type": "string",
"minLength": 1
},
"user": {
"type": "string",
"minLength": 1
}
}
}
`
func getDNSUnoeuro() Provider { func getDNSUnoeuro() Provider {
return Provider{ return Provider{
AcmeshName: "dns_unoeuro", Title: "dns_unoeuro",
Schema: unoEuroSchema, AdditionalProperties: false,
Fields: []providerField{ Required: []string{
{ "UNO_Key",
Name: "Key", "UNO_User",
Type: "password", },
MetaKey: "api_key", Properties: map[string]providerField{
EnvKey: "UNO_Key", "UNO_Key": {
IsRequired: true, Title: "key",
Type: "string",
MinLength: 1,
IsSecret: true, IsSecret: true,
}, },
{ "UNO_User": {
Name: "User", Title: "user",
Type: "text", Type: "string",
MetaKey: "user", MinLength: 1,
EnvKey: "UNO_User",
IsRequired: true,
IsSecret: true, IsSecret: true,
}, },
}, },

View File

@ -2,15 +2,16 @@ package dnsproviders
func getDNSVscale() Provider { func getDNSVscale() Provider {
return Provider{ return Provider{
AcmeshName: "dns_vscale", Title: "dns_vscale",
Schema: commonKeySchema, AdditionalProperties: false,
Fields: []providerField{ Required: []string{
{ "VSCALE_API_KEY",
Name: "API Key", },
Type: "password", Properties: map[string]providerField{
MetaKey: "api_key", "VSCALE_API_KEY": {
EnvKey: "VSCALE_API_KEY", Title: "api-key",
IsRequired: true, Type: "string",
MinLength: 1,
}, },
}, },
} }

View File

@ -2,15 +2,16 @@ package dnsproviders
func getDNSYandex() Provider { func getDNSYandex() Provider {
return Provider{ return Provider{
AcmeshName: "dns_yandex", Title: "dns_yandex",
Schema: commonKeySchema, AdditionalProperties: false,
Fields: []providerField{ Required: []string{
{ "PDD_Token",
Name: "Token", },
Type: "password", Properties: map[string]providerField{
MetaKey: "api_key", "PDD_Token": {
EnvKey: "PDD_Token", Title: "token",
IsRequired: true, Type: "string",
MinLength: 1,
IsSecret: true, IsSecret: true,
}, },
}, },

View File

@ -2,15 +2,16 @@ package dnsproviders
func getDNSDNZilore() Provider { func getDNSDNZilore() Provider {
return Provider{ return Provider{
AcmeshName: "dns_zilore", Title: "dns_zilore",
Schema: commonKeySchema, AdditionalProperties: false,
Fields: []providerField{ Required: []string{
{ "Zilore_Key",
Name: "API Key", },
Type: "text", Properties: map[string]providerField{
MetaKey: "api_key", "Zilore_Key": {
EnvKey: "Zilore_Key", Title: "api-key",
IsRequired: true, Type: "string",
MinLength: 1,
IsSecret: true, IsSecret: true,
}, },
}, },

View File

@ -2,15 +2,16 @@ package dnsproviders
func getDNSZonomi() Provider { func getDNSZonomi() Provider {
return Provider{ return Provider{
AcmeshName: "dns_zonomi", Title: "dns_zonomi",
Schema: commonKeySchema, AdditionalProperties: false,
Fields: []providerField{ Required: []string{
{ "ZM_Key",
Name: "API Key", },
Type: "password", Properties: map[string]providerField{
MetaKey: "api_key", "ZM_Key": {
EnvKey: "ZM_Key", Title: "api-key",
IsRequired: true, Type: "string",
MinLength: 1,
IsSecret: true, IsSecret: true,
}, },
}, },

View File

@ -87,15 +87,24 @@ func (m *Model) GetAcmeShEnvVars() ([]string, error) {
return nil, err return nil, err
} }
envs := make([]string, 0) // Convert the meta interface to envs slice for use by acme.sh
envs := getEnvsFromMeta(m.Meta.Decoded)
// Then, using the meta, convert to env vars
envPairs := acmeDNSProvider.GetAcmeEnvVars(m.Meta.Decoded)
logger.Debug("meta: %+v", m.Meta)
logger.Debug("envPairs: %+v", envPairs)
for envName, envValue := range envPairs {
envs = append(envs, fmt.Sprintf(`%s=%v`, envName, envValue))
}
return envs, nil return envs, nil
} }
func getEnvsFromMeta(meta interface{}) []string {
if rec, ok := meta.(map[string]interface{}); ok {
envs := make([]string, 0)
for key, val := range rec {
if f, ok := val.(string); ok {
envs = append(envs, fmt.Sprintf(`%s=%v`, key, f))
} else if f, ok := val.(int); ok {
envs = append(envs, fmt.Sprintf(`%s=%d`, key, f))
}
}
return envs
} else {
logger.Debug("getEnvsFromMeta: meta is not an map of strings")
return nil
}
}

View File

@ -3,9 +3,9 @@
"version": "3.0.0", "version": "3.0.0",
"private": true, "private": true,
"dependencies": { "dependencies": {
"@chakra-ui/react": "^2.2.4", "@chakra-ui/react": "^2.4.7",
"@emotion/react": "^11", "@emotion/react": "^11.10.5",
"@emotion/styled": "^11.9.3", "@emotion/styled": "^11.10.5",
"@testing-library/jest-dom": "5.16.4", "@testing-library/jest-dom": "5.16.4",
"@testing-library/react": "13.3.0", "@testing-library/react": "13.3.0",
"@types/humps": "^2.0.2", "@types/humps": "^2.0.2",
@ -34,7 +34,7 @@
"eslint-plugin-react": "^7.30.1", "eslint-plugin-react": "^7.30.1",
"eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-react-hooks": "^4.6.0",
"formik": "^2.2.9", "formik": "^2.2.9",
"framer-motion": "^6", "framer-motion": "^8.4.2",
"humps": "^2.0.1", "humps": "^2.0.1",
"jest-date-mock": "1.0.8", "jest-date-mock": "1.0.8",
"jest-fetch-mock": "3.0.3", "jest-fetch-mock": "3.0.3",
@ -59,7 +59,7 @@
"react-table": "7.8.0", "react-table": "7.8.0",
"rooks": "5.11.8", "rooks": "5.11.8",
"tmp": "^0.2.1", "tmp": "^0.2.1",
"typescript": "^4.7.4" "typescript": "^4.9.4"
}, },
"scripts": { "scripts": {
"start": "react-scripts start", "start": "react-scripts start",

View File

@ -28,21 +28,22 @@ function buildBody(data?: Record<string, any>) {
} }
} }
async function processResponse(response: Response) { async function processResponse(response: Response, skipCamelize = false) {
const payload = await response.json(); const payload = await response.json();
if (!response.ok) { if (!response.ok) {
throw new Error(payload.error.message); throw new Error(payload.error.message);
} }
return camelizeKeys(payload) as any; return (skipCamelize ? payload : camelizeKeys(payload)) as any;
} }
interface GetArgs { interface GetArgs {
url: string; url: string;
params?: queryString.StringifiableRecord; params?: queryString.StringifiableRecord;
skipCamelize?: boolean;
} }
export async function get( export async function get(
{ url, params }: GetArgs, { url, params, skipCamelize }: GetArgs,
abortController?: AbortController, abortController?: AbortController,
) { ) {
const apiUrl = buildUrl({ url, params }); const apiUrl = buildUrl({ url, params });
@ -50,7 +51,7 @@ export async function get(
const signal = abortController?.signal; const signal = abortController?.signal;
const headers = buildAuthHeader(); const headers = buildAuthHeader();
const response = await fetch(apiUrl, { method, headers, signal }); const response = await fetch(apiUrl, { method, headers, signal });
return processResponse(response); return processResponse(response, skipCamelize);
} }
interface PostArgs { interface PostArgs {

View File

@ -7,6 +7,8 @@ export async function getDNSProvidersAcmesh(
const { result } = await api.get( const { result } = await api.get(
{ {
url: "dns-providers/acmesh", url: "dns-providers/acmesh",
// Important for this endpoint:
skipCamelize: true,
}, },
abortController, abortController,
); );

View File

@ -74,18 +74,25 @@ export interface DNSProvider {
meta: any; meta: any;
} }
export interface DNSProvidersAcmeshField { export interface DNSProvidersAcmeshProperty {
name: string; title: string;
type: string; type: string;
metaKey: string; additionalProperties: boolean;
isRequired: boolean; minimum: number;
maximum: number;
minLength: number;
maxLength: number;
pattern: string;
isSecret: boolean; isSecret: boolean;
} }
export interface DNSProvidersAcmesh { export interface DNSProvidersAcmesh {
name: string; title: string;
acmeshName: string; type: string;
fields: DNSProvidersAcmeshField[]; additionalProperties: boolean;
minProperties: number;
required: string[];
properties: any;
} }
export interface Host { export interface Host {

View File

@ -137,6 +137,108 @@
"acmesh.dns_zonomi": { "acmesh.dns_zonomi": {
"defaultMessage": "Zonomi" "defaultMessage": "Zonomi"
}, },
"acmesh-property.access-key-id": {
"defaultMessage": "Access Key ID"
},
"acmesh-property.account-id": {
"defaultMessage": "Account ID"
},
"acmesh-property.api-key": {
"defaultMessage": "API Key"
},
"acmesh-property.api-url": {
"defaultMessage": "API URL"
},
"acmesh-property.app-id": {
"defaultMessage": "APP ID"
},
"acmesh-property.auth-id": {
"defaultMessage": "Auth ID"
},
"acmesh-property.base-url": {
"defaultMessage": "Base URL"
},
"acmesh-property.client-id": {
"defaultMessage": "Client ID"
},
"acmesh-property.client-secret": {
"defaultMessage": "Client Secret"
},
"acmesh-property.credentials": {
"defaultMessage": "Credentials"
},
"acmesh-property.context": {
"defaultMessage": "Context"
},
"acmesh-property.customer": {
"defaultMessage": "Customer"
},
"acmesh-property.email": {
"defaultMessage": "Email"
},
"acmesh-property.id": {
"defaultMessage": "ID"
},
"acmesh-property.insecure": {
"defaultMessage": "Insecure"
},
"acmesh-property.key": {
"defaultMessage": "Key"
},
"acmesh-property.oauth-token": {
"defaultMessage": "OAuth Token"
},
"acmesh-property.otp-secret": {
"defaultMessage": "OTP Secret"
},
"acmesh-property.password": {
"defaultMessage": "Password"
},
"acmesh-property.secret": {
"defaultMessage": "Secret"
},
"acmesh-property.secret-access-key": {
"defaultMessage": "Secret Access Key"
},
"acmesh-property.server": {
"defaultMessage": "Server"
},
"acmesh-property.server-id": {
"defaultMessage": "Server ID"
},
"acmesh-property.slow-rate": {
"defaultMessage": "Slow Rate"
},
"acmesh-property.subdomain": {
"defaultMessage": "Subdomain"
},
"acmesh-property.subscription-id": {
"defaultMessage": "Subscription ID"
},
"acmesh-property.sub-auth-id": {
"defaultMessage": "Sub-Auth ID"
},
"acmesh-property.tenant-id": {
"defaultMessage": "Tenant ID"
},
"acmesh-property.token": {
"defaultMessage": "Token"
},
"acmesh-property.ttl": {
"defaultMessage": "TTL"
},
"acmesh-property.user": {
"defaultMessage": "User"
},
"acmesh-property.username": {
"defaultMessage": "Username"
},
"acmesh-property.url": {
"defaultMessage": "URL"
},
"acmesh-property.zone-id": {
"defaultMessage": "Zone ID"
},
"action.edit": { "action.edit": {
"defaultMessage": "Edit" "defaultMessage": "Edit"
}, },

View File

@ -0,0 +1,284 @@
import { useEffect, useState } from "react";
import {
Button,
Checkbox,
FormControl,
FormErrorMessage,
FormLabel,
Input,
Modal,
ModalOverlay,
ModalContent,
ModalHeader,
ModalCloseButton,
ModalBody,
ModalFooter,
Select,
Stack,
useToast,
} from "@chakra-ui/react";
import {
DNSProvider,
DNSProvidersAcmesh,
DNSProvidersAcmeshProperty,
} from "api/npm";
import { PrettyButton } from "components";
import { Formik, Form, Field } from "formik";
import { useSetDNSProvider, useDNSProvidersAcmesh } from "hooks";
import { intl } from "locale";
import { validateString } from "modules/Validations";
interface DNSProviderCreateModalProps {
isOpen: boolean;
onClose: () => void;
}
function DNSProviderCreateModal({
isOpen,
onClose,
}: DNSProviderCreateModalProps) {
const toast = useToast();
const { mutate: setDNSProvider } = useSetDNSProvider();
const {
isLoading: acmeshIsLoading,
// isError: acmeshIsError,
// error: acmeshError,
data: acmeshDataResp,
} = useDNSProvidersAcmesh();
const [acmeshData, setAcmeshData] = useState([] as DNSProvidersAcmesh[]);
const [acmeshItem, setAcmeshItem] = useState("");
useEffect(() => {
setAcmeshData(acmeshDataResp || []);
}, [acmeshDataResp]);
const onSubmit = async (
payload: DNSProvider,
{ setErrors, setSubmitting }: any,
) => {
// TODO: filter out the meta object and only include items that apply to the acmesh provider selected
const showErr = (msg: string) => {
toast({
description: intl.formatMessage({
id: `error.${msg}`,
}),
status: "error",
position: "top",
duration: 3000,
isClosable: true,
});
};
setDNSProvider(payload, {
onError: (err: any) => {
if (err.message === "ca-bundle-does-not-exist") {
setErrors({
caBundle: intl.formatMessage({
id: `error.${err.message}`,
}),
});
} else {
showErr(err.message);
}
},
onSuccess: () => onClose(),
onSettled: () => setSubmitting(false),
});
};
const getAcmeshItem = (name: string): DNSProvidersAcmesh | undefined => {
return acmeshData.find((item) => item.title === name);
};
const fullItem = getAcmeshItem(acmeshItem);
const itemProperties = fullItem?.properties;
const renderInputType = (
field: any,
fieldName: string,
f: DNSProvidersAcmeshProperty,
value: any,
) => {
if (f.type === "bool") {
return (
<Checkbox {...field} size="md" colorScheme="orange" isChecked={value}>
{f.title}
</Checkbox>
);
}
let type = "text";
let props: any = {};
if (fullItem?.required.indexOf(fieldName) !== -1) {
// This is required
props.required = true;
}
if (f.type === "string") {
props.minLength = f.minLength || null;
props.maxLength = f.maxLength || null;
props.pattern = f.pattern || null;
}
if (f.type === "integer") {
type = "number";
props.min = f.minimum || null;
props.max = f.maximum || null;
}
if (f.isSecret) {
type = "password";
}
return (
<Input
{...field}
id={fieldName}
type={type}
defaultValue={value}
{...props}
/>
);
};
return (
<Modal isOpen={isOpen} onClose={onClose} closeOnOverlayClick={false}>
<ModalOverlay />
<ModalContent>
{acmeshIsLoading ? (
"loading"
) : (
<Formik
initialValues={
{
acmeshName: "",
name: "",
dnsSleep: 0,
meta: {},
} as DNSProvider
}
onSubmit={onSubmit}>
{({ isSubmitting, handleChange, values, setValues }) => (
<Form>
<ModalHeader>
{intl.formatMessage({ id: "dns-provider.create" })}
</ModalHeader>
<ModalCloseButton />
<ModalBody>
<Stack spacing={4}>
<Field name="name" validate={validateString(1, 100)}>
{({ field, form }: any) => (
<FormControl
isRequired
isInvalid={form.errors.name && form.touched.name}>
<FormLabel htmlFor="name">
{intl.formatMessage({
id: "dns-provider.name",
})}
</FormLabel>
<Input
{...field}
id="name"
placeholder={intl.formatMessage({
id: "dns-provider.name",
})}
/>
<FormErrorMessage>
{form.errors.name}
</FormErrorMessage>
</FormControl>
)}
</Field>
<Field name="acmeshName">
{({ field, form }: any) => (
<FormControl
isRequired
isInvalid={
form.errors.acmeshName && form.touched.acmeshName
}>
<FormLabel htmlFor="acmeshName">
{intl.formatMessage({
id: "dns-provider.acmesh-name",
})}
</FormLabel>
<Select
{...field}
id="acmeshName"
onChange={(e: any) => {
handleChange(e);
setAcmeshItem(e.target.value);
}}>
<option value="" />
{acmeshData.map((item: DNSProvidersAcmesh) => {
return (
<option key={item.title} value={item.title}>
{intl.formatMessage({
id: `acmesh.${item.title}`,
})}
</option>
);
})}
</Select>
<FormErrorMessage>
{form.errors.acmeshName}
</FormErrorMessage>
</FormControl>
)}
</Field>
{acmeshItem !== "" ? <hr /> : null}
{itemProperties
? Object.keys(itemProperties).map((fieldName, _) => {
const f = itemProperties[fieldName];
const name = `meta[${fieldName}]`;
return (
<Field
name={fieldName}
type={
f.type === "boolean" ? "checkbox" : undefined
}>
{({ field, form }: any) => (
<FormControl
isRequired={f.isRequired}
isInvalid={
form.errors[name] && form.touched[name]
}>
{f.type !== "bool" ? (
<FormLabel htmlFor={name}>
{f.title}
{/* todo: locale for this*/}
</FormLabel>
) : null}
{renderInputType(
field,
fieldName,
f,
values.meta[f.title],
)}
<FormErrorMessage>
{form.errors[name]}
</FormErrorMessage>
</FormControl>
)}
</Field>
);
})
: null}
</Stack>
</ModalBody>
<ModalFooter>
<PrettyButton mr={3} isLoading={isSubmitting}>
{intl.formatMessage({ id: "form.save" })}
</PrettyButton>
<Button onClick={onClose} isLoading={isSubmitting}>
{intl.formatMessage({ id: "form.cancel" })}
</Button>
</ModalFooter>
</Form>
)}
</Formik>
)}
</ModalContent>
</Modal>
);
}
export { DNSProviderCreateModal };

View File

@ -21,7 +21,7 @@ import {
import { import {
DNSProvider, DNSProvider,
DNSProvidersAcmesh, DNSProvidersAcmesh,
DNSProvidersAcmeshField, DNSProvidersAcmeshProperty,
} from "api/npm"; } from "api/npm";
import { PrettyButton } from "components"; import { PrettyButton } from "components";
import { Formik, Form, Field } from "formik"; import { Formik, Form, Field } from "formik";
@ -53,11 +53,17 @@ function DNSProviderCreateModal({
setAcmeshData(acmeshDataResp || []); setAcmeshData(acmeshDataResp || []);
}, [acmeshDataResp]); }, [acmeshDataResp]);
const onModalClose = () => {
setAcmeshItem("");
onClose();
};
const onSubmit = async ( const onSubmit = async (
payload: DNSProvider, payload: DNSProvider,
{ setErrors, setSubmitting }: any, { setErrors, setSubmitting }: any,
) => { ) => {
// TODO: filter out the meta object and only include items that apply to the acmesh provider selected // TODO: filter out the meta object and only include items that apply to the acmesh provider selected
console.log("PAYLOAD:", payload);
const showErr = (msg: string) => { const showErr = (msg: string) => {
toast({ toast({
@ -83,35 +89,63 @@ function DNSProviderCreateModal({
showErr(err.message); showErr(err.message);
} }
}, },
onSuccess: () => onClose(), onSuccess: () => onModalClose(),
onSettled: () => setSubmitting(false), onSettled: () => setSubmitting(false),
}); });
}; };
const getAcmeshItem = (name: string): DNSProvidersAcmesh | undefined => { const getAcmeshItem = (name: string): DNSProvidersAcmesh | undefined => {
return acmeshData.find((item) => item.acmeshName === name); return acmeshData.find((item) => item.title === name);
}; };
const fullItem = getAcmeshItem(acmeshItem);
const itemProperties = fullItem?.properties;
const renderInputType = ( const renderInputType = (
field: any, field: any,
f: DNSProvidersAcmeshField, fieldName: string,
f: DNSProvidersAcmeshProperty,
value: any, value: any,
) => { ) => {
if (f.type === "bool") { if (["bool", "boolean"].indexOf(f.type) !== -1) {
return ( return (
<Checkbox {...field} size="md" colorScheme="orange" isChecked={value}> <Checkbox size="md" colorScheme="orange" isChecked={value} {...field}>
{f.name} {f.title}
</Checkbox> </Checkbox>
); );
} }
let type = "text";
let props: any = {};
if (f.type === "string") {
props.minLength = f.minLength || null;
props.maxLength = f.maxLength || null;
props.pattern = f.pattern || null;
}
if (f.type === "integer") {
type = "number";
props.min = f.minimum || null;
props.max = f.maximum || null;
}
if (f.isSecret) {
type = "password";
}
return ( return (
<Input {...field} id={f.metaKey} type={f.type} defaultValue={value} /> <Input
{...field}
id={fieldName}
type={type}
defaultValue={value}
placeholder={fieldName}
{...props}
/>
); );
}; };
return ( return (
<Modal isOpen={isOpen} onClose={onClose} closeOnOverlayClick={false}> <Modal isOpen={isOpen} onClose={onModalClose} closeOnOverlayClick={false}>
<ModalOverlay /> <ModalOverlay />
<ModalContent> <ModalContent>
{acmeshIsLoading ? ( {acmeshIsLoading ? (
@ -135,6 +169,44 @@ function DNSProviderCreateModal({
<ModalCloseButton /> <ModalCloseButton />
<ModalBody> <ModalBody>
<Stack spacing={4}> <Stack spacing={4}>
<Field name="acmeshName">
{({ field, form }: any) => (
<FormControl
isRequired
isInvalid={
form.errors.acmeshName && form.touched.acmeshName
}>
<FormLabel htmlFor="acmeshName">
{intl.formatMessage({
id: "dns-provider.acmesh-name",
})}
</FormLabel>
<Select
{...field}
id="acmeshName"
onChange={(e: any) => {
handleChange(e);
setAcmeshItem(e.target.value);
}}>
<option value="" />
{acmeshData.map((item: DNSProvidersAcmesh) => {
return (
<option key={item.title} value={item.title}>
{intl.formatMessage({
id: `acmesh.${item.title}`,
})}
</option>
);
})}
</Select>
<FormErrorMessage>
{form.errors.acmeshName}
</FormErrorMessage>
</FormControl>
)}
</Field>
{acmeshItem !== "" ? (
<>
<Field name="name" validate={validateString(1, 100)}> <Field name="name" validate={validateString(1, 100)}>
{({ field, form }: any) => ( {({ field, form }: any) => (
<FormControl <FormControl
@ -158,64 +230,40 @@ function DNSProviderCreateModal({
</FormControl> </FormControl>
)} )}
</Field> </Field>
<Field name="acmeshName"> {itemProperties
{({ field, form }: any) => ( ? Object.keys(itemProperties).map((fieldName, _) => {
<FormControl const f = itemProperties[fieldName];
isRequired const name = `meta[${fieldName}]`;
isInvalid={
form.errors.acmeshName && form.touched.acmeshName
}>
<FormLabel htmlFor="acmeshName">
{intl.formatMessage({
id: "dns-provider.acmesh-name",
})}
</FormLabel>
<Select
{...field}
id="acmeshName"
onChange={(e: any) => {
handleChange(e);
setAcmeshItem(e.target.value);
}}>
<option value="" />
{acmeshData.map((item: DNSProvidersAcmesh) => {
return (
<option
key={item.acmeshName}
value={item.acmeshName}>
{intl.formatMessage({
id: `acmesh.${item.acmeshName}`,
})}
</option>
);
})}
</Select>
<FormErrorMessage>
{form.errors.acmeshName}
</FormErrorMessage>
</FormControl>
)}
</Field>
{acmeshItem !== "" ? <hr /> : null}
{getAcmeshItem(acmeshItem)?.fields.map((f) => {
const name = `meta[${f.metaKey}]`;
return ( return (
<Field <Field
name={name} name={`meta[${fieldName}]`}
type={f.type === "bool" ? "checkbox" : undefined}> type={
f.type === "boolean"
? "checkbox"
: undefined
}>
{({ field, form }: any) => ( {({ field, form }: any) => (
<FormControl <FormControl
isRequired={f.isRequired} isRequired={
fullItem?.required.indexOf(
fieldName,
) !== -1
}
isInvalid={ isInvalid={
form.errors[name] && form.touched[name] form.errors[name] && form.touched[name]
}> }>
{f.type !== "bool" ? ( {f.type !== "bool" ? (
<FormLabel htmlFor={name}>{f.name}</FormLabel> <FormLabel htmlFor={name}>
{intl.formatMessage({
id: `acmesh-property.${f.title}`,
})}
</FormLabel>
) : null} ) : null}
{renderInputType( {renderInputType(
field, field,
fieldName,
f, f,
values.meta[f.metaKey], values.meta[f.title],
)} )}
<FormErrorMessage> <FormErrorMessage>
{form.errors[name]} {form.errors[name]}
@ -224,14 +272,17 @@ function DNSProviderCreateModal({
)} )}
</Field> </Field>
); );
})} })
: null}
</>
) : null}
</Stack> </Stack>
</ModalBody> </ModalBody>
<ModalFooter> <ModalFooter>
<PrettyButton mr={3} isLoading={isSubmitting}> <PrettyButton mr={3} isLoading={isSubmitting}>
{intl.formatMessage({ id: "form.save" })} {intl.formatMessage({ id: "form.save" })}
</PrettyButton> </PrettyButton>
<Button onClick={onClose} isLoading={isSubmitting}> <Button onClick={onModalClose} isLoading={isSubmitting}>
{intl.formatMessage({ id: "form.cancel" })} {intl.formatMessage({ id: "form.cancel" })}
</Button> </Button>
</ModalFooter> </ModalFooter>

File diff suppressed because it is too large Load Diff