Anonymous avatar Anonymous committed 7660231

Fixed the handlers support.
Replaced the proxyhandler and password manager to better support the OCC environment.

Comments (0)

Files changed (2)

eodsfetch/eodsfetch.bat

 rem                         level should be DEBUG, INFO, WARNING, ERROR
 rem   -c RETRIEVE_COMMAND, --retrieve-command=RETRIEVE_COMMAND
 rem                         Web site path to retrieval command (relative to url)
+rem   -r PROXY_SERVER, --proxy-server=PROXY_SERVER
+rem                         Optional proxy server and port (server:port)
 rem   -s SAVE_FILE, --save-file=SAVE_FILE
 rem                         filename to save data
+rem   -w PROXY_PASSWORD, --proxy-password=PROXY_PASSWORD
+rem                         Password for the proxy server '-' for prompt
+rem   -i PROXY_USER, --proxy-user=PROXY_USER
+rem                         User name for the proxy server
+
+set HTTP_PROXY=10.104.1.200:8080
 
 rem To retrieve data from the dev01 demonstration site, use the following command:
-rem eodsfetch.exe -u http://dev01.hrworx.com:8180/occ/formworx/admin/ -n occ.formworx@hrworx.com -p manager -c newhires/RetrieveQueuedExport.do -s c:\EODS.xml
+rem eodsfetch.exe -u http://dev01.hrworx.com:8180/occ/formworx/admin/ -n occ.formworx@hrworx.com -p manager -c newhires/RetrieveQueuedExport.do -s c:\EODS.xml  -i COC\psoft01 -w - -l debug
 
 rem To review the data (without purging the records), use the "Review" command:
-rem eodsfetch.exe -u http://dev01.hrworx.com:8180/occ/formworx/admin/ -n occ.formworx@hrworx.com -p manager -c newhires/ReviewQueuedExport.do -s c:\EODS.xml
+eodsfetch.exe -u http://dev01.hrworx.com:8180/occ/formworx/admin/ -n occ.formworx@hrworx.com -p manager -c newhires/ReviewQueuedExport.do -s c:\EODS.xml -i COC\psoft01 -w - -l debug
 
 rem If you don't specify a file to save to, the XML will be output to the screen
 rem eodsfetch.exe -u http://dev01.hrworx.com:8180/occ/formworx/admin/ -n occ.formworx@hrworx.com -p manager -c newhires/ReviewQueuedExport.do

eodsfetch/eodsfetch.py

 from urlparse import urljoin
 import logging
 
+# subclass the default ProxyBasicAuthHandler because it doesn't read multiple
+# proxy entries (see urllib2.AbstractBasicAuthHandler.http_error_auth_reqed)
+class ProxyBasicAuthHandler( urllib2.ProxyBasicAuthHandler ):
+
+	def http_error_407(self, req, fp, code, msg, headers):
+		authority = req.get_host()
+		log.debug( 'authority is' )
+		return self.http_error_auth_reqed('proxy-authenticate',
+										  authority, req, headers)
+
+	def http_error_auth_reqed(self, authreq, host, req, headers):
+		log.debug( 'headers are %s', headers )
+		result = urllib2.ProxyBasicAuthHandler.http_error_auth_reqed( self, authreq, host, req, headers )
+		if result is None:
+			headers[authreq] = 'Basic realm="NTLM_PWS"'
+			result = urllib2.ProxyBasicAuthHandler.http_error_auth_reqed( self, authreq, host, req, headers )
+		return result
+
+class OCCProxyPasswordManager( object ):
+	"A simple password manager that always returns the same username and password"
+	def __init__( self ):
+		self.username = None
+		self.password = None
+		
+	def add_password( self, realm, uri, username, password ):
+		self.username = username
+		self.password = password
+
+	def find_user_password( self, realm, uri ):
+		return self.username, self.password
+
 def getArgs( ):
 	parser = OptionParser()
 	parser.add_option( "-u", "--url", dest="url", default="http://dev01.hrworx.com:8180/occ/formworx/admin/", help="URL for the admin site" )
 	global log
 	log = logging.getLogger( 'eodsfetch' )
 	logging.basicConfig( level = getattr( logging, options.log_level.upper() ) )
+	log.debug( 'debug logging enabled' )
 
 def installOpener():
 	handlers = [ urllib2.HTTPCookieProcessor ]
 	if options.proxy_user and options.proxy_password:
-		pwMgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
+		pwMgr = OCCProxyPasswordManager()
 		if options.proxy_password == '-':
 			options.proxy_password = getpass( )
-		pwMgr.add_password( "NTLM_PWS", "http://dev01.hrworx.com:8180", options.proxy_user, options.proxy_password )
-		pwMgr.add_password( "NTLM_PWS", "http://occ.hrservices.accenture.com", options.proxy_user, options.proxy_password )
-		handler = urllib2.ProxyBasicAuthHandler( pwMgr )
+		pwMgr.add_password( None, None, options.proxy_user, options.proxy_password )	
+		handler = ProxyBasicAuthHandler( pwMgr )
 		handlers.append( handler )
 	if options.proxy_server:
 		handlers.append( urllib2.ProxyHandler( { 'http': options.proxy_server } ) )
-	opener = urllib2.build_opener( handlers )
+	opener = urllib2.build_opener( *handlers )
 	urllib2.install_opener( opener )
 
 def getLoginPage():
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.