Skip to content

Commit 0e8ffcb

Browse files
committed
Don't decode user_data
1 parent c5d03df commit 0e8ffcb

2 files changed

Lines changed: 2 additions & 33 deletions

File tree

openstack/compute/v2/extensions/extendedserverattributes/results.go

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
package extendedserverattributes
22

3-
import (
4-
"encoding/base64"
5-
"encoding/json"
6-
)
7-
83
// ServerAttributesExt represents basic OS-EXT-SRV-ATTR server response fields.
94
// You should use extract methods from microversions.go to retrieve additional
105
// fields.
@@ -45,31 +40,5 @@ type ServerAttributesExt struct {
4540

4641
// Userdata is the userdata of the instance.
4742
// This requires microversion 2.3 or later.
48-
Userdata *string `json:"-"`
49-
}
50-
51-
func (r *ServerAttributesExt) UnmarshalJSON(b []byte) error {
52-
type tmp ServerAttributesExt
53-
var s struct {
54-
tmp
55-
Userdata *string `json:"OS-EXT-SRV-ATTR:user_data"`
56-
}
57-
err := json.Unmarshal(b, &s)
58-
if err != nil {
59-
return err
60-
}
61-
62-
*r = ServerAttributesExt(s.tmp)
63-
64-
if s.Userdata != nil {
65-
r.Userdata = new(string)
66-
if v, err := base64.StdEncoding.DecodeString(*s.Userdata); err != nil {
67-
r.Userdata = s.Userdata
68-
} else {
69-
v := string(v)
70-
r.Userdata = &v
71-
}
72-
}
73-
74-
return err
43+
Userdata *string `json:"OS-EXT-SRV-ATTR:user_data"`
7544
}

openstack/compute/v2/extensions/extendedserverattributes/testing/requests_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestServerWithUsageExt(t *testing.T) {
3636
th.AssertEquals(t, serverWithAttributesExt.Host, "compute01")
3737
th.AssertEquals(t, serverWithAttributesExt.InstanceName, "instance-00000001")
3838
th.AssertEquals(t, serverWithAttributesExt.HypervisorHostname, "compute01")
39-
th.AssertEquals(t, *serverWithAttributesExt.Userdata, "foo")
39+
th.AssertEquals(t, *serverWithAttributesExt.Userdata, "Zm9v")
4040
th.AssertEquals(t, *serverWithAttributesExt.ReservationID, "r-ky9gim1l")
4141
th.AssertEquals(t, *serverWithAttributesExt.LaunchIndex, 0)
4242
th.AssertEquals(t, *serverWithAttributesExt.Hostname, "test00")

0 commit comments

Comments
 (0)