mirror of
https://github.com/rancher/norman.git
synced 2025-08-16 06:23:36 +00:00
JSON encode schemas URL passed to html template
This commit is contained in:
parent
8339c491a8
commit
c7ba5c4dcd
@ -1,6 +1,7 @@
|
|||||||
package writer
|
package writer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/rancher/norman/api/builtin"
|
"github.com/rancher/norman/api/builtin"
|
||||||
@ -23,7 +24,7 @@ var (
|
|||||||
<script>
|
<script>
|
||||||
var user = "admin";
|
var user = "admin";
|
||||||
var curlUser='${CATTLE_ACCESS_KEY}:${CATTLE_SECRET_KEY}';
|
var curlUser='${CATTLE_ACCESS_KEY}:${CATTLE_SECRET_KEY}';
|
||||||
var schemas="%SCHEMAS%";
|
var schemas=%SCHEMAS%;
|
||||||
var data =
|
var data =
|
||||||
`
|
`
|
||||||
end = []byte(`</script>
|
end = []byte(`</script>
|
||||||
@ -51,7 +52,7 @@ func (h *HTMLResponseWriter) Write(apiContext *types.APIContext, code int, obj i
|
|||||||
schemaSchema := apiContext.Schemas.Schema(&builtin.Version, "schema")
|
schemaSchema := apiContext.Schemas.Schema(&builtin.Version, "schema")
|
||||||
headerString := start
|
headerString := start
|
||||||
if schemaSchema != nil {
|
if schemaSchema != nil {
|
||||||
headerString = strings.Replace(headerString, "%SCHEMAS%", apiContext.URLBuilder.Collection(schemaSchema, apiContext.Version), 1)
|
headerString = strings.Replace(headerString, "%SCHEMAS%", jsonEncodeURL(apiContext.URLBuilder.Collection(schemaSchema, apiContext.Version)), 1)
|
||||||
}
|
}
|
||||||
var jsurl, cssurl string
|
var jsurl, cssurl string
|
||||||
if h.CSSURL != nil && h.JSURL != nil && h.CSSURL() != "" && h.JSURL() != "" {
|
if h.CSSURL != nil && h.JSURL != nil && h.CSSURL() != "" && h.JSURL() != "" {
|
||||||
@ -73,3 +74,8 @@ func (h *HTMLResponseWriter) Write(apiContext *types.APIContext, code int, obj i
|
|||||||
apiContext.Response.Write(end)
|
apiContext.Response.Write(end)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func jsonEncodeURL(str string) string {
|
||||||
|
data, _ := json.Marshal(str)
|
||||||
|
return string(data)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user