1 package gitlab
2
3 import (
4 "fmt"
5 "net/http"
6 "time"
7 )
8
9
10
11
12
13 type GroupSSHCertificatesService struct {
14 client *Client
15 }
16
17
18
19
20 type GroupSSHCertificate struct {
21 ID int `json:"id"`
22 Title string `json:"title"`
23 Key string `json:"key"`
24 CreatedAt *time.Time `json:"created_at"`
25 }
26
27
28
29
30
31
32 func (s *GroupSSHCertificatesService) ListGroupSSHCertificates(gid interface{}, options ...RequestOptionFunc) ([]*GroupSSHCertificate, *Response, error) {
33 group, err := parseID(gid)
34 if err != nil {
35 return nil, nil, err
36 }
37 u := fmt.Sprintf("groups/%s/ssh_certificates", PathEscape(group))
38
39 req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
40 if err != nil {
41 return nil, nil, err
42 }
43
44 var certs []*GroupSSHCertificate
45 resp, err := s.client.Do(req, &certs)
46 if err != nil {
47 return nil, resp, err
48 }
49
50 return certs, resp, nil
51 }
52
53
54
55
56
57
58 type CreateGroupSSHCertificateOptions struct {
59 Key *string `url:"key,omitempty" json:"key,omitempty"`
60 Title *string `url:"title,omitempty" json:"title,omitempty"`
61 }
62
63
64
65
66
67 func (s *GroupSSHCertificatesService) CreateGroupSSHCertificate(gid interface{}, opt *CreateGroupSSHCertificateOptions, options ...RequestOptionFunc) (*GroupSSHCertificate, *Response, error) {
68 group, err := parseID(gid)
69 if err != nil {
70 return nil, nil, err
71 }
72 u := fmt.Sprintf("groups/%s/ssh_certificates", PathEscape(group))
73
74 req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
75 if err != nil {
76 return nil, nil, err
77 }
78
79 cert := new(GroupSSHCertificate)
80 resp, err := s.client.Do(req, cert)
81 if err != nil {
82 return nil, resp, err
83 }
84
85 return cert, resp, nil
86 }
87
88
89
90
91
92 func (s *GroupSSHCertificatesService) DeleteGroupSSHCertificate(gid interface{}, cert int, options ...RequestOptionFunc) (*Response, error) {
93 group, err := parseID(gid)
94 if err != nil {
95 return nil, err
96 }
97 u := fmt.Sprintf("groups/%s/ssh_certificates/%d", PathEscape(group), cert)
98
99 req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
100 if err != nil {
101 return nil, err
102 }
103
104 return s.client.Do(req, nil)
105 }
106
View as plain text