(s *schema.Schema, identifier string)
| 202 | } |
| 203 | |
| 204 | func (gohanClientCLI *GohanClientCLI) getResourceID(s *schema.Schema, identifier string) (string, error) { |
| 205 | url := fmt.Sprintf("%s%s/%s", gohanClientCLI.opts.gohanEndpointURL, s.URL, u.QueryEscape(identifier)) |
| 206 | gohanClientCLI.logRequest("GET", url, gohanClientCLI.provider.TokenID, nil) |
| 207 | _, err := gohanClientCLI.handleResponse(gohanClientCLI.provider.Request(http.MethodGet, url, &gophercloud.RequestOpts{})) |
| 208 | if err == nil { |
| 209 | return identifier, nil |
| 210 | } |
| 211 | |
| 212 | url = fmt.Sprintf("%s%s?name=%s", gohanClientCLI.opts.gohanEndpointURL, s.URL, u.QueryEscape(identifier)) |
| 213 | gohanClientCLI.logRequest("GET", url, gohanClientCLI.provider.TokenID, nil) |
| 214 | result, err := gohanClientCLI.handleResponse(gohanClientCLI.provider.Request(http.MethodGet, url, &gophercloud.RequestOpts{})) |
| 215 | if err != nil { |
| 216 | return "", err |
| 217 | } |
| 218 | resourcesMap, ok := result.(map[string]interface{}) |
| 219 | if !ok { |
| 220 | return "", fmt.Errorf(resourceNotFoundError) |
| 221 | } |
| 222 | resources, ok := resourcesMap[s.Plural].([]interface{}) |
| 223 | if !ok { |
| 224 | return "", fmt.Errorf(resourceNotFoundError) |
| 225 | } |
| 226 | |
| 227 | if len(resources) == 1 { |
| 228 | return resources[0].(map[string]interface{})["id"].(string), nil |
| 229 | } |
| 230 | if len(resources) > 1 { |
| 231 | return "", fmt.Errorf(multipleResourcesFoundError, s.Plural, identifier) |
| 232 | } |
| 233 | |
| 234 | return "", fmt.Errorf(resourceNotFoundError) |
| 235 | } |
no test coverage detected