2023-02-28 15:50:35 +01:00
|
|
|
package spec
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
2024-02-27 14:14:30 +01:00
|
|
|
agentFlag "forge.cadoles.com/Cadoles/emissary/internal/command/client/agent/flag"
|
|
|
|
"forge.cadoles.com/Cadoles/emissary/internal/command/client/apierr"
|
|
|
|
clientFlag "forge.cadoles.com/Cadoles/emissary/internal/command/client/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 GetCommand() *cli.Command {
|
|
|
|
return &cli.Command{
|
|
|
|
Name: "get",
|
2024-03-13 16:07:16 +01:00
|
|
|
Usage: "Get agent specification",
|
|
|
|
Flags: agentFlag.WithAgentFlags(
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "spec-name",
|
|
|
|
Usage: "use `NAME` as specification's name",
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "spec-version",
|
|
|
|
Usage: "use `VERSION` as specification's version",
|
|
|
|
Value: "0.0.0",
|
|
|
|
},
|
|
|
|
),
|
2023-02-28 15:50:35 +01:00
|
|
|
Action: func(ctx *cli.Context) error {
|
|
|
|
baseFlags := clientFlag.GetBaseFlags(ctx)
|
|
|
|
agentID, err := agentFlag.AssertAgentID(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return errors.WithStack(err)
|
|
|
|
}
|
|
|
|
|
2023-03-08 19:42:40 +01:00
|
|
|
token, err := clientFlag.GetToken(baseFlags)
|
|
|
|
if err != nil {
|
|
|
|
return errors.WithStack(apierr.Wrap(err))
|
|
|
|
}
|
|
|
|
|
2024-03-13 16:07:16 +01:00
|
|
|
specDefName, err := assertSpecDefName(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return errors.WithStack(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
specDefVersion, err := assertSpecDefVersion(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return errors.WithStack(err)
|
|
|
|
}
|
|
|
|
|
2023-03-08 19:42:40 +01:00
|
|
|
client := client.New(baseFlags.ServerURL, client.WithToken(token))
|
2023-02-28 15:50:35 +01:00
|
|
|
|
2024-03-13 16:07:16 +01:00
|
|
|
spec, err := client.GetAgentSpec(ctx.Context, agentID, specDefName, specDefVersion)
|
2023-02-28 15:50:35 +01:00
|
|
|
if err != nil {
|
|
|
|
return errors.WithStack(apierr.Wrap(err))
|
|
|
|
}
|
|
|
|
|
2024-03-12 16:22:35 +01:00
|
|
|
hints := specHints(baseFlags.OutputMode)
|
2023-02-28 15:50:35 +01:00
|
|
|
|
2024-03-13 16:07:16 +01:00
|
|
|
if err := format.Write(baseFlags.Format, os.Stdout, hints, spec); err != nil {
|
2023-02-28 15:50:35 +01:00
|
|
|
return errors.WithStack(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|