diff --git a/pkg/scd/operational_intents_handler.go b/pkg/scd/operational_intents_handler.go index 6a50043b6..4902e7818 100644 --- a/pkg/scd/operational_intents_handler.go +++ b/pkg/scd/operational_intents_handler.go @@ -363,7 +363,7 @@ func (a *Server) UpdateOperationalIntentReference(ctx context.Context, req *rest return restapi.UpdateOperationalIntentReferenceResponseSet{Response200: respOK} } -type validOIRUpsertParams struct { +type validOIRParams struct { id dssmodels.ID ovn restapi.EntityOVN state scdmodels.OperationalIntentState @@ -381,9 +381,9 @@ func validateAndReturnUpsertParams( ovn restapi.EntityOVN, params *restapi.PutOperationalIntentReferenceParameters, allowHTTPBaseUrls bool, -) (*validOIRUpsertParams, error) { +) (*validOIRParams, error) { - valid := &validOIRUpsertParams{} + valid := &validOIRParams{} var err error valid.id, err = dssmodels.IDFromString(string(entityid)) @@ -480,15 +480,15 @@ func checkUpsertPermissionsAndReturnManager(authorizedManager *api.Authorization // upsertOperationalIntentReference inserts or updates an Operational Intent. // If the ovn argument is empty (""), it will attempt to create a new Operational Intent. -func (a *Server) upsertOperationalIntentReference(ctx context.Context, authorizedManager *api.AuthorizationResult, entityid restapi.EntityID, ovn restapi.EntityOVN, params *restapi.PutOperationalIntentReferenceParameters, +func (a *Server) upsertOperationalIntentReference(ctx context.Context, authorizedManager *api.AuthorizationResult, entityid restapi.EntityID, ovn restapi.EntityOVN, unsafeParams *restapi.PutOperationalIntentReferenceParameters, ) (*restapi.ChangeOperationalIntentReferenceResponse, *restapi.AirspaceConflictResponse, error) { - // Note: validateAndReturnUpsertParams and checkUpsertPermissionsAndReturnManager could be moved out of this method and only the valid params passed, + // Note: validateAndReturnUpsertParams and checkUpsertPermissionsAndReturnManager could be moved out of this method and only the valid parameters passed, // but this requires some changes in the caller that go beyond the immediate scope of #1088 and can be done later. - upsertParams, err := validateAndReturnUpsertParams(entityid, ovn, params, a.AllowHTTPBaseUrls) + okParams, err := validateAndReturnUpsertParams(entityid, ovn, unsafeParams, a.AllowHTTPBaseUrls) if err != nil { return nil, nil, stacktrace.PropagateWithCode(err, dsserr.BadRequest, "Failed to validate Operational Intent Reference upsert parameters") } - manager, err := checkUpsertPermissionsAndReturnManager(authorizedManager, upsertParams.state) + manager, err := checkUpsertPermissionsAndReturnManager(authorizedManager, okParams.state) if err != nil { return nil, nil, stacktrace.PropagateWithCode(err, dsserr.PermissionDenied, "Caller is not allowed to upsert with the requested state") } @@ -500,13 +500,13 @@ func (a *Server) upsertOperationalIntentReference(ctx context.Context, authorize // Lock subscriptions based on the cell to reduce the number of retries under concurrent load. // See issue #1002 for details. - err = r.LockSubscriptionsOnCells(ctx, upsertParams.cells) + err = r.LockSubscriptionsOnCells(ctx, okParams.cells) if err != nil { return stacktrace.Propagate(err, "Unable to acquire lock") } // Get existing OperationalIntent, if any, and validate request - old, err := r.GetOperationalIntent(ctx, upsertParams.id) + old, err := r.GetOperationalIntent(ctx, okParams.id) if err != nil { return stacktrace.Propagate(err, "Could not get OperationalIntent from repo") } @@ -530,14 +530,14 @@ func (a *Server) upsertOperationalIntentReference(ctx context.Context, authorize } var sub *scdmodels.Subscription - if upsertParams.subscriptionID.Empty() { - // Create an implicit subscription if the implicit subscription params are set: - // for situations where these params are required but have not been set, + if okParams.subscriptionID.Empty() { + // Create an implicit subscription if the implicit subscription unsafeParams are set: + // for situations where these unsafeParams are required but have not been set, // an error will have been returned earlier. // If they are not set at this point, continue without creating an implicit subscription. - if params.NewSubscription != nil && params.NewSubscription.UssBaseUrl != "" { + if unsafeParams.NewSubscription != nil && unsafeParams.NewSubscription.UssBaseUrl != "" { if !a.AllowHTTPBaseUrls { - err := scdmodels.ValidateUSSBaseURL(string(params.NewSubscription.UssBaseUrl)) + err := scdmodels.ValidateUSSBaseURL(string(unsafeParams.NewSubscription.UssBaseUrl)) if err != nil { return stacktrace.PropagateWithCode(err, dsserr.BadRequest, "Failed to validate USS base URL") } @@ -546,17 +546,17 @@ func (a *Server) upsertOperationalIntentReference(ctx context.Context, authorize subToUpsert := scdmodels.Subscription{ ID: dssmodels.ID(uuid.New().String()), Manager: manager, - StartTime: upsertParams.uExtent.StartTime, - EndTime: upsertParams.uExtent.EndTime, - AltitudeLo: upsertParams.uExtent.SpatialVolume.AltitudeLo, - AltitudeHi: upsertParams.uExtent.SpatialVolume.AltitudeHi, - Cells: upsertParams.cells, - USSBaseURL: string(params.NewSubscription.UssBaseUrl), + StartTime: okParams.uExtent.StartTime, + EndTime: okParams.uExtent.EndTime, + AltitudeLo: okParams.uExtent.SpatialVolume.AltitudeLo, + AltitudeHi: okParams.uExtent.SpatialVolume.AltitudeHi, + Cells: okParams.cells, + USSBaseURL: string(unsafeParams.NewSubscription.UssBaseUrl), NotifyForOperationalIntents: true, ImplicitSubscription: true, } - if params.NewSubscription.NotifyForConstraints != nil { - subToUpsert.NotifyForConstraints = *params.NewSubscription.NotifyForConstraints + if unsafeParams.NewSubscription.NotifyForConstraints != nil { + subToUpsert.NotifyForConstraints = *unsafeParams.NewSubscription.NotifyForConstraints } sub, err = r.UpsertSubscription(ctx, &subToUpsert) @@ -567,38 +567,38 @@ func (a *Server) upsertOperationalIntentReference(ctx context.Context, authorize } else { // Use existing Subscription - sub, err = r.GetSubscription(ctx, upsertParams.subscriptionID) + sub, err = r.GetSubscription(ctx, okParams.subscriptionID) if err != nil { return stacktrace.Propagate(err, "Unable to get Subscription") } if sub == nil { - return stacktrace.NewErrorWithCode(dsserr.BadRequest, "Specified Subscription %s does not exist", upsertParams.subscriptionID) + return stacktrace.NewErrorWithCode(dsserr.BadRequest, "Specified Subscription %s does not exist", okParams.subscriptionID) } if sub.Manager != manager { return stacktrace.Propagate( stacktrace.NewErrorWithCode(dsserr.PermissionDenied, "Specificed Subscription is owned by different client"), - "Subscription %s owned by %s, but %s attempted to use it for an OperationalIntent", upsertParams.subscriptionID, sub.Manager, manager) + "Subscription %s owned by %s, but %s attempted to use it for an OperationalIntent", okParams.subscriptionID, sub.Manager, manager) } updateSub := false - if sub.StartTime != nil && sub.StartTime.After(*upsertParams.uExtent.StartTime) { + if sub.StartTime != nil && sub.StartTime.After(*okParams.uExtent.StartTime) { if sub.ImplicitSubscription { - sub.StartTime = upsertParams.uExtent.StartTime + sub.StartTime = okParams.uExtent.StartTime updateSub = true } else { return stacktrace.NewErrorWithCode(dsserr.BadRequest, "Subscription does not begin until after the OperationalIntent starts") } } - if sub.EndTime != nil && sub.EndTime.Before(*upsertParams.uExtent.EndTime) { + if sub.EndTime != nil && sub.EndTime.Before(*okParams.uExtent.EndTime) { if sub.ImplicitSubscription { - sub.EndTime = upsertParams.uExtent.EndTime + sub.EndTime = okParams.uExtent.EndTime updateSub = true } else { return stacktrace.NewErrorWithCode(dsserr.BadRequest, "Subscription ends before the OperationalIntent ends") } } - if !sub.Cells.Contains(upsertParams.cells) { + if !sub.Cells.Contains(okParams.cells) { if sub.ImplicitSubscription { - sub.Cells = s2.CellUnionFromUnion(sub.Cells, upsertParams.cells) + sub.Cells = s2.CellUnionFromUnion(sub.Cells, okParams.cells) updateSub = true } else { return stacktrace.NewErrorWithCode(dsserr.BadRequest, "Subscription does not cover entire spatial area of the OperationalIntent") @@ -612,25 +612,25 @@ func (a *Server) upsertOperationalIntentReference(ctx context.Context, authorize } } - if upsertParams.state.RequiresKey() { + if okParams.state.RequiresKey() { // Construct a hash set of OVNs as the key key := map[scdmodels.OVN]bool{} - if params.Key != nil { - for _, ovn := range *params.Key { + if unsafeParams.Key != nil { + for _, ovn := range *unsafeParams.Key { key[scdmodels.OVN(ovn)] = true } } // Identify OperationalIntents missing from the key var missingOps []*scdmodels.OperationalIntent - relevantOps, err := r.SearchOperationalIntents(ctx, upsertParams.uExtent) + relevantOps, err := r.SearchOperationalIntents(ctx, okParams.uExtent) if err != nil { return stacktrace.Propagate(err, "Unable to SearchOperations") } for _, relevantOp := range relevantOps { _, ok := key[relevantOp.OVN] // Note: The OIR being mutated does not need to be specified in the key: - if !ok && relevantOp.RequiresKey() && relevantOp.ID != upsertParams.id { + if !ok && relevantOp.RequiresKey() && relevantOp.ID != okParams.id { if relevantOp.Manager != manager { relevantOp.OVN = scdmodels.NoOvnPhrase } @@ -641,7 +641,7 @@ func (a *Server) upsertOperationalIntentReference(ctx context.Context, authorize // Identify Constraints missing from the key var missingConstraints []*scdmodels.Constraint if sub != nil && sub.NotifyForConstraints { - constraints, err := r.SearchConstraints(ctx, upsertParams.uExtent) + constraints, err := r.SearchConstraints(ctx, okParams.uExtent) if err != nil { return stacktrace.Propagate(err, "Unable to SearchConstraints") } @@ -699,19 +699,19 @@ func (a *Server) upsertOperationalIntentReference(ctx context.Context, authorize // Construct the new OperationalIntent op := &scdmodels.OperationalIntent{ - ID: upsertParams.id, + ID: okParams.id, Manager: manager, Version: scdmodels.VersionNumber(version + 1), - StartTime: upsertParams.uExtent.StartTime, - EndTime: upsertParams.uExtent.EndTime, - AltitudeLower: upsertParams.uExtent.SpatialVolume.AltitudeLo, - AltitudeUpper: upsertParams.uExtent.SpatialVolume.AltitudeHi, - Cells: upsertParams.cells, + StartTime: okParams.uExtent.StartTime, + EndTime: okParams.uExtent.EndTime, + AltitudeLower: okParams.uExtent.SpatialVolume.AltitudeLo, + AltitudeUpper: okParams.uExtent.SpatialVolume.AltitudeHi, + Cells: okParams.cells, - USSBaseURL: string(params.UssBaseUrl), + USSBaseURL: string(unsafeParams.UssBaseUrl), SubscriptionID: subID, - State: upsertParams.state, + State: okParams.state, } err = op.ValidateTimeRange() if err != nil { @@ -721,7 +721,7 @@ func (a *Server) upsertOperationalIntentReference(ctx context.Context, authorize // Compute total affected Volume4D for notification purposes var notifyVol4 *dssmodels.Volume4D if old == nil { - notifyVol4 = upsertParams.uExtent + notifyVol4 = okParams.uExtent } else { oldVol4 := &dssmodels.Volume4D{ StartTime: old.StartTime, @@ -733,7 +733,7 @@ func (a *Server) upsertOperationalIntentReference(ctx context.Context, authorize return old.Cells, nil }), }} - notifyVol4, err = dssmodels.UnionVolumes4D(upsertParams.uExtent, oldVol4) + notifyVol4, err = dssmodels.UnionVolumes4D(okParams.uExtent, oldVol4) if err != nil { return stacktrace.Propagate(err, "Error constructing 4D volumes union") }