From 2672518812d6ad17aca0cf0e785ea8b24e475ce4 Mon Sep 17 00:00:00 2001 From: Julien Perrochet Date: Wed, 25 Sep 2024 01:28:42 +0200 Subject: [PATCH] [mock_uss] OIR creation selects the proper scope for the requested state (#788) --- monitoring/monitorlib/clients/scd.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/monitoring/monitorlib/clients/scd.py b/monitoring/monitorlib/clients/scd.py index 7f88384ba1..da3c0d531f 100644 --- a/monitoring/monitorlib/clients/scd.py +++ b/monitoring/monitorlib/clients/scd.py @@ -1,5 +1,7 @@ from typing import List, Optional, Tuple +from uas_standards.astm.f3548.v21.api import OperationalIntentState + from monitoring.monitorlib import fetch, scd from monitoring.monitorlib.clients import call_query_hooks from monitoring.monitorlib.fetch import QueryError, Query, QueryType @@ -8,6 +10,20 @@ from uas_standards.astm.f3548.v21 import api +def _scopes_for_state(state: OperationalIntentState) -> List[str]: + """ + The scope required to set an OIR's state depends on the state itself: Contingent and Nonconforming + require the CMSA scope in addition to SC. + """ + scopes = [scd.SCOPE_SC] + if ( + state == OperationalIntentState.Contingent + or state == OperationalIntentState.Nonconforming + ): + scopes.append(scd.SCOPE_CM_SA) + return scopes + + # === DSS operations defined in ASTM API === @@ -52,8 +68,9 @@ def create_operational_intent_reference( url = "/dss/v1/operational_intent_references/{}".format(id) subject = f"createOperationalIntentReference to {url}" query = fetch.query_and_describe( - utm_client, "PUT", url, json=req, scopes=[scd.SCOPE_SC, scd.SCOPE_CM_SA] + utm_client, "PUT", url, json=req, scopes=_scopes_for_state(req.state) ) + if query.status_code != 200 and query.status_code != 201: raise QueryError( msg="{} failed {}:\n{}".format( @@ -84,7 +101,7 @@ def update_operational_intent_reference( url = "/dss/v1/operational_intent_references/{}/{}".format(id, ovn) subject = f"updateOperationalIntentReference to {url}" query = fetch.query_and_describe( - utm_client, "PUT", url, json=req, scopes=[scd.SCOPE_SC, scd.SCOPE_CM_SA] + utm_client, "PUT", url, json=req, scopes=_scopes_for_state(req.state) ) if query.status_code != 200 and query.status_code != 201: raise QueryError(