Refactor credential passing
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				continuous-integration/drone Build is passing
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	continuous-integration/drone Build is passing
				
			This commit is contained in:
		
							
								
								
									
										19
									
								
								camdetect.py
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								camdetect.py
									
									
									
									
									
								
							| @@ -24,8 +24,21 @@ from sanic.log import logger | |||||||
| from sanic_prometheus import monitor | from sanic_prometheus import monitor | ||||||
| from sanic.response import stream | from sanic.response import stream | ||||||
| from time import time | from time import time | ||||||
|  | from urllib.parse import urlparse | ||||||
|  |  | ||||||
| _, url = sys.argv | _, target = sys.argv | ||||||
|  |  | ||||||
|  | # Override basic auth password from env var | ||||||
|  | basic_auth_password = os.getenv("BASIC_AUTH_PASSWORD") | ||||||
|  | if basic_auth_password: | ||||||
|  |     o = urlparse(target) | ||||||
|  |     netloc = o.netloc | ||||||
|  |     username = "" | ||||||
|  |     if "@" in netloc: | ||||||
|  |         username, netloc = o.netloc.split("@", 1) | ||||||
|  |         if ":" in username: | ||||||
|  |             username, _ = username.split(":") | ||||||
|  |     target = o._replace(netloc="%s:%s@%s" % (username, basic_auth_password, netloc)).geturl() | ||||||
|  |  | ||||||
| AWS_ACCESS_KEY_ID = os.environ["AWS_ACCESS_KEY_ID"] | AWS_ACCESS_KEY_ID = os.environ["AWS_ACCESS_KEY_ID"] | ||||||
| AWS_SECRET_ACCESS_KEY = os.environ["AWS_SECRET_ACCESS_KEY"] | AWS_SECRET_ACCESS_KEY = os.environ["AWS_SECRET_ACCESS_KEY"] | ||||||
| @@ -411,9 +424,9 @@ async def downloader(queue: asyncio.Queue): | |||||||
|     while True: |     while True: | ||||||
|         to = aiohttp.ClientTimeout(connect=5, sock_read=2) |         to = aiohttp.ClientTimeout(connect=5, sock_read=2) | ||||||
|         async with aiohttp.ClientSession(timeout=to) as session: |         async with aiohttp.ClientSession(timeout=to) as session: | ||||||
|             logger.info("Opening connection to %s", url) |             logger.info("Opening connection to %s", target) | ||||||
|             try: |             try: | ||||||
|                 async with session.get(url) as resp: |                 async with session.get(target) as resp: | ||||||
|                     await download(resp, queue) |                     await download(resp, queue) | ||||||
|             except (aiohttp.ClientError, asyncio.exceptions.TimeoutError) as e: |             except (aiohttp.ClientError, asyncio.exceptions.TimeoutError) as e: | ||||||
|                 j = "%s.%s" % (e.__class__.__module__, e.__class__.__name__) |                 j = "%s.%s" % (e.__class__.__module__, e.__class__.__name__) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user