Commit b4ee1fc
authored
feat(maas): add BFF CRUD endpoints for MaaSAuthPolicy resources (opendatahub-io#7007)
* feat(maas): add BFF CRUD endpoints for MaaSAuthPolicy resources
Add standalone policy management endpoints mirroring the existing
subscription CRUD pattern: list, view, create, update, delete policies,
plus a shared form-data endpoint that now includes policies in its response.
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
* feat(maas): add subscriptions to policy form data endpoint
Enhance the subscription-policy-form-data endpoint to return all
subscriptions on the cluster. This supports the priority feature by
allowing users to see which subscriptions a model is associated with
and avoid overlaps when creating policies.
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
* test(maas): add comprehensive policy handler tests
Add integration tests for all policy CRUD endpoints following the
existing Ginkgo/Gomega BDD pattern from subscription tests. Tests cover:
- CreatePolicyHandler: success (201), duplicate (409), validation (400)
- ListPoliciesHandler: success (200) with verification
- GetPolicyInfoHandler: success (200), not found (404), empty name (400)
- UpdatePolicyHandler: success (200), not found (404), validation (400)
- DeletePolicyHandler: success (200), not found (404), empty name (400)
- Form data endpoint: includes policies and subscriptions
Total: 16 test cases using envtest with real K8s API server.
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
* fix(maas): Address CodeRabbit review comments for policy CRUD endpoints
This commit addresses all CodeRabbit review comments from PR opendatahub-io#7007:
1. Use ReadJSON helper to enforce 1MB request body limit
- Updated CreatePolicyHandler to use app.ReadJSON instead of json.NewDecoder
- Updated UpdatePolicyHandler to use app.ReadJSON instead of json.NewDecoder
- Removed unused "encoding/json" import from policy_handlers.go
2. Surface conversion errors instead of silently dropping policies
- Changed ListPolicies to return error immediately when policy conversion fails
- Prevents silent data loss from malformed CRDs or conversion bugs
3. Fix tests that pass nil to handlers
- Updated GetPolicyInfoHandler test to create minimal App instance instead of nil
- Updated DeletePolicyHandler test to create minimal App instance instead of nil
- Added necessary imports (log/slog, os) to policy_handlers_test.go
4. Use typed errors instead of string matching for conflict detection
- Created repositories/errors.go with ErrAlreadyExists and ErrNotFound sentinels
- Updated CreatePolicy to wrap errors with ErrAlreadyExists
- Updated DeletePolicy to wrap errors with ErrNotFound
- Updated handlers to use errors.Is() instead of strings.Contains()
- More robust error handling that won't break if error messages change
5. Merge spec fields instead of overwriting to preserve unknown CRD fields
- Fixed updateAuthPolicySpec to get existing spec and merge fields
- Preserves any unknown fields in the spec when updating
- Prevents data loss from future CRD schema extensions
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
* fix(maas): wrap sentinel errors in mock policy repository
MockPoliciesRepository was returning plain fmt.Errorf strings instead of
wrapping ErrAlreadyExists/ErrNotFound, causing handlers to return 500
instead of 409/404 in mock mode.
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
* docs(maas): add policy CRUD endpoints to OpenAPI spec
Add missing path entries for the 6 policy endpoints (list, get, create,
update, delete, form-data) and their request/response schemas. Also
update SubscriptionFormDataResponse with the new policies and
subscriptions fields.
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
* chore(maas): remove OPENAPI_CHANGES.md
Changes are now documented directly in the OpenAPI spec.
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
* refactor(maas): address Griffin's review comments on policy endpoints
- Wrap all policy handler responses in Envelope for consistency
- Rename GetSubscriptionFormDataHandler to GetSubscriptionPolicyFormDataHandler
- Merge SubscriptionFormDataPath and PolicyFormDataPath into single
SubscriptionPolicyFormDataPath under General MaaS routes section
- Move policy request/response types to dedicated models/policy.go
- Add optional DisplayName and Description to CreatePolicyRequest,
UpdatePolicyRequest, and MaaSAuthPolicy model
- Update all tests for Envelope responses and new route paths
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
* fix(maas): address Griffin's second review on policy endpoints
- Remove GET /api/v1/new-subscription from OpenAPI (handler already removed)
- Move /api/v1/subscription-policy-form-data to "general" tag
- Add displayName and description to CreatePolicyRequest and
UpdatePolicyRequest in OpenAPI spec
- Set openshift.io/display-name and openshift.io/description annotations
on MaaSAuthPolicy K8s resources during create and update
- Read annotations back in convertUnstructuredToAuthPolicy
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
* fix(maas): delete displayName/description annotations on empty update
When updating a policy with empty displayName or description, delete
the corresponding openshift.io/display-name or openshift.io/description
annotation from the K8s resource instead of silently keeping the old value.
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
---------
Signed-off-by: Wen Liang <liangwen12year@gmail.com>1 parent 33ad8dc commit b4ee1fc
File tree
20 files changed
+1543
-74
lines changed- packages/maas/bff
- internal
- api
- constants
- models
- repositories
20 files changed
+1543
-74
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
| 138 | + | |
138 | 139 | | |
139 | 140 | | |
140 | 141 | | |
141 | 142 | | |
| 143 | + | |
142 | 144 | | |
143 | 145 | | |
144 | 146 | | |
| 147 | + | |
145 | 148 | | |
146 | 149 | | |
147 | 150 | | |
148 | | - | |
| 151 | + | |
149 | 152 | | |
150 | 153 | | |
151 | 154 | | |
| |||
192 | 195 | | |
193 | 196 | | |
194 | 197 | | |
| 198 | + | |
195 | 199 | | |
196 | 200 | | |
197 | 201 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
140 | | - | |
| 140 | + | |
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
0 commit comments