improved persistent configuration management
This commit is contained in:
		
							parent
							
								
									798681c47c
								
							
						
					
					
						commit
						037f3a9a5e
					
				
					 4 changed files with 19 additions and 8 deletions
				
			
		|  | @ -23,6 +23,10 @@ pipenv run python register.py --help | |||
| Snaha je, aby se co nejvíce dokumentace nacházelo v kódu. Vysvětlení proto získáte zavoláním programu s argumentem | ||||
| `--help`. Žádné další informace by k tomu neměly být potřeba. | ||||
| 
 | ||||
| ## Konfigurace | ||||
| 
 | ||||
| Pro perzistentní konfiguraci je možné použít soubor `config.py` zkopírováním z `config_default.py`. | ||||
| 
 | ||||
| ## Dokumentace API Gitei | ||||
| 
 | ||||
| Gitea má specifikaci API popsanou dle specifikace OpenAPI 2.0 (dříve nazýváno Swagger). Pokud není explicitně řečeno | ||||
|  |  | |||
|  | @ -1,3 +0,0 @@ | |||
| # Zde je mozne nastavit vychozi hodnoty | ||||
| HOST = 'https://gitea.url/api/v1' | ||||
| ADMIN_TOKEN = '' | ||||
							
								
								
									
										5
									
								
								config_default.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								config_default.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,5 @@ | |||
| # base URL adresa pro API | ||||
| HOST = 'https://try.gitea.io/api/v1' | ||||
| 
 | ||||
| # autorizacni token administratora | ||||
| ADMIN_TOKEN = '' | ||||
							
								
								
									
										15
									
								
								register.py
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								register.py
									
									
									
									
									
								
							|  | @ -13,6 +13,16 @@ import random | |||
| import string | ||||
| 
 | ||||
| 
 | ||||
| # load configuration | ||||
| try: | ||||
|     import config | ||||
| except ImportError: | ||||
|     import config_default as config | ||||
| 
 | ||||
| HOST = config.HOST | ||||
| ADMIN_TOKEN = config.ADMIN_TOKEN | ||||
| 
 | ||||
| 
 | ||||
| def rand_str(n) -> str: | ||||
|     return ''.join([random.choice(string.ascii_lowercase) for _ in range(n)]) | ||||
| 
 | ||||
|  | @ -118,11 +128,6 @@ def reset_password(email: str): | |||
|             raise ApiException(status=resp.status_code, reason=resp.reason, http_resp='Form submission failed.') | ||||
| 
 | ||||
| 
 | ||||
| import config | ||||
| HOST = config.HOST | ||||
| ADMIN_TOKEN = config.ADMIN_TOKEN | ||||
| 
 | ||||
| 
 | ||||
| @click.command() | ||||
| @click.option('-a', '--admin-token', help='Admin access token') | ||||
| @click.option('-h', '--host', help='Gitea URL (default: {})'.format(HOST)) | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue