(httpClient *http.Client, host string, keyID string)
| 35 | } |
| 36 | |
| 37 | func getSSHKey(httpClient *http.Client, host string, keyID string) (*sshKey, error) { |
| 38 | url := fmt.Sprintf("%suser/keys/%s", ghinstance.RESTPrefix(host), keyID) |
| 39 | req, err := http.NewRequest("GET", url, nil) |
| 40 | if err != nil { |
| 41 | return nil, err |
| 42 | } |
| 43 | |
| 44 | resp, err := httpClient.Do(req) |
| 45 | if err != nil { |
| 46 | return nil, err |
| 47 | } |
| 48 | defer resp.Body.Close() |
| 49 | |
| 50 | if resp.StatusCode > 299 { |
| 51 | return nil, api.HandleHTTPError(resp) |
| 52 | } |
| 53 | |
| 54 | b, err := io.ReadAll(resp.Body) |
| 55 | if err != nil { |
| 56 | return nil, err |
| 57 | } |
| 58 | |
| 59 | var key sshKey |
| 60 | err = json.Unmarshal(b, &key) |
| 61 | if err != nil { |
| 62 | return nil, err |
| 63 | } |
| 64 | |
| 65 | return &key, nil |
| 66 | } |
no test coverage detected