/
keys.go
60 lines (50 loc) · 1.16 KB
/
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
package repo
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"runtime"
)
// sshKey is a type for a ssh key
type sshKey struct {
filename string
content []byte
}
// pgpKey is a type for a pgp key
type pgpKey struct {
name string
public string
private string
id string
}
func (r Repo) setupSSHKey() ([]string, error) {
if r.sshKey == nil {
return nil, fmt.Errorf("no ssh keys to setup")
}
gitSSHCmd := exec.Command("ssh").Path
gitSSHCmd += " -i " + r.sshKey.filename
gitSSHCmd += " -o IdentitiesOnly=yes"
gitSSHCmd += " -o StrictHostKeyChecking=no"
keyDir := filepath.Dir(r.sshKey.filename)
var wrapper, wrapperPath string
if runtime.GOOS == "windows" {
gitSSHCmd += ` %*`
wrapper = `@echo off
` + gitSSHCmd
wrapperPath = filepath.Join(keyDir, "gitwrapper.bat")
} else {
gitSSHCmd += ` "$@"`
wrapper = `#!/bin/sh
` + gitSSHCmd
wrapperPath = filepath.Join(keyDir, "gitwrapper")
}
if err := ioutil.WriteFile(wrapperPath, []byte(wrapper), os.FileMode(0700)); err != nil {
return nil, err
}
return []string{"GIT_SSH=" + wrapperPath, "PKEY=" + r.sshKey.filename}, nil
}
func (r Repo) installGPGKey() error {
return nil
}