diff --git a/cmd/api_keys.go b/cmd/api_keys.go index 0c638f4..66e0033 100644 --- a/cmd/api_keys.go +++ b/cmd/api_keys.go @@ -76,11 +76,12 @@ func newAPIKeysListCommand(env *environment) *cobra.Command { formatMoney(key.MonthlySpend), formatLimit(key.MonthlyLimit), formatExpiry(key.ExpiresAt), + formatDate(key.CreatedAt), formatLabels(key.Labels), }) } - return writeTable(out, []string{"ID", "NAME", "SPEND", "LIMIT", "EXPIRES", "LABELS"}, rows) + return writeTable(out, []string{"ID", "NAME", "SPEND", "LIMIT", "EXPIRES", "CREATED", "LABELS"}, rows) }, } } @@ -115,6 +116,7 @@ func newAPIKeysShowCommand(env *environment) *cobra.Command { {"Spend this month", formatMoney(key.MonthlySpend)}, {"Monthly limit", formatLimit(key.MonthlyLimit)}, {"Expires", formatExpiry(key.ExpiresAt)}, + {"Created at", formatTime(key.CreatedAt)}, {"Permissions", formatPermissions(key.Permissions)}, {"Logging", strconv.FormatBool(key.Logging)}, {"Group", formatGroup(key.Group)}, diff --git a/internal/client/api_keys.go b/internal/client/api_keys.go index cee4cd7..8cb1aea 100644 --- a/internal/client/api_keys.go +++ b/internal/client/api_keys.go @@ -46,6 +46,7 @@ type APIKey struct { MonthlyLimit decimal.Decimal `json:"monthly_limit"` MonthlySpend decimal.Decimal `json:"monthly_spend"` ExpiresAt *time.Time `json:"expires_at,omitempty"` + CreatedAt time.Time `json:"created_at"` Permissions APIKeyPermissions `json:"permissions"` Labels map[string]string `json:"labels,omitempty"` CreatedBy *APIKeyUser `json:"created_by,omitempty"` @@ -61,6 +62,7 @@ type APIKeyDetails struct { MonthlyLimit decimal.Decimal `json:"monthly_limit"` MonthlySpend decimal.Decimal `json:"monthly_spend"` ExpiresAt *time.Time `json:"expires_at,omitempty"` + CreatedAt time.Time `json:"created_at"` Permissions APIKeyPermissions `json:"permissions"` Group *APIKeyGroup `json:"group,omitempty"` } diff --git a/internal/client/api_keys_test.go b/internal/client/api_keys_test.go index 25e64d9..9c27f86 100644 --- a/internal/client/api_keys_test.go +++ b/internal/client/api_keys_test.go @@ -62,7 +62,7 @@ func mustParseTime(t *testing.T, value string) *time.Time { func TestClientAPIKeys(t *testing.T) { reply := `{"keys":[{"id":"key-1","name":"production","monthly_limit":"500","monthly_spend":"12.5",` + - `"expires_at":"2026-12-31T23:59:59Z",` + + `"expires_at":"2026-12-31T23:59:59Z","created_at":"2026-01-15T10:30:00Z",` + `"permissions":{"manage":"read","completions":"write"},"labels":{"env":"prod"},` + `"created_by":{"id":"user-1","email":"you@example.com"},"group":{"id":"group-1"}}]}` client, seen := newTestClient(t, http.StatusOK, reply) @@ -79,6 +79,7 @@ func TestClientAPIKeys(t *testing.T) { MonthlyLimit: decimal.RequireFromString("500"), MonthlySpend: decimal.RequireFromString("12.5"), ExpiresAt: mustParseTime(t, "2026-12-31T23:59:59Z"), + CreatedAt: time.Date(2026, time.January, 15, 10, 30, 0, 0, time.UTC), Permissions: APIKeyPermissions{Manage: APIKeyPermissionRead, Completions: APIKeyPermissionWrite}, Labels: map[string]string{"env": "prod"}, CreatedBy: &APIKeyUser{ID: "user-1", Email: "you@example.com"}, @@ -88,7 +89,7 @@ func TestClientAPIKeys(t *testing.T) { func TestClientAPIKey(t *testing.T) { reply := `{"id":"key-1","name":"production","logging":true,"monthly_limit":"0","monthly_spend":"3",` + - `"expires_at":"2026-12-31T23:59:59Z",` + + `"expires_at":"2026-12-31T23:59:59Z","created_at":"2026-01-15T10:30:00Z",` + `"permissions":{"manage":"none","completions":"write"},"group":{"id":"group-1"}}` client, seen := newTestClient(t, http.StatusOK, reply) @@ -104,6 +105,7 @@ func TestClientAPIKey(t *testing.T) { MonthlyLimit: decimal.RequireFromString("0"), MonthlySpend: decimal.RequireFromString("3"), ExpiresAt: mustParseTime(t, "2026-12-31T23:59:59Z"), + CreatedAt: time.Date(2026, time.January, 15, 10, 30, 0, 0, time.UTC), Permissions: APIKeyPermissions{Manage: APIKeyPermissionNone, Completions: APIKeyPermissionWrite}, Group: &APIKeyGroup{ID: "group-1"}, }, key)