blob: 91476298a363c69d6fb35fb3e065a06e82ff2c35 [file] [log] [blame]
Giorgi Lekveishvili52814d92023-06-15 19:30:32 +04001package main
2
3import (
4 "fmt"
5 "os/exec"
6)
7
8type client struct {
9 config string
10}
11
12func newClient(config string) *client {
13 return &client{
14 config: fmt.Sprintf("--config=%s", config),
15 }
16}
17
18func (c *client) createUser(name string) error {
19 cmd := exec.Command("headscale", c.config, "users", "create", name)
20 out, err := cmd.Output()
21 fmt.Println(string(out))
22 return err
23}
24
25func (c *client) createPreAuthKey(user string) (string, error) {
26 // TODO(giolekva): make expiration configurable, and auto-refresh
27 cmd := exec.Command("headscale", c.config, "--user", user, "preauthkeys", "create", "--reusable", "--expiration", "365d")
28 out, err := cmd.Output()
29 fmt.Println(string(out))
30 return string(out), err
31}
32
33func (c *client) enableRoute(id string) error {
34 // TODO(giolekva): make expiration configurable, and auto-refresh
35 cmd := exec.Command("headscale", c.config, "routes", "enable", "-r", id)
36 out, err := cmd.Output()
37 fmt.Println(string(out))
38 return err
39}