2024-02-27 14:14:30 +01:00
|
|
|
package tenant
|
2023-02-28 15:50:35 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
2024-02-27 14:14:30 +01:00
|
|
|
"forge.cadoles.com/Cadoles/emissary/internal/command/client/apierr"
|
|
|
|
clientFlag "forge.cadoles.com/Cadoles/emissary/internal/command/client/flag"
|
|
|
|
tenantFlag "forge.cadoles.com/Cadoles/emissary/internal/command/client/tenant/flag"
|
2023-06-25 19:45:43 +02:00
|
|
|
"forge.cadoles.com/Cadoles/emissary/pkg/client"
|
2023-02-28 15:50:35 +01:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/urfave/cli/v2"
|
2024-02-26 18:20:40 +01:00
|
|
|
"gitlab.com/wpetit/goweb/cli/format"
|
2023-02-28 15:50:35 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func UpdateCommand() *cli.Command {
|
|
|
|
return &cli.Command{
|
|
|
|
Name: "update",
|
2024-02-27 14:14:30 +01:00
|
|
|
Usage: "Update tenant",
|
|
|
|
Flags: tenantFlag.WithTenantFlags(
|
2023-04-01 13:28:18 +02:00
|
|
|
&cli.StringFlag{
|
2024-02-27 14:14:30 +01:00
|
|
|
Name: "tenant-label",
|
|
|
|
Usage: "Set `TENANT_LABEL` to targeted tenant",
|
2023-04-01 13:28:18 +02:00
|
|
|
Value: "",
|
|
|
|
},
|
2023-02-28 15:50:35 +01:00
|
|
|
),
|
|
|
|
Action: func(ctx *cli.Context) error {
|
|
|
|
baseFlags := clientFlag.GetBaseFlags(ctx)
|
|
|
|
|
2023-03-07 23:10:42 +01:00
|
|
|
token, err := clientFlag.GetToken(baseFlags)
|
|
|
|
if err != nil {
|
|
|
|
return errors.WithStack(apierr.Wrap(err))
|
|
|
|
}
|
|
|
|
|
2024-02-27 14:14:30 +01:00
|
|
|
tenantID, err := tenantFlag.AssertTenantID(ctx)
|
2023-02-28 15:50:35 +01:00
|
|
|
if err != nil {
|
|
|
|
return errors.WithStack(err)
|
|
|
|
}
|
|
|
|
|
2024-02-27 14:14:30 +01:00
|
|
|
options := make([]client.UpdateTenantOptionFunc, 0)
|
2023-02-28 15:50:35 +01:00
|
|
|
|
2024-02-27 14:14:30 +01:00
|
|
|
label := ctx.String("tenant-label")
|
2023-04-01 13:28:18 +02:00
|
|
|
if label != "" {
|
2024-02-27 14:14:30 +01:00
|
|
|
options = append(options, client.WithTenantLabel(label))
|
2023-04-01 13:28:18 +02:00
|
|
|
}
|
|
|
|
|
2023-03-07 23:10:42 +01:00
|
|
|
client := client.New(baseFlags.ServerURL, client.WithToken(token))
|
2023-02-28 15:50:35 +01:00
|
|
|
|
2024-02-27 14:14:30 +01:00
|
|
|
agent, err := client.UpdateTenant(ctx.Context, tenantID, options...)
|
2023-02-28 15:50:35 +01:00
|
|
|
if err != nil {
|
|
|
|
return errors.WithStack(apierr.Wrap(err))
|
|
|
|
}
|
|
|
|
|
2024-02-27 14:14:30 +01:00
|
|
|
hints := tenantHints(baseFlags.OutputMode)
|
2023-02-28 15:50:35 +01:00
|
|
|
|
|
|
|
if err := format.Write(baseFlags.Format, os.Stdout, hints, agent); err != nil {
|
|
|
|
return errors.WithStack(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|