Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 970e97f

Browse files
James FisherSamuel Ortiz
authored andcommitted
extract Metadata
1 parent d0109db commit 970e97f

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

openstack/imageservice/v2/requests_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ func TestCreateImage(t *testing.T) {
4040
Owner: "b4eedccc6fb74fa8a7ad6b08382b852b",
4141

4242
Visibility: ImageVisibilityPrivate,
43+
44+
Metadata: make(map[string]string),
4345
}
4446

4547
th.AssertDeepEquals(t, &expectedImage, actualImage)
@@ -78,6 +80,8 @@ func TestGetImage(t *testing.T) {
7880

7981
Checksum: &checksum,
8082
SizeBytes: &sizebytes,
83+
84+
Metadata: make(map[string]string),
8185
}
8286

8387
th.AssertDeepEquals(t, &expectedImage, actualImage)

openstack/imageservice/v2/results.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package v2
33
import (
44
"errors"
55
"fmt"
6-
"reflect"
76

87
"github.com/rackspace/gophercloud"
98
//"github.com/rackspace/gophercloud/pagination"
@@ -101,7 +100,15 @@ func asNoneableInteger(any interface{}) (*int, error) {
101100
return nil, errors.New(fmt.Sprintf("expected \"None\" or integer value, but found unexpected string: \"%s\"", s))
102101
}
103102
} else {
104-
return nil, errors.New(fmt.Sprintf("expected \"None\" or integer value, but found: %#v of type %s", any, reflect.TypeOf(any)))
103+
return nil, errors.New(fmt.Sprintf("expected \"None\" or integer value, but found: %T(%#v)", any, any))
104+
}
105+
}
106+
107+
func asMapStringString(any interface{}) (map[string]string, error) {
108+
if mss, ok := any.(map[string]string); ok {
109+
return mss, nil
110+
} else {
111+
return nil, errors.New(fmt.Sprintf("expected map[string]string, but found: %#v", any))
105112
}
106113
}
107114

@@ -208,6 +215,14 @@ func extractImageVisibilityAtKey(m map[string]interface{}, k string) (ImageVisib
208215
}
209216
}
210217

218+
func extractMapStringStringAtKeyOptional(m map[string]interface{}, k string, ifMissing map[string]string) (map[string]string, error) {
219+
if any, ok := m[k]; ok {
220+
return asMapStringString(any)
221+
} else {
222+
return ifMissing, nil
223+
}
224+
}
225+
211226
func extractImage(res gophercloud.ErrResult) (*Image, error) {
212227
if res.Err != nil {
213228
return nil, res.Err
@@ -274,6 +289,10 @@ func extractImage(res gophercloud.ErrResult) (*Image, error) {
274289
return nil, err
275290
}
276291

292+
if image.Metadata, err = extractMapStringStringAtKeyOptional(body, "metadata", make(map[string]string)); err != nil {
293+
return nil, err
294+
}
295+
277296
// TODO Metadata map[string]string `mapstructure:"metadata"`
278297
// TODO Properties map[string]string `mapstructure:"properties"`
279298

0 commit comments

Comments
 (0)