File
Blob: internal/client/owner.go
| 1 | package client |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | |
| 6 | "go.miragespace.co/specter/tun/client" |
| 7 | ) |
| 8 | |
| 9 | // OpenOwner opens a registered owner for management commands. It cannot obtain |
| 10 | // or renew owner certificates; the tunnel runtime owns those operations. |
| 11 | func OpenOwner(ctx context.Context, configPath string, opts Options) (*client.Client, func(), error) { |
| 12 | cfg, apex, err := loadOwnerConfig(configPath) |
| 13 | if err != nil { |
| 14 | return nil, nil, err |
| 15 | } |
| 16 | _, transport, closeTransport, err := openTransport(opts, apex, nil) |
| 17 | if err != nil { |
| 18 | return nil, nil, err |
| 19 | } |
| 20 | c, err := client.NewClient(ctx, client.ClientConfig{ |
| 21 | Logger: opts.Logger, |
| 22 | Configuration: cfg, |
| 23 | ServerTransport: transport, |
| 24 | }) |
| 25 | if err != nil { |
| 26 | closeTransport() |
| 27 | return nil, nil, err |
| 28 | } |
| 29 | closeClient := func() { |
| 30 | c.Close() |
| 31 | closeTransport() |
| 32 | } |
| 33 | if err := c.Register(ctx); err != nil { |
| 34 | closeClient() |
| 35 | return nil, nil, err |
| 36 | } |
| 37 | return c, closeClient, nil |
| 38 | } |