MCPcopy Index your code
hub / github.com/cli/cli / getSSHKey

Function getSSHKey

pkg/cmd/ssh-key/delete/http.go:37–66  ·  view source on GitHub ↗
(httpClient *http.Client, host string, keyID string)

Source from the content-addressed store, hash-verified

35}
36
37func 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}

Callers 1

deleteRunFunction · 0.85

Calls 4

RESTPrefixFunction · 0.92
HandleHTTPErrorFunction · 0.92
DoMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected