Escape deployment and manifest names.

pull/256/head
jackgr 9 years ago
parent 6d02090169
commit edd4e9dcba

@ -206,26 +206,19 @@ func execute() {
os.Exit(1) os.Exit(1)
} }
path := fmt.Sprintf("deployments/%s", args[1]) path := fmt.Sprintf("deployments/%s", url.QueryEscape(args[1]))
action := fmt.Sprintf("get deployment named %s", args[1]) action := fmt.Sprintf("get deployment named %s", args[1])
callService(path, "GET", action, nil) callService(path, "GET", action, nil)
case "manifest": case "manifest":
msg := "Must specify manifest in the form <deployment>/<manifest> or <deployment> to list." msg := "Must specify manifest in the form <deployment> <manifest> or just <deployment> to list."
if len(args) < 2 { if len(args) < 2 || len(args) > 3 {
fmt.Fprintln(os.Stderr, msg) fmt.Fprintln(os.Stderr, msg)
os.Exit(1) os.Exit(1)
} }
s := strings.Split(args[1], "/") path := fmt.Sprintf("deployments/%s/manifests", url.QueryEscape(args[1]))
ls := len(s) if len(args) > 2 {
if ls < 1 || ls > 2 { path = path + fmt.Sprintf("/%s", url.QueryEscape(args[2]))
fmt.Fprintln(os.Stderr, fmt.Sprintf("Invalid manifest (%s), %s", args[1], msg))
os.Exit(1)
}
path := fmt.Sprintf("deployments/%s/manifests", s[0])
if ls == 2 {
path = path + fmt.Sprintf("/%s", s[1])
} }
action := fmt.Sprintf("get manifest %s", args[1]) action := fmt.Sprintf("get manifest %s", args[1])
@ -236,12 +229,12 @@ func execute() {
os.Exit(1) os.Exit(1)
} }
path := fmt.Sprintf("deployments/%s", args[1]) path := fmt.Sprintf("deployments/%s", url.QueryEscape(args[1]))
action := fmt.Sprintf("delete deployment named %s", args[1]) action := fmt.Sprintf("delete deployment named %s", args[1])
callService(path, "DELETE", action, nil) callService(path, "DELETE", action, nil)
case "update": case "update":
template := loadTemplate(args) template := loadTemplate(args)
path := fmt.Sprintf("deployments/%s", template.Name) path := fmt.Sprintf("deployments/%s", url.QueryEscape(template.Name))
action := fmt.Sprintf("delete deployment named %s", template.Name) action := fmt.Sprintf("delete deployment named %s", template.Name)
callService(path, "PUT", action, marshalTemplate(template)) callService(path, "PUT", action, marshalTemplate(template))
case "deployed-types": case "deployed-types":
@ -274,9 +267,14 @@ func execute() {
} }
func callService(path, method, action string, reader io.ReadCloser) { func callService(path, method, action string, reader io.ReadCloser) {
u := fmt.Sprintf("%s/%s", *service, path) var URL *url.URL
URL, err := url.Parse(*service)
if err != nil {
panic(fmt.Errorf("cannot parse url (%s): %s\n", path, err))
}
resp := callHTTP(u, method, action, reader) URL.Path += path
resp := callHTTP(URL.String(), method, action, reader)
var j interface{} var j interface{}
if err := json.Unmarshal([]byte(resp), &j); err != nil { if err := json.Unmarshal([]byte(resp), &j); err != nil {
panic(fmt.Errorf("Failed to parse JSON response from service: %s", resp)) panic(fmt.Errorf("Failed to parse JSON response from service: %s", resp))

Loading…
Cancel
Save