|
9 | 9 | from outsystems.exceptions.app_does_not_exist import AppDoesNotExistError
|
10 | 10 | from outsystems.exceptions.server_error import ServerError
|
11 | 11 | # Functions
|
12 |
| -from outsystems.lifetime.lifetime_base import send_get_request |
| 12 | +from outsystems.lifetime.lifetime_base import send_get_request, send_post_request |
13 | 13 | from outsystems.lifetime.lifetime_applications import _get_application_info
|
14 | 14 | from outsystems.file_helpers.file import load_data, store_data, clear_cache
|
15 | 15 | # Variables
|
16 | 16 | from outsystems.vars.lifetime_vars import ENVIRONMENTS_ENDPOINT, ENVIRONMENT_APPLICATIONS_ENDPOINT, ENVIRONMENTS_SUCCESS_CODE, \
|
17 | 17 | ENVIRONMENTS_NOT_FOUND_CODE, ENVIRONMENTS_FAILED_CODE, ENVIRONMENT_APP_SUCCESS_CODE, ENVIRONMENT_APP_NOT_STATUS_CODE, \
|
18 | 18 | ENVIRONMENT_APP_NO_PERMISSION_CODE, ENVIRONMENT_APP_NOT_FOUND, ENVIRONMENT_APP_FAILED_CODE, ENVIRONMENT_DEPLOYMENT_ZONES_ENDPOINT, \
|
19 | 19 | ENVIRONMENT_ZONES_SUCCESS_CODE, ENVIRONMENT_ZONES_NOT_STATUS_CODE, ENVIRONMENT_ZONES_NO_PERMISSION_CODE, ENVIRONMENT_ZONES_NOT_FOUND, \
|
20 |
| - ENVIRONMENT_ZONES_FAILED_CODE |
21 |
| -from outsystems.vars.file_vars import ENVIRONMENTS_FILE, ENVIRONMENT_FOLDER, ENVIRONMENT_APPLICATION_FILE, ENVIRONMENT_DEPLOYMENT_ZONES_FILE |
| 20 | + ENVIRONMENT_ZONES_FAILED_CODE, ENVIRONMENT_APPLICATIONS_SOURCECODE_ENDPOINT, ENVIRONMENT_SOURCECODE_PACKAGE_SUCCESS_CODE, \ |
| 21 | + ENVIRONMENT_SOURCECODE_LINK_SUCCESS_CODE, ENVIRONMENT_SOURCECODE_FAILED_CODE |
| 22 | +from outsystems.vars.file_vars import ENVIRONMENTS_FILE, ENVIRONMENT_FOLDER, ENVIRONMENT_APPLICATION_FILE, \ |
| 23 | + ENVIRONMENT_DEPLOYMENT_ZONES_FILE, ENVIRONMENT_SOURCECODE_FOLDER, ENVIRONMENT_SOURCECODE_STATUS_FILE, \ |
| 24 | + ENVIRONMENT_SOURCECODE_LINK_FILE |
22 | 25 |
|
23 | 26 |
|
24 | 27 | # Lists all the environments in the infrastructure.
|
@@ -120,6 +123,91 @@ def get_environment_deployment_zones(artifact_dir: str, endpoint: str, auth_toke
|
120 | 123 | "There was an error. Response from server: {}".format(response))
|
121 | 124 |
|
122 | 125 |
|
| 126 | +# Returns the package key to download the source code of the specified application in a given environment. |
| 127 | +def get_environment_app_source_code(artifact_dir: str, endpoint: str, auth_token: str, **kwargs): |
| 128 | + # Tuple with (AppName, AppKey): app_tuple[0] = AppName; app_tuple[1] = AppKey |
| 129 | + app_tuple = _get_application_info( |
| 130 | + artifact_dir, endpoint, auth_token, **kwargs) |
| 131 | + # Tuple with (EnvName, EnvKey): env_tuple[0] = EnvName; env_tuple[1] = EnvKey |
| 132 | + env_tuple = _get_environment_info( |
| 133 | + artifact_dir, endpoint, auth_token, **kwargs) |
| 134 | + # Builds the query and arguments for the call to the API |
| 135 | + query = "{}/{}/{}/{}/{}".format(ENVIRONMENTS_ENDPOINT, env_tuple[1], |
| 136 | + ENVIRONMENT_APPLICATIONS_ENDPOINT, app_tuple[1], |
| 137 | + ENVIRONMENT_APPLICATIONS_SOURCECODE_ENDPOINT) |
| 138 | + # Sends the request |
| 139 | + response = send_post_request(endpoint, auth_token, query, None) |
| 140 | + status_code = int(response["http_status"]) |
| 141 | + if status_code == ENVIRONMENT_SOURCECODE_PACKAGE_SUCCESS_CODE: |
| 142 | + return response["response"] |
| 143 | + elif status_code == ENVIRONMENT_SOURCECODE_FAILED_CODE: |
| 144 | + raise ServerError("Failed to access the source code of an application. Details: {}".format( |
| 145 | + response["response"])) |
| 146 | + else: |
| 147 | + raise NotImplementedError( |
| 148 | + "There was an error. Response from server: {}".format(response)) |
| 149 | + |
| 150 | + |
| 151 | +# Returns current status of source code package of the specified application in a given environment. |
| 152 | +def get_environment_app_source_code_status(artifact_dir: str, endpoint: str, auth_token: str, **kwargs): |
| 153 | + # Tuple with (AppName, AppKey): app_tuple[0] = AppName; app_tuple[1] = AppKey |
| 154 | + app_tuple = _get_application_info( |
| 155 | + artifact_dir, endpoint, auth_token, **kwargs) |
| 156 | + # Tuple with (EnvName, EnvKey): env_tuple[0] = EnvName; env_tuple[1] = EnvKey |
| 157 | + env_tuple = _get_environment_info( |
| 158 | + artifact_dir, endpoint, auth_token, **kwargs) |
| 159 | + # Builds the query and arguments for the call to the API |
| 160 | + query = "{}/{}/{}/{}/{}/{}/status".format(ENVIRONMENTS_ENDPOINT, env_tuple[1], |
| 161 | + ENVIRONMENT_APPLICATIONS_ENDPOINT, app_tuple[1], |
| 162 | + ENVIRONMENT_APPLICATIONS_SOURCECODE_ENDPOINT, kwargs["pkg_key"]) |
| 163 | + # Sends the request |
| 164 | + response = send_get_request(endpoint, auth_token, query, None) |
| 165 | + status_code = int(response["http_status"]) |
| 166 | + if status_code == ENVIRONMENT_SOURCECODE_PACKAGE_SUCCESS_CODE: |
| 167 | + # Stores the result |
| 168 | + filename = "{}{}".format( |
| 169 | + kwargs["pkg_key"], ENVIRONMENT_SOURCECODE_STATUS_FILE) |
| 170 | + filename = os.path.join(ENVIRONMENT_SOURCECODE_FOLDER, filename) |
| 171 | + store_data(artifact_dir, filename, response["response"]) |
| 172 | + return response["response"] |
| 173 | + elif status_code == ENVIRONMENT_SOURCECODE_FAILED_CODE: |
| 174 | + raise ServerError("Failed to access the source code package status of an application. Details: {}".format( |
| 175 | + response["response"])) |
| 176 | + else: |
| 177 | + raise NotImplementedError( |
| 178 | + "There was an error. Response from server: {}".format(response)) |
| 179 | + |
| 180 | + |
| 181 | +# Returns download link of source code package of the specified application in a given environment. |
| 182 | +def get_environment_app_source_code_link(artifact_dir: str, endpoint: str, auth_token: str, **kwargs): |
| 183 | + # Tuple with (AppName, AppKey): app_tuple[0] = AppName; app_tuple[1] = AppKey |
| 184 | + app_tuple = _get_application_info( |
| 185 | + artifact_dir, endpoint, auth_token, **kwargs) |
| 186 | + # Tuple with (EnvName, EnvKey): env_tuple[0] = EnvName; env_tuple[1] = EnvKey |
| 187 | + env_tuple = _get_environment_info( |
| 188 | + artifact_dir, endpoint, auth_token, **kwargs) |
| 189 | + # Builds the query and arguments for the call to the API |
| 190 | + query = "{}/{}/{}/{}/{}/{}/download".format(ENVIRONMENTS_ENDPOINT, env_tuple[1], |
| 191 | + ENVIRONMENT_APPLICATIONS_ENDPOINT, app_tuple[1], |
| 192 | + ENVIRONMENT_APPLICATIONS_SOURCECODE_ENDPOINT, kwargs["pkg_key"]) |
| 193 | + # Sends the request |
| 194 | + response = send_get_request(endpoint, auth_token, query, None) |
| 195 | + status_code = int(response["http_status"]) |
| 196 | + if status_code == ENVIRONMENT_SOURCECODE_LINK_SUCCESS_CODE: |
| 197 | + # Stores the result |
| 198 | + filename = "{}{}".format( |
| 199 | + kwargs["pkg_key"], ENVIRONMENT_SOURCECODE_LINK_FILE) |
| 200 | + filename = os.path.join(ENVIRONMENT_SOURCECODE_FOLDER, filename) |
| 201 | + store_data(artifact_dir, filename, response["response"]) |
| 202 | + return response["response"] |
| 203 | + elif status_code == ENVIRONMENT_SOURCECODE_FAILED_CODE: |
| 204 | + raise ServerError("Failed to access the source code package link of an application. Details: {}".format( |
| 205 | + response["response"])) |
| 206 | + else: |
| 207 | + raise NotImplementedError( |
| 208 | + "There was an error. Response from server: {}".format(response)) |
| 209 | + |
| 210 | + |
123 | 211 | # ---------------------- PRIVATE METHODS ----------------------
|
124 | 212 | # Private method to get the App name or key into a tuple (name,key).
|
125 | 213 | def _get_environment_info(artifact_dir: str, api_url: str, auth_token: str, **kwargs):
|
|
0 commit comments