From b0edd24e9d8c80f4285575c9dc30f2c9daf74e5a Mon Sep 17 00:00:00 2001 From: Julien Perrochet Date: Mon, 2 Sep 2024 21:30:42 +0200 Subject: [PATCH] [scd] oir upsert: fail early with Bad request if both a subscription ID and implicit request are specified --- pkg/scd/operational_intents_handler.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/scd/operational_intents_handler.go b/pkg/scd/operational_intents_handler.go index 226ed0440..ba95a63f6 100644 --- a/pkg/scd/operational_intents_handler.go +++ b/pkg/scd/operational_intents_handler.go @@ -444,6 +444,18 @@ func validateAndReturnUpsertParams( } } + if params.NewSubscription != nil { + // The spec states that NewSubscription.UssBaseUrl is required and an empty value + // makes no sense, so we will fail if an implicit subscription is requested but the base url is empty + if params.NewSubscription.UssBaseUrl == "" { + return nil, stacktrace.NewError("Missing required USS base url for new subscription (in parameters for implicit subscription)") + } + // If an implicit subscription is requested, the Subscription ID cannot be present. + if params.SubscriptionId != nil { + return nil, stacktrace.NewError("Cannot provide both a Subscription ID and request an implicit subscription") + } + } + // Check if a subscription is required for this request: // OIRs in an accepted state do not need a subscription. if valid.state.RequiresSubscription() &&