Skip to content

Commit 03b0528

Browse files
authored
Merge pull request #326 from meshery/Abhi/cfgSchema
Add the configuration schema for importing designs, applications and filters
2 parents 7cfaf1a + 29cadeb commit 03b0528

File tree

9 files changed

+382
-0
lines changed

9 files changed

+382
-0
lines changed

schemas/configuration.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package schemas
2+
3+
import "embed"
4+
//go:embed configuration
5+
var Schemas embed.FS
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
{
2+
"//playground": "https://rjsf-team.github.io/react-jsonschema-form/#eyJmb3JtRGF0YSI6eyJhcHBsaWNhdGlvblR5cGUiOiJIZWxtIENoYXJ0In0sInNjaGVtYSI6eyJ0aXRsZSI6IlVwbG9hZCBBcHBsaWNhdGlvbiBGaWxlIiwicHJvcGVydGllcyI6eyJuYW1lIjp7InR5cGUiOiJzdHJpbmciLCJ0aXRsZSI6IkdpdmUgeW91ciBhcHBsaWNhdGlvbiBmaWxlIGEgbmFtZSIsIngtcmpzZi1ncmlkLWFyZWEiOiI2In0sImFwcGxpY2F0aW9uVHlwZSI6eyJ0aXRsZSI6IlNlbGVjdCBhcHBsaWNhdGlvbiB0eXBlIiwiZW51bSI6WyJIZWxtIENoYXJ0IiwiS3ViZXJuZXRlcyBNYW5pZmVzdCIsIkRvY2tlciBDb21wb3NlIl0sImRlZmF1bHQiOiJIZWxtIENoYXJ0IiwieC1yanNmLWdyaWQtYXJlYSI6IjYifX0sImRlcGVuZGVuY2llcyI6eyJhcHBsaWNhdGlvblR5cGUiOnsib25lT2YiOlt7InByb3BlcnRpZXMiOnsiYXBwbGljYXRpb25UeXBlIjp7ImNvbnN0IjoiSGVsbSBDaGFydCJ9LCJ1cmwiOnsidHlwZSI6InN0cmluZyIsImZvcm1hdCI6InVyaSIsInRpdGxlIjoiVVJMIiwiZGVzY3JpcHRpb24iOiJyYXcgVVJMIG9mIHRoZSBhc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Jhdy5naXRodWIuY29tLy4uLiIsIngtcmpzZi1ncmlkLWFyZWEiOiIxMiJ9fSwicmVxdWlyZWQiOlsidXJsIl19LHsicHJvcGVydGllcyI6eyJmaWxlIjp7InR5cGUiOiJzdHJpbmciLCJmb3JtYXQiOiJkYXRhLXVybCIsInRpdGxlIjoiRmlsZSBVcGxvYWQiLCJkZXNjcmlwdGlvbiI6IkJyb3dzZSB0aGUgYXBwbGljYXRpb24gZmlsZSBmcm9tIHlvdXIgZmlsZSBzeXN0ZW0iLCJ4LXJqc2YtZ3JpZC1hcmVhIjoiMTIifX0sInJlcXVpcmVkIjpbImZpbGUiXX1dfV19fX0sInVpU2NoZW1hIjp7ImFwcGxpY2F0aW9uVHlwZSI6eyJ1aTp3aWRnZXQiOiJyYWRpbyJ9fSwidGhlbWUiOiJtYXRlcmlhbC11aS01IiwibGl2ZVNldHRpbmdzIjp7fX0=",
3+
"title": "Upload Application File",
4+
"properties": {
5+
"name": {
6+
"type": "string",
7+
"title": "Application Name",
8+
"x-rjsf-grid-area": "6",
9+
"description": "The name of Application"
10+
},
11+
"applicationType": {
12+
"title": "Application Type",
13+
"description": "Choose the type of application you want to upload",
14+
"enum": [
15+
"Helm Chart",
16+
"Kubernetes Manifest",
17+
"Docker Compose"
18+
],
19+
"default": "Helm Chart",
20+
"x-rjsf-grid-area": "6"
21+
}
22+
},
23+
"dependencies": {
24+
"applicationType": {
25+
"oneOf": [
26+
{
27+
"properties": {
28+
"applicationType": {
29+
"const": "Helm Chart"
30+
},
31+
"url": {
32+
"type": "string",
33+
"format": "uri",
34+
"title": "URL",
35+
"description": "raw URL of the application file, example: https://raw.github.com/...",
36+
"x-rjsf-grid-area": "12"
37+
}
38+
},
39+
"required": [
40+
"url"
41+
]
42+
},
43+
{
44+
"properties": {
45+
"applicationType": {
46+
"const": "Kubernetes Manifest"
47+
}
48+
},
49+
"oneOf": [
50+
{
51+
"title": "URL Upload",
52+
"properties": {
53+
"url": {
54+
"type": "string",
55+
"format": "uri",
56+
"title": "URL",
57+
"description": "raw URL of the application file, example: https://raw.github.com/...",
58+
"x-rjsf-grid-area": "12"
59+
}
60+
},
61+
"required": [
62+
"url"
63+
]
64+
},
65+
{
66+
"title": "File Upload",
67+
"properties": {
68+
"file": {
69+
"type": "string",
70+
"format": "data-url",
71+
"title": "File Upload",
72+
"description": "Browse the application file from your file system",
73+
"x-rjsf-grid-area": "12"
74+
}
75+
},
76+
"required": [
77+
"file"
78+
]
79+
}
80+
]
81+
},
82+
{
83+
"properties": {
84+
"applicationType": {
85+
"const": "Docker Compose"
86+
}
87+
},
88+
"oneOf": [
89+
{
90+
"title": "URL Upload",
91+
"properties": {
92+
"url": {
93+
"type": "string",
94+
"format": "uri",
95+
"title": "URL",
96+
"description": "raw URL of the application file, example: https://raw.github.com/...",
97+
"x-rjsf-grid-area": "12"
98+
}
99+
},
100+
"required": [
101+
"url"
102+
]
103+
},
104+
{
105+
"title": "File Upload",
106+
"properties": {
107+
"file": {
108+
"type": "string",
109+
"format": "data-url",
110+
"title": "File Upload",
111+
"description": "Browse the application file from your file system",
112+
"x-rjsf-grid-area": "12"
113+
}
114+
},
115+
"required": [
116+
"file"
117+
]
118+
}
119+
]
120+
}
121+
]
122+
}
123+
}
124+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"title": "Upload Design File",
3+
"properties": {
4+
"name": {
5+
"type": "string",
6+
"title": "Give your design file a name",
7+
"default": "Untitled Design",
8+
"x-rjsf-grid-area" : "12"
9+
},
10+
"uploadType": {
11+
"title": "Select the Upload Method",
12+
"enum": [
13+
"File Upload",
14+
"URL Upload"
15+
],
16+
"default": "File Upload",
17+
"x-rjsf-grid-area" : "12"
18+
}
19+
},
20+
"allOf": [
21+
{
22+
"if": {
23+
"properties": {
24+
"uploadType": {
25+
"const": "File Upload"
26+
}
27+
}
28+
},
29+
"then": {
30+
"title": "via URL",
31+
"properties": {
32+
"file": {
33+
"type": "string",
34+
"format": "file",
35+
"description": "Browse the design file from your file system",
36+
"x-rjsf-grid-area" : "12"
37+
}
38+
},
39+
"required": [
40+
"file"
41+
]
42+
}
43+
},
44+
{
45+
"if": {
46+
"properties": {
47+
"uploadType": {
48+
"const": "URL Upload"
49+
}
50+
}
51+
},
52+
"then": {
53+
"title": "via URL",
54+
"properties": {
55+
"url": {
56+
"type": "string",
57+
"title": "URL",
58+
"description": "raw url of the design file, example: https://raw.github.com/...",
59+
"x-rjsf-grid-area" : "12"
60+
}
61+
},
62+
"required": [
63+
"url"
64+
]
65+
}
66+
}
67+
]
68+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"name": {
5+
"type": "string",
6+
"title": "Name",
7+
"description": "The name of Filter",
8+
"default": "Unitled Filter File",
9+
"x-rjsf-grid-area" : "6"
10+
},
11+
"config": {
12+
"type": "string",
13+
"title": "WASM Filter Config",
14+
"format": "textarea",
15+
"description": "Enter the configuration details. The configuration detail is the yaml string with running details",
16+
"default": "This is an Exmaple config, config could be Yaml or JSON\ntyped_config:\r\n \"@type\": type.googleapis.com/envoy.extensions.filters.http.wasm.v3.Wasm\r\n config:\r\n name: example-filter\r\n rootId: my_root_id\r\n vmConfig:\r\n code:\r\n local:\r\n filename: /var/local/lib/wasm-filters/example-filter.wasm\r\n runtime: envoy.wasm.runtime.v8\r\n vmId: example-filter\r\n allow_precompiled: true\r\nname: envoy.filters.http.wasm",
17+
"x-rjsf-grid-area" : "12"
18+
},
19+
"uploadType": {
20+
"title": "Select the Upload Method",
21+
"enum": [
22+
"File Upload",
23+
"URL Upload"
24+
],
25+
"default": "File Upload",
26+
"x-rjsf-grid-area" : "6"
27+
}
28+
},
29+
"allOf": [
30+
{
31+
"if": {
32+
"properties": {
33+
"uploadType": {
34+
"const": "File Upload"
35+
}
36+
}
37+
},
38+
"then": {
39+
"title": "via File",
40+
"properties": {
41+
"file": {
42+
"type": "string",
43+
"format": "file",
44+
"description": "Browse the filter file from your file system",
45+
"x-rjsf-grid-area" : "12"
46+
}
47+
},
48+
"required": [
49+
"file"
50+
]
51+
}
52+
},
53+
{
54+
"if": {
55+
"properties": {
56+
"uploadType": {
57+
"const": "URL Upload"
58+
}
59+
}
60+
},
61+
"then": {
62+
"title": "via URL",
63+
"properties": {
64+
"url": {
65+
"type": "string",
66+
"title": "URL",
67+
"format": "uri",
68+
"description": "raw url of the filter file, example: https://raw.github.com/...",
69+
"x-rjsf-grid-area" : "12"
70+
}
71+
},
72+
"required": [
73+
"url"
74+
]
75+
}
76+
}
77+
]
78+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"compatibility": {
5+
"type": "array",
6+
"title": "Technology",
7+
"items": {
8+
"enum": ["istio", "linkerd"],
9+
"type": "string"
10+
},
11+
"uniqueItems": true,
12+
"minItems": 1,
13+
"description": "The list of compatible technologies.",
14+
"x-rjsf-grid-area": 6
15+
},
16+
"pattern_caveats": {
17+
"type": "string",
18+
"title": "Caveats and Considerations",
19+
"description": "Caveats related to the design.",
20+
"format": "textarea",
21+
"x-rjsf-grid-area": 12
22+
},
23+
"pattern_info": {
24+
"type": "string",
25+
"title": "Description",
26+
"description": "Additional information about the design.",
27+
"format": "textarea",
28+
"x-rjsf-grid-area": 12
29+
},
30+
"type": {
31+
"type": "string",
32+
"title": "Type",
33+
"examples": [
34+
"deployment",
35+
"observability",
36+
"resiliency",
37+
"scaling",
38+
"security",
39+
"traffic-management",
40+
"troubleshooting",
41+
"workloads"
42+
],
43+
"description": "The category of the pattern.",
44+
"x-rjsf-grid-area": 6
45+
}
46+
},
47+
"required": ["compatibility", "pattern_caveats", "pattern_info", "type"]
48+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"applicationType": {
3+
"ui:widget": "radio"
4+
}
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"uploadType": {
3+
"ui:widget": "radio"
4+
}
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"ui:order" : ["type", "compatibility", "pattern_caveats", "pattern_info"]
3+
}

