Adds changing name and exiting

This commit is contained in:
Daniel Svitan 2025-04-12 16:06:33 +02:00
parent 9547c72f5a
commit 473ea2ba74

View File

@ -40,8 +40,8 @@ func load() error {
return nil
}
func makeReq(method string, url string, body io.Reader) error {
req, err := http.NewRequest(method, url, body)
func makeReq(method string, url string) error {
req, err := http.NewRequest(method, url, nil)
if err != nil {
return err
}
@ -84,7 +84,7 @@ func main() {
Flags: []cli.Flag{
&cli.StringFlag{
Name: "id",
Usage: "optional id of a client to fetch",
Usage: "optional id of the client to fetch",
},
},
Action: clients,
@ -95,7 +95,7 @@ func main() {
Flags: []cli.Flag{
&cli.StringFlag{
Name: "id",
Usage: "optional id of a client to log",
Usage: "optional id of the client to log",
},
&cli.StringFlag{
Name: "date",
@ -112,6 +112,35 @@ func main() {
},
Action: logs,
},
{
Name: "name",
Usage: "rename a client",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "id",
Usage: "id of the client",
Required: true,
},
&cli.StringFlag{
Name: "new",
Usage: "new name of the client",
Required: true,
},
},
Action: name,
},
{
Name: "exit",
Usage: "request a client to disconnect",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "id",
Usage: "id of the client",
Required: true,
},
},
Action: exit,
},
},
}
@ -135,7 +164,7 @@ func clients(ctx context.Context, cmd *cli.Command) error {
url = fmt.Sprintf("%s/admin/clients", server)
}
return makeReq(http.MethodGet, url, nil)
return makeReq(http.MethodGet, url)
}
func logs(ctx context.Context, cmd *cli.Command) error {
@ -170,5 +199,28 @@ func logs(ctx context.Context, cmd *cli.Command) error {
url = fmt.Sprintf("%s/admin/logs", server)
}
return makeReq(http.MethodGet, url, nil)
return makeReq(http.MethodGet, url)
}
func name(ctx context.Context, cmd *cli.Command) error {
err := load()
if err != nil {
return err
}
id := cmd.String("id")
name := cmd.String("new")
url := fmt.Sprintf("%s/admin/name/%s?name=%s", server, id, name)
return makeReq(http.MethodPost, url)
}
func exit(ctx context.Context, cmd *cli.Command) error {
err := load()
if err != nil {
return err
}
id := cmd.String("id")
url := fmt.Sprintf("%s/admin/exit/%s", server, id)
return makeReq(http.MethodPost, url)
}