Skip to content
Merged
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
31 changes: 15 additions & 16 deletions proxy/middleware/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,21 @@ func isAlertsAPICall(path string) bool {
return strings.HasPrefix(path, "/api/alerts/")
}

// Determines whether to add the org_id to the request from the custom header.
//
// Requests that need to have "org_id" query parameter added:
// - /api/flightctl: General flightctl API calls (see exclusions below)
// - /api/alerts: Alerts API calls
//
// Requests that do not need to have "org_id" query parameter added:
// - /api/flightctl/api/v1/organizations: To retrieve all possible organizations, "org_id" must not be sent
// - /api/terminal: Since websocket connections cannot use custom headers, "org_id" is already added to the original URL
func isImageBuilderAPICall(path string) bool {
return strings.HasPrefix(path, "/api/imagebuilder/")
}

func shouldAddOrgIDFromHeader(path string) bool {
if strings.HasPrefix(path, "/api/flightctl/api/v1/organizations") {
return false
}
if strings.HasPrefix(path, "/api/flightctl/api/v1/auth/config") {
return false
if isFlightCtlAPICall(path) {
// This request is used to fetch all existing organizations
if strings.HasPrefix(path, "/api/flightctl/api/v1/organizations") {
return false
}
// This request is used to fetch authentication providers from all organizations
if strings.HasPrefix(path, "/api/flightctl/api/v1/auth/config") {
return false
}
return true
}

return isFlightCtlAPICall(path) || isAlertsAPICall(path)
return isAlertsAPICall(path) || isImageBuilderAPICall(path)
}