Skip to content

Commit e327ebe

Browse files
committed
fix(quota): detect project from auth token and guard empty project ID
Application credentials are always scoped to a project, but the project ID was never extracted from the auth token — the stub was left as a TODO. This caused quota lookups to fail with a 403 because the API URL contained an empty project ID (/os-quota-sets//detail). Extract the project from the token via ExtractProject() so it is pre-selected on startup, and add a guard in fetchQuotas() to return a clear error instead of making a malformed API call.
1 parent 445b795 commit e327ebe

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

src/internal/app/app.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"charm.land/bubbles/v2/key"
1111
"charm.land/bubbletea/v2"
12+
"github.com/gophercloud/gophercloud/v2/openstack/identity/v3/tokens"
1213
"github.com/larkly/lazystack/internal/cloud"
1314
"github.com/larkly/lazystack/internal/compute"
1415
"github.com/larkly/lazystack/internal/config"
@@ -1081,11 +1082,14 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
10811082
for _, p := range projs {
10821083
infos = append(infos, shared.ProjectInfo{ID: p.ID, Name: p.Name})
10831084
}
1084-
// Try to get current project ID from the auth scope
1085+
// Extract current project ID from the auth token scope
10851086
currentID := ""
1086-
if pc.GetAuthResult() != nil {
1087-
// The token should have project scope info
1088-
// We'll match by checking project IDs
1087+
if ar, ok := pc.GetAuthResult().(interface {
1088+
ExtractProject() (*tokens.Project, error)
1089+
}); ok {
1090+
if proj, err := ar.ExtractProject(); err == nil && proj != nil {
1091+
currentID = proj.ID
1092+
}
10891093
}
10901094
return shared.ProjectsLoadedMsg{Projects: infos, CurrentID: currentID}
10911095
})

src/internal/ui/quotaview/quotaview.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ func (m *Model) fetchQuotas() tea.Cmd {
9494
projectID := m.projectID
9595

9696
return func() tea.Msg {
97+
if projectID == "" {
98+
return quotaLoadedMsg{err: fmt.Errorf("no project selected")}
99+
}
97100
ctx := context.Background()
98101
var (
99102
computeQuotas []quota.QuotaUsage

0 commit comments

Comments
 (0)