File
Blob: internal/client/lightweight.go
| 1 | package client |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "io" |
| 6 | "os/signal" |
| 7 | "syscall" |
| 8 | |
| 9 | "go.miragespace.co/specter/tun/client" |
| 10 | "go.miragespace.co/specter/tun/client/dialer" |
| 11 | ) |
| 12 | |
| 13 | type LightweightOptions struct { |
| 14 | Options |
| 15 | Apex string |
| 16 | Target string |
| 17 | Token string |
| 18 | Output io.Writer |
| 19 | } |
| 20 | |
| 21 | func RunLightweight(ctx context.Context, opts LightweightOptions) error { |
| 22 | apex, err := dialer.ParseApex(opts.Apex) |
| 23 | if err != nil { |
| 24 | return err |
| 25 | } |
| 26 | ctx, cancel := signal.NotifyContext(ctx, syscall.SIGINT, syscall.SIGTERM) |
| 27 | defer cancel() |
| 28 | tlsConfig, transport, closeTransport, err := openTransport(opts.Options, apex, nil) |
| 29 | if err != nil { |
| 30 | return err |
| 31 | } |
| 32 | defer closeTransport() |
| 33 | l, err := client.NewLightweightClient(client.LightweightConfig{ |
| 34 | Logger: opts.Logger, |
| 35 | Transport: transport, |
| 36 | PKIClient: dialer.GetPKIClient(tlsConfig.Clone(), apex), |
| 37 | Apex: apex, |
| 38 | Target: opts.Target, |
| 39 | Token: opts.Token, |
| 40 | Output: opts.Output, |
| 41 | }) |
| 42 | if err != nil { |
| 43 | return err |
| 44 | } |
| 45 | return l.Run(ctx) |
| 46 | } |