mirror of
https://github.com/coalaura/up.git
synced 2025-07-17 21:44:35 +00:00
improved logging
This commit is contained in:
@ -7,7 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/urfave/cli/v3"
|
"github.com/urfave/cli/v3"
|
||||||
)
|
)
|
||||||
@ -50,16 +50,30 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func run(_ context.Context, cmd *cli.Command) error {
|
func run(_ context.Context, cmd *cli.Command) error {
|
||||||
kPath := cmd.String("key")
|
path := cmd.String("key")
|
||||||
if kPath == "" {
|
if path == "" {
|
||||||
return errors.New("missing private key")
|
return errors.New("missing private key")
|
||||||
}
|
}
|
||||||
|
|
||||||
fPath := cmd.String("file")
|
kPath, err := filepath.Abs(path)
|
||||||
if fPath == "" {
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to get key path: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("using key %s", kPath)
|
||||||
|
|
||||||
|
path = cmd.String("file")
|
||||||
|
if path == "" {
|
||||||
return errors.New("missing file")
|
return errors.New("missing file")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fPath, err := filepath.Abs(path)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to get file path: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("using file %s", fPath)
|
||||||
|
|
||||||
file, err := os.OpenFile(fPath, os.O_RDONLY, 0)
|
file, err := os.OpenFile(fPath, os.O_RDONLY, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to open file: %v", err)
|
return fmt.Errorf("failed to open file: %v", err)
|
||||||
@ -72,11 +86,11 @@ func run(_ context.Context, cmd *cli.Command) error {
|
|||||||
return errors.New("missing target")
|
return errors.New("missing target")
|
||||||
}
|
}
|
||||||
|
|
||||||
if colon := strings.Index(target, ":"); colon != -1 {
|
target = fmt.Sprintf("https://%s", target)
|
||||||
target = fmt.Sprintf("http://%s", target)
|
|
||||||
} else {
|
log.Printf("using target %s", target)
|
||||||
target = fmt.Sprintf("https://%s", target)
|
|
||||||
}
|
log.Printf("loading key")
|
||||||
|
|
||||||
private, err := LoadPrivateKey(kPath)
|
private, err := LoadPrivateKey(kPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -85,19 +99,21 @@ func run(_ context.Context, cmd *cli.Command) error {
|
|||||||
|
|
||||||
public := base64.StdEncoding.EncodeToString(private.PublicKey().Marshal())
|
public := base64.StdEncoding.EncodeToString(private.PublicKey().Marshal())
|
||||||
|
|
||||||
log.Println("Requesting challenge...")
|
log.Println("requesting challenge")
|
||||||
|
|
||||||
challenge, err := RequestChallenge(target, public)
|
challenge, err := RequestChallenge(target, public)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("Completing challenge...")
|
log.Println("completing challenge")
|
||||||
|
|
||||||
response, err := CompleteChallenge(target, public, private, challenge)
|
response, err := CompleteChallenge(target, public, private, challenge)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Println("uploading file")
|
||||||
|
|
||||||
return SendFile(target, response.Token, file)
|
return SendFile(target, response.Token, file)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user