-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitlab.go
47 lines (39 loc) · 1.03 KB
/
gitlab.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
package vcs
import (
"context"
"net/http"
gogitlab "github.com/xanzy/go-gitlab"
)
const (
GitLabSSHKey = "gitlab.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAfuCHKVTjquxvt6CM6tdG4SLp1Btn/nOeHHE5UOzRdf"
)
type gitlabClient struct {
client *gogitlab.Client
}
func NewGitlabClient(httpClient *http.Client, token string) (*gitlabClient, error) {
client, err := gogitlab.NewClient(token, gogitlab.WithHTTPClient(httpClient))
if err != nil {
return nil, err
}
return &gitlabClient{
client: client,
}, nil
}
var _ providerClient = (*gitlabClient)(nil)
func (g *gitlabClient) CreateDeployKey(ctx context.Context, id string, opts ...deployKeyOption) (*deployKey, error) {
deployKey, err := genDeployKey(opts...)
if err != nil {
return nil, err
}
_, _, err = g.client.DeployKeys.AddDeployKey(id, &gogitlab.AddDeployKeyOptions{
Title: &deployKey.title,
Key: &deployKey.publicKeyOpenSSH,
})
if err != nil {
return nil, err
}
return deployKey, nil
}
func (g *gitlabClient) GetHostPublicSSHKey() string {
return GitLabSSHKey
}