1 | # Licensed to the StackStorm, Inc ('StackStorm') under one or more |
||
0 ignored issues
–
show
There seems to be a cyclic import (st2common.models.api.base -> st2common.util.schema -> st2common.util.action_db -> st2common.persistence.liveaction -> st2common.transport -> st2common.transport.reactor -> st2common.models.api.trace).
Cyclic imports may cause partly loaded modules to be returned. This might lead to unexpected runtime behavior which is hard to debug.
Loading history...
There seems to be a cyclic import (st2common.models.api.base -> st2common.util.schema -> st2common.util.action_db -> st2common.persistence.action -> st2common.persistence.executionstate -> st2common.persistence.base -> st2common.transport.reactor -> st2common.models.api.trace).
Cyclic imports may cause partly loaded modules to be returned. This might lead to unexpected runtime behavior which is hard to debug.
Loading history...
There seems to be a cyclic import (st2common.models.api.base -> st2common.util.schema -> st2common.util.action_db -> st2common.persistence.action -> st2common.persistence.actionalias -> st2common.persistence.base -> st2common.transport.reactor -> st2common.models.api.trace).
Cyclic imports may cause partly loaded modules to be returned. This might lead to unexpected runtime behavior which is hard to debug.
Loading history...
There seems to be a cyclic import (st2common.models.db.action -> st2common.models.db.liveaction -> st2common.util.action_db -> st2common.persistence.action).
Cyclic imports may cause partly loaded modules to be returned. This might lead to unexpected runtime behavior which is hard to debug.
Loading history...
There seems to be a cyclic import (st2common.models.api.base -> st2common.util.schema -> st2common.util.action_db -> st2common.persistence.action -> st2common.persistence.execution -> st2common.persistence.base -> st2common.transport.reactor -> st2common.models.api.trace).
Cyclic imports may cause partly loaded modules to be returned. This might lead to unexpected runtime behavior which is hard to debug.
Loading history...
There seems to be a cyclic import (st2common.models.api.base -> st2common.util.schema -> st2common.util.action_db -> st2common.persistence.action -> st2common.persistence.execution -> st2common.transport -> st2common.transport.reactor -> st2common.models.api.trace).
Cyclic imports may cause partly loaded modules to be returned. This might lead to unexpected runtime behavior which is hard to debug.
Loading history...
There seems to be a cyclic import (st2common.models.api.base -> st2common.util.schema -> st2common.util.action_db -> st2common.persistence.action -> st2common.persistence.runner -> st2common.persistence.base -> st2common.transport.reactor -> st2common.models.api.trace).
Cyclic imports may cause partly loaded modules to be returned. This might lead to unexpected runtime behavior which is hard to debug.
Loading history...
There seems to be a cyclic import (st2common.models.api.base -> st2common.util.schema -> st2common.util.action_db -> st2common.persistence.runner -> st2common.persistence.base -> st2common.transport.reactor -> st2common.models.api.trace).
Cyclic imports may cause partly loaded modules to be returned. This might lead to unexpected runtime behavior which is hard to debug.
Loading history...
There seems to be a cyclic import (st2common.models.api.base -> st2common.util.schema -> st2common.util.action_db -> st2common.persistence.action -> st2common.persistence.liveaction -> st2common.persistence.base -> st2common.transport.reactor -> st2common.models.api.trace).
Cyclic imports may cause partly loaded modules to be returned. This might lead to unexpected runtime behavior which is hard to debug.
Loading history...
|
|||
2 | # contributor license agreements. See the NOTICE file distributed with |
||
3 | # this work for additional information regarding copyright ownership. |
||
4 | # The ASF licenses this file to You under the Apache License, Version 2.0 |
||
5 | # (the "License"); you may not use this file except in compliance with |
||
6 | # the License. You may obtain a copy of the License at |
||
7 | # |
||
8 | # http://www.apache.org/licenses/LICENSE-2.0 |
||
9 | # |
||
10 | # Unless required by applicable law or agreed to in writing, software |
||
11 | # distributed under the License is distributed on an "AS IS" BASIS, |
||
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
13 | # See the License for the specific language governing permissions and |
||
14 | # limitations under the License. |
||
15 | |||
16 | """ |
||
17 | A script that validates each entry defined in OpenAPI-Spec for st2 APIs |
||
18 | (in st2common/openapi.yaml) has a corresponding API model class defined |
||
19 | in st2common/models/api/. |
||
20 | """ |
||
21 | |||
22 | from __future__ import absolute_import |
||
23 | import os |
||
24 | |||
25 | from oslo_config import cfg |
||
26 | from prance import ResolvingParser |
||
27 | |||
28 | from st2common import config |
||
29 | from st2common import log as logging |
||
30 | from st2common.util import spec_loader |
||
31 | from st2common.script_setup import setup as common_setup |
||
32 | from st2common.script_setup import teardown as common_teardown |
||
33 | import six |
||
34 | |||
35 | |||
36 | __all__ = [ |
||
37 | 'main' |
||
38 | ] |
||
39 | |||
40 | |||
41 | cfg.CONF.register_cli_opt( |
||
42 | cfg.StrOpt('spec-file', short='f', required=False, |
||
43 | default='st2common/st2common/openapi.yaml') |
||
44 | ) |
||
45 | |||
46 | cfg.CONF.register_cli_opt( |
||
47 | cfg.BoolOpt('generate', short='-c', required=False, |
||
48 | default=False) |
||
49 | ) |
||
50 | |||
51 | LOG = logging.getLogger(__name__) |
||
52 | |||
53 | |||
54 | def setup(): |
||
55 | common_setup(config=config, setup_db=False, register_mq_exchanges=False) |
||
56 | |||
57 | |||
58 | def _validate_definitions(spec): |
||
59 | defs = spec.get('definitions', None) |
||
60 | error = False |
||
61 | verbose = cfg.CONF.verbose |
||
62 | |||
63 | for (model, definition) in six.iteritems(defs): |
||
64 | api_model = definition.get('x-api-model', None) |
||
65 | |||
66 | if not api_model: |
||
67 | msg = ( |
||
68 | 'API model field "x-api-model" not defined for definition "%s".' % model |
||
69 | ) |
||
70 | |||
71 | if verbose: |
||
72 | LOG.info('Supplied definition for model %s: \n\n%s.', model, definition) |
||
73 | |||
74 | error = True |
||
75 | LOG.error(msg) |
||
76 | |||
77 | return error |
||
78 | |||
79 | |||
80 | def validate_spec(): |
||
81 | spec_file = cfg.CONF.spec_file |
||
82 | generate_spec = cfg.CONF.generate |
||
83 | |||
84 | if not os.path.exists(spec_file) and not generate_spec: |
||
85 | msg = ('No spec file found in location %s. ' % spec_file + |
||
86 | 'Provide a valid spec file or ' + |
||
87 | 'pass --generate-api-spec to genrate a spec.') |
||
88 | raise Exception(msg) |
||
89 | |||
90 | if generate_spec: |
||
91 | if not spec_file: |
||
92 | raise Exception('Supply a path to write to spec file to.') |
||
93 | |||
94 | spec_string = spec_loader.generate_spec('st2common', 'openapi.yaml.j2') |
||
95 | |||
96 | with open(spec_file, 'w') as f: |
||
97 | f.write(spec_string) |
||
98 | f.flush() |
||
99 | |||
100 | parser = ResolvingParser(spec_file) |
||
101 | spec = parser.specification |
||
102 | |||
103 | return _validate_definitions(spec) |
||
104 | |||
105 | |||
106 | def teartown(): |
||
107 | common_teardown() |
||
108 | |||
109 | |||
110 | def main(): |
||
111 | setup() |
||
112 | |||
113 | try: |
||
114 | ret = validate_spec() |
||
115 | except Exception as e: |
||
116 | LOG.error(e.message) |
||
117 | ret = 1 |
||
118 | finally: |
||
119 | teartown() |
||
120 | |||
121 | return ret |
||
122 |
Cyclic imports may cause partly loaded modules to be returned. This might lead to unexpected runtime behavior which is hard to debug.