schemas/schemaProvider.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package schemas
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
func getSchemaMap() map[string]string {
8+
return map[string]string{
9+
"application": "configuration/applicationImport.json",
10+
"filter": "configuration/filterImport.json",
11+
"design": "configuration/designImport.json",
12+
}
13+
}
14+
15+
func getUiSchemaMap() map[string]string {
16+
return map[string]string{
17+
"application": "configuration/uiSchemaApplication.json",
18+
"design": "configuration/uiSchemaDesignImport.json",
19+
}
20+
}
21+
22+
// ServeJSonFile serves the content of the JSON schema along with the uiSchema if any is present
23+
func ServeJSonFile(resourceName string) ([]byte, []byte, error) {
24+
schemaLocation := getSchemaMap()[resourceName]
25+
if schemaLocation == "" {
26+
return nil, nil, fmt.Errorf("requested resource's (%s) schema is not found", resourceName)
27+
}
28+
29+
jsonContent, err := Schemas.ReadFile(schemaLocation)
30+
31+
if err != nil {
32+
return nil, nil, fmt.Errorf("error reading json file: %s", err)
33+
}
34+
35+
uiSchemaLocation := getUiSchemaMap()[resourceName]
36+
if uiSchemaLocation == "" {
37+
return jsonContent, nil, nil
38+
}
39+
40+
uiSchemaJsonContent, err := Schemas.ReadFile(uiSchemaLocation)
41+
if err != nil {
42+
return jsonContent, nil, nil
43+
}
44+
45+
return jsonContent, uiSchemaJsonContent, nil
46+
}

0 commit comments

Comments
 (0)