MCPcopy Index your code
hub / github.com/cli/cli / automaticSSHKeyPair

Function automaticSSHKeyPair

pkg/cmd/codespace/ssh.go:383–407  ·  view source on GitHub ↗

automaticSSHKeyPair returns the paths to the automatic key pair files, if they both exist

(sshContext ssh.Context)

Source from the content-addressed store, hash-verified

381
382// automaticSSHKeyPair returns the paths to the automatic key pair files, if they both exist
383func automaticSSHKeyPair(sshContext ssh.Context) *ssh.KeyPair {
384 publicKeys, err := sshContext.LocalPublicKeys()
385 if err != nil {
386 // The error would be that the .ssh dir doesn't exist, which just means that the keypair also doesn't exist
387 return nil
388 }
389
390 for _, publicKey := range publicKeys {
391 if filepath.Base(publicKey) != automaticPrivateKeyName+".pub" {
392 continue
393 }
394
395 privateKey := strings.TrimSuffix(publicKey, ".pub")
396
397 _, err := os.Stat(privateKey)
398 if err == nil {
399 return &ssh.KeyPair{
400 PrivateKeyPath: privateKey,
401 PublicKeyPath: publicKey,
402 }
403 }
404 }
405
406 return nil
407}
408
409func generateAutomaticSSHKeys(sshContext ssh.Context) (*ssh.KeyPair, error) {
410 keyPair := checkAndUpdateOldKeyPair(sshContext)

Callers 1

selectSSHKeysFunction · 0.85

Calls 2

LocalPublicKeysMethod · 0.80
BaseMethod · 0.80

Tested by

no test coverage detected