MCPcopy Create free account
hub / github.com/cli/cli / getSSHKey

Function getSSHKey

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

Source from the content-addressed store, hash-verified

38}
39
40func getSSHKey(httpClient *http.Client, host string, keyID string) (*sshKey, error) {
41 url, err := safeurl.JoinPathWithHostPrefix(ghinstance.RESTPrefix(host), "user", "keys", keyID)
42 if err != nil {
43 return nil, err
44 }
45 req, err := http.NewRequest("GET", url.String(), nil)
46 if err != nil {
47 return nil, err
48 }
49
50 resp, err := httpClient.Do(req)
51 if err != nil {
52 return nil, err
53 }
54 defer resp.Body.Close()
55
56 if resp.StatusCode > 299 {
57 return nil, api.HandleHTTPError(resp)
58 }
59
60 b, err := io.ReadAll(resp.Body)
61 if err != nil {
62 return nil, err
63 }
64
65 var key sshKey
66 err = json.Unmarshal(b, &key)
67 if err != nil {
68 return nil, err
69 }
70
71 return &key, nil
72}

Callers 1

deleteRunFunction · 0.85

Calls 6

JoinPathWithHostPrefixFunction · 0.92
RESTPrefixFunction · 0.92
HandleHTTPErrorFunction · 0.92
StringMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected