2022-05-11 22:47:31 +00:00
|
|
|
package schema
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"npm/internal/dnsproviders"
|
2023-01-12 06:25:43 +00:00
|
|
|
"npm/internal/logger"
|
2022-05-11 22:47:31 +00:00
|
|
|
"npm/internal/util"
|
2023-02-24 07:19:07 +00:00
|
|
|
|
|
|
|
"github.com/rotisserie/eris"
|
2022-05-11 22:47:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// CreateDNSProvider is the schema for incoming data validation
|
|
|
|
func CreateDNSProvider() string {
|
|
|
|
allProviders := dnsproviders.GetAll()
|
|
|
|
fmtStr := fmt.Sprintf(`{"oneOf": [%s]}`, strings.TrimRight(strings.Repeat("\n%s,", len(allProviders)), ","))
|
|
|
|
|
|
|
|
allSchemasWrapped := make([]string, 0)
|
|
|
|
for providerName, provider := range allProviders {
|
2023-01-12 06:25:43 +00:00
|
|
|
schema, err := provider.GetJsonSchema()
|
|
|
|
if err != nil {
|
2023-02-24 07:19:07 +00:00
|
|
|
logger.Error("ProviderSchemaError", eris.Wrapf(err, "Invalid Provider Schema for %s: %v", provider.Title, err))
|
2023-01-12 06:25:43 +00:00
|
|
|
} else {
|
|
|
|
allSchemasWrapped = append(allSchemasWrapped, createDNSProviderType(providerName, schema))
|
|
|
|
}
|
2022-05-11 22:47:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Sprintf(fmtStr, util.ConvertStringSliceToInterface(allSchemasWrapped)...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func createDNSProviderType(name, metaSchema string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
{
|
|
|
|
"type": "object",
|
|
|
|
"additionalProperties": false,
|
|
|
|
"required": [
|
|
|
|
"acmesh_name",
|
|
|
|
"name",
|
|
|
|
"meta"
|
|
|
|
],
|
|
|
|
"properties": {
|
|
|
|
"acmesh_name": {
|
|
|
|
"type": "string",
|
|
|
|
"pattern": "^%s$"
|
|
|
|
},
|
|
|
|
"name": {
|
|
|
|
"type": "string",
|
|
|
|
"minLength": 1,
|
|
|
|
"maxLength": 100
|
|
|
|
},
|
|
|
|
"dns_sleep": {
|
|
|
|
"type": "integer"
|
|
|
|
},
|
|
|
|
"meta": %s
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, name, metaSchema)
|
|
|
|
}
|