@@ -106,7 +106,7 @@ func stringToImageStatus(s string) (ImageStatus, error) {
106
106
} else if s == "active" {
107
107
return ImageStatusActive , nil
108
108
} else {
109
- return "" , errors .New (fmt .Sprintf ("expected \" active\" as image status, but found: \" %s\" " , s ))
109
+ return "" , errors .New (fmt .Sprintf ("expected \" queued \" or \" active\" as image status, but found: \" %s\" " , s ))
110
110
}
111
111
}
112
112
@@ -122,6 +122,28 @@ func extractImageStatusAtKey(m map[string]interface{}, k string) (ImageStatus, e
122
122
}
123
123
}
124
124
125
+ func stringToImageVisibility (s string ) (ImageVisibility , error ) {
126
+ if s == "public" {
127
+ return ImageVisibilityPublic , nil
128
+ } else if s == "private" {
129
+ return ImageVisibilityPrivate , nil
130
+ } else {
131
+ return "" , errors .New (fmt .Sprintf ("expected \" public\" or \" private\" as image status, but found: \" %s\" " , s ))
132
+ }
133
+ }
134
+
135
+ func extractImageVisibilityAtKey (m map [string ]interface {}, k string ) (ImageVisibility , error ) {
136
+ if any , ok := m [k ]; ok {
137
+ if str , ok := any .(string ); ok {
138
+ return stringToImageVisibility (str )
139
+ } else {
140
+ return "" , errors .New (fmt .Sprintf ("expected string as \" %s\" value, but found: %#v" , k , any ))
141
+ }
142
+ } else {
143
+ return "" , errors .New (fmt .Sprintf ("expected key \" %s\" in map, but this key is not present" , k ))
144
+ }
145
+ }
146
+
125
147
func extractImage (res gophercloud.ErrResult ) (* Image , error ) {
126
148
if res .Err != nil {
127
149
return nil , res .Err
@@ -167,6 +189,10 @@ func extractImage(res gophercloud.ErrResult) (*Image, error) {
167
189
if image .Protected , err = extractBoolAtKey (body , "protected" ); err != nil {
168
190
return nil , err
169
191
}
192
+
193
+ if image .Visibility , err = extractImageVisibilityAtKey (body , "visibility" ); err != nil {
194
+ return nil , err
195
+ }
170
196
171
197
return & image , nil
172
198
}
0 commit comments