feat: tenants querying
All checks were successful
arcad/emissary/pipeline/pr-master This commit looks good
All checks were successful
arcad/emissary/pipeline/pr-master This commit looks good
This commit is contained in:
63
internal/command/client/tenant/query.go
Normal file
63
internal/command/client/tenant/query.go
Normal file
@ -0,0 +1,63 @@
|
||||
package tenant
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/command/client/apierr"
|
||||
clientFlag "forge.cadoles.com/Cadoles/emissary/internal/command/client/flag"
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/datastore"
|
||||
"forge.cadoles.com/Cadoles/emissary/pkg/client"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli/v2"
|
||||
"gitlab.com/wpetit/goweb/cli/format"
|
||||
)
|
||||
|
||||
func QueryCommand() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "query",
|
||||
Usage: "Query tenants",
|
||||
Flags: clientFlag.ComposeFlags(
|
||||
&cli.Int64SliceFlag{
|
||||
Name: "ids",
|
||||
Usage: "use `IDS` as query filter",
|
||||
},
|
||||
),
|
||||
Action: func(ctx *cli.Context) error {
|
||||
baseFlags := clientFlag.GetBaseFlags(ctx)
|
||||
|
||||
token, err := clientFlag.GetToken(baseFlags)
|
||||
if err != nil {
|
||||
return errors.WithStack(apierr.Wrap(err))
|
||||
}
|
||||
|
||||
options := make([]client.QueryTenantsOptionFunc, 0)
|
||||
|
||||
rawIDs := ctx.StringSlice("ids")
|
||||
if rawIDs != nil {
|
||||
tenantIDs := func(ids []string) []datastore.TenantID {
|
||||
tenantIDs := make([]datastore.TenantID, len(ids))
|
||||
for i, id := range ids {
|
||||
tenantIDs[i] = datastore.TenantID(id)
|
||||
}
|
||||
return tenantIDs
|
||||
}(rawIDs)
|
||||
options = append(options, client.WithQueryTenantsID(tenantIDs...))
|
||||
}
|
||||
|
||||
client := client.New(baseFlags.ServerURL, client.WithToken(token))
|
||||
|
||||
tenants, _, err := client.QueryTenants(ctx.Context, options...)
|
||||
if err != nil {
|
||||
return errors.WithStack(apierr.Wrap(err))
|
||||
}
|
||||
|
||||
hints := tenantHints(baseFlags.OutputMode)
|
||||
|
||||
if err := format.Write(baseFlags.Format, os.Stdout, hints, clientFlag.AsAnySlice(tenants)...); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
@ -13,6 +13,7 @@ func Root() *cli.Command {
|
||||
GetCommand(),
|
||||
UpdateCommand(),
|
||||
DeleteCommand(),
|
||||
QueryCommand(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user