Skip to content

Commit 22dfae9

Browse files
authored
Merge pull request #20 from sap-linuxlab/dev
Merge dev to main for release 1.1.1
2 parents 85d6cb9 + fe49e80 commit 22dfae9

File tree

3 files changed

+15
-82
lines changed

3 files changed

+15
-82
lines changed

docs/EXEC_EXAMPLES.md

Lines changed: 5 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
suser_id: "{{ suser_id }}"
4747
suser_password: "{{ suser_password }}"
4848
softwarecenter_search_query: "{{ item }}"
49-
dest: "/tmp/"
49+
dest: "/tmp/"
5050
loop: "{{ softwarecenter_search_list }}"
5151
loop_control:
5252
label: "{{ item }} : {{ download_task.msg }}"
@@ -68,84 +68,6 @@ ansible-galaxy collection install community.sap_launchpad
6868
ansible-playbook --timeout 60 ./community.sap_launchpad/playbooks/sample-download-install-media.yml --inventory "localhost," --connection=local
6969
```
7070

71-
## Execution example with Ansible Playbook calling Ansible Role
72-
73-
**Ansible Playbook YAML, execute Ansible Role on target/remote host**
74-
```yaml
75-
---
76-
- hosts: all
77-
78-
collections:
79-
- community.sap_launchpad
80-
81-
pre_tasks:
82-
- name: Install Python package manager pip3 to system Python
83-
ansible.builtin.package:
84-
name: python3-pip
85-
state: present
86-
- name: Install Python dependencies for Ansible Modules to system Python
87-
ansible.builtin.pip:
88-
name:
89-
- urllib3
90-
- requests
91-
- beautifulsoup4
92-
- lxml
93-
94-
# Prompt for Ansible Variables
95-
vars_prompt:
96-
- name: suser_id
97-
prompt: Please enter S-User
98-
private: no
99-
- name: suser_password
100-
prompt: Please enter Password
101-
private: yes
102-
103-
# Define Ansible Variables
104-
vars:
105-
ansible_python_interpreter: python3
106-
softwarecenter_search_list:
107-
- 'SAPCAR_1324-80000936.EXE'
108-
- 'HCMT_057_0-80003261.SAR'
109-
110-
# Option 1: Use roles declaration
111-
roles:
112-
- { role: community.sap_launchpad.software_center_download }
113-
114-
# Option 2: Use sequential parse/execution, by using include_role inside Task block
115-
tasks:
116-
- name: Execute Ansible Role to download SAP software
117-
include_role:
118-
name: { role: community.sap_launchpad.software_center_download }
119-
vars:
120-
suser_id: "{{ suser_id }}"
121-
suser_password: "{{ suser_password }}"
122-
softwarecenter_search_query: "{{ item }}"
123-
loop: "{{ softwarecenter_search_list }}"
124-
loop_control:
125-
label: "{{ item }} : {{ download_task.msg }}"
126-
register: download_task
127-
retries: 1
128-
until: download_task is not failed
129-
130-
131-
# Option 3: Use task block with import_roles
132-
tasks:
133-
- name: Execute Ansible Role to download SAP software
134-
import_roles:
135-
name: { role: community.sap_launchpad.software_center_download }
136-
vars:
137-
suser_id: "{{ suser_id }}"
138-
suser_password: "{{ suser_password }}"
139-
softwarecenter_search_query: "{{ item }}"
140-
loop: "{{ softwarecenter_search_list }}"
141-
loop_control:
142-
label: "{{ item }} : {{ download_task.msg }}"
143-
register: download_task
144-
retries: 1
145-
until: download_task is not failed
146-
147-
```
148-
14971
**Execution of Ansible Playbook, with in-line Ansible Inventory of target/remote hosts**
15072

15173
```shell
@@ -192,17 +114,19 @@ python3
192114

193115
**Execute Python Functions**
194116
```python
117+
>>> from module_utils.sap_id_sso import sap_sso_login
195118
>>> from module_utils.sap_launchpad_software_center_download_runner import *
196119
>>>
197120
>>> # Debug
198121
>>> # from module_utils.sap_api_common import debug_https
199122
>>> # debug_https()
200123
>>>
201-
>>> ## Perform API requests to SAP Support
124+
>>> ## Perform API login requests to SAP Support
202125
>>> username='S0000000'
203126
>>> password='password'
204127
>>> sap_sso_login(username, password)
205-
>>> query_result = search_software_filename("HCMT_057_0-80003261.SAR")
128+
>>> ## Perform API activity requests to SAP Support (e.g. software search without deduplication, and download software)
129+
>>> query_result = search_software_filename("HCMT_057_0-80003261.SAR",'')
206130
>>> download_software(*query_result, output_dir='/tmp')
207131
...
208132
>>> ## API responses from SAP Support

plugins/module_utils/sap_api_common.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ def _request(url, **kwargs):
3636

3737
method = 'POST' if kwargs.get('data') or kwargs.get('json') else 'GET'
3838
res = https_session.request(method, url, **kwargs)
39+
40+
if (res.status_code == 403
41+
and res.json()['errorMessage'].startswith('Account Temporarily Locked Out')):
42+
raise Exception('SAP ID Service has reported `Account Temporarily Locked Out`. Please reset password to regain access and try again.')
43+
3944
res.raise_for_status()
4045

4146
return res

plugins/module_utils/sap_id_sso.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,12 @@ def _get_sso_endpoint_meta(url, **kwargs):
4545

4646
def sap_sso_login(username, password):
4747
https_session.cookies.clear()
48+
49+
# Ensure usage of SAP User ID even when SAP Universal ID is used,
50+
# login with email address of SAP Universal ID will otherwise
51+
# incorrectly default to the last used SAP User ID
4852
if not re.match(r'^[sS]\d+$', username):
49-
raise ValueError('Please login with SID (like `S1234567890`)')
53+
raise ValueError('Please login with SAP User ID (like `S1234567890`)')
5054

5155
endpoint = C.URL_LAUNCHPAD
5256
meta = {}

0 commit comments

Comments
 (0)