Skip to content

Commit 16b3df0

Browse files
fix: accept bare hosts in SanitizeNullifyHost and update generator (#130)
SanitizeNullifyHost now accepts bare hosts (e.g. acme.nullify.ai) in addition to api-prefixed hosts. The code generator template is updated to include the apiHost prefix logic so regeneration preserves the behavior. User-facing messages updated accordingly. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 31eb1bd commit 16b3df0

5 files changed

Lines changed: 28 additions & 11 deletions

File tree

cmd/cli/cmd/auth.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ var loginCmd = &cobra.Command{
4545

4646
// If still no host, prompt
4747
if loginHost == "" {
48-
fmt.Print("Enter your Nullify instance (e.g., api.acme.nullify.ai): ")
48+
fmt.Print("Enter your Nullify instance (e.g., acme.nullify.ai): ")
4949
_, _ = fmt.Scanln(&loginHost)
5050
}
5151

5252
sanitizedHost, err := lib.SanitizeNullifyHost(loginHost)
5353
if err != nil {
54-
fmt.Fprintf(os.Stderr, "Error: invalid host %q - must be in the format api.<your-instance>.nullify.ai\n", loginHost)
54+
fmt.Fprintf(os.Stderr, "Error: invalid host %q - must be in the format <your-instance>.nullify.ai\n", loginHost)
5555
os.Exit(1)
5656
}
5757

@@ -90,12 +90,12 @@ var statusCmd = &cobra.Command{
9090
Run: func(cmd *cobra.Command, args []string) {
9191
cfg, err := auth.LoadConfig()
9292
if err != nil {
93-
fmt.Println("Not configured. Run 'nullify auth login --host api.<your-instance>.nullify.ai' to get started.")
93+
fmt.Println("Not configured. Run 'nullify auth login --host <your-instance>.nullify.ai' to get started.")
9494
return
9595
}
9696

9797
if cfg.Host == "" {
98-
fmt.Println("No host configured. Run 'nullify auth login --host api.<your-instance>.nullify.ai'")
98+
fmt.Println("No host configured. Run 'nullify auth login --host <your-instance>.nullify.ai'")
9999
return
100100
}
101101

@@ -160,7 +160,7 @@ var switchCmd = &cobra.Command{
160160
// List available hosts
161161
creds, err := auth.LoadCredentials()
162162
if err != nil || len(creds) == 0 {
163-
fmt.Println("No configured hosts. Run 'nullify auth login --host api.<your-instance>.nullify.ai'")
163+
fmt.Println("No configured hosts. Run 'nullify auth login --host <your-instance>.nullify.ai'")
164164
return
165165
}
166166

cmd/cli/cmd/root.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func Execute() error {
4242
}
4343

4444
func init() {
45-
rootCmd.PersistentFlags().StringVar(&host, "host", "", "The base URL of your Nullify API instance (e.g., api.acme.nullify.ai)")
45+
rootCmd.PersistentFlags().StringVar(&host, "host", "", "The base URL of your Nullify API instance (e.g., acme.nullify.ai)")
4646
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose logging")
4747
rootCmd.PersistentFlags().BoolVarP(&debug, "debug", "d", false, "Enable debug logging")
4848
rootCmd.PersistentFlags().StringVarP(&outputFmt, "output", "o", "json", "Output format (json, table, yaml)")
@@ -124,7 +124,7 @@ func resolveHost(ctx context.Context) string {
124124
sanitized, err := lib.SanitizeNullifyHost(host)
125125
if err != nil {
126126
logger.L(ctx).Error(
127-
"invalid host, must be in the format api.<your-instance>.nullify.ai",
127+
"invalid host, must be in the format <your-instance>.nullify.ai",
128128
logger.String("host", host),
129129
)
130130
os.Exit(1)
@@ -146,7 +146,7 @@ func resolveHost(ctx context.Context) string {
146146
}
147147
}
148148

149-
logger.L(ctx).Error("no host configured. Run 'nullify auth login --host api.<your-instance>.nullify.ai' to configure.")
149+
logger.L(ctx).Error("no host configured. Run 'nullify auth login --host <your-instance>.nullify.ai' to configure.")
150150
os.Exit(1)
151151
return ""
152152
}

internal/lib/urls.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ func SanitizeNullifyHost(nullifyHost string) (string, error) {
5050
return "", err
5151
}
5252

53-
if !strings.HasPrefix(nullifyURL.Host, "api.") || !strings.HasSuffix(nullifyURL.Host, ".nullify.ai") {
54-
return "", errors.New("invalid host, must be in the format api.<your-instance>.nullify.ai")
53+
if !strings.HasSuffix(nullifyURL.Host, ".nullify.ai") {
54+
return "", errors.New("invalid host, must be in the format <your-instance>.nullify.ai")
5555
}
5656

5757
return nullifyURL.Host, nil

internal/lib/urls_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ func TestSanitizeNullifyHost(t *testing.T) {
8383
expectedHost: "api.example.nullify.ai",
8484
wantErr: false,
8585
},
86+
{
87+
name: "bare host without api prefix",
88+
inputHost: "acme.nullify.ai",
89+
expectedHost: "acme.nullify.ai",
90+
wantErr: false,
91+
},
92+
{
93+
name: "bare host with scheme",
94+
inputHost: "https://acme.nullify.ai",
95+
expectedHost: "acme.nullify.ai",
96+
wantErr: false,
97+
},
8698
{
8799
name: "input host with invalid scheme delimiter",
88100
inputHost: "random:/|api.example.nullify.ai",

scripts/generate/main.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ import (
405405
"fmt"
406406
"io"
407407
"net/http"
408+
"strings"
408409
)
409410
410411
// Client is a typed HTTP client for the Nullify API.
@@ -417,8 +418,12 @@ type Client struct {
417418
418419
// NewClient creates a new Nullify API client.
419420
func NewClient(host string, token string, defaultParams map[string]string) *Client {
421+
apiHost := host
422+
if !strings.HasPrefix(host, "api.") {
423+
apiHost = "api." + host
424+
}
420425
return &Client{
421-
BaseURL: "https://" + host,
426+
BaseURL: "https://" + apiHost,
422427
Token: token,
423428
DefaultParams: defaultParams,
424429
HTTPClient: &http.Client{},

0 commit comments

Comments
 (0)