this repo has no description
1package git
2
3import (
4 "os"
5
6 "github.com/go-git/go-git/v5/plumbing/transport"
7 "github.com/go-git/go-git/v5/plumbing/transport/http"
8 "github.com/go-git/go-git/v5/plumbing/transport/ssh"
9)
10
11func GetAuth() (transport.AuthMethod, error) {
12
13 if sshKey, exists := os.LookupEnv("NOX_GIT_SSH_KEY_FILE"); exists {
14 pemBytes, err := os.ReadFile(sshKey)
15 if err != nil {
16 return nil, err
17 }
18 passPhrase := ""
19 if sshPass, exists := os.LookupEnv("NOX_GIT_SSH_KEY_PASSWORD"); exists {
20 passPhrase = sshPass
21 }
22
23 pubKey, err := ssh.NewPublicKeys("git", pemBytes, passPhrase)
24 if err != nil {
25 return nil, err
26 }
27
28 return pubKey, nil
29 }
30
31 if gitToken, exists := os.LookupEnv("NOX_GIT_TOKEN"); exists {
32 return &http.BasicAuth{
33 Username: "nox",
34 Password: gitToken,
35 }, nil
36 }
37 return nil, nil
38}