(urlString string, action SmartServiceAction)
| 67 | } |
| 68 | |
| 69 | func (t *sshSmartSubtransport) Action(urlString string, action SmartServiceAction) (SmartSubtransportStream, error) { |
| 70 | runtime.LockOSThread() |
| 71 | defer runtime.UnlockOSThread() |
| 72 | |
| 73 | u, err := url.Parse(urlString) |
| 74 | if err != nil { |
| 75 | return nil, err |
| 76 | } |
| 77 | |
| 78 | // Escape \ and '. |
| 79 | uPath := strings.Replace(u.Path, `\`, `\\`, -1) |
| 80 | uPath = strings.Replace(uPath, `'`, `\'`, -1) |
| 81 | |
| 82 | // TODO: Add percentage decode similar to libgit2. |
| 83 | // Refer: https://github.com/libgit2/libgit2/blob/358a60e1b46000ea99ef10b4dd709e92f75ff74b/src/str.c#L455-L481 |
| 84 | |
| 85 | var cmd string |
| 86 | switch action { |
| 87 | case SmartServiceActionUploadpackLs, SmartServiceActionUploadpack: |
| 88 | if t.currentStream != nil { |
| 89 | if t.lastAction == SmartServiceActionUploadpackLs { |
| 90 | return t.currentStream, nil |
| 91 | } |
| 92 | t.Close() |
| 93 | } |
| 94 | cmd = fmt.Sprintf("git-upload-pack '%s'", uPath) |
| 95 | |
| 96 | case SmartServiceActionReceivepackLs, SmartServiceActionReceivepack: |
| 97 | if t.currentStream != nil { |
| 98 | if t.lastAction == SmartServiceActionReceivepackLs { |
| 99 | return t.currentStream, nil |
| 100 | } |
| 101 | t.Close() |
| 102 | } |
| 103 | cmd = fmt.Sprintf("git-receive-pack '%s'", uPath) |
| 104 | |
| 105 | default: |
| 106 | return nil, fmt.Errorf("unexpected action: %v", action) |
| 107 | } |
| 108 | |
| 109 | cred, err := t.transport.SmartCredentials("", CredentialTypeSSHKey|CredentialTypeSSHMemory) |
| 110 | if err != nil { |
| 111 | return nil, err |
| 112 | } |
| 113 | defer cred.Free() |
| 114 | |
| 115 | sshConfig, err := getSSHConfigFromCredential(cred) |
| 116 | if err != nil { |
| 117 | return nil, err |
| 118 | } |
| 119 | sshConfig.HostKeyCallback = func(hostname string, remote net.Addr, key ssh.PublicKey) error { |
| 120 | marshaledKey := key.Marshal() |
| 121 | cert := &Certificate{ |
| 122 | Kind: CertificateHostkey, |
| 123 | Hostkey: HostkeyCertificate{ |
| 124 | Kind: HostkeySHA1 | HostkeyMD5 | HostkeySHA256 | HostkeyRaw, |
| 125 | HashMD5: md5.Sum(marshaledKey), |
| 126 | HashSHA1: sha1.Sum(marshaledKey), |
nothing calls this directly
no test coverage detected