···
"github.com/haileyok/cocoon/server"
_ "github.com/joho/godotenv/autoload"
"github.com/urfave/cli/v2"
···
Commands: []*cli.Command{
···
-
var run = &cli.Command{
Usage: "Start the cocoon PDS",
···
···
+
"github.com/bluesky-social/indigo/atproto/crypto"
+
"github.com/bluesky-social/indigo/atproto/syntax"
+
"github.com/haileyok/cocoon/internal/helpers"
"github.com/haileyok/cocoon/server"
_ "github.com/joho/godotenv/autoload"
+
"github.com/lestrrat-go/jwx/v2/jwk"
"github.com/urfave/cli/v2"
+
"golang.org/x/crypto/bcrypt"
+
"gorm.io/driver/sqlite"
···
Commands: []*cli.Command{
···
+
var runServe = &cli.Command{
Usage: "Start the cocoon PDS",
···
+
var runCreateRotationKey = &cli.Command{
+
Name: "create-rotation-key",
+
Usage: "creates a rotation key for your pds",
+
Usage: "output file for your rotation key",
+
Action: func(cmd *cli.Context) error {
+
key, err := crypto.GeneratePrivateKeyK256()
+
if err := os.WriteFile(cmd.String("out"), bytes, 0644); err != nil {
+
var runCreatePrivateJwk = &cli.Command{
+
Name: "create-private-jwk",
+
Usage: "creates a private jwk for your pds",
+
Usage: "output file for your jwk",
+
Action: func(cmd *cli.Context) error {
+
privKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
+
key, err := jwk.FromRaw(privKey)
+
kid := fmt.Sprintf("%d", time.Now().Unix())
+
if err := key.Set(jwk.KeyIDKey, kid); err != nil {
+
b, err := json.Marshal(key)
+
if err := os.WriteFile(cmd.String("out"), b, 0644); err != nil {
+
var runCreateInviteCode = &cli.Command{
+
Name: "create-invite-code",
+
Usage: "creates an invite code",
+
Usage: "optional did to assign the invite code to",
+
Usage: "number of times the invite code can be used",
+
Action: func(cmd *cli.Context) error {
+
forDid := "did:plc:123"
+
if cmd.String("for") != "" {
+
did, err := syntax.ParseDID(cmd.String("for"))
+
uses := cmd.Int("uses")
+
code := fmt.Sprintf("%s-%s", helpers.RandomVarchar(8), helpers.RandomVarchar(8))
+
if err := db.Exec("INSERT INTO invite_codes (did, code, remaining_use_count) VALUES (?, ?, ?)", forDid, code, uses).Error; err != nil {
+
fmt.Printf("New invite code created with %d uses: %s\n", uses, code)
+
var runResetPassword = &cli.Command{
+
Name: "reset-password",
+
Usage: "resets a password",
+
Usage: "did of the user who's password you want to reset",
+
Action: func(cmd *cli.Context) error {
+
didStr := cmd.String("did")
+
did, err := syntax.ParseDID(didStr)
+
newPass := fmt.Sprintf("%s-%s", helpers.RandomVarchar(12), helpers.RandomVarchar(12))
+
hashed, err := bcrypt.GenerateFromPassword([]byte(newPass), 10)
+
if err := db.Exec("UPDATE repos SET password = ? WHERE did = ?", hashed, did.String()).Error; err != nil {
+
fmt.Printf("Password for %s has been reset to: %s", did.String(), newPass)
+
func newDb() (*gorm.DB, error) {
+
return gorm.Open(sqlite.Open("cocoon.db"), &gorm.Config{})