Created
March 18, 2018 05:50
-
-
Save AKSarav/58619fd829d411fcd0e7efd22b8c6d85 to your computer and use it in GitHub Desktop.
weblogic REST ful CLI interface
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# | |
# | |
import os | |
import sys | |
import getpass | |
import time | |
import base64 | |
import subprocess | |
import re | |
text=[] | |
output = "" | |
print "-"*90 | |
print "\t\tWeblogic REST CLI Helper tool - by www.mwinventory.in" | |
print "-"*90 | |
print "Instrutions\n------------" | |
print "This is Weblogic REST CLI helper tool created to efficiently pass the username and password to CURL" | |
print "Now you will be prompted for username & password" | |
print "After Entering the username and password you DO NOT have to use --user username:password in your request header" | |
print "The Tool will take care of passing the credentials as a Authorization header" | |
print "Note*: Your details will not be saved and only valid for this session" | |
print "\nExample:" | |
print "--------" | |
print " curl -v \ " | |
print " -H X-Requested-By:MyClient \ " | |
print " -H Accept:application/json \ " | |
print " -X GET http://localhost:7001/management/weblogic/latest/serverConfig?links=none " | |
print " END" | |
print "-"*90 | |
# Get username and password | |
username = raw_input("Enter the Username: ") | |
password=getpass.getpass("Enter the Password: ") | |
cred_enc=base64.b64encode(username+":"+password) | |
print "INFO: the entered user credentials have been encrypted and will be sent as a header" | |
#cred_dec=base64.b64decode(cred_enc) | |
#print cred_dec | |
def makerequest(): | |
print "" | |
print "Enter the whole request line by line, type END and hit enter once done" | |
#read -d '' i << END | |
while True: | |
line=raw_input("") | |
text.append(line) | |
if "END" in line: | |
break | |
text.pop() | |
#update the basic auth header | |
text.insert(1,'-H "Authorization: Basic '+cred_enc+'"') | |
print text | |
cmd = " ".join(text) | |
print "COMMAND",cmd | |
cmd=re.sub('[\\\]','', cmd) | |
print "==========================" | |
print "Execution Result" | |
print "==========================" | |
output = subprocess.Popen([cmd], shell=True, stdout = subprocess.PIPE).communicate()[0] | |
print output | |
print "==========================" | |
makerequest() | |
while True: | |
ans=raw_input("Would you like to Proceed and Make a New Request ? Yes to Continue| No to exit : ") | |
if "y" in ans or "Y" in ans or "yes" in ans or "Yes" in ans or "YES" in ans: | |
text=[]; | |
makerequest() | |
else: | |
sys.exit(0); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment