Skip to content

Commit aa33ae5

Browse files
committed
feat: atproto auth & persistence
* added TUI (form) for auth
1 parent a05250d commit aa33ae5

File tree

10 files changed

+1700
-42
lines changed

10 files changed

+1700
-42
lines changed

cmd/publication_commands.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
// TODO: implement prompt for password
2-
//
3-
// See: https://github.com/charmbracelet/bubbletea/blob/main/examples/textinputs/main.go
41
package main
52

63
import (
74
"fmt"
85

96
"github.com/spf13/cobra"
107
"github.com/stormlightlabs/noteleaf/internal/handlers"
8+
"github.com/stormlightlabs/noteleaf/internal/ui"
119
)
1210

1311
// PublicationCommand implements [CommandGroup] for leaflet publication commands
@@ -52,7 +50,7 @@ For the password, use an app password (not your main password):
5250
2. Create a new app password named "noteleaf"
5351
3. Use that password here
5452
55-
The password will be prompted securely if not provided via flag.`,
53+
If credentials are not provided via flags, use the interactive input.`,
5654
Args: cobra.MaximumNArgs(1),
5755
RunE: func(cmd *cobra.Command, args []string) error {
5856
var handle string
@@ -62,19 +60,26 @@ The password will be prompted securely if not provided via flag.`,
6260

6361
password, _ := cmd.Flags().GetString("password")
6462

65-
if handle == "" {
66-
return fmt.Errorf("handle is required")
63+
if handle != "" && password != "" {
64+
defer c.handler.Close()
65+
return c.handler.Auth(cmd.Context(), handle, password)
6766
}
6867

69-
if password == "" {
70-
return fmt.Errorf("password is required (use --password flag)")
68+
form := ui.NewAuthForm(handle, ui.AuthFormOptions{})
69+
result, err := form.Run()
70+
if err != nil {
71+
return fmt.Errorf("failed to display auth form: %w", err)
72+
}
73+
74+
if result.Canceled {
75+
return fmt.Errorf("authentication canceled")
7176
}
7277

7378
defer c.handler.Close()
74-
return c.handler.Auth(cmd.Context(), handle, password)
79+
return c.handler.Auth(cmd.Context(), result.Handle, result.Password)
7580
},
7681
}
77-
authCmd.Flags().StringP("password", "p", "", "App password (will be prompted if not provided)")
82+
authCmd.Flags().StringP("password", "p", "", "App password (will prompt if not provided)")
7883
root.AddCommand(authCmd)
7984

8085
pullCmd := &cobra.Command{
@@ -96,7 +101,6 @@ Notes are matched by their leaflet record key (rkey) stored in the database.`,
96101
}
97102
root.AddCommand(pullCmd)
98103

99-
// List command
100104
listCmd := &cobra.Command{
101105
Use: "list [--published|--draft|--all]",
102106
Short: "List notes synced with leaflet",

go.mod

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,58 @@ require (
1616
)
1717

1818
require (
19+
github.com/bluesky-social/indigo v0.0.0-20251031012455-0b4bd2478a61
1920
github.com/gomarkdown/markdown v0.0.0-20250810172220-2e2c11897d1a
2021
github.com/jaswdr/faker/v2 v2.8.0
2122
)
2223

2324
require (
2425
github.com/cpuguy83/go-md2man/v2 v2.0.6 // indirect
26+
github.com/earthboundkid/versioninfo/v2 v2.24.1 // indirect
27+
github.com/felixge/httpsnoop v1.0.4 // indirect
28+
github.com/go-logr/logr v1.4.1 // indirect
29+
github.com/go-logr/stdr v1.2.2 // indirect
30+
github.com/gogo/protobuf v1.3.2 // indirect
31+
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
32+
github.com/hashicorp/go-retryablehttp v0.7.5 // indirect
33+
github.com/hashicorp/golang-lru v1.0.2 // indirect
34+
github.com/ipfs/bbloom v0.0.4 // indirect
35+
github.com/ipfs/go-block-format v0.2.0 // indirect
36+
github.com/ipfs/go-cid v0.4.1 // indirect
37+
github.com/ipfs/go-datastore v0.6.0 // indirect
38+
github.com/ipfs/go-ipfs-blockstore v1.3.1 // indirect
39+
github.com/ipfs/go-ipfs-ds-help v1.1.1 // indirect
40+
github.com/ipfs/go-ipfs-util v0.0.3 // indirect
41+
github.com/ipfs/go-ipld-cbor v0.1.0 // indirect
42+
github.com/ipfs/go-ipld-format v0.6.0 // indirect
43+
github.com/ipfs/go-log v1.0.5 // indirect
44+
github.com/ipfs/go-log/v2 v2.5.1 // indirect
45+
github.com/ipfs/go-metrics-interface v0.0.1 // indirect
46+
github.com/jbenet/goprocess v0.1.4 // indirect
47+
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
48+
github.com/minio/sha256-simd v1.0.1 // indirect
49+
github.com/mr-tron/base58 v1.2.0 // indirect
50+
github.com/multiformats/go-base32 v0.1.0 // indirect
51+
github.com/multiformats/go-base36 v0.2.0 // indirect
52+
github.com/multiformats/go-multibase v0.2.0 // indirect
53+
github.com/multiformats/go-multihash v0.2.3 // indirect
54+
github.com/multiformats/go-varint v0.0.7 // indirect
55+
github.com/opentracing/opentracing-go v1.2.0 // indirect
56+
github.com/polydawn/refmt v0.89.1-0.20221221234430-40501e09de1f // indirect
2557
github.com/russross/blackfriday/v2 v2.1.0 // indirect
58+
github.com/spaolacci/murmur3 v1.1.0 // indirect
59+
github.com/whyrusleeping/cbor-gen v0.2.1-0.20241030202151-b7a6831be65e // indirect
60+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 // indirect
61+
go.opentelemetry.io/otel v1.21.0 // indirect
62+
go.opentelemetry.io/otel/metric v1.21.0 // indirect
63+
go.opentelemetry.io/otel/trace v1.21.0 // indirect
64+
go.uber.org/atomic v1.11.0 // indirect
65+
go.uber.org/multierr v1.11.0 // indirect
66+
go.uber.org/zap v1.26.0 // indirect
67+
golang.org/x/crypto v0.43.0 // indirect
68+
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
2669
gopkg.in/yaml.v3 v3.0.1 // indirect
70+
lukechampine.com/blake3 v1.2.1 // indirect
2771
)
2872

2973
require (
@@ -90,7 +134,7 @@ require (
90134
github.com/rivo/uniseg v0.4.7 // indirect
91135
github.com/spf13/pflag v1.0.6 // indirect
92136
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
93-
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
137+
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
94138
golang.org/x/sys v0.37.0 // indirect
95139
golang.org/x/text v0.30.0
96140
)

0 commit comments

Comments
 (0)