| Giorgi Lekveishvili | 52814d9 | 2023-06-15 19:30:32 +0400 | [diff] [blame] | 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "os/exec" |
| 6 | ) |
| 7 | |
| 8 | type client struct { |
| 9 | config string |
| 10 | } |
| 11 | |
| 12 | func newClient(config string) *client { |
| 13 | return &client{ |
| 14 | config: fmt.Sprintf("--config=%s", config), |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | func (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 | |
| 25 | func (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 | |
| 33 | func (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 | } |