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:
Change Log
==========
0.0.23
------
- osdu version shows service versions
- added info subcommand to entitlements, legal, schema, search, unit, workflow.
0.0.22
------
......
......@@ -12,4 +12,4 @@
""" OSDU command line environment"""
__VERSION__ = "0.0.22"
__VERSION__ = "0.0.23"
......@@ -131,7 +131,7 @@ class CliOsduClient(OsduClient):
)
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"""
unit_url = self.config.get("core", config_url_key)
url = urljoin(self.server_url, unit_url) + url_extra_path
......@@ -147,7 +147,7 @@ class CliOsduClient(OsduClient):
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].
"""
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)
if ok_status_codes is not None and response.status_code not in ok_status_codes:
raise HTTPError(response=response)
......@@ -163,7 +163,7 @@ class CliOsduClient(OsduClient):
url_extra_path (str): extra path to add to the base path
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)
def cli_post_returning_json(
......@@ -184,7 +184,7 @@ class CliOsduClient(OsduClient):
Returns:
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)
def cli_delete(
......@@ -205,7 +205,7 @@ class CliOsduClient(OsduClient):
[type]: [description]
"""
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)
return
except HTTPError as ex:
......@@ -235,7 +235,7 @@ class CliOsduClient(OsduClient):
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].
"""
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)
if ok_status_codes is not None and response.status_code not in ok_status_codes:
raise HTTPError(response=response)
......@@ -259,5 +259,5 @@ class CliOsduClient(OsduClient):
Returns:
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)
# 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
from osducli.click_cli import CustomClickCommand, State, command_with_output
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 (
CONFIG_ENTITLEMENTS_URL,
CONFIG_FILE_URL,
CONFIG_LEGAL_URL,
CONFIG_SCHEMA_URL,
......@@ -51,15 +61,16 @@ def status(state: State): # pylint: disable=unused-argument
results = []
services = [
("File service", CONFIG_FILE_URL, "readiness_check"),
("Legal service", CONFIG_LEGAL_URL, "_ah/readiness_check"),
("Schema service", CONFIG_SCHEMA_URL, "schema?limit=1"),
("Search service", CONFIG_SEARCH_URL, "health/readiness_check"),
(ENTITLEMENTS_SERVICE_NAME, CONFIG_ENTITLEMENTS_URL, ENTITLEMENTS_STATUS_PATH),
(LEGAL_SERVICE_NAME, CONFIG_LEGAL_URL, LEGAL_STATUS_PATH),
(SCHEMA_SERVICE_NAME, CONFIG_SCHEMA_URL, SCHEMA_STATUS_PATH),
(SEARCH_SERVICE_NAME, CONFIG_SEARCH_URL, SEARCH_STATUS_PATH),
("Storage service", CONFIG_STORAGE_URL, "health"),
("Unit service", CONFIG_UNIT_URL, "../_ah/readiness_check"),
("Workflow service", CONFIG_WORKFLOW_URL, "../readiness_check"),
(UNIT_SERVICE_NAME, CONFIG_UNIT_URL, UNIT_STATUS_PATH),
(WORKFLOW_SERVICE_NAME, CONFIG_WORKFLOW_URL, WORKFLOW_STATUS_PATH),
]
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)
if state.is_user_friendly_mode():
print(f"{result['name'].ljust(20)} {result['status']}\t {result['reason']}")
......@@ -67,7 +78,7 @@ def status(state: State): # pylint: disable=unused-argument
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"""
try:
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 @@
import sys
import click
from requests.exceptions import RequestException
import osducli
from osducli.click_cli import CustomClickCommand, global_params
from osducli.cliclient import handle_cli_exceptions
from osducli.click_cli import CustomClickCommand, State, command_with_output
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.command(cls=CustomClickCommand)
@handle_cli_exceptions
@global_params
def _click_command(_):
@command_with_output("results[]")
def _click_command(state: State):
"""Version information"""
version()
return version(state)
def get_runtime_version() -> str:
......@@ -45,8 +56,40 @@ def get_runtime_version() -> str:
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."""
version_info = f"OSDU Cli Version {osducli.__VERSION__}"
version_info += get_runtime_version()
print(version_info)
if state.is_user_friendly_mode():
version_info = f"OSDU Cli Version {osducli.__VERSION__}"
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,
)
# 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.
"""Service information"""
from osducli.click_cli import State
from osducli.cliclient import CliOsduClient
from osducli.commands.status.status import check_status
from osducli.commands.version.version import get_api_info
def info(state: State, name: str, config_url_key: str, status_path: str, swagger_path: str) -> dict:
"""Return information about the service
Args:
state (State): Global state
name (str): Name of the service
config_url_key (str): Config url key
status_path (str): Path to status service
swagger_path (str): Swagger path
Returns:
dict: Response from service
"""
connection = CliOsduClient(state.config)
status = check_status(connection, name, config_url_key, status_path)
if state.is_user_friendly_mode():
print("Status:", status["status"])
print("Reason:", status["reason"])
version = get_api_info(connection, config_url_key, "info")
if state.is_user_friendly_mode():
if version:
print("Version:", version["version"])
print("Build Time:", version["buildTime"])
print("Branch:", version["branch"])
print("Commit Id:", version["commitId"])
else:
print("No version information available")
swagger_path_expanded = (
connection.url_from_config(config_url_key, swagger_path) if swagger_path else None
)
if state.is_user_friendly_mode():
if swagger_path_expanded:
print("Swagger:", swagger_path_expanded)
else:
print("Swagger path unknown")
return (
None
if state.is_user_friendly_mode()