Commit cab9e3fb authored by Mark Hewitt's avatar Mark Hewitt
Browse files

Merge branch 'feature/version_info' into 'main'

service version information

See merge request !4
parents 335c4b32 808d7c37
Pipeline #75566 passed with stages
in 2 minutes and 31 seconds
...@@ -28,6 +28,12 @@ For more information, specify the `-h` flag: ...@@ -28,6 +28,12 @@ For more information, specify the `-h` flag:
Change Log Change Log
========== ==========
0.0.23
------
- osdu version shows service versions
- added info subcommand to entitlements, legal, schema, search, unit, workflow.
0.0.22 0.0.22
------ ------
......
...@@ -12,4 +12,4 @@ ...@@ -12,4 +12,4 @@
""" OSDU command line environment""" """ OSDU command line environment"""
__VERSION__ = "0.0.22" __VERSION__ = "0.0.23"
...@@ -131,7 +131,7 @@ class CliOsduClient(OsduClient): ...@@ -131,7 +131,7 @@ class CliOsduClient(OsduClient):
) )
sys.exit(1) sys.exit(1)
def _url_from_config(self, config_url_key: str, url_extra_path: str) -> str: def url_from_config(self, config_url_key: str, url_extra_path: str) -> str:
"""Construct a url using values from configuration""" """Construct a url using values from configuration"""
unit_url = self.config.get("core", config_url_key) unit_url = self.config.get("core", config_url_key)
url = urljoin(self.server_url, unit_url) + url_extra_path url = urljoin(self.server_url, unit_url) + url_extra_path
...@@ -147,7 +147,7 @@ class CliOsduClient(OsduClient): ...@@ -147,7 +147,7 @@ class CliOsduClient(OsduClient):
url_extra_path (str): extra path to add to the base path url_extra_path (str): extra path to add to the base path
ok_status_codes (list, optional): Status codes for successful call. Defaults to [200]. ok_status_codes (list, optional): Status codes for successful call. Defaults to [200].
""" """
url = self._url_from_config(config_url_key, url_extra_path) url = self.url_from_config(config_url_key, url_extra_path)
response = self.get(url) response = self.get(url)
if ok_status_codes is not None and response.status_code not in ok_status_codes: if ok_status_codes is not None and response.status_code not in ok_status_codes:
raise HTTPError(response=response) raise HTTPError(response=response)
...@@ -163,7 +163,7 @@ class CliOsduClient(OsduClient): ...@@ -163,7 +163,7 @@ class CliOsduClient(OsduClient):
url_extra_path (str): extra path to add to the base path url_extra_path (str): extra path to add to the base path
ok_status_codes (list, optional): accepted ok response codes. Defaults to None. ok_status_codes (list, optional): accepted ok response codes. Defaults to None.
""" """
url = self._url_from_config(config_url_key, url_extra_path) url = self.url_from_config(config_url_key, url_extra_path)
return self.get_returning_json(url, ok_status_codes) return self.get_returning_json(url, ok_status_codes)
def cli_post_returning_json( def cli_post_returning_json(
...@@ -184,7 +184,7 @@ class CliOsduClient(OsduClient): ...@@ -184,7 +184,7 @@ class CliOsduClient(OsduClient):
Returns: Returns:
dict: returned json dict: returned json
""" """
url = self._url_from_config(config_url_key, url_extra_path) url = self.url_from_config(config_url_key, url_extra_path)
return self.post_returning_json(url, data, ok_status_codes) return self.post_returning_json(url, data, ok_status_codes)
def cli_delete( def cli_delete(
...@@ -205,7 +205,7 @@ class CliOsduClient(OsduClient): ...@@ -205,7 +205,7 @@ class CliOsduClient(OsduClient):
[type]: [description] [type]: [description]
""" """
try: try:
url = self._url_from_config(config_url_key, url_extra_path) url = self.url_from_config(config_url_key, url_extra_path)
self.delete(url, ok_status_codes) self.delete(url, ok_status_codes)
return return
except HTTPError as ex: except HTTPError as ex:
...@@ -235,7 +235,7 @@ class CliOsduClient(OsduClient): ...@@ -235,7 +235,7 @@ class CliOsduClient(OsduClient):
url_extra_path (str): extra path to add to the base path url_extra_path (str): extra path to add to the base path
ok_status_codes (list, optional): Status codes for successful call. Defaults to [200]. ok_status_codes (list, optional): Status codes for successful call. Defaults to [200].
""" """
url = self._url_from_config(config_url_key, url_extra_path) url = self.url_from_config(config_url_key, url_extra_path)
response = self.put(url, data) response = self.put(url, data)
if ok_status_codes is not None and response.status_code not in ok_status_codes: if ok_status_codes is not None and response.status_code not in ok_status_codes:
raise HTTPError(response=response) raise HTTPError(response=response)
...@@ -259,5 +259,5 @@ class CliOsduClient(OsduClient): ...@@ -259,5 +259,5 @@ class CliOsduClient(OsduClient):
Returns: Returns:
dict: returned json dict: returned json
""" """
url = self._url_from_config(config_url_key, url_extra_path) url = self.url_from_config(config_url_key, url_extra_path)
return self.put_returning_json(url, data, ok_status_codes) return self.put_returning_json(url, data, ok_status_codes)
# 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.
"""Entitlements constants"""
ENTITLEMENTS_SERVICE_NAME = "Entitlements Service"
ENTITLEMENTS_STATUS_PATH = "_ah/readiness_check"
ENTITLEMENTS_SWAGGER_PATH = "swagger-ui.html"
# 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.
"""Entitlements info command"""
import click
from osducli.click_cli import CustomClickCommand, State, command_with_output
from osducli.cliclient import handle_cli_exceptions
from osducli.config import CONFIG_ENTITLEMENTS_URL
from osducli.util.service_info import info
from ._const import (
ENTITLEMENTS_SERVICE_NAME,
ENTITLEMENTS_STATUS_PATH,
ENTITLEMENTS_SWAGGER_PATH,
)
# click entry point
@click.command(cls=CustomClickCommand)
@handle_cli_exceptions
@command_with_output(None)
def _click_command(state: State) -> dict:
"""Information about the service"""
return info(
state,
ENTITLEMENTS_SERVICE_NAME,
CONFIG_ENTITLEMENTS_URL,
ENTITLEMENTS_STATUS_PATH,
ENTITLEMENTS_SWAGGER_PATH,
)
# 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.
"""Legal constants"""
LEGAL_SERVICE_NAME = "Legal service"
LEGAL_STATUS_PATH = "_ah/readiness_check"
LEGAL_SWAGGER_PATH = "swagger-ui.html"
# 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.
"""Legal info command"""
import click
from osducli.click_cli import CustomClickCommand, State, command_with_output
from osducli.cliclient import handle_cli_exceptions
from osducli.config import CONFIG_LEGAL_URL
from osducli.util.service_info import info
from ._const import LEGAL_SERVICE_NAME, LEGAL_STATUS_PATH, LEGAL_SWAGGER_PATH
# click entry point
@click.command(cls=CustomClickCommand)
@handle_cli_exceptions
@command_with_output(None)
def _click_command(state: State) -> dict:
"""Information about the service"""
return info(state, LEGAL_SERVICE_NAME, CONFIG_LEGAL_URL, LEGAL_STATUS_PATH, LEGAL_SWAGGER_PATH)
# 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.
"""Schema constants"""
SCHEMA_SERVICE_NAME = "Schema service"
SCHEMA_STATUS_PATH = "schema?limit=1"
SCHEMA_SWAGGER_PATH = "swagger-ui.html"
# 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.
"""Schema info command"""
import click
from osducli.click_cli import CustomClickCommand, State, command_with_output
from osducli.cliclient import handle_cli_exceptions
from osducli.config import CONFIG_SCHEMA_URL
from osducli.util.service_info import info
from osducli.commands.schema._const import (
SCHEMA_SERVICE_NAME,
SCHEMA_STATUS_PATH,
SCHEMA_SWAGGER_PATH,
)
# click entry point
@click.command(cls=CustomClickCommand)
@handle_cli_exceptions
@command_with_output(None)
def _click_command(state: State) -> dict:
"""Information about the service"""
return info(
state, SCHEMA_SERVICE_NAME, CONFIG_SCHEMA_URL, SCHEMA_STATUS_PATH, SCHEMA_SWAGGER_PATH
)
# 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.
"""Search constants"""
SEARCH_SERVICE_NAME = "Search service"
SEARCH_STATUS_PATH = "health/readiness_check"
SEARCH_SWAGGER_PATH = "swagger-ui.html"
# 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.
"""Search info command"""
import click
from osducli.click_cli import CustomClickCommand, State, command_with_output
from osducli.cliclient import handle_cli_exceptions
from osducli.config import CONFIG_SEARCH_URL
from osducli.util.service_info import info
from ._const import SEARCH_SERVICE_NAME, SEARCH_STATUS_PATH, SEARCH_SWAGGER_PATH
# click entry point
@click.command(cls=CustomClickCommand)
@handle_cli_exceptions
@command_with_output(None)
def _click_command(state: State) -> dict:
"""Information about the service"""
return info(
state, SEARCH_SERVICE_NAME, CONFIG_SEARCH_URL, SEARCH_STATUS_PATH, SEARCH_SWAGGER_PATH
)
...@@ -17,7 +17,17 @@ from requests.exceptions import RequestException ...@@ -17,7 +17,17 @@ from requests.exceptions import RequestException
from osducli.click_cli import CustomClickCommand, State, command_with_output from osducli.click_cli import CustomClickCommand, State, command_with_output
from osducli.cliclient import CliOsduClient, handle_cli_exceptions from osducli.cliclient import CliOsduClient, handle_cli_exceptions
from osducli.commands.entitlements._const import (
ENTITLEMENTS_SERVICE_NAME,
ENTITLEMENTS_STATUS_PATH,
)
from osducli.commands.legal._const import LEGAL_SERVICE_NAME, LEGAL_STATUS_PATH
from osducli.commands.schema._const import SCHEMA_SERVICE_NAME, SCHEMA_STATUS_PATH
from osducli.commands.search._const import SEARCH_SERVICE_NAME, SEARCH_STATUS_PATH
from osducli.commands.unit._const import UNIT_SERVICE_NAME, UNIT_STATUS_PATH
from osducli.commands.workflow._const import WORKFLOW_SERVICE_NAME, WORKFLOW_STATUS_PATH
from osducli.config import ( from osducli.config import (
CONFIG_ENTITLEMENTS_URL,
CONFIG_FILE_URL, CONFIG_FILE_URL,
CONFIG_LEGAL_URL, CONFIG_LEGAL_URL,
CONFIG_SCHEMA_URL, CONFIG_SCHEMA_URL,
...@@ -51,15 +61,16 @@ def status(state: State): # pylint: disable=unused-argument ...@@ -51,15 +61,16 @@ def status(state: State): # pylint: disable=unused-argument
results = [] results = []
services = [ services = [
("File service", CONFIG_FILE_URL, "readiness_check"), ("File service", CONFIG_FILE_URL, "readiness_check"),
("Legal service", CONFIG_LEGAL_URL, "_ah/readiness_check"), (ENTITLEMENTS_SERVICE_NAME, CONFIG_ENTITLEMENTS_URL, ENTITLEMENTS_STATUS_PATH),
("Schema service", CONFIG_SCHEMA_URL, "schema?limit=1"), (LEGAL_SERVICE_NAME, CONFIG_LEGAL_URL, LEGAL_STATUS_PATH),
("Search service", CONFIG_SEARCH_URL, "health/readiness_check"), (SCHEMA_SERVICE_NAME, CONFIG_SCHEMA_URL, SCHEMA_STATUS_PATH),
(SEARCH_SERVICE_NAME, CONFIG_SEARCH_URL, SEARCH_STATUS_PATH),
("Storage service", CONFIG_STORAGE_URL, "health"), ("Storage service", CONFIG_STORAGE_URL, "health"),
("Unit service", CONFIG_UNIT_URL, "../_ah/readiness_check"), (UNIT_SERVICE_NAME, CONFIG_UNIT_URL, UNIT_STATUS_PATH),
("Workflow service", CONFIG_WORKFLOW_URL, "../readiness_check"), (WORKFLOW_SERVICE_NAME, CONFIG_WORKFLOW_URL, WORKFLOW_STATUS_PATH),
] ]
for service in services: for service in services:
result = _check_status(connection, service[0], service[1], service[2]) result = check_status(connection, service[0], service[1], service[2])
results.append(result) results.append(result)
if state.is_user_friendly_mode(): if state.is_user_friendly_mode():
print(f"{result['name'].ljust(20)} {result['status']}\t {result['reason']}") print(f"{result['name'].ljust(20)} {result['status']}\t {result['reason']}")
...@@ -67,7 +78,7 @@ def status(state: State): # pylint: disable=unused-argument ...@@ -67,7 +78,7 @@ def status(state: State): # pylint: disable=unused-argument
return None if state.is_user_friendly_mode() else {"results": results} return None if state.is_user_friendly_mode() else {"results": results}
def _check_status(connection: CliOsduClient, name: str, config_url_key: str, url_extra_path: str): def check_status(connection: CliOsduClient, name: str, config_url_key: str, url_extra_path: str):
"""Check the status of the given service""" """Check the status of the given service"""
try: try:
response = connection.cli_get(config_url_key, url_extra_path) response = connection.cli_get(config_url_key, url_extra_path)
......
# 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.
"""Unit constants"""
UNIT_SERVICE_NAME = "Unit service"
UNIT_STATUS_PATH = "../_ah/readiness_check"
UNIT_SWAGGER_PATH = "../swagger-ui.html"
# 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.
"""Unit info command"""
import click
from osducli.click_cli import CustomClickCommand, State, command_with_output
from osducli.cliclient import handle_cli_exceptions
from osducli.config import CONFIG_UNIT_URL
from osducli.util.service_info import info
from ._const import UNIT_SERVICE_NAME, UNIT_STATUS_PATH, UNIT_SWAGGER_PATH
# click entry point
@click.command(cls=CustomClickCommand)
@handle_cli_exceptions
@command_with_output(None)
def _click_command(state: State) -> dict:
"""Information about the service"""
return info(state, UNIT_SERVICE_NAME, CONFIG_UNIT_URL, UNIT_STATUS_PATH, UNIT_SWAGGER_PATH)
...@@ -15,19 +15,30 @@ ...@@ -15,19 +15,30 @@
import sys import sys
import click import click
from requests.exceptions import RequestException
import osducli import osducli
from osducli.click_cli import CustomClickCommand, global_params from osducli.click_cli import CustomClickCommand, State, command_with_output
from osducli.cliclient import handle_cli_exceptions from osducli.cliclient import CliOsduClient, handle_cli_exceptions
from osducli.config import (
CONFIG_ENTITLEMENTS_URL,
CONFIG_LEGAL_URL,
CONFIG_SCHEMA_URL,
CONFIG_SEARCH_URL,
CONFIG_STORAGE_URL,
)
from osducli.log import get_logger
logger = get_logger(__name__)
# click entry point # click entry point
@click.command(cls=CustomClickCommand) @click.command(cls=CustomClickCommand)
@handle_cli_exceptions @handle_cli_exceptions
@global_params @command_with_output("results[]")
def _click_command(_): def _click_command(state: State):
"""Version information""" """Version information"""
version() return version(state)
def get_runtime_version() -> str: def get_runtime_version() -> str:
...@@ -45,8 +56,40 @@ def get_runtime_version() -> str: ...@@ -45,8 +56,40 @@ def get_runtime_version() -> str:
return version_info return version_info
def version(): def get_api_info(connection: CliOsduClient, config_url_key: str, url_extra_path: str):
"""Check the status of the given service"""
try:
response = connection.cli_get_returning_json(config_url_key, url_extra_path)
return response
except RequestException: # pylint: disable=broad-except
return None
def version(state: State):
"""Print version information to standard system out.""" """Print version information to standard system out."""
version_info = f"OSDU Cli Version {osducli.__VERSION__}" if state.is_user_friendly_mode():
version_info += get_runtime_version() version_info = f"OSDU Cli Version {osducli.__VERSION__}"
print(version_info) version_info += get_runtime_version()
print(version_info)
services = [
("File service", CONFIG_ENTITLEMENTS_URL, "info"),
("Legal service", CONFIG_LEGAL_URL, "info"),
("Schema service", CONFIG_SCHEMA_URL, "info"),
("Search service", CONFIG_SEARCH_URL, "info"),
("Storage service", CONFIG_STORAGE_URL, "info"),
]
results = []
connection = CliOsduClient(state.config)
for service in services:
result = get_api_info(connection, service[1], service[2])
results.append(result)
if state.is_user_friendly_mode():
print()
print(service[0])
print(" Version:", result["version"])
print(" Build Time:", result["buildTime"])
print(" Branch:", result["branch"])
print(" Commit Id:", result["commitId"])
return None if state.is_user_friendly_mode() else {"results": results}
# 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.
"""Workflow constants"""
WORKFLOW_SERVICE_NAME = "Workflow service"
WORKFLOW_STATUS_PATH = "../readiness_check"
WORKFLOW_SWAGGER_PATH = None
# 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.
"""Workflow info command"""
import click
from osducli.click_cli import CustomClickCommand, State, command_with_output
from osducli.cliclient import handle_cli_exceptions
from osducli.config import CONFIG_WORKFLOW_URL
from osducli.util.service_info import info
from ._const import WORKFLOW_SERVICE_NAME, WORKFLOW_STATUS_PATH, WORKFLOW_SWAGGER_PATH
# click entry point
@click.command(cls=CustomClickCommand)
@handle_cli_exceptions
@command_with_output(None)
def _click_command(state: State) -> dict:
"""Information about the service"""
return info(
state,
WORKFLOW_SERVICE_NAME,
CONFIG_WORKFLOW_URL,
WORKFLOW_STATUS_PATH,
WORKFLOW_SWAGGER_PATH,