add(checking schema to set configuration and unsafe flag)
This commit is contained in:
1 parent
3543ded23e
commit
c8d028fcd4
14 files changed
+156
-45
No files matched your search
@@ -0,0 +1,36 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/xeipuuv/gojsonschema"
|
||||
)
|
||||
|
||||
var UnsafeService unsafeService
|
||||
|
||||
type unsafeService struct {
|
||||
Enable bool
|
||||
}
|
||||
|
||||
func (s unsafeService) CheckConfigurationSchema(moduleId int32, object map[string]interface{}) (bool, error) {
|
||||
if s.Enable {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
if resp, err := ConfigClient.GetSchemaByModuleId(moduleId); err != nil {
|
||||
return false, err
|
||||
} else {
|
||||
schemaLoader := gojsonschema.NewGoLoader(resp.Schema)
|
||||
documentLoader := gojsonschema.NewGoLoader(object)
|
||||
|
||||
if result, err := gojsonschema.Validate(schemaLoader, documentLoader); err != nil {
|
||||
return false, err
|
||||
} else if result.Valid() {
|
||||
return true, nil
|
||||
} else {
|
||||
for _, desc := range result.Errors() {
|
||||
fmt.Printf("- %s\n", desc)
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user