From 5d0b282baec9f25c5d819c5565ae2c33e3355f13 Mon Sep 17 00:00:00 2001 From: sean-freeman <1815807+sean-freeman@users.noreply.github.com> Date: Mon, 18 Mar 2024 15:07:11 +0000 Subject: [PATCH 1/4] fix: exception when account locked --- plugins/module_utils/sap_api_common.py | 5 +++++ plugins/module_utils/sap_id_sso.py | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/plugins/module_utils/sap_api_common.py b/plugins/module_utils/sap_api_common.py index 8e55032..204b492 100644 --- a/plugins/module_utils/sap_api_common.py +++ b/plugins/module_utils/sap_api_common.py @@ -36,6 +36,11 @@ def _request(url, **kwargs): method = 'POST' if kwargs.get('data') or kwargs.get('json') else 'GET' res = https_session.request(method, url, **kwargs) + + if (res.status_code == 403 + and res.json()['errorMessage'].startswith('Account Temporarily Locked Out')): + raise Exception('SAP ID Service has reported `Account Temporarily Locked Out`. Please reset password to regain access and try again.') + res.raise_for_status() return res diff --git a/plugins/module_utils/sap_id_sso.py b/plugins/module_utils/sap_id_sso.py index 406ee8c..c0028d2 100644 --- a/plugins/module_utils/sap_id_sso.py +++ b/plugins/module_utils/sap_id_sso.py @@ -45,8 +45,12 @@ def _get_sso_endpoint_meta(url, **kwargs): def sap_sso_login(username, password): https_session.cookies.clear() + + # Ensure usage of SAP User ID even when SAP Universal ID is used, + # login with email address of SAP Universal ID will otherwise + # incorrectly default to the last used SAP User ID if not re.match(r'^[sS]\d+$', username): - raise ValueError('Please login with SID (like `S1234567890`)') + raise ValueError('Please login with SAP User ID (like `S1234567890`)') endpoint = C.URL_LAUNCHPAD meta = {} From b1bfe14be3612649da4cfd49d2225e41f41bd08b Mon Sep 17 00:00:00 2001 From: sean-freeman <1815807+sean-freeman@users.noreply.github.com> Date: Mon, 18 Mar 2024 15:15:24 +0000 Subject: [PATCH 2/4] fix: manual python example --- docs/EXEC_EXAMPLES.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/EXEC_EXAMPLES.md b/docs/EXEC_EXAMPLES.md index de5282f..4091985 100644 --- a/docs/EXEC_EXAMPLES.md +++ b/docs/EXEC_EXAMPLES.md @@ -198,11 +198,12 @@ python3 >>> # from module_utils.sap_api_common import debug_https >>> # debug_https() >>> ->>> ## Perform API requests to SAP Support +>>> ## Perform API login requests to SAP Support >>> username='S0000000' >>> password='password' >>> sap_sso_login(username, password) ->>> query_result = search_software_filename("HCMT_057_0-80003261.SAR") +>>> ## Perform API activity requests to SAP Support (e.g. software search without deduplication, and download software) +>>> query_result = search_software_filename("HCMT_057_0-80003261.SAR",'') >>> download_software(*query_result, output_dir='/tmp') ... >>> ## API responses from SAP Support From e895b3e0fd0fd2f3110ad167bd5d242d0f96c5f9 Mon Sep 17 00:00:00 2001 From: sean-freeman <1815807+sean-freeman@users.noreply.github.com> Date: Mon, 18 Mar 2024 15:16:30 +0000 Subject: [PATCH 3/4] fix: manual python login command --- docs/EXEC_EXAMPLES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/EXEC_EXAMPLES.md b/docs/EXEC_EXAMPLES.md index 4091985..fb88f99 100644 --- a/docs/EXEC_EXAMPLES.md +++ b/docs/EXEC_EXAMPLES.md @@ -192,6 +192,7 @@ python3 **Execute Python Functions** ```python +>>> from module_utils.sap_id_sso import sap_sso_login >>> from module_utils.sap_launchpad_software_center_download_runner import * >>> >>> # Debug From fe49e80d77b19d73d4d66029e75e09ad6d60737d Mon Sep 17 00:00:00 2001 From: sean-freeman <1815807+sean-freeman@users.noreply.github.com> Date: Mon, 18 Mar 2024 15:24:28 +0000 Subject: [PATCH 4/4] fix: incorrect example for role exec --- docs/EXEC_EXAMPLES.md | 80 +------------------------------------------ 1 file changed, 1 insertion(+), 79 deletions(-) diff --git a/docs/EXEC_EXAMPLES.md b/docs/EXEC_EXAMPLES.md index fb88f99..2288d4f 100644 --- a/docs/EXEC_EXAMPLES.md +++ b/docs/EXEC_EXAMPLES.md @@ -46,7 +46,7 @@ suser_id: "{{ suser_id }}" suser_password: "{{ suser_password }}" softwarecenter_search_query: "{{ item }}" - dest: "/tmp/" + dest: "/tmp/" loop: "{{ softwarecenter_search_list }}" loop_control: label: "{{ item }} : {{ download_task.msg }}" @@ -68,84 +68,6 @@ ansible-galaxy collection install community.sap_launchpad ansible-playbook --timeout 60 ./community.sap_launchpad/playbooks/sample-download-install-media.yml --inventory "localhost," --connection=local ``` -## Execution example with Ansible Playbook calling Ansible Role - -**Ansible Playbook YAML, execute Ansible Role on target/remote host** -```yaml ---- -- hosts: all - - collections: - - community.sap_launchpad - - pre_tasks: - - name: Install Python package manager pip3 to system Python - ansible.builtin.package: - name: python3-pip - state: present - - name: Install Python dependencies for Ansible Modules to system Python - ansible.builtin.pip: - name: - - urllib3 - - requests - - beautifulsoup4 - - lxml - -# Prompt for Ansible Variables - vars_prompt: - - name: suser_id - prompt: Please enter S-User - private: no - - name: suser_password - prompt: Please enter Password - private: yes - -# Define Ansible Variables - vars: - ansible_python_interpreter: python3 - softwarecenter_search_list: - - 'SAPCAR_1324-80000936.EXE' - - 'HCMT_057_0-80003261.SAR' - -# Option 1: Use roles declaration - roles: - - { role: community.sap_launchpad.software_center_download } - -# Option 2: Use sequential parse/execution, by using include_role inside Task block - tasks: - - name: Execute Ansible Role to download SAP software - include_role: - name: { role: community.sap_launchpad.software_center_download } - vars: - suser_id: "{{ suser_id }}" - suser_password: "{{ suser_password }}" - softwarecenter_search_query: "{{ item }}" - loop: "{{ softwarecenter_search_list }}" - loop_control: - label: "{{ item }} : {{ download_task.msg }}" - register: download_task - retries: 1 - until: download_task is not failed - - -# Option 3: Use task block with import_roles - tasks: - - name: Execute Ansible Role to download SAP software - import_roles: - name: { role: community.sap_launchpad.software_center_download } - vars: - suser_id: "{{ suser_id }}" - suser_password: "{{ suser_password }}" - softwarecenter_search_query: "{{ item }}" - loop: "{{ softwarecenter_search_list }}" - loop_control: - label: "{{ item }} : {{ download_task.msg }}" - register: download_task - retries: 1 - until: download_task is not failed - -``` - **Execution of Ansible Playbook, with in-line Ansible Inventory of target/remote hosts** ```shell