Skip to content

Commit e2d3072

Browse files
authored
Fix panic when serializing UUID-typed request parameters (#160)
generateConvertCode treated the generated "UUID" Go type the same as "string" when building toURLValues(), emitting v.(string) for a value that is actually stored as cloudstack.UUID. That type assertion panics at runtime since Go requires an exact dynamic type match. Affects managementserverid, currently the only parameter routed through the UUID type, on listAsyncJobs, listHosts, listHostsMetrics, triggerShutdown, cancelShutdown, prepareForShutdown, listWebhookDeliveries, and deleteWebhookDelivery. It was previously dormant since the parameter is optional on all of them and the setter was never exercised by the standard generated tests. Assert the value as UUID and convert to string, instead of asserting it as string.
1 parent 70fb49a commit e2d3072

5 files changed

Lines changed: 12 additions & 10 deletions

File tree

‎cloudstack/AsyncjobService.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (p *ListAsyncJobsParams) toURLValues() url.Values {
6060
u.Set("listall", vv)
6161
}
6262
if v, found := p.p["managementserverid"]; found {
63-
u.Set("managementserverid", v.(string))
63+
u.Set("managementserverid", string(v.(UUID)))
6464
}
6565
if v, found := p.p["page"]; found {
6666
vv := strconv.Itoa(v.(int))

‎cloudstack/HostService.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2842,7 +2842,7 @@ func (p *ListHostsParams) toURLValues() url.Values {
28422842
u.Set("keyword", v.(string))
28432843
}
28442844
if v, found := p.p["managementserverid"]; found {
2845-
u.Set("managementserverid", v.(string))
2845+
u.Set("managementserverid", string(v.(UUID)))
28462846
}
28472847
if v, found := p.p["name"]; found {
28482848
u.Set("name", v.(string))
@@ -3546,7 +3546,7 @@ func (p *ListHostsMetricsParams) toURLValues() url.Values {
35463546
u.Set("keyword", v.(string))
35473547
}
35483548
if v, found := p.p["managementserverid"]; found {
3549-
u.Set("managementserverid", v.(string))
3549+
u.Set("managementserverid", string(v.(UUID)))
35503550
}
35513551
if v, found := p.p["name"]; found {
35523552
u.Set("name", v.(string))

‎cloudstack/ManagementService.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (p *CancelShutdownParams) toURLValues() url.Values {
5858
return u
5959
}
6060
if v, found := p.p["managementserverid"]; found {
61-
u.Set("managementserverid", v.(string))
61+
u.Set("managementserverid", string(v.(UUID)))
6262
}
6363
return u
6464
}
@@ -765,7 +765,7 @@ func (p *PrepareForShutdownParams) toURLValues() url.Values {
765765
return u
766766
}
767767
if v, found := p.p["managementserverid"]; found {
768-
u.Set("managementserverid", v.(string))
768+
u.Set("managementserverid", string(v.(UUID)))
769769
}
770770
return u
771771
}
@@ -838,7 +838,7 @@ func (p *ReadyForShutdownParams) toURLValues() url.Values {
838838
return u
839839
}
840840
if v, found := p.p["managementserverid"]; found {
841-
u.Set("managementserverid", v.(string))
841+
u.Set("managementserverid", string(v.(UUID)))
842842
}
843843
return u
844844
}
@@ -914,7 +914,7 @@ func (p *TriggerShutdownParams) toURLValues() url.Values {
914914
return u
915915
}
916916
if v, found := p.p["managementserverid"]; found {
917-
u.Set("managementserverid", v.(string))
917+
u.Set("managementserverid", string(v.(UUID)))
918918
}
919919
return u
920920
}

‎cloudstack/WebhookService.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ func (p *DeleteWebhookDeliveryParams) toURLValues() url.Values {
458458
u.Set("id", v.(string))
459459
}
460460
if v, found := p.p["managementserverid"]; found {
461-
u.Set("managementserverid", v.(string))
461+
u.Set("managementserverid", string(v.(UUID)))
462462
}
463463
if v, found := p.p["startdate"]; found {
464464
u.Set("startdate", v.(string))
@@ -878,7 +878,7 @@ func (p *ListWebhookDeliveriesParams) toURLValues() url.Values {
878878
u.Set("keyword", v.(string))
879879
}
880880
if v, found := p.p["managementserverid"]; found {
881-
u.Set("managementserverid", v.(string))
881+
u.Set("managementserverid", string(v.(UUID)))
882882
}
883883
if v, found := p.p["page"]; found {
884884
vv := strconv.Itoa(v.(int))

‎generate/generate.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1355,8 +1355,10 @@ func (s *service) generateConvertCode(cmd, name, typ string) {
13551355
pn := s.pn
13561356

13571357
switch typ {
1358-
case "string", "UUID":
1358+
case "string":
13591359
pn("u.Set(\"%s\", v.(string))", name)
1360+
case "UUID":
1361+
pn("u.Set(\"%s\", string(v.(UUID)))", name)
13601362
case "int":
13611363
pn("vv := strconv.Itoa(v.(int))")
13621364
pn("u.Set(\"%s\", vv)", name)

0 commit comments

Comments
 (0)