errorsis
This commit is contained in:
parent
6b1b85ba3d
commit
0e01da82d6
@ -7,6 +7,7 @@ import (
|
|||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
@ -26,7 +27,7 @@ func privateKey() (ssh.Signer, error) {
|
|||||||
|
|
||||||
keyPath := filepath.Join(home, ".ollama", defaultPrivateKey)
|
keyPath := filepath.Join(home, ".ollama", defaultPrivateKey)
|
||||||
privateKeyFile, err := os.ReadFile(keyPath)
|
privateKeyFile, err := os.ReadFile(keyPath)
|
||||||
if os.IsNotExist(err) {
|
if errors.Is(err, os.ErrNotExist) {
|
||||||
err := initializeKeypair()
|
err := initializeKeypair()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -50,7 +51,7 @@ func GetPublicKey() (ssh.PublicKey, error) {
|
|||||||
|
|
||||||
pubkeyPath := filepath.Join(home, ".ollama", defaultPrivateKey+".pub")
|
pubkeyPath := filepath.Join(home, ".ollama", defaultPrivateKey+".pub")
|
||||||
pubKeyFile, err := os.ReadFile(pubkeyPath)
|
pubKeyFile, err := os.ReadFile(pubkeyPath)
|
||||||
if os.IsNotExist(err) {
|
if errors.Is(err, os.ErrNotExist) {
|
||||||
// try from privateKey
|
// try from privateKey
|
||||||
privateKey, err := privateKey()
|
privateKey, err := privateKey()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -113,7 +114,7 @@ func initializeKeypair() error {
|
|||||||
pubKeyPath := filepath.Join(home, ".ollama", "id_ed25519.pub")
|
pubKeyPath := filepath.Join(home, ".ollama", "id_ed25519.pub")
|
||||||
|
|
||||||
_, err = os.Stat(privKeyPath)
|
_, err = os.Stat(privKeyPath)
|
||||||
if os.IsNotExist(err) {
|
if errors.Is(err, os.ErrNotExist) {
|
||||||
fmt.Printf("Couldn't find '%s'. Generating new private key.\n", privKeyPath)
|
fmt.Printf("Couldn't find '%s'. Generating new private key.\n", privKeyPath)
|
||||||
cryptoPublicKey, cryptoPrivateKey, err := ed25519.GenerateKey(rand.Reader)
|
cryptoPublicKey, cryptoPrivateKey, err := ed25519.GenerateKey(rand.Reader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user