forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cacert.go
46 lines (39 loc) · 1.08 KB
/
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"
"path/filepath"
s2igit "github.com/openshift/source-to-image/pkg/scm/git"
)
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 s2igit.URL
}
// Setup creates a .gitconfig fragment that points to the given ca.crt
func (s CACert) Setup(baseDir string, context SCMAuthContext) error {
if !(s.SourceURL.Type == s2igit.URLTypeURL && s.SourceURL.URL.Scheme == "https" && s.SourceURL.URL.Opaque == "") {
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
}