diff --git a/doc/source/admin/configuration/config-guide.rst b/doc/source/admin/configuration/config-guide.rst index e6ec3f0d4..4e4d37bdc 100644 --- a/doc/source/admin/configuration/config-guide.rst +++ b/doc/source/admin/configuration/config-guide.rst @@ -284,6 +284,16 @@ directory. [notifier] notify = [ {"type": "webhook", "url": "http://example.com", "headers": {"X-Auth-Token": "XXXX"}}, {"type": "custom_publisher"} ] +#. Configure info endpoint. Info endpoint could be used for exposing some + important for support data in json format. This endpoint should be enabled + manually. Store filled info file into environment where Mistral will be + running. + + The default configuration is the following:: + [api] + enable_info_endpoint = False + info_json_file_path = info.json + #. Finally, try to run mistral engine and verify that it is running without any error:: diff --git a/mistral/api/controllers/info.py b/mistral/api/controllers/info.py new file mode 100644 index 000000000..b16837f92 --- /dev/null +++ b/mistral/api/controllers/info.py @@ -0,0 +1,39 @@ +# Copyright 2022 - NetCracker Technology Corp. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import json +from mistral import exceptions as exc +from mistral.utils import rest_utils +import os.path +from oslo_config import cfg +import pecan +from pecan import rest + + +class InfoController(rest.RestController): + + @rest_utils.wrap_pecan_controller_exception + @pecan.expose('json') + def get(self): + if not cfg.CONF.api.enable_info_endpoint: + raise exc.InfoEndpointNotAvailableException( + "Info endpoint disabled." + ) + file_path = cfg.CONF.api.info_json_file_path + if not os.path.exists(file_path): + raise exc.InfoEndpointNotAvailableException( + "Incorrect path to info json file." + ) + with open(file_path) as f: + return json.load(f) diff --git a/mistral/api/controllers/root.py b/mistral/api/controllers/root.py index 355c3b1ba..22943abf5 100644 --- a/mistral/api/controllers/root.py +++ b/mistral/api/controllers/root.py @@ -17,6 +17,7 @@ import pecan from wsme import types as wtypes import wsmeext.pecan as wsme_pecan +from mistral.api.controllers import info from mistral.api.controllers import resource from mistral.api.controllers.v2 import root as v2_root @@ -62,6 +63,7 @@ class APIVersions(resource.Resource): class RootController(object): v2 = v2_root.Controller() + info = info.InfoController() @wsme_pecan.wsexpose(APIVersions) def index(self): diff --git a/mistral/config.py b/mistral/config.py index 3aa4f44d4..ba4344539 100644 --- a/mistral/config.py +++ b/mistral/config.py @@ -129,7 +129,19 @@ api_opts = [ "turned off in the API request. 'disabled' disables validation " "for all API requests. 'mandatory' enables validation for all " "API requests.") - ) + ), + cfg.BoolOpt( + 'enable_info_endpoint', + default=False, + help=_('Enable API for exposing info json about ' + 'current Mistral build.') + ), + cfg.StrOpt( + 'info_json_file_path', + default='info.json', + help=_("Specify the path to info json file which will be " + "exposed via /info endpoint.") + ), ] js_impl_opt = cfg.StrOpt( diff --git a/mistral/context.py b/mistral/context.py index 614786ab4..adc684c29 100644 --- a/mistral/context.py +++ b/mistral/context.py @@ -36,7 +36,13 @@ LOG = logging.getLogger(__name__) CONF = cfg.CONF _CTX_THREAD_LOCAL_NAME = "MISTRAL_APP_CTX_THREAD_LOCAL" -ALLOWED_WITHOUT_AUTH = ['/', '/v2/', '/workflowv2/', '/workflowv2/v2/'] +ALLOWED_WITHOUT_AUTH = [ + '/', + '/info', + '/v2/', + '/workflowv2/', + '/workflowv2/v2/' +] class MistralContext(oslo_context.RequestContext): diff --git a/mistral/exceptions.py b/mistral/exceptions.py index d6b60ba60..237e70bc0 100644 --- a/mistral/exceptions.py +++ b/mistral/exceptions.py @@ -190,6 +190,10 @@ class UnauthorizedException(MistralException): message = "Unauthorized" +class InfoEndpointNotAvailableException(MistralException): + http_code = 400 + + class KombuException(Exception): def __init__(self, e): super(KombuException, self).__init__(e)