Skip to content

Commit 5cd18d0

Browse files
committed
get proxy
1 parent 41f6e3c commit 5cd18d0

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

tasks/main.yml

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
with_items:
3939
- { source: 'templates/condor_config', dest: '/etc/condor/condor_config' }
4040
- { source: 'templates/get_proxy.py', dest: '/home/censtos/get_proxy.py' }
41+
- { source: 'templates/get_proxy.sh', dest: '/home/censtos/get_proxy.sh' }
4142

4243
- name: copy job example
4344
become: yes

templates/get_proxy.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,16 @@ def generate_proxy(self):
290290

291291
"""Execute the get_proxy routine."""
292292

293+
TOKEN = os.getenv("TOKEN")
294+
293295
configuration = {
294296
'CREDENTIAL_ENDPOINT' : 'https://dodas-tts.cloud.cnaf.infn.it/api/v2/iam/credential',
295297
'IAM_ENDPOINT':'https://dodas-iam.cloud.cnaf.infn.it/',
296298
'TTS':'https://dodas-tts.cloud.cnaf.infn.it',
297-
'IAM_CLIENT_ID': "{{ iam.client_id }}",
298-
'IAM_CLIENT_SECRET': "{{ iam.client_secret }}",
299+
'IAM_CLIENT_ID': "{{ tts.client_id }}",
300+
'IAM_CLIENT_SECRET': "{{ tts.client_secret }}",
299301
'AUDIENCE' : 'https://dodas-tts.cloud.cnaf.infn.it',
300-
'IAM_TOKEN': "{{ iam.token }}" }
302+
'IAM_TOKEN': TOKEN }
301303

302304
proxy_manager = ProxyManager(configuration)
303305
proxy_file = proxy_manager.generate_proxy()

templates/get_proxy.sh

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
3+
IAM_CLIENT_ID=dodas-demo
4+
IAM_CLIENT_SECRET=dodas-demo
5+
IAM_USER=
6+
7+
IAM_CLIENT_ID={{ iam.client_id }}
8+
IAM_CLIENT_SECRET={{ iam.client_secret }}
9+
10+
11+
if [[ -z "${IAM_CLIENT_SECRET}" ]]; then
12+
echo "Please provide a client secret setting the IAM_CLIENT_SECRET env variable."
13+
exit 1;
14+
fi
15+
16+
if [[ -z ${IAM_USER} ]]; then
17+
read -p "Username: " IAM_USER
18+
fi
19+
20+
echo -ne "Password:"
21+
read -s IAM_PASSWORD
22+
echo
23+
24+
result=$(curl -s -L \
25+
-d client_id=${IAM_CLIENT_ID} \
26+
-d client_secret=${IAM_CLIENT_SECRET} \
27+
-d grant_type=password \
28+
-d username=${IAM_USER} \
29+
-d password=${IAM_PASSWORD} \
30+
-d scope="openid profile email offline_access" \
31+
${IAM_ENDPOINT:-https://dodas-iam.cloud.cnaf.infn.it/token}) #| tee /tmp/response | jq
32+
33+
if [[ $? != 0 ]]; then
34+
echo "Error!"
35+
echo $result
36+
exit 1
37+
fi
38+
39+
echo $result
40+
41+
access_token=$(echo $result | jq -r .access_token)
42+
43+
echo "export TOKEN=\"${access_token}\""
44+
export TOKEN="${access_token}"
45+
46+
python /home/censtos/get_proxy.py

0 commit comments

Comments
 (0)