github.com/google/go-github/v74@v74.0.0/github/enterprise_manage_ghes_ssh.go (about) 1 // Copyright 2025 The go-github AUTHORS. All rights reserved. 2 // 3 // Use of this source code is governed by a BSD-style 4 // license that can be found in the LICENSE file. 5 6 package github 7 8 import ( 9 "context" 10 ) 11 12 // SSHKeyStatus represents the status of a SSH key operation. 13 type SSHKeyStatus struct { 14 Hostname *string `json:"hostname,omitempty"` 15 UUID *string `json:"uuid,omitempty"` 16 Message *string `json:"message,omitempty"` 17 Modified *bool `json:"modified,omitempty"` 18 } 19 20 // SSHKeyOptions specifies the parameters to the SSH create and delete functions. 21 type SSHKeyOptions struct { 22 // Key is the SSH key to add to the instance. 23 Key string `json:"key"` 24 } 25 26 // ClusterSSHKey represents the SSH keys configured for the instance. 27 type ClusterSSHKey struct { 28 Key *string `json:"key,omitempty"` 29 Fingerprint *string `json:"fingerprint,omitempty"` 30 } 31 32 // DeleteSSHKey deletes the SSH key from the instance. 33 // 34 // GitHub API docs: https://docs.github.com/enterprise-server@3.17/rest/enterprise-admin/manage-ghes#delete-a-ssh-key 35 // 36 //meta:operation DELETE /manage/v1/access/ssh 37 func (s *EnterpriseService) DeleteSSHKey(ctx context.Context, key string) ([]*SSHKeyStatus, *Response, error) { 38 u := "manage/v1/access/ssh" 39 opts := &SSHKeyOptions{ 40 Key: key, 41 } 42 req, err := s.client.NewRequest("DELETE", u, opts) 43 if err != nil { 44 return nil, nil, err 45 } 46 47 var sshStatus []*SSHKeyStatus 48 resp, err := s.client.Do(ctx, req, &sshStatus) 49 if err != nil { 50 return nil, resp, err 51 } 52 53 return sshStatus, resp, nil 54 } 55 56 // GetSSHKey gets the SSH keys configured for the instance. 57 // 58 // GitHub API docs: https://docs.github.com/enterprise-server@3.17/rest/enterprise-admin/manage-ghes#get-the-configured-ssh-keys 59 // 60 //meta:operation GET /manage/v1/access/ssh 61 func (s *EnterpriseService) GetSSHKey(ctx context.Context) ([]*ClusterSSHKey, *Response, error) { 62 u := "manage/v1/access/ssh" 63 req, err := s.client.NewRequest("GET", u, nil) 64 if err != nil { 65 return nil, nil, err 66 } 67 68 var sshKeys []*ClusterSSHKey 69 resp, err := s.client.Do(ctx, req, &sshKeys) 70 if err != nil { 71 return nil, resp, err 72 } 73 74 return sshKeys, resp, nil 75 } 76 77 // CreateSSHKey adds a new SSH key to the instance. 78 // 79 // GitHub API docs: https://docs.github.com/enterprise-server@3.17/rest/enterprise-admin/manage-ghes#set-a-new-ssh-key 80 // 81 //meta:operation POST /manage/v1/access/ssh 82 func (s *EnterpriseService) CreateSSHKey(ctx context.Context, key string) ([]*SSHKeyStatus, *Response, error) { 83 u := "manage/v1/access/ssh" 84 opts := &SSHKeyOptions{ 85 Key: key, 86 } 87 req, err := s.client.NewRequest("POST", u, opts) 88 if err != nil { 89 return nil, nil, err 90 } 91 92 var sshKeyResponse []*SSHKeyStatus 93 resp, err := s.client.Do(ctx, req, &sshKeyResponse) 94 if err != nil { 95 return nil, resp, err 96 } 97 98 return sshKeyResponse, resp, nil 99 }