Skip to content

Commit 020871f

Browse files
mlsorensenMarcus Sorensen
andauthored
Fix registerTemplate/updateTemplate details map (#44)
Signed-off-by: Marcus Sorensen <[email protected]> Signed-off-by: Marcus Sorensen <[email protected]> Co-authored-by: Marcus Sorensen <[email protected]>
1 parent e285bd0 commit 020871f

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

cloudstack/TemplateService.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2322,8 +2322,8 @@ func (p *RegisterTemplateParams) toURLValues() url.Values {
23222322
}
23232323
if v, found := p.p["details"]; found {
23242324
m := v.(map[string]string)
2325-
for i, k := range getSortedKeysFromMap(m) {
2326-
u.Set(fmt.Sprintf("details[%d].%s", i, k), m[k])
2325+
for _, k := range getSortedKeysFromMap(m) {
2326+
u.Set(fmt.Sprintf("details[0].%s", k), m[k])
23272327
}
23282328
}
23292329
if v, found := p.p["directdownload"]; found {
@@ -2906,8 +2906,8 @@ func (p *UpdateTemplateParams) toURLValues() url.Values {
29062906
}
29072907
if v, found := p.p["details"]; found {
29082908
m := v.(map[string]string)
2909-
for i, k := range getSortedKeysFromMap(m) {
2910-
u.Set(fmt.Sprintf("details[%d].%s", i, k), m[k])
2909+
for _, k := range getSortedKeysFromMap(m) {
2910+
u.Set(fmt.Sprintf("details[0].%s", k), m[k])
29112911
}
29122912
}
29132913
if v, found := p.p["displaytext"]; found {

generate/generate.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ var detailsRequireKeyValue = map[string]bool{
4949
"updateZone": true,
5050
}
5151

52+
// detailsRequireZeroIndex is a prefilled map with a list of details
53+
// that need to be encoded using zero indexing
54+
var detailsRequireZeroIndex = map[string]bool{
55+
"registerTemplate": true,
56+
"updateTemplate": true,
57+
}
58+
5259
var mapRequireList = map[string]map[string]bool{
5360
"deployVirtualMachine": map[string]bool{
5461
"dhcpoptionsnetworklist": true,
@@ -1295,14 +1302,23 @@ func (s *service) generateConvertCode(cmd, name, typ string) {
12951302
pn("}")
12961303
case "map[string]string":
12971304
pn("m := v.(map[string]string)")
1298-
pn("for i, k := range getSortedKeysFromMap(m) {")
1305+
zeroIndex := detailsRequireZeroIndex[cmd]
1306+
if zeroIndex {
1307+
pn("for _, k := range getSortedKeysFromMap(m) {")
1308+
} else {
1309+
pn("for i, k := range getSortedKeysFromMap(m) {")
1310+
}
12991311
switch name {
13001312
case "details":
13011313
if detailsRequireKeyValue[cmd] {
13021314
pn(" u.Set(fmt.Sprintf(\"%s[%%d].key\", i), k)", name)
13031315
pn(" u.Set(fmt.Sprintf(\"%s[%%d].value\", i), m[k])", name)
13041316
} else {
1305-
pn(" u.Set(fmt.Sprintf(\"%s[%%d].%%s\", i, k), m[k])", name)
1317+
if zeroIndex {
1318+
pn(" u.Set(fmt.Sprintf(\"%s[0].%%s\", k), m[k])", name)
1319+
} else {
1320+
pn(" u.Set(fmt.Sprintf(\"%s[%%d].%%s\", i, k), m[k])", name)
1321+
}
13061322
}
13071323
case "serviceproviderlist":
13081324
pn(" u.Set(fmt.Sprintf(\"%s[%%d].service\", i), k)", name)

0 commit comments

Comments
 (0)