Skip to content
Open
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
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ tool (

require (
github.com/Masterminds/semver/v3 v3.4.0
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2
github.com/charmbracelet/bubbletea v1.3.10
github.com/cli/safeexec v1.0.1
github.com/fatih/color v1.18.0
Expand Down Expand Up @@ -55,6 +56,7 @@ require (
github.com/containerd/errdefs v1.0.0 // indirect
github.com/containerd/errdefs/pkg v0.3.0 // indirect
github.com/containerd/stargz-snapshotter/estargz v0.18.1 // indirect
github.com/creack/pty v1.1.17 // indirect
github.com/danieljoos/wincred v1.2.3 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/distribution/reference v0.6.0 // indirect
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ github.com/Masterminds/semver/v3 v3.4.0 h1:Zog+i5UMtVoCU8oKka5P7i9q9HgrJeGzI9SA1
github.com/Masterminds/semver/v3 v3.4.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s=
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w=
github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk=
github.com/adrg/xdg v0.5.3 h1:xRnxJXne7+oWDatRhR1JLnvuccuIeCoBu2rtuLqQB78=
github.com/adrg/xdg v0.5.3/go.mod h1:nlTsY+NNiCBGCK2tpm09vRqfVzrc2fLmXGpBLF0zlTQ=
Expand Down Expand Up @@ -56,6 +58,8 @@ github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3
github.com/containerd/stargz-snapshotter/estargz v0.18.1 h1:cy2/lpgBXDA3cDKSyEfNOFMA/c10O1axL69EU7iirO8=
github.com/containerd/stargz-snapshotter/estargz v0.18.1/go.mod h1:ALIEqa7B6oVDsrF37GkGN20SuvG/pIMm7FwP7ZmRb0Q=
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI=
github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
github.com/danieljoos/wincred v1.2.3 h1:v7dZC2x32Ut3nEfRH+vhoZGvN72+dQ/snVXo/vMFLdQ=
github.com/danieljoos/wincred v1.2.3/go.mod h1:6qqX0WNrS4RzPZ1tnroDzq9kY3fu1KwE7MRLQK4X0bs=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -372,6 +376,7 @@ github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
Expand Down
11 changes: 2 additions & 9 deletions internal/tiger/cmd/auth.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"bufio"
"context"
"errors"
"fmt"
Expand All @@ -12,7 +11,6 @@ import (

"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
"golang.org/x/term"
"golang.org/x/text/cases"
"golang.org/x/text/language"

Expand Down Expand Up @@ -286,12 +284,10 @@ func promptForCredentials(ctx context.Context, consoleURL string, creds credenti

fmt.Printf("You can find your API credentials at: %s/dashboard/settings\n\n", consoleURL)

reader := bufio.NewReader(os.Stdin)

// Prompt for public key if missing
if creds.publicKey == "" {
fmt.Print("Enter your public key: ")
publicKey, err := readString(ctx, func() (string, error) { return reader.ReadString('\n') })
publicKey, err := readLine(ctx, os.Stdin)
if err != nil {
return credentials{}, err
}
Expand All @@ -301,10 +297,7 @@ func promptForCredentials(ctx context.Context, consoleURL string, creds credenti
// Prompt for secret key if missing
if creds.secretKey == "" {
fmt.Print("Enter your secret key: ")
password, err := readString(ctx, func() (string, error) {
val, err := term.ReadPassword(int(os.Stdin.Fd()))
return string(val), err
})
password, err := readPassword(ctx, os.Stdin)
if err != nil {
return credentials{}, err
}
Expand Down
21 changes: 6 additions & 15 deletions internal/tiger/cmd/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/base64"
"errors"
"fmt"
"io"
"net/http"
"os"
"os/exec"
Expand All @@ -15,7 +16,6 @@ import (
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"
"github.com/spf13/cobra"
"golang.org/x/term"

"github.com/timescale/tiger-cli/internal/tiger/api"
"github.com/timescale/tiger-cli/internal/tiger/common"
Expand All @@ -26,18 +26,9 @@ var (
// getServiceDetailsFunc can be overridden for testing
getServiceDetailsFunc = getServiceDetails

// checkStdinIsTTY can be overridden for testing to bypass TTY detection
checkStdinIsTTY = func() bool {
return util.IsTerminal(os.Stdin)
}

// readPasswordFromTerminal can be overridden for testing to inject password input
readPasswordFromTerminal = func() (string, error) {
val, err := term.ReadPassword(int(os.Stdin.Fd()))
if err != nil {
return "", err
}
return string(val), nil
// checkOutputIsTTY can be overridden for testing to bypass TTY detection
checkOutputIsTTY = func(w io.Writer) bool {
return util.IsTerminal(w)
}
)

Expand Down Expand Up @@ -350,12 +341,12 @@ Examples:
passwordToSave = envPassword
} else {
// Interactive prompt - check if we're in a terminal
if !checkStdinIsTTY() {
if !checkOutputIsTTY(cmd.OutOrStdout()) {
return fmt.Errorf("TTY not detected - password required. Use --password flag or TIGER_NEW_PASSWORD environment variable")
}

fmt.Fprint(cmd.OutOrStdout(), "Enter password: ")
passwordToSave, err = readString(cmd.Context(), readPasswordFromTerminal)
passwordToSave, err = readPassword(cmd.Context(), cmd.InOrStdin())
if err != nil {
return fmt.Errorf("failed to read password: %w", err)
}
Expand Down
25 changes: 13 additions & 12 deletions internal/tiger/cmd/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"fmt"
"io"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -1147,18 +1148,18 @@ func TestDBSavePassword_InteractivePrompt(t *testing.T) {
testPassword := "interactive-password-999"

// Mock TTY check to return true (simulate terminal)
originalCheckStdinIsTTY := checkStdinIsTTY
checkStdinIsTTY = func() bool {
originalCheckStdinIsTTY := checkOutputIsTTY
checkOutputIsTTY = func(w io.Writer) bool {
return true
}
defer func() { checkStdinIsTTY = originalCheckStdinIsTTY }()
defer func() { checkOutputIsTTY = originalCheckStdinIsTTY }()

// Mock password reading to return our test password
originalReadPasswordFromTerminal := readPasswordFromTerminal
readPasswordFromTerminal = func() (string, error) {
originalReadPassword := readPassword
readPassword = func(ctx context.Context, in io.Reader) (string, error) {
return testPassword, nil
}
defer func() { readPasswordFromTerminal = originalReadPasswordFromTerminal }()
defer func() { readPassword = originalReadPassword }()

// Execute save-password without --password flag or env var
output, err := executeDBCommand(t.Context(), "db", "save-password")
Expand Down Expand Up @@ -1225,18 +1226,18 @@ func TestDBSavePassword_InteractivePromptEmpty(t *testing.T) {
os.Unsetenv("TIGER_NEW_PASSWORD")

// Mock TTY check to return true (simulate terminal)
originalCheckStdinIsTTY := checkStdinIsTTY
checkStdinIsTTY = func() bool {
originalCheckStdinIsTTY := checkOutputIsTTY
checkOutputIsTTY = func(w io.Writer) bool {
return true
}
defer func() { checkStdinIsTTY = originalCheckStdinIsTTY }()
defer func() { checkOutputIsTTY = originalCheckStdinIsTTY }()

// Mock password reading to return empty password
originalReadPasswordFromTerminal := readPasswordFromTerminal
readPasswordFromTerminal = func() (string, error) {
originalReadPassword := readPassword
readPassword = func(ctx context.Context, in io.Reader) (string, error) {
return "", nil
}
defer func() { readPasswordFromTerminal = originalReadPasswordFromTerminal }()
defer func() { readPassword = originalReadPassword }()

// Execute the command
_, err = executeDBCommand(t.Context(), "db", "save-password")
Expand Down
Loading