details
This commit is contained in:
		
					parent
					
						
							
								6a2e0336d9
							
						
					
				
			
			
				commit
				
					
						2d8c68665e
					
				
			
		
					 3 changed files with 14 additions and 11 deletions
				
			
		
							
								
								
									
										4
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							| 
						 | 
					@ -1 +1,5 @@
 | 
				
			||||||
 | 
					.coverage
 | 
				
			||||||
 | 
					.env
 | 
				
			||||||
 | 
					.mypy_cache
 | 
				
			||||||
coverage.xml
 | 
					coverage.xml
 | 
				
			||||||
 | 
					htmlcov
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,4 @@
 | 
				
			||||||
FROM python:3.9-slim
 | 
					FROM python:3.9
 | 
				
			||||||
 | 
					
 | 
				
			||||||
EXPOSE 4785
 | 
					EXPOSE 4785
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -14,7 +14,9 @@ BOT_URL = 'http://localhost:4785'
 | 
				
			||||||
MATRIX_URL, MATRIX_ID, MATRIX_PW = (environ[v] for v in ['MATRIX_URL', 'MATRIX_ID', 'MATRIX_PW'])
 | 
					MATRIX_URL, MATRIX_ID, MATRIX_PW = (environ[v] for v in ['MATRIX_URL', 'MATRIX_ID', 'MATRIX_PW'])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def check_json(url: str, key: str) -> bool:
 | 
					def wait_available(url: str, key: str, timeout: int = 10) -> bool:
 | 
				
			||||||
 | 
					    """Wait until a service answer correctly or timeout."""
 | 
				
			||||||
 | 
					    def check_json(url: str, key: str) -> bool:
 | 
				
			||||||
        """Ensure a service at a given url answers with valid json containing a certain key."""
 | 
					        """Ensure a service at a given url answers with valid json containing a certain key."""
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            data = httpx.get(url).json()
 | 
					            data = httpx.get(url).json()
 | 
				
			||||||
| 
						 | 
					@ -22,9 +24,6 @@ def check_json(url: str, key: str) -> bool:
 | 
				
			||||||
        except httpx.ConnectError:
 | 
					        except httpx.ConnectError:
 | 
				
			||||||
            return False
 | 
					            return False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
def wait_available(url: str, key: str, timeout: int = 10) -> bool:
 | 
					 | 
				
			||||||
    """Wait until a service answer correctly or timeout."""
 | 
					 | 
				
			||||||
    start = time()
 | 
					    start = time()
 | 
				
			||||||
    while True:
 | 
					    while True:
 | 
				
			||||||
        if check_json(url, key):
 | 
					        if check_json(url, key):
 | 
				
			||||||
| 
						 | 
					@ -38,7 +37,7 @@ def run_and_test():
 | 
				
			||||||
    if not wait_available(f'{MATRIX_URL}/_matrix/client/r0/login', 'flows'):
 | 
					    if not wait_available(f'{MATRIX_URL}/_matrix/client/r0/login', 'flows'):
 | 
				
			||||||
        return False
 | 
					        return False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Try to register an user for the bot.
 | 
					    # Try to register a user for the bot.
 | 
				
			||||||
    with open('/srv/homeserver.yaml') as f:
 | 
					    with open('/srv/homeserver.yaml') as f:
 | 
				
			||||||
        secret = yaml.safe_load(f.read()).get("registration_shared_secret", None)
 | 
					        secret = yaml.safe_load(f.read()).get("registration_shared_secret", None)
 | 
				
			||||||
    request_registration(MATRIX_ID, MATRIX_PW, MATRIX_URL, secret, admin=True)
 | 
					    request_registration(MATRIX_ID, MATRIX_PW, MATRIX_URL, secret, admin=True)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue