Changes
2 changed files (+69/-1)
-
-
@@ -40,7 +40,11 @@ "init-admin-creation-password", false, "Whether generate a password for initial admin user creation",) var shouldCreateAlice = flag.Bool( "create-alice", false, "Create an admin user \"Alice/Alice's password\"?", "create-alice", false, "Create an admin user \"alice@example.com/Alice's password\"?", ) var shouldCreateBob = flag.Bool( "create-bob", false, "Create a viewer user \"bob@example.com/Bob's password\"?", ) // charmbracelet/log uses 256-color for default styles.
-
@@ -120,6 +124,17 @@ logger.Fatal(err)} logger.Infof("Created admin user Alice. ID=%s", id) } if *shouldCreateBob { logger.Debug("Creating viewer user Bob...") id, err := setups.CreateBob(db) if err != nil { logger.Fatal(err) } logger.Infof("Created viewer user Bob. ID=%s", id) } addr := fmt.Sprintf("%s:%d", *host, *port)
-
-
setups/create_bob.go (new)
-
@@ -0,0 +1,53 @@// Copyright 2025 Shota FUJI // // This source code is licensed under Zero-Clause BSD License. // You can find a copy of the Zero-Clause BSD License at LICENSES/0BSD.txt // You may also obtain a copy of the Zero-Clause BSD License at // <https://opensource.org/license/0bsd> // // SPDX-License-Identifier: 0BSD package setups import ( "database/sql" "fmt" "github.com/google/uuid" "google.golang.org/protobuf/proto" "pocka.jp/x/event_sourcing_user_management_poc/auth" "pocka.jp/x/event_sourcing_user_management_poc/events" "pocka.jp/x/event_sourcing_user_management_poc/gen/event" "pocka.jp/x/event_sourcing_user_management_poc/gen/model" ) // CreateBob creates a new viewer user named "Bob" with demo password of // "Bob's password". // CreateBob returns an ID of the created user on success. func CreateBob(db *sql.DB) (string, error) { id := uuid.New().String() passwordHash, salt := auth.HashPasswordWithRandomSalt("Bob's password") if err := events.Insert(db, []proto.Message{ &event.UserCreated{ Id: proto.String(id), DisplayName: proto.String("Bob"), Email: proto.String("bob@example.com"), }, &event.PasswordLoginConfigured{ UserId: proto.String(id), PasswordHash: passwordHash, Salt: salt, }, &event.RoleAssigned{ UserId: proto.String(id), Role: model.Role.Enum(model.Role_ROLE_VIEWER), }, }); err != nil { return "", fmt.Errorf("Unable to create Bob: %s", err) } return id, nil }
-