-
Notifications
You must be signed in to change notification settings - Fork 3
fix: auto-create diagram groupings on first diagram POST #415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -565,7 +565,7 @@ func (h *SystemSecurityPlanHandler) GetCharacteristicsNetworkArchitecture(ctx ec | |
| // CreateCharacteristicsNetworkArchitectureDiagram godoc | ||
| // | ||
| // @Summary Create a Network Architecture Diagram | ||
| // @Description Creates a new Diagram under the Network Architecture of a System Security Plan. | ||
| // @Description Creates a new Diagram under the Network Architecture of a System Security Plan. Creates the Network Architecture grouping if it does not exist yet. | ||
| // @Tags System Security Plans | ||
| // @Accept json | ||
| // @Produce json | ||
|
|
@@ -600,7 +600,14 @@ func (h *SystemSecurityPlanHandler) CreateCharacteristicsNetworkArchitectureDiag | |
|
|
||
| na := ssp.SystemCharacteristics.NetworkArchitecture | ||
| if na == nil || na.ID == nil { | ||
| return ctx.JSON(http.StatusNotFound, api.NewError(fmt.Errorf("no network architecture for system security plan %s", idParam))) | ||
| if ssp.SystemCharacteristics.ID == nil { | ||
| return ctx.JSON(http.StatusNotFound, api.NewError(fmt.Errorf("no system characteristics for system security plan %s", idParam))) | ||
| } | ||
| na = &relational.NetworkArchitecture{SystemCharacteristicsId: *ssp.SystemCharacteristics.ID} | ||
| if err := h.db.Create(na).Error; err != nil { | ||
| h.sugar.Errorf("Failed to create network architecture: %v", err) | ||
| return ctx.JSON(http.StatusInternalServerError, api.NewError(err)) | ||
| } | ||
|
Comment on lines
+603
to
+610
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make grouping+diagram creation atomic and validate input before mutating DB. All three handlers can persist a new grouping before Wrap “ensure grouping + create diagram” in one transaction, and move request bind/validation before any write. Suggested pattern (apply to all three handlers)- // ensure/create grouping first
- if group == nil || group.ID == nil {
- if ssp.SystemCharacteristics.ID == nil { ...404... }
- group = &relational.<Grouping>{SystemCharacteristicsId: *ssp.SystemCharacteristics.ID}
- if err := h.db.Create(group).Error; err != nil { ...500... }
- }
-
- // then bind/validate diagram
+ // bind/validate first (no side effects on 400)
+ var oscalDiag oscalTypes_1_1_3.Diagram
+ if err := ctx.Bind(&oscalDiag); err != nil { ...400... }
+ if oscalDiag.UUID == "" { ...400... }
+ if _, err := uuid.Parse(oscalDiag.UUID); err != nil { ...400... }
+
+ err = h.db.Transaction(func(tx *gorm.DB) error {
+ // idempotent ensure-grouping (conflict-safe)
+ // then create diagram under resolved grouping ID
+ // return error to rollback both on any failure
+ return nil
+ })
+ if err != nil { ...500... }Also applies to: 848-855, 1089-1096 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| // Bind incoming diagram | ||
|
|
@@ -803,7 +810,7 @@ func (h *SystemSecurityPlanHandler) GetCharacteristicsDataFlow(ctx echo.Context) | |
| // CreateCharacteristicsDataFlowDiagram godoc | ||
| // | ||
| // @Summary Create a Data Flow Diagram | ||
| // @Description Creates a new Diagram under the Data Flow of a System Security Plan. | ||
| // @Description Creates a new Diagram under the Data Flow of a System Security Plan. Creates the Data Flow grouping if it does not exist yet. | ||
| // @Tags System Security Plans | ||
| // @Accept json | ||
| // @Produce json | ||
|
|
@@ -838,7 +845,14 @@ func (h *SystemSecurityPlanHandler) CreateCharacteristicsDataFlowDiagram(ctx ech | |
|
|
||
| df := ssp.SystemCharacteristics.DataFlow | ||
| if df == nil || df.ID == nil { | ||
| return ctx.JSON(http.StatusNotFound, api.NewError(fmt.Errorf("no data flow for system security plan %s", idParam))) | ||
| if ssp.SystemCharacteristics.ID == nil { | ||
| return ctx.JSON(http.StatusNotFound, api.NewError(fmt.Errorf("no system characteristics for system security plan %s", idParam))) | ||
| } | ||
| df = &relational.DataFlow{SystemCharacteristicsId: *ssp.SystemCharacteristics.ID} | ||
| if err := h.db.Create(df).Error; err != nil { | ||
| h.sugar.Errorf("Failed to create data flow: %v", err) | ||
| return ctx.JSON(http.StatusInternalServerError, api.NewError(err)) | ||
| } | ||
| } | ||
|
|
||
| var oscalDiag oscalTypes_1_1_3.Diagram | ||
|
|
@@ -1037,7 +1051,7 @@ func (h *SystemSecurityPlanHandler) GetCharacteristicsAuthorizationBoundary(ctx | |
| // CreateCharacteristicsAuthorizationBoundaryDiagram godoc | ||
| // | ||
| // @Summary Create an Authorization Boundary Diagram | ||
| // @Description Creates a new Diagram under the Authorization Boundary of a System Security Plan. | ||
| // @Description Creates a new Diagram under the Authorization Boundary of a System Security Plan. Creates the Authorization Boundary grouping if it does not exist yet. | ||
| // @Tags System Security Plans | ||
| // @Accept json | ||
| // @Produce json | ||
|
|
@@ -1072,7 +1086,14 @@ func (h *SystemSecurityPlanHandler) CreateCharacteristicsAuthorizationBoundaryDi | |
|
|
||
| ab := ssp.SystemCharacteristics.AuthorizationBoundary | ||
| if ab == nil || ab.ID == nil { | ||
| return ctx.JSON(http.StatusNotFound, api.NewError(fmt.Errorf("no authorization boundary for system security plan %s", idParam))) | ||
| if ssp.SystemCharacteristics.ID == nil { | ||
| return ctx.JSON(http.StatusNotFound, api.NewError(fmt.Errorf("no system characteristics for system security plan %s", idParam))) | ||
| } | ||
| ab = &relational.AuthorizationBoundary{SystemCharacteristicsId: *ssp.SystemCharacteristics.ID} | ||
| if err := h.db.Create(ab).Error; err != nil { | ||
| h.sugar.Errorf("Failed to create authorization boundary: %v", err) | ||
| return ctx.JSON(http.StatusInternalServerError, api.NewError(err)) | ||
| } | ||
| } | ||
|
|
||
| var oscalDiag oscalTypes_1_1_3.Diagram | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: compliance-framework/api
Length of output: 1324
Fix Swagger YAML description inconsistency across generated artifacts
docs/swagger.jsonanddocs/docs.gocontain the updated descriptions for Authorization Boundary (16628), Data Flow (16893), and Network Architecture (17158).docs/swagger.yamlcontains only the updated Data Flow description (but is missing the Authorization Boundary and Network Architecture “grouping if it does not exist yet” descriptions).swag init) and ensuredocs/swagger.yamlis regenerated to match the other artifacts.🤖 Prompt for AI Agents
Source: Learnings