forked from plouc/go-gitlab-client
/
deploy_keys.go
113 lines (77 loc) · 2.07 KB
/
deploy_keys.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package gitlab
import (
"encoding/json"
"net/url"
)
const (
ProjectDeployKeysApiPath = "/projects/:id/keys"
ProjectDeployKeyApiPath = "/projects/:id/keys/:key_id"
)
/*
Get list of project deploy keys.
GET /projects/:id/keys
Parameters:
id The ID of a project
*/
func (g *Gitlab) ProjectDeployKeys(id string) ([]*SshKey, *ResponseMeta, error) {
u := g.ResourceUrl(ProjectDeployKeysApiPath, map[string]string{":id": id})
var deployKeys []*SshKey
contents, meta, err := g.buildAndExecRequest("GET", u.String(), nil)
if err == nil {
err = json.Unmarshal(contents, &deployKeys)
}
return deployKeys, meta, err
}
/*
Get single project deploy key.
GET /projects/:id/keys/:key_id
Parameters:
id The ID of a project
keyId The ID of a key
*/
func (g *Gitlab) ProjectDeployKey(id, keyId string) (*SshKey, *ResponseMeta, error) {
u := g.ResourceUrl(ProjectDeployKeyApiPath, map[string]string{
":id": id,
":key_id": keyId,
})
var deployKey *SshKey
contents, meta, err := g.buildAndExecRequest("GET", u.String(), nil)
if err == nil {
err = json.Unmarshal(contents, &deployKey)
}
return deployKey, meta, err
}
/*
Add deploy key to project.
POST /projects/:id/keys
Parameters:
id The ID of a project
title The key title
key The key value
*/
func (g *Gitlab) AddProjectDeployKey(id, title, key string) (*ResponseMeta, error) {
u := g.ResourceUrl(ProjectDeployKeysApiPath, map[string]string{":id": id})
var err error
v := url.Values{}
v.Set("title", title)
v.Set("key", key)
body := v.Encode()
_, meta, err := g.buildAndExecRequest("POST", u.String(), []byte(body))
return meta, err
}
/*
Remove deploy key from project
DELETE /projects/:id/keys/:key_id
Parameters:
id The ID of a project
keyId The ID of a key
*/
func (g *Gitlab) RemoveProjectDeployKey(id, keyId string) (*ResponseMeta, error) {
u := g.ResourceUrl(ProjectDeployKeyApiPath, map[string]string{
":id": id,
":key_id": keyId,
})
var err error
_, meta, err := g.buildAndExecRequest("DELETE", u.String(), nil)
return meta, err
}