domino-cli 2.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- domino_cli/__init__.py +20 -0
- domino_cli/__main__.py +4 -0
- domino_cli/core/ApplicationContext.py +144 -0
- domino_cli/core/__init__.py +0 -0
- domino_cli/core/cli/CLI.py +23 -0
- domino_cli/core/cli/__init__.py +0 -0
- domino_cli/core/client/DominoClient.py +31 -0
- domino_cli/core/client/OAuthAuthorizationClient.py +54 -0
- domino_cli/core/client/__init__.py +0 -0
- domino_cli/core/command/AbstractCommand.py +31 -0
- domino_cli/core/command/AbstractLifecycleCommand.py +26 -0
- domino_cli/core/command/AuthCommand.py +46 -0
- domino_cli/core/command/DeployApplicationCommand.py +36 -0
- domino_cli/core/command/ExitCommand.py +16 -0
- domino_cli/core/command/HelpCommand.py +18 -0
- domino_cli/core/command/InfoCommand.py +14 -0
- domino_cli/core/command/RestartApplicationCommand.py +14 -0
- domino_cli/core/command/StartApplicationCommand.py +14 -0
- domino_cli/core/command/StopApplicationCommand.py +14 -0
- domino_cli/core/command/WizardCommand.py +27 -0
- domino_cli/core/command/__init__.py +0 -0
- domino_cli/core/domain/AuthMode.py +23 -0
- domino_cli/core/domain/AuthRequest.py +18 -0
- domino_cli/core/domain/CommandDescriptor.py +17 -0
- domino_cli/core/domain/DominoCommand.py +26 -0
- domino_cli/core/domain/DominoRequest.py +15 -0
- domino_cli/core/domain/HTTPMethod.py +12 -0
- domino_cli/core/domain/OAuthConfig.py +47 -0
- domino_cli/core/domain/SessionContext.py +7 -0
- domino_cli/core/domain/__init__.py +0 -0
- domino_cli/core/service/AuthenticationService.py +75 -0
- domino_cli/core/service/CommandProcessor.py +36 -0
- domino_cli/core/service/ConfigurationWizardService.py +41 -0
- domino_cli/core/service/DominoService.py +53 -0
- domino_cli/core/service/SessionContextHolder.py +27 -0
- domino_cli/core/service/__init__.py +0 -0
- domino_cli/core/service/auth/AbstractAuthHandler.py +29 -0
- domino_cli/core/service/auth/AuthUtils.py +39 -0
- domino_cli/core/service/auth/DirectAuthHandler.py +47 -0
- domino_cli/core/service/auth/OAuthAuthHandler.py +32 -0
- domino_cli/core/service/auth/__init__.py +0 -0
- domino_cli/core/service/utility/BCryptUtil.py +15 -0
- domino_cli/core/service/utility/__init__.py +0 -0
- domino_cli/core/service/wizard/AbstractAgentConfigWizard.py +79 -0
- domino_cli/core/service/wizard/AbstractWizard.py +120 -0
- domino_cli/core/service/wizard/BinaryExecutableAgentConfigWizard.py +60 -0
- domino_cli/core/service/wizard/CoordinatorConfigWizard.py +99 -0
- domino_cli/core/service/wizard/DeploymentConfigWizard.py +117 -0
- domino_cli/core/service/wizard/DockerAgentConfigWizard.py +53 -0
- domino_cli/core/service/wizard/InstallerWizard.py +62 -0
- domino_cli/core/service/wizard/__init__.py +0 -0
- domino_cli/core/service/wizard/installer/BinaryExecutablePlatformComponentInstaller.py +79 -0
- domino_cli/core/service/wizard/installer/DockerPlatformComponentInstaller.py +85 -0
- domino_cli/core/service/wizard/installer/DockerVersionResolver.py +24 -0
- domino_cli/core/service/wizard/installer/GitHubReleaseVersionResolver.py +36 -0
- domino_cli/core/service/wizard/installer/PlatformComponentInstaller.py +58 -0
- domino_cli/core/service/wizard/installer/__init__.py +18 -0
- domino_cli/core/service/wizard/mapping/BinaryExecutableAgentConfigWizardDataMapping.py +26 -0
- domino_cli/core/service/wizard/mapping/CommonAgentConfigWizardDataMapping.py +27 -0
- domino_cli/core/service/wizard/mapping/CoordinatorConfigWizardDataMapping.py +43 -0
- domino_cli/core/service/wizard/mapping/DeploymentConfigWizardDataMapping.py +47 -0
- domino_cli/core/service/wizard/mapping/DockerAgentConfigWizardDataMapping.py +20 -0
- domino_cli/core/service/wizard/mapping/InstallerWizardDataMapping.py +27 -0
- domino_cli/core/service/wizard/mapping/WizardDataMappingBaseEnum.py +68 -0
- domino_cli/core/service/wizard/mapping/__init__.py +0 -0
- domino_cli/core/service/wizard/render/WizardResultConsoleRenderer.py +19 -0
- domino_cli/core/service/wizard/render/WizardResultFileRenderer.py +35 -0
- domino_cli/core/service/wizard/render/__init__.py +0 -0
- domino_cli/core/service/wizard/step/BaseWizardStep.py +47 -0
- domino_cli/core/service/wizard/step/KeyValuePairAnswerWizardStep.py +30 -0
- domino_cli/core/service/wizard/step/MultiAnswerWizardStep.py +24 -0
- domino_cli/core/service/wizard/step/OptionSelectorWizardStep.py +59 -0
- domino_cli/core/service/wizard/step/WizardStep.py +80 -0
- domino_cli/core/service/wizard/step/__init__.py +0 -0
- domino_cli/core/service/wizard/transformer/AbstractWizardResultTransformer.py +109 -0
- domino_cli/core/service/wizard/transformer/BinaryExecutableAgentConfigWizardResultTransformer.py +39 -0
- domino_cli/core/service/wizard/transformer/CoordinatorConfigWizardResultTransformer.py +47 -0
- domino_cli/core/service/wizard/transformer/DeploymentConfigWizardResultTransformer.py +87 -0
- domino_cli/core/service/wizard/transformer/DockerAgentConfigWizardResultTransformer.py +39 -0
- domino_cli/core/service/wizard/transformer/__init__.py +0 -0
- domino_cli/core/util/ArrayStream.py +40 -0
- domino_cli/core/util/__init__.py +0 -0
- domino_cli/installer_config.py +34 -0
- domino_cli/resource/__init__.py +0 -0
- domino_cli/resource/help.txt +14 -0
- domino_cli-2.0.0.dist-info/METADATA +198 -0
- domino_cli-2.0.0.dist-info/RECORD +89 -0
- domino_cli-2.0.0.dist-info/WHEEL +4 -0
- domino_cli-2.0.0.dist-info/entry_points.txt +2 -0
domino_cli/__init__.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""
|
|
2
|
+
domino_cli.py :: Main entry point for Domino CLI application.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
__version__ = "2.0.0"
|
|
6
|
+
|
|
7
|
+
import os
|
|
8
|
+
|
|
9
|
+
from domino_cli.core.ApplicationContext import ApplicationContext
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _set_work_dir() -> None:
|
|
13
|
+
script_path: str = os.path.realpath(__file__)
|
|
14
|
+
script_dir: str = os.path.dirname(script_path)
|
|
15
|
+
os.chdir(script_dir)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def main() -> None:
|
|
19
|
+
_set_work_dir()
|
|
20
|
+
ApplicationContext.init_cli(__version__).run_loop()
|
domino_cli/__main__.py
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
from domino_cli.core.cli.CLI import CLI
|
|
4
|
+
from domino_cli.core.client.DominoClient import DominoClient
|
|
5
|
+
from domino_cli.core.client.OAuthAuthorizationClient import OAuthAuthorizationClient
|
|
6
|
+
from domino_cli.core.command.AuthCommand import AuthCommand
|
|
7
|
+
from domino_cli.core.command.DeployApplicationCommand import DeployApplicationCommand
|
|
8
|
+
from domino_cli.core.command.ExitCommand import ExitCommand
|
|
9
|
+
from domino_cli.core.command.HelpCommand import HelpCommand
|
|
10
|
+
from domino_cli.core.command.InfoCommand import InfoCommand
|
|
11
|
+
from domino_cli.core.command.RestartApplicationCommand import RestartApplicationCommand
|
|
12
|
+
from domino_cli.core.command.StartApplicationCommand import StartApplicationCommand
|
|
13
|
+
from domino_cli.core.command.StopApplicationCommand import StopApplicationCommand
|
|
14
|
+
from domino_cli.core.command.WizardCommand import WizardCommand
|
|
15
|
+
from domino_cli.core.domain.AuthMode import AuthMode
|
|
16
|
+
from domino_cli.core.domain.OAuthConfig import OAuthConfig
|
|
17
|
+
from domino_cli.core.service.AuthenticationService import AuthenticationService
|
|
18
|
+
from domino_cli.core.service.CommandProcessor import CommandProcessor
|
|
19
|
+
from domino_cli.core.service.ConfigurationWizardService import ConfigurationWizardService
|
|
20
|
+
from domino_cli.core.service.DominoService import DominoService
|
|
21
|
+
from domino_cli.core.service.SessionContextHolder import SessionContextHolder
|
|
22
|
+
from domino_cli.core.service.auth.DirectAuthHandler import DirectAuthHandler
|
|
23
|
+
from domino_cli.core.service.auth.OAuthAuthHandler import OAuthAuthHandler
|
|
24
|
+
from domino_cli.core.service.wizard.BinaryExecutableAgentConfigWizard import BinaryExecutableAgentConfigWizard
|
|
25
|
+
from domino_cli.core.service.wizard.CoordinatorConfigWizard import CoordinatorConfigWizard
|
|
26
|
+
from domino_cli.core.service.wizard.DeploymentConfigWizard import DeploymentConfigWizard
|
|
27
|
+
from domino_cli.core.service.wizard.DockerAgentConfigWizard import DockerAgentConfigWizard
|
|
28
|
+
from domino_cli.core.service.wizard.InstallerWizard import InstallerWizard
|
|
29
|
+
from domino_cli.core.service.wizard.installer.BinaryExecutablePlatformComponentInstaller import \
|
|
30
|
+
BinaryExecutablePlatformComponentInstaller
|
|
31
|
+
from domino_cli.core.service.wizard.installer.DockerPlatformComponentInstaller import DockerPlatformComponentInstaller
|
|
32
|
+
from domino_cli.core.service.wizard.installer.DockerVersionResolver import DockerVersionResolver
|
|
33
|
+
from domino_cli.core.service.wizard.installer.GitHubReleaseVersionResolver import GitHubReleaseVersionResolver
|
|
34
|
+
from domino_cli.core.service.wizard.render.WizardResultConsoleRenderer import WizardResultConsoleRenderer
|
|
35
|
+
from domino_cli.core.service.wizard.render.WizardResultFileRenderer import WizardResultFileRenderer
|
|
36
|
+
from domino_cli.core.service.wizard.transformer.BinaryExecutableAgentConfigWizardResultTransformer import \
|
|
37
|
+
BinaryExecutableAgentConfigWizardResultTransformer
|
|
38
|
+
from domino_cli.core.service.wizard.transformer.CoordinatorConfigWizardResultTransformer import \
|
|
39
|
+
CoordinatorConfigWizardResultTransformer
|
|
40
|
+
from domino_cli.core.service.wizard.transformer.DeploymentConfigWizardResultTransformer import \
|
|
41
|
+
DeploymentConfigWizardResultTransformer
|
|
42
|
+
from domino_cli.core.service.wizard.transformer.DockerAgentConfigWizardResultTransformer import \
|
|
43
|
+
DockerAgentConfigWizardResultTransformer
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class ApplicationContext:
|
|
47
|
+
"""
|
|
48
|
+
Simple IoC container for Domino CLI.
|
|
49
|
+
"""
|
|
50
|
+
@staticmethod
|
|
51
|
+
def init_cli(version: str) -> CLI:
|
|
52
|
+
|
|
53
|
+
print("Initializing Domino CLI...")
|
|
54
|
+
|
|
55
|
+
# configuration properties
|
|
56
|
+
_domino_base_url = ApplicationContext._assert_config_value("DOMINO_BASE_URL")
|
|
57
|
+
_default_auth_mode = AuthMode.by_value(os.getenv("DOMINO_DEFAULT_AUTH_MODE", AuthMode.DIRECT.value))
|
|
58
|
+
_oauth_config = OAuthConfig()
|
|
59
|
+
|
|
60
|
+
# wizards
|
|
61
|
+
_wizard_result_console_renderer = WizardResultConsoleRenderer()
|
|
62
|
+
_wizard_result_file_renderer = WizardResultFileRenderer()
|
|
63
|
+
_deployment_config_wizard_result_transformer = DeploymentConfigWizardResultTransformer()
|
|
64
|
+
_coordinator_config_wizard_result_transformer = CoordinatorConfigWizardResultTransformer()
|
|
65
|
+
_docker_agent_config_wizard_result_transformer = DockerAgentConfigWizardResultTransformer()
|
|
66
|
+
_bin_exec_agent_config_wizard_result_transformer = BinaryExecutableAgentConfigWizardResultTransformer()
|
|
67
|
+
_deployment_config_wizard = DeploymentConfigWizard(_deployment_config_wizard_result_transformer,
|
|
68
|
+
_wizard_result_console_renderer,
|
|
69
|
+
_wizard_result_file_renderer)
|
|
70
|
+
_coordinator_config_wizard = CoordinatorConfigWizard(_coordinator_config_wizard_result_transformer,
|
|
71
|
+
_wizard_result_console_renderer,
|
|
72
|
+
_wizard_result_file_renderer)
|
|
73
|
+
_docker_agent_config_wizard = DockerAgentConfigWizard(_docker_agent_config_wizard_result_transformer,
|
|
74
|
+
_wizard_result_console_renderer,
|
|
75
|
+
_wizard_result_file_renderer)
|
|
76
|
+
_bin_exec_agent_config_wizard = BinaryExecutableAgentConfigWizard(_bin_exec_agent_config_wizard_result_transformer,
|
|
77
|
+
_wizard_result_console_renderer,
|
|
78
|
+
_wizard_result_file_renderer)
|
|
79
|
+
|
|
80
|
+
# installer
|
|
81
|
+
_docker_version_resolver = DockerVersionResolver()
|
|
82
|
+
_github_release_version_resolver = GitHubReleaseVersionResolver()
|
|
83
|
+
_docker_platform_component_installer = DockerPlatformComponentInstaller(_docker_version_resolver)
|
|
84
|
+
_bin_exec_platform_component_installer = BinaryExecutablePlatformComponentInstaller(_github_release_version_resolver)
|
|
85
|
+
_installer_wizard = InstallerWizard(_docker_platform_component_installer, _bin_exec_platform_component_installer)
|
|
86
|
+
|
|
87
|
+
# common components
|
|
88
|
+
_session_context_holder = SessionContextHolder()
|
|
89
|
+
_domino_client = DominoClient(_domino_base_url, _session_context_holder)
|
|
90
|
+
_oauth_authorization_client = OAuthAuthorizationClient(_oauth_config)
|
|
91
|
+
_domino_service = DominoService(_domino_client)
|
|
92
|
+
_direct_auth_handler = DirectAuthHandler(_domino_client)
|
|
93
|
+
_oauth_auth_handler = OAuthAuthHandler(_oauth_config, _oauth_authorization_client)
|
|
94
|
+
_auth_service = AuthenticationService(_default_auth_mode, _session_context_holder, [
|
|
95
|
+
_direct_auth_handler,
|
|
96
|
+
_oauth_auth_handler
|
|
97
|
+
])
|
|
98
|
+
_config_wizard_service = ConfigurationWizardService([
|
|
99
|
+
_deployment_config_wizard,
|
|
100
|
+
_coordinator_config_wizard,
|
|
101
|
+
_docker_agent_config_wizard,
|
|
102
|
+
_bin_exec_agent_config_wizard,
|
|
103
|
+
_installer_wizard
|
|
104
|
+
])
|
|
105
|
+
|
|
106
|
+
# commands
|
|
107
|
+
_command_exit = ExitCommand()
|
|
108
|
+
_command_help = HelpCommand()
|
|
109
|
+
_command_start_app = StartApplicationCommand(_domino_service)
|
|
110
|
+
_command_stop_app = StopApplicationCommand(_domino_service)
|
|
111
|
+
_command_restart_app = RestartApplicationCommand(_domino_service)
|
|
112
|
+
_command_deploy_app = DeployApplicationCommand(_domino_service)
|
|
113
|
+
_command_auth = AuthCommand(_auth_service)
|
|
114
|
+
_command_wizard = WizardCommand(_config_wizard_service)
|
|
115
|
+
_command_info = InfoCommand(_domino_service)
|
|
116
|
+
|
|
117
|
+
# command processor
|
|
118
|
+
_command_processor = CommandProcessor(_command_help, [
|
|
119
|
+
_command_help,
|
|
120
|
+
_command_exit,
|
|
121
|
+
_command_auth,
|
|
122
|
+
_command_deploy_app,
|
|
123
|
+
_command_restart_app,
|
|
124
|
+
_command_start_app,
|
|
125
|
+
_command_stop_app,
|
|
126
|
+
_command_wizard,
|
|
127
|
+
_command_info
|
|
128
|
+
])
|
|
129
|
+
|
|
130
|
+
_cli = CLI(_command_processor)
|
|
131
|
+
|
|
132
|
+
print(f"Domino CLI v{version} initialized.")
|
|
133
|
+
print("-" * 30)
|
|
134
|
+
|
|
135
|
+
return _cli
|
|
136
|
+
|
|
137
|
+
@staticmethod
|
|
138
|
+
def _assert_config_value(config_parameter: str) -> str:
|
|
139
|
+
|
|
140
|
+
config_value = os.getenv(config_parameter)
|
|
141
|
+
if config_value is None:
|
|
142
|
+
raise Exception("Configuration parameter {0} is not specified".format(config_parameter))
|
|
143
|
+
|
|
144
|
+
return config_value
|
|
File without changes
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from domino_cli.core.domain.CommandDescriptor import CommandDescriptor
|
|
2
|
+
from domino_cli.core.service.CommandProcessor import CommandProcessor
|
|
3
|
+
|
|
4
|
+
_PROMPT = "\nDomino CLI > "
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class CLI:
|
|
8
|
+
"""
|
|
9
|
+
Command line interface (CLI) executor.
|
|
10
|
+
"""
|
|
11
|
+
def __init__(self, command_processor: CommandProcessor):
|
|
12
|
+
self._command_processor = command_processor
|
|
13
|
+
|
|
14
|
+
def run_loop(self) -> None:
|
|
15
|
+
"""
|
|
16
|
+
Runs CLI command execution loop until an exit command terminates it.
|
|
17
|
+
"""
|
|
18
|
+
while True:
|
|
19
|
+
command = CommandDescriptor(input(_PROMPT))
|
|
20
|
+
continue_loop = self._command_processor.execute_command(command)
|
|
21
|
+
|
|
22
|
+
if not continue_loop:
|
|
23
|
+
break
|
|
File without changes
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import urllib.parse
|
|
2
|
+
|
|
3
|
+
import requests
|
|
4
|
+
from requests import Response
|
|
5
|
+
|
|
6
|
+
from domino_cli.core.domain.DominoRequest import DominoRequest
|
|
7
|
+
from domino_cli.core.service.SessionContextHolder import SessionContextHolder
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class DominoClient:
|
|
11
|
+
"""
|
|
12
|
+
HTTP client implementation for sending REST request to Domino.
|
|
13
|
+
"""
|
|
14
|
+
def __init__(self, domino_base_url: str, session_context_holder: SessionContextHolder):
|
|
15
|
+
self._domino_base_url = domino_base_url
|
|
16
|
+
self._session_context_holder = session_context_holder
|
|
17
|
+
|
|
18
|
+
print("Domino CLI is configured to communicate with Domino on {0}".format(domino_base_url))
|
|
19
|
+
|
|
20
|
+
def send_command(self, domino_request: DominoRequest) -> Response:
|
|
21
|
+
"""
|
|
22
|
+
Prepares and sends a REST request to Domino based on the given DominoRequest object.
|
|
23
|
+
|
|
24
|
+
:param domino_request: DominoRequest object specifying request parameters
|
|
25
|
+
:return: Response object
|
|
26
|
+
"""
|
|
27
|
+
resolved_path = urllib.parse.urljoin(self._domino_base_url, domino_request.path)
|
|
28
|
+
json_body = domino_request.body
|
|
29
|
+
auth = self._session_context_holder.get_bearer_auth() if domino_request.authenticated else None
|
|
30
|
+
|
|
31
|
+
return requests.request(domino_request.method.value, resolved_path, json=json_body, headers=auth)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import base64
|
|
2
|
+
|
|
3
|
+
import requests
|
|
4
|
+
from requests import Response
|
|
5
|
+
|
|
6
|
+
from domino_cli.core.domain.HTTPMethod import HTTPMethod
|
|
7
|
+
from domino_cli.core.domain.OAuthConfig import OAuthConfig
|
|
8
|
+
|
|
9
|
+
_ENCODING = "UTF-8"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class OAuthAuthorizationClient:
|
|
13
|
+
"""
|
|
14
|
+
HTTP client implementation for sending requests to the configured OAuth Authorization Server.
|
|
15
|
+
"""
|
|
16
|
+
def __init__(self, oauth_config: OAuthConfig):
|
|
17
|
+
self._oauth_config = oauth_config
|
|
18
|
+
|
|
19
|
+
def request_authorization(self) -> Response:
|
|
20
|
+
"""
|
|
21
|
+
Requests an access token from the configured OAuth Authorization Server.
|
|
22
|
+
Request is sent as Client Credentials Grant Flow token request, including the client ID and the scope,
|
|
23
|
+
as well as the basic authorization header.
|
|
24
|
+
|
|
25
|
+
:return: the response object
|
|
26
|
+
"""
|
|
27
|
+
return requests.request(str(HTTPMethod.POST.value),
|
|
28
|
+
self._prepare_token_url(),
|
|
29
|
+
data=self._prepare_token_request_form(),
|
|
30
|
+
headers=self._prepare_token_request_headers())
|
|
31
|
+
|
|
32
|
+
def _prepare_token_url(self) -> str:
|
|
33
|
+
|
|
34
|
+
return self._oauth_config.token_url \
|
|
35
|
+
if self._oauth_config.audience is None \
|
|
36
|
+
else f"{self._oauth_config.token_url}?audience={self._oauth_config.audience}"
|
|
37
|
+
|
|
38
|
+
def _prepare_token_request_form(self) -> dict[str, str]:
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
"grant_type": "client_credentials",
|
|
42
|
+
"client_id": self._oauth_config.client_id,
|
|
43
|
+
"scope": self._oauth_config.scope
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
def _prepare_token_request_headers(self) -> dict[str, str]:
|
|
47
|
+
|
|
48
|
+
credentials: str = f"{self._oauth_config.client_id}:{self._oauth_config.client_secret}"
|
|
49
|
+
base64_encoded_credentials: str = base64.b64encode(bytes(credentials, _ENCODING)).decode(_ENCODING)
|
|
50
|
+
auth_header_value: str = f"Basic {base64_encoded_credentials}"
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
"Authorization": auth_header_value
|
|
54
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
from abc import abstractmethod
|
|
2
|
+
from abc import ABCMeta
|
|
3
|
+
|
|
4
|
+
from domino_cli.core.domain.CommandDescriptor import CommandDescriptor
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class AbstractCommand(object, metaclass=ABCMeta):
|
|
8
|
+
"""
|
|
9
|
+
Command interface.
|
|
10
|
+
Implementations should contain the associated logic for each supported command.
|
|
11
|
+
"""
|
|
12
|
+
def __init__(self, command_name: str):
|
|
13
|
+
self._command_name = command_name
|
|
14
|
+
|
|
15
|
+
def is_applicable(self, command_descriptor: CommandDescriptor) -> bool:
|
|
16
|
+
"""
|
|
17
|
+
Checks if the currently selected command implementation supports the requested command.
|
|
18
|
+
|
|
19
|
+
:param command_descriptor: CommandDescriptor object containing the requested command with its arguments
|
|
20
|
+
:return: boolean, true if the implementation is applicable, false otherwise
|
|
21
|
+
"""
|
|
22
|
+
return command_descriptor.command == self._command_name
|
|
23
|
+
|
|
24
|
+
@abstractmethod
|
|
25
|
+
def execute_command(self, command_descriptor: CommandDescriptor) -> None:
|
|
26
|
+
"""
|
|
27
|
+
Executes implemented command logic.
|
|
28
|
+
|
|
29
|
+
:param command_descriptor: CommandDescriptor object containing the requested command with its arguments
|
|
30
|
+
"""
|
|
31
|
+
pass
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from domino_cli.core.command.AbstractCommand import AbstractCommand
|
|
2
|
+
from domino_cli.core.domain.CommandDescriptor import CommandDescriptor
|
|
3
|
+
from domino_cli.core.domain.DominoCommand import DominoCommand
|
|
4
|
+
from domino_cli.core.service.DominoService import DominoService
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class AbstractLifecycleCommand(AbstractCommand):
|
|
8
|
+
"""
|
|
9
|
+
Abstract base class for simple lifecycle commands (with only the name of the application as parameter).
|
|
10
|
+
"""
|
|
11
|
+
def __init__(self, command_name: str, domino_service: DominoService, domino_command: DominoCommand):
|
|
12
|
+
super().__init__(command_name)
|
|
13
|
+
self._domino_service = domino_service
|
|
14
|
+
self._domino_command = domino_command
|
|
15
|
+
|
|
16
|
+
def execute_command(self, command_descriptor: CommandDescriptor) -> None:
|
|
17
|
+
"""
|
|
18
|
+
Executes a simple lifecycle command (currently supported commands are start, stop, restart).
|
|
19
|
+
Argument array should only contain the name of the application.
|
|
20
|
+
|
|
21
|
+
:param command_descriptor: CommandDescriptor object containing the command arguments
|
|
22
|
+
"""
|
|
23
|
+
if not len(command_descriptor.arguments) == 1:
|
|
24
|
+
print("Application name required")
|
|
25
|
+
else:
|
|
26
|
+
self._domino_service.execute_lifecycle_command(self._domino_command, command_descriptor.arguments[0])
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
from domino_cli.core.command.AbstractCommand import AbstractCommand
|
|
2
|
+
from domino_cli.core.domain.CommandDescriptor import CommandDescriptor
|
|
3
|
+
from domino_cli.core.service.AuthenticationService import AuthenticationService
|
|
4
|
+
|
|
5
|
+
_COMMAND_NAME = "auth"
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class AuthCommand(AbstractCommand):
|
|
9
|
+
"""
|
|
10
|
+
Command implementation for authentication related operations.
|
|
11
|
+
"""
|
|
12
|
+
def __init__(self, authentication_service: AuthenticationService):
|
|
13
|
+
super().__init__(_COMMAND_NAME)
|
|
14
|
+
self._authentication_service = authentication_service
|
|
15
|
+
|
|
16
|
+
def execute_command(self, command_descriptor: CommandDescriptor) -> None:
|
|
17
|
+
"""
|
|
18
|
+
Routes authentication command processing to the proper handler.
|
|
19
|
+
|
|
20
|
+
:param command_descriptor: CommandDescriptor object containing the command arguments
|
|
21
|
+
"""
|
|
22
|
+
if not 0 < len(command_descriptor.arguments) < 3:
|
|
23
|
+
AuthCommand._show_help()
|
|
24
|
+
else:
|
|
25
|
+
additional_parameter: str = command_descriptor.arguments[1] \
|
|
26
|
+
if len(command_descriptor.arguments) == 2 \
|
|
27
|
+
else None
|
|
28
|
+
self._route_auth_request(command_descriptor.arguments[0], additional_parameter)
|
|
29
|
+
|
|
30
|
+
def _route_auth_request(self, operation_flag: str, additional_parameter: str):
|
|
31
|
+
|
|
32
|
+
if operation_flag == "--encrypt-password":
|
|
33
|
+
self._authentication_service.encrypt_password()
|
|
34
|
+
elif operation_flag == "--generate-token":
|
|
35
|
+
self._authentication_service.generate_token()
|
|
36
|
+
elif operation_flag == "--open-session":
|
|
37
|
+
self._authentication_service.open_session()
|
|
38
|
+
elif operation_flag == "--set-mode":
|
|
39
|
+
self._authentication_service.set_mode(additional_parameter)
|
|
40
|
+
else:
|
|
41
|
+
AuthCommand._show_help()
|
|
42
|
+
|
|
43
|
+
@staticmethod
|
|
44
|
+
def _show_help():
|
|
45
|
+
print("Auth command requires operation flag of: --encrypt-password | --generate-token | --open-session "
|
|
46
|
+
"| --set-mode direct|oauth")
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from domino_cli.core.command.AbstractCommand import AbstractCommand
|
|
2
|
+
from domino_cli.core.domain.CommandDescriptor import CommandDescriptor
|
|
3
|
+
from domino_cli.core.domain.DominoCommand import DominoCommand
|
|
4
|
+
from domino_cli.core.service.DominoService import DominoService
|
|
5
|
+
|
|
6
|
+
_LATEST_KEYWORD = "latest"
|
|
7
|
+
_COMMAND_NAME = "deploy"
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class DeployApplicationCommand(AbstractCommand):
|
|
11
|
+
"""
|
|
12
|
+
Lifecycle command implementation being able to send a deploy command for the given application.
|
|
13
|
+
"""
|
|
14
|
+
def __init__(self, domino_service: DominoService):
|
|
15
|
+
super().__init__(_COMMAND_NAME)
|
|
16
|
+
self._domino_service = domino_service
|
|
17
|
+
|
|
18
|
+
def execute_command(self, command_descriptor: CommandDescriptor) -> None:
|
|
19
|
+
"""
|
|
20
|
+
Sends a deployment command for the given application.
|
|
21
|
+
Argument array must contain two parameters:
|
|
22
|
+
- application name
|
|
23
|
+
- "latest" keyword or an explicit version of the application to be deployed
|
|
24
|
+
|
|
25
|
+
:param command_descriptor: CommandDescriptor object containing the command arguments
|
|
26
|
+
"""
|
|
27
|
+
if not len(command_descriptor.arguments) == 2:
|
|
28
|
+
print("Application name and 'latest' keyword or explicit version is required")
|
|
29
|
+
else:
|
|
30
|
+
application: str = command_descriptor.arguments[0]
|
|
31
|
+
version: str = command_descriptor.arguments[1]
|
|
32
|
+
command: DominoCommand = DominoCommand.DEPLOY_LATEST \
|
|
33
|
+
if version == _LATEST_KEYWORD \
|
|
34
|
+
else DominoCommand.DEPLOY_VERSION
|
|
35
|
+
|
|
36
|
+
self._domino_service.execute_lifecycle_command(command, application, version)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from domino_cli.core.domain.CommandDescriptor import CommandDescriptor
|
|
2
|
+
from domino_cli.core.command.AbstractCommand import AbstractCommand
|
|
3
|
+
|
|
4
|
+
_COMMAND_NAME = "exit"
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class ExitCommand(AbstractCommand):
|
|
8
|
+
"""
|
|
9
|
+
Exit command implementation.
|
|
10
|
+
Interrupts CLI execution loop.
|
|
11
|
+
"""
|
|
12
|
+
def __init__(self):
|
|
13
|
+
super().__init__(_COMMAND_NAME)
|
|
14
|
+
|
|
15
|
+
def execute_command(self, command_descriptor: CommandDescriptor) -> None:
|
|
16
|
+
print("Bye!")
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from domino_cli.core.domain.CommandDescriptor import CommandDescriptor
|
|
2
|
+
from domino_cli.core.command.AbstractCommand import AbstractCommand
|
|
3
|
+
|
|
4
|
+
_COMMAND_NAME = "help"
|
|
5
|
+
_HELP_FILE = "./domino_cli/resource/help.txt"
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class HelpCommand(AbstractCommand):
|
|
9
|
+
"""
|
|
10
|
+
Prints help contents, containing information about the supported commands.
|
|
11
|
+
"""
|
|
12
|
+
def __init__(self):
|
|
13
|
+
super().__init__(_COMMAND_NAME)
|
|
14
|
+
with open(_HELP_FILE, "r") as help_contents:
|
|
15
|
+
self._help_text = help_contents.readlines()
|
|
16
|
+
|
|
17
|
+
def execute_command(self, command_descriptor: CommandDescriptor) -> None:
|
|
18
|
+
[print(line, end="") for line in self._help_text]
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from domino_cli.core.command.AbstractLifecycleCommand import AbstractLifecycleCommand
|
|
2
|
+
from domino_cli.core.domain.DominoCommand import DominoCommand
|
|
3
|
+
from domino_cli.core.service.DominoService import DominoService
|
|
4
|
+
|
|
5
|
+
_COMMAND_NAME = "info"
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class InfoCommand(AbstractLifecycleCommand):
|
|
9
|
+
"""
|
|
10
|
+
Lifecycle command implementation being able to send an info request command for the given application.
|
|
11
|
+
"""
|
|
12
|
+
def __init__(self, domino_service: DominoService):
|
|
13
|
+
super().__init__(_COMMAND_NAME, domino_service, DominoCommand.INFO)
|
|
14
|
+
self._domino_service = domino_service
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from domino_cli.core.command.AbstractLifecycleCommand import AbstractLifecycleCommand
|
|
2
|
+
from domino_cli.core.domain.DominoCommand import DominoCommand
|
|
3
|
+
from domino_cli.core.service.DominoService import DominoService
|
|
4
|
+
|
|
5
|
+
_COMMAND_NAME = "restart"
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class RestartApplicationCommand(AbstractLifecycleCommand):
|
|
9
|
+
"""
|
|
10
|
+
Lifecycle command implementation being able to send a restart command for the given application.
|
|
11
|
+
"""
|
|
12
|
+
def __init__(self, domino_service: DominoService):
|
|
13
|
+
super().__init__(_COMMAND_NAME, domino_service, DominoCommand.RESTART)
|
|
14
|
+
self._domino_service = domino_service
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from domino_cli.core.command.AbstractLifecycleCommand import AbstractLifecycleCommand
|
|
2
|
+
from domino_cli.core.domain.DominoCommand import DominoCommand
|
|
3
|
+
from domino_cli.core.service.DominoService import DominoService
|
|
4
|
+
|
|
5
|
+
_COMMAND_NAME = "start"
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class StartApplicationCommand(AbstractLifecycleCommand):
|
|
9
|
+
"""
|
|
10
|
+
Lifecycle command implementation being able to send a start command for the given application.
|
|
11
|
+
"""
|
|
12
|
+
def __init__(self, domino_service: DominoService):
|
|
13
|
+
super().__init__(_COMMAND_NAME, domino_service, DominoCommand.START)
|
|
14
|
+
self._domino_service = domino_service
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from domino_cli.core.command.AbstractLifecycleCommand import AbstractLifecycleCommand
|
|
2
|
+
from domino_cli.core.domain.DominoCommand import DominoCommand
|
|
3
|
+
from domino_cli.core.service.DominoService import DominoService
|
|
4
|
+
|
|
5
|
+
_COMMAND_NAME = "stop"
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class StopApplicationCommand(AbstractLifecycleCommand):
|
|
9
|
+
"""
|
|
10
|
+
Lifecycle command implementation being able to send a stop command for the given application.
|
|
11
|
+
"""
|
|
12
|
+
def __init__(self, domino_service: DominoService):
|
|
13
|
+
super().__init__(_COMMAND_NAME, domino_service, DominoCommand.STOP)
|
|
14
|
+
self._domino_service = domino_service
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from domino_cli.core.command.AbstractCommand import AbstractCommand
|
|
2
|
+
from domino_cli.core.domain.CommandDescriptor import CommandDescriptor
|
|
3
|
+
from domino_cli.core.service.ConfigurationWizardService import ConfigurationWizardService
|
|
4
|
+
|
|
5
|
+
_COMMAND_NAME = "wizard"
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class WizardCommand(AbstractCommand):
|
|
9
|
+
"""
|
|
10
|
+
Command implementation for wizard related operations.
|
|
11
|
+
"""
|
|
12
|
+
def __init__(self, configuration_wizard_service: ConfigurationWizardService):
|
|
13
|
+
super().__init__(_COMMAND_NAME)
|
|
14
|
+
self._configuration_wizard_service: ConfigurationWizardService = configuration_wizard_service
|
|
15
|
+
|
|
16
|
+
def execute_command(self, command_descriptor: CommandDescriptor) -> None:
|
|
17
|
+
"""
|
|
18
|
+
Instructs ConfigurationWizardService to start execution of the specified wizard.
|
|
19
|
+
Shows available wizards in case of missing wizard name parameter.
|
|
20
|
+
|
|
21
|
+
:param command_descriptor: CommandDescriptor object containing the command arguments
|
|
22
|
+
"""
|
|
23
|
+
if not len(command_descriptor.arguments) == 1:
|
|
24
|
+
print("Wizard name required")
|
|
25
|
+
self._configuration_wizard_service.show_available_wizards()
|
|
26
|
+
else:
|
|
27
|
+
self._configuration_wizard_service.run_wizard(command_descriptor.arguments[0])
|
|
File without changes
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from enum import Enum
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class AuthMode(Enum):
|
|
7
|
+
"""
|
|
8
|
+
Supported modes for authenticating with Domino.
|
|
9
|
+
"""
|
|
10
|
+
DIRECT = "direct"
|
|
11
|
+
OAUTH = "oauth"
|
|
12
|
+
|
|
13
|
+
@staticmethod
|
|
14
|
+
def by_value(auth_mode: str) -> AuthMode:
|
|
15
|
+
"""
|
|
16
|
+
Parses auth mode.
|
|
17
|
+
Converts the given auth mode parameter to uppercase, before trying to convert it by name.
|
|
18
|
+
|
|
19
|
+
:param auth_mode: auth mode value
|
|
20
|
+
:return: parsed AuthMode
|
|
21
|
+
:raise KeyError in case the given auth mode is unsupported
|
|
22
|
+
"""
|
|
23
|
+
return AuthMode[auth_mode.upper()]
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
class AuthRequest:
|
|
2
|
+
"""
|
|
3
|
+
Authentication request data domain class.
|
|
4
|
+
"""
|
|
5
|
+
def __init__(self, username: str, password: str):
|
|
6
|
+
self.username = username
|
|
7
|
+
self.password = password
|
|
8
|
+
|
|
9
|
+
def get_as_dict(self) -> dict:
|
|
10
|
+
"""
|
|
11
|
+
Returns the contents as dict (JSON-serializable).
|
|
12
|
+
|
|
13
|
+
:return: contents as dict
|
|
14
|
+
"""
|
|
15
|
+
return {
|
|
16
|
+
"username": self.username,
|
|
17
|
+
"password": self.password
|
|
18
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
class CommandDescriptor:
|
|
2
|
+
"""
|
|
3
|
+
Tokenized wrapper of a parsed command.
|
|
4
|
+
Every command must consist of the command itself and an unlimited number of arguments, separated by spaces.
|
|
5
|
+
"""
|
|
6
|
+
def __init__(self, raw_input: str):
|
|
7
|
+
|
|
8
|
+
command_tokens = str(raw_input).split(" ")
|
|
9
|
+
self.command = str(command_tokens[0]).lower()
|
|
10
|
+
|
|
11
|
+
if len(command_tokens) > 1:
|
|
12
|
+
self.arguments = command_tokens[1:len(command_tokens)]
|
|
13
|
+
else:
|
|
14
|
+
self.arguments = []
|
|
15
|
+
|
|
16
|
+
def __repr__(self):
|
|
17
|
+
return "cmd={0};args={1}".format(self.command, self.arguments)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
|
|
3
|
+
from domino_cli.core.domain.HTTPMethod import HTTPMethod
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class DominoRequestDescriptor:
|
|
7
|
+
"""
|
|
8
|
+
Command descriptor for Domino commands, specifying the expected HTTP method and a request path template.
|
|
9
|
+
"""
|
|
10
|
+
def __init__(self, method: HTTPMethod, path_template: str):
|
|
11
|
+
self.method = method
|
|
12
|
+
self.path_template = path_template
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class DominoCommand(Enum):
|
|
16
|
+
"""
|
|
17
|
+
Enum of possible Domino commands.
|
|
18
|
+
Each enum value must specify its own DominoRequestDescriptor instance.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
START = DominoRequestDescriptor(HTTPMethod.PUT, "/lifecycle/{0}/start")
|
|
22
|
+
STOP = DominoRequestDescriptor(HTTPMethod.DELETE, "/lifecycle/{0}/stop")
|
|
23
|
+
RESTART = DominoRequestDescriptor(HTTPMethod.PUT, "/lifecycle/{0}/restart")
|
|
24
|
+
DEPLOY_LATEST = DominoRequestDescriptor(HTTPMethod.PUT, "/lifecycle/{0}/deploy")
|
|
25
|
+
DEPLOY_VERSION = DominoRequestDescriptor(HTTPMethod.PUT, "/lifecycle/{0}/deploy/{1}")
|
|
26
|
+
INFO = DominoRequestDescriptor(HTTPMethod.GET, "/lifecycle/{0}/info")
|