forked from plouc/go-gitlab-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy_keys.go
119 lines (79 loc) · 2.14 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
114
115
116
117
118
119
package gogitlab
import (
"encoding/json"
"net/url"
)
const (
// ID
project_url_deploy_keys = "/projects/:id/keys" // Get list of project deploy keys
// PROJECT ID AND KEY ID
project_url_deploy_key = "/projects/:id/keys/:key_id" // Get single project deploy key
)
/*
Get list of project deploy keys.
GET /projects/:id/keys
Parameters:
id The ID of a project
*/
func (g *Gitlab) ProjectDeployKeys(id string) ([]*PublicKey, error) {
url, opaque := g.ResourceUrlRaw(project_url_deploy_keys, map[string]string{":id": id})
var deployKeys []*PublicKey
contents, err := g.buildAndExecRequestRaw("GET", url, opaque, nil)
if err == nil {
err = json.Unmarshal(contents, &deployKeys)
}
return deployKeys, err
}
/*
Get single project deploy key.
GET /projects/:id/keys/:key_id
Parameters:
id The ID of a project
key_id The ID of a key
*/
func (g *Gitlab) ProjectDeployKey(id, key_id string) (*PublicKey, error) {
url, opaque := g.ResourceUrlRaw(project_url_deploy_key, map[string]string{
":id": id,
":key_id": key_id,
})
var deployKey *PublicKey
contents, err := g.buildAndExecRequestRaw("GET", url, opaque, nil)
if err == nil {
err = json.Unmarshal(contents, &deployKey)
}
return deployKey, 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) error {
path, opaque := g.ResourceUrlRaw(project_url_deploy_keys, map[string]string{":id": id})
var err error
v := url.Values{}
v.Set("title", title)
v.Set("key", key)
body := v.Encode()
_, err = g.buildAndExecRequestRaw("POST", path, opaque, []byte(body))
return err
}
/*
Remove deploy key from project
DELETE /projects/:id/keys/:key_id
Parameters:
id The ID of a project
key_id The ID of a key
*/
func (g *Gitlab) RemoveProjectDeployKey(id, key_id string) error {
url, opaque := g.ResourceUrlRaw(project_url_deploy_key, map[string]string{
":id": id,
":key_id": key_id,
})
var err error
_, err = g.buildAndExecRequestRaw("DELETE", url, opaque, nil)
return err
}