mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-01-06 03:31:02 -06:00
Silo List command
This commit is contained in:
@@ -15,7 +15,8 @@ func setupSiloCommand() *cobra.Command {
|
||||
}
|
||||
cmd.AddCommand([]*cobra.Command{
|
||||
setupSiloCreateCommand(),
|
||||
setupLibraryDeleteCommand(),
|
||||
setupSiloListCommand(),
|
||||
setupSiloDeleteCommand(),
|
||||
}...)
|
||||
return cmd
|
||||
}
|
||||
@@ -23,7 +24,7 @@ func setupSiloCommand() *cobra.Command {
|
||||
func setupSiloCreateCommand() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "create storage-backend owner display-name",
|
||||
Short: "Create Library",
|
||||
Short: "Create Silo",
|
||||
Args: cobra.ExactArgs(3),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
id := uuid.New()
|
||||
@@ -48,7 +49,31 @@ func setupSiloCreateCommand() *cobra.Command {
|
||||
}
|
||||
}
|
||||
|
||||
func setupLibraryDeleteCommand() *cobra.Command {
|
||||
func setupSiloListCommand() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List Silos",
|
||||
Args: cobra.ExactArgs(0),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
ctx := context.Background()
|
||||
silos, err := fs.ListSilos(ctx)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
for _, silo := range silos {
|
||||
logrus.Infof("%-16s: %s\n", silo.Name, silo.ID.String())
|
||||
logrus.Infof(" storage: %s\n", silo.Storage)
|
||||
if owner, err := userManager.UserById(ctx, silo.Owner); err == nil {
|
||||
logrus.Infof(" owner: %5d - %s\n", silo.Owner, owner.Username)
|
||||
} else {
|
||||
logrus.Infof(" owner not found: %5d\n", silo.Owner)
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func setupSiloDeleteCommand() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "delete id",
|
||||
Short: "Delete Silo",
|
||||
|
||||
@@ -37,6 +37,10 @@ func (fs FileSystem) CreateSilo(ctx context.Context, id uuid.UUID, owner int32,
|
||||
})
|
||||
}
|
||||
|
||||
func (fs FileSystem) ListSilos(ctx context.Context) ([]sql.Silo, error) {
|
||||
return fs.db.Queries().ListSilos(ctx)
|
||||
}
|
||||
|
||||
func (fs FileSystem) OpenSilo(ctx context.Context, id uuid.UUID) (*Silo, error) {
|
||||
silo, err := fs.db.Queries().SiloById(ctx, id)
|
||||
if err != nil {
|
||||
|
||||
@@ -37,6 +37,23 @@ func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, e
|
||||
return i, err
|
||||
}
|
||||
|
||||
const userById = `-- name: UserById :one
|
||||
SELECT id, display_name, username, password_hash, deleted from users WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) UserById(ctx context.Context, id int32) (User, error) {
|
||||
row := q.db.QueryRow(ctx, userById, id)
|
||||
var i User
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.DisplayName,
|
||||
&i.Username,
|
||||
&i.PasswordHash,
|
||||
&i.Deleted,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const userByUsername = `-- name: UserByUsername :one
|
||||
SELECT id, display_name, username, password_hash, deleted from users WHERE username = $1
|
||||
`
|
||||
|
||||
@@ -25,3 +25,7 @@ func (m Manager) CreateUser(ctx context.Context, username, displayName, password
|
||||
func (m Manager) FindUser(ctx context.Context, username string) (sql.User, error) {
|
||||
return m.db.Queries().UserByUsername(ctx, username)
|
||||
}
|
||||
|
||||
func (m Manager) UserById(ctx context.Context, id int32) (sql.User, error) {
|
||||
return m.db.Queries().UserById(ctx, id)
|
||||
}
|
||||
|
||||
@@ -8,4 +8,7 @@ RETURNING *;
|
||||
|
||||
|
||||
-- name: UserByUsername :one
|
||||
SELECT * from users WHERE username = $1;
|
||||
SELECT * from users WHERE username = $1;
|
||||
|
||||
-- name: UserById :one
|
||||
SELECT * from users WHERE id = $1;
|
||||
Reference in New Issue
Block a user