Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ env:
TAILOUT_NON_INTERACTIVE: "true"
TAILOUT_CREATE_CONNECT: "true"
TAILOUT_CREATE_SHUTDOWN: 5m
TAILOUT_TAILSCALE_TAILNET: ${{ secrets.TAILSCALE_TAILNET }}
TAILOUT_TAILSCALE_API_KEY: ${{ secrets.TAILSCALE_API_KEY }}
TAILOUT_TAILSCALE_AUTH_KEY: ${{ secrets.TAILSCALE_AUTH_KEY }}

Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ Go to your [Tailscale API key settings](https://login.tailscale.com/admin/settin
```yaml
tailscale:
api_key: tskey-api-xxx-xxx
tailnet: <your tailnet name>
```

- Run `tailout init`, review the changes that will be done to your policy and accept
Expand Down Expand Up @@ -90,7 +89,6 @@ For exemple, you could have this content in `/etc/tailout/config.yml`:
```yaml
tailscale:
api_key: tskey-api-xxx-xxx
tailnet: <your tailnet name>
region: eu-west-3
create:
shutdown: 15m
Expand Down
1 change: 0 additions & 1 deletion cmd/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func buildConnectCommand(app *tailout.App) *cobra.Command {

cmd.PersistentFlags().BoolVarP(&app.Config.NonInteractive, "non-interactive", "n", false, "Disable interactive prompts")
cmd.PersistentFlags().StringVar(&app.Config.Tailscale.APIKey, "tailscale-api-key", "", "Tailscale API key used to perform operations on your tailnet")
cmd.PersistentFlags().StringVar(&app.Config.Tailscale.Tailnet, "tailscale-tailnet", "", "Tailscale Tailnet to use for operations")
cmd.PersistentFlags().StringVar(&app.Config.Tailscale.BaseURL, "tailscale-base-url", "https://api.tailscale.com", "Tailscale base API URL, change this if you are using Headscale")

return cmd
Expand Down
1 change: 0 additions & 1 deletion cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func buildCreateCommand(app *tailout.App) *cobra.Command {
}

cmd.PersistentFlags().StringVar(&app.Config.Tailscale.APIKey, "tailscale-api-key", "", "Tailscale API key used to perform operations on your tailnet")
cmd.PersistentFlags().StringVar(&app.Config.Tailscale.Tailnet, "tailscale-tailnet", "", "Tailscale Tailnet to use for operations")
cmd.PersistentFlags().StringVar(&app.Config.Tailscale.BaseURL, "tailscale-base-url", "https://api.tailscale.com", "Tailscale base API URL, change this if you are using Headscale")
cmd.PersistentFlags().BoolVarP(&app.Config.DryRun, "dry-run", "d", false, "Dry run mode (no changes will be made)")
cmd.PersistentFlags().BoolVarP(&app.Config.NonInteractive, "non-interactive", "n", false, "Disable interactive prompts")
Expand Down
1 change: 0 additions & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ func buildInitCommand(app *tailout.App) *cobra.Command {
}

cmd.PersistentFlags().StringVar(&app.Config.Tailscale.APIKey, "tailscale-api-key", "", "Tailscale API key used to perform operations on your tailnet")
cmd.PersistentFlags().StringVar(&app.Config.Tailscale.Tailnet, "tailscale-tailnet", "", "Tailscale Tailnet to use for operations")
cmd.PersistentFlags().StringVar(&app.Config.Tailscale.BaseURL, "tailscale-base-url", "https://api.tailscale.com", "Tailscale base API URL, change this if you are using Headscale")
cmd.PersistentFlags().BoolVarP(&app.Config.NonInteractive, "non-interactive", "n", false, "Disable interactive prompts")
cmd.PersistentFlags().BoolVarP(&app.Config.DryRun, "dry-run", "d", false, "Dry run mode (no changes will be made)")
Expand Down
1 change: 0 additions & 1 deletion cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func buildStatusCommand(app *tailout.App) *cobra.Command {
}

cmd.PersistentFlags().StringVar(&app.Config.Tailscale.APIKey, "tailscale-api-key", "", "Tailscale API key used to perform operations on your tailnet")
cmd.PersistentFlags().StringVar(&app.Config.Tailscale.Tailnet, "tailscale-tailnet", "", "Tailscale Tailnet to use for operations")
cmd.PersistentFlags().StringVar(&app.Config.Tailscale.BaseURL, "tailscale-base-url", "https://api.tailscale.com", "Tailscale base API URL, change this if you are using Headscale")

return cmd
Expand Down
1 change: 0 additions & 1 deletion cmd/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func buildStopCommand(app *tailout.App) *cobra.Command {
}

cmd.PersistentFlags().StringVar(&app.Config.Tailscale.APIKey, "tailscale-api-key", "", "Tailscale API key used to perform operations on your tailnet")
cmd.PersistentFlags().StringVar(&app.Config.Tailscale.Tailnet, "tailscale-tailnet", "", "Tailscale Tailnet to use for operations")
cmd.PersistentFlags().StringVar(&app.Config.Tailscale.BaseURL, "tailscale-base-url", "https://api.tailscale.com", "Tailscale base API URL, change this if you are using Headscale")
cmd.PersistentFlags().BoolVarP(&app.Config.NonInteractive, "non-interactive", "n", false, "Disable interactive prompts")
cmd.PersistentFlags().BoolVarP(&app.Config.DryRun, "dry-run", "d", false, "Dry run mode (no changes will be made)")
Expand Down
1 change: 0 additions & 1 deletion tailout/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ type CreateConfig struct {
type TailscaleConfig struct {
BaseURL string `mapstructure:"base_url"`
APIKey string `mapstructure:"api_key"`
Tailnet string `mapstructure:"tailnet"`
}

type StopConfig struct {
Expand Down
1 change: 0 additions & 1 deletion tailout/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func (app *App) Connect(ctx context.Context, args []string) error {

apiClient := &tsapi.Client{
APIKey: app.Config.Tailscale.APIKey,
Tailnet: app.Config.Tailscale.Tailnet,
BaseURL: baseURL,
}

Expand Down
22 changes: 14 additions & 8 deletions tailout/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ import (
tsapi "tailscale.com/client/tailscale/v2"
)

var ErrUserAborted = errors.New("user aborted instance creation")
var (
ErrUserAborted = errors.New("user aborted instance creation")
ErrDryRun = errors.New("dry run successful")
)

func (app *App) Create(ctx context.Context) error {
nonInteractive := app.Config.NonInteractive
Expand All @@ -40,7 +43,6 @@ func (app *App) Create(ctx context.Context) error {

apiClient := &tsapi.Client{
APIKey: app.Config.Tailscale.APIKey,
Tailnet: app.Config.Tailscale.Tailnet,
BaseURL: baseURL,
}

Expand Down Expand Up @@ -104,13 +106,13 @@ func (app *App) Create(ctx context.Context) error {
runInput, errPrep := prepareInstance(ctx, cfg, aws.Bool(dryRun), strconv.Itoa(durationMinutes))
if errPrep != nil {
if errors.Is(errPrep, ErrUserAborted) {
fmt.Println("Instance creation aborted.")
fmt.Println("instance creation aborted.")
return nil
}
return fmt.Errorf("failed to prepare instance: %w", errPrep)
}
if runInput == nil {
fmt.Println("Instance creation aborted.")
fmt.Println("no user input provided, aborting instance creation")
return nil
}

Expand All @@ -123,20 +125,25 @@ func (app *App) Create(ctx context.Context) error {
if createErr != nil {
return createErr
}
if dryRun {
return ErrDryRun
}
if instance.InstanceID == "" {
return errors.New("instance creation aborted")
return errors.New("no instance ID returned")
}
instanceID = instance.InstanceID
nodeName = instance.Name
publicIPAddress = instance.IP
return nil
}).Run()
if errSpin != nil {
if errors.Is(errSpin, ErrDryRun) {
fmt.Println("Dry run successful. Instance can be created.")
return nil
}
return fmt.Errorf("failed to create instance: %w", errSpin)
}

// If dry run, exit here?

st := spinner.New().Type(spinner.Dots).Title("Installing Tailscale...")
errSpint := st.Context(ctx).ActionWithErr(func(context.Context) error {
errInstall := installTailScale(ctx, cfg, key.Key, nodeName, instanceID, st)
Expand Down Expand Up @@ -308,7 +315,6 @@ func createInstance(ctx context.Context, cfg aws.Config, runInput *ec2.RunInstan
if runErr != nil {
var dryRunErr *smithy.GenericAPIError
if errors.As(runErr, &dryRunErr) && dryRunErr.Code == "DryRunOperation" {
fmt.Println("Dry run successful. Instance can be created.")
return instance, nil
}
return instance, fmt.Errorf("failed to create EC2 instance: %w", runErr)
Expand Down
2 changes: 1 addition & 1 deletion tailout/disconnect.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ func (app *App) Disconnect(ctx context.Context) error {
if err != nil {
return fmt.Errorf("failed to parse base URL: %w", err)
}

apiClient := &tsapi.Client{
APIKey: app.Config.Tailscale.APIKey,
Tailnet: app.Config.Tailscale.Tailnet,
BaseURL: baseURL,
}

Expand Down
1 change: 0 additions & 1 deletion tailout/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ func (app *App) Init(ctx context.Context) error {

apiClient := &tsapi.Client{
APIKey: app.Config.Tailscale.APIKey,
Tailnet: app.Config.Tailscale.Tailnet,
BaseURL: baseURL,
}

Expand Down
13 changes: 6 additions & 7 deletions tailout/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ func (app *App) Status(ctx context.Context) error {
return fmt.Errorf("failed to parse base URL: %w", err)
}

var localClient tslocal.Client
status, err := localClient.Status(ctx)
if err != nil {
return fmt.Errorf("failed to get tailscale status: %w", err)
}

client := &tsapi.Client{
APIKey: app.Config.Tailscale.APIKey,
Tailnet: app.Config.Tailscale.Tailnet,
BaseURL: baseURL,
}

Expand All @@ -31,12 +36,6 @@ func (app *App) Status(ctx context.Context) error {
return fmt.Errorf("failed to get active nodes: %w", err)
}

var localClient tslocal.Client
status, err := localClient.Status(ctx)
if err != nil {
return fmt.Errorf("failed to get tailscale preferences: %w", err)
}

var currentNode tsapi.Device

if status.ExitNodeStatus != nil {
Expand Down
1 change: 0 additions & 1 deletion tailout/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ func (app *App) Stop(ctx context.Context, args []string) error {

client := &tsapi.Client{
APIKey: app.Config.Tailscale.APIKey,
Tailnet: app.Config.Tailscale.Tailnet,
BaseURL: baseURL,
}

Expand Down
1 change: 0 additions & 1 deletion tailout/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func (app *App) UI(ctx context.Context) error {

client := &tsapi.Client{
APIKey: app.Config.Tailscale.APIKey,
Tailnet: app.Config.Tailscale.Tailnet,
BaseURL: baseURL,
}

Expand Down
Loading