1313import click
1414import yaml
1515
16- from scs_cert_lib import load_spec , annotate_validity , add_period
16+ from scs_cert_lib import load_spec , annotate_validity , add_period , normalize_scope
1717
1818
19+ HERE = os .path .dirname (__file__ )
1920DEFAULT_SPECPATH = {
20- '50393e6f-2ae1-4c5c-a62c-3b75f2abef3f' : './ scs-compatible-iaas.yaml' ,
21- '1fffebe6-fd4b-44d3-a36c-fc58b4bb0180' : './ scs-compatible-kaas.yaml' ,
21+ '50393e6f-2ae1-4c5c-a62c-3b75f2abef3f' : os . path . join ( HERE , ' scs-compatible-iaas.yaml') ,
22+ '1fffebe6-fd4b-44d3-a36c-fc58b4bb0180' : os . path . join ( HERE , ' scs-compatible-kaas.yaml') ,
2223}
2324
2425logger = logging .getLogger (__name__ )
2526
2627
28+ def _load_spec (specpath ):
29+ specpath = DEFAULT_SPECPATH .get (normalize_scope (specpath ), specpath )
30+ with open (specpath , "r" , encoding = "UTF-8" ) as fileobj :
31+ return load_spec (yaml .load (fileobj , Loader = yaml .SafeLoader ))
32+
33+
2734def select_valid (versions : list ) -> list :
2835 return [version for version in versions if version ['_explicit_validity' ]]
2936
@@ -37,10 +44,9 @@ def cli():
3744@click .option ('--version' , '-V' , 'version' , type = str , default = None )
3845@click .option ('--tests' , '-t' , 'tests' , type = str , default = None )
3946@click .option ('--section' , '-S' , 'sections' , type = str , multiple = True )
40- @click .argument ('specpath' , type = click . Path ( exists = True ) )
47+ @click .argument ('specpath' , type = str )
4148def select (specpath , version , sections , tests ):
42- with open (specpath , "r" , encoding = "UTF-8" ) as specfile :
43- spec = load_spec (yaml .load (specfile , Loader = yaml .SafeLoader ))
49+ spec = _load_spec (specpath )
4450 checkdate = datetime .date .today ()
4551 annotate_validity (spec ['timeline' ], spec ['versions' ], checkdate )
4652 if version is None :
@@ -121,13 +127,12 @@ def score(specpath, subject, score_yaml, report_yaml):
121127 if not subject :
122128 subject = scorecard ['subject' ]
123129 if not specpath :
124- specpath = DEFAULT_SPECPATH [ scorecard ['scope' ] ]
130+ specpath = scorecard ['scope' ]
125131 elif not subject :
126132 raise click .UsageError ('need to supply at least one of -s or -S' )
127133 elif not specpath :
128134 raise click .UsageError ('need to supply at least one of --spec or -S' )
129- with open (specpath , "r" , encoding = "UTF-8" ) as specfile :
130- spec = load_spec (yaml .load (specfile , Loader = yaml .SafeLoader ))
135+ spec = _load_spec (specpath )
131136 scopeuuid = spec ['uuid' ]
132137 snippet = yaml .load (sys .stdin .read (), Loader = yaml .SafeLoader )
133138 if not snippet :
@@ -161,8 +166,7 @@ def score(specpath, subject, score_yaml, report_yaml):
161166@click .option ('--spec' , 'specpath' , type = click .Path (exists = True ))
162167@click .argument ('score_yaml' , type = click .Path (exists = False ))
163168def init (specpath , subject , score_yaml ):
164- with open (specpath , "r" , encoding = "UTF-8" ) as specfile :
165- spec = load_spec (yaml .load (specfile , Loader = yaml .SafeLoader ))
169+ spec = _load_spec (specpath )
166170 scorecard = {
167171 'subject' : subject ,
168172 'scope' : spec ['uuid' ],
0 commit comments