forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cacert.go
46 lines (40 loc) · 1002 Bytes
/
cacert.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
package scmauth
import (
"fmt"
"io/ioutil"
"net/url"
"path/filepath"
"strings"
)
const (
CACertName = "ca.crt"
CACertConfig = `# SSL cert
[http]
sslCAInfo = %[1]s
`
)
// CACert implements SCMAuth interface for using a custom certificate authority
type CACert struct {
SourceURL url.URL
}
// Setup creates a .gitconfig fragment that points to the given ca.crt
func (s CACert) Setup(baseDir string, context SCMAuthContext) error {
if strings.ToLower(s.SourceURL.Scheme) != "https" {
return nil
}
gitconfig, err := ioutil.TempFile("", "ca.crt.")
if err != nil {
return err
}
defer gitconfig.Close()
gitconfig.WriteString(fmt.Sprintf(CACertConfig, filepath.Join(baseDir, CACertName)))
return ensureGitConfigIncludes(gitconfig.Name(), context)
}
// Name returns the name of this auth method.
func (_ CACert) Name() string {
return CACertName
}
// Handles returns true if the secret is a CA certificate
func (_ CACert) Handles(name string) bool {
return name == CACertName
}