-
Notifications
You must be signed in to change notification settings - Fork 7
/
createAccount.go
85 lines (73 loc) · 1.98 KB
/
createAccount.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
Copyright © 2024 Savely Krasovsky <savely@krasovs.ky>
*/
package cmd
import (
"context"
"encoding/json"
"fmt"
"io"
"strings"
comatproto "github.com/bluesky-social/indigo/api/atproto"
"github.com/bluesky-social/indigo/util/cliutil"
"github.com/bluesky-social/indigo/xrpc"
"github.com/spf13/cobra"
)
// createAccountCmd represents the createAccount command
var createAccountCmd = &cobra.Command{
Use: "createAccount",
Short: "Allows to create account at chosen PDS",
RunE: createAccount,
}
var (
pds string
inviteCode string
email string
password string
)
func init() {
rootCmd.AddCommand(createAccountCmd)
createAccountCmd.Flags().StringVar(&pds, "pds", "", "PDS URL")
createAccountCmd.MarkFlagRequired("pds")
createAccountCmd.Flags().StringVar(&handle, "handle", "", "Your handle")
createAccountCmd.MarkFlagRequired("handle")
createAccountCmd.Flags().StringVar(&inviteCode, "invite", "", "Invite code")
createAccountCmd.MarkFlagRequired("invite")
createAccountCmd.Flags().StringVar(&email, "email", "", "Initial email")
createAccountCmd.MarkFlagRequired("email")
createAccountCmd.Flags().StringVar(&password, "password", "", "Initial password")
createAccountCmd.MarkFlagRequired("password")
}
func createAccount(cmd *cobra.Command, args []string) error {
rawStr, err := io.ReadAll(cmd.InOrStdin())
if err != nil {
return err
}
jwtToken := strings.TrimSpace(string(rawStr))
client := &xrpc.Client{
Client: cliutil.NewHttpClient(),
Host: pds,
Auth: &xrpc.AuthInfo{
AccessJwt: jwtToken,
Handle: handle,
Did: "did:web:" + handle,
},
}
did := "did:web:" + handle
acc, err := comatproto.ServerCreateAccount(context.TODO(), client, &comatproto.ServerCreateAccount_Input{
Did: &did,
Email: &email,
Handle: handle,
InviteCode: &inviteCode,
Password: &password,
})
if err != nil {
return err
}
b, err := json.MarshalIndent(acc, "", " ")
if err != nil {
return err
}
fmt.Println(string(b))
return nil
}