mirror of
				https://git.collinwebdesigns.de/oscar.krause/fastapi-dls.git
				synced 2025-11-04 06:20:22 +01:00 
			
		
		
		
	code styling
This commit is contained in:
		@@ -50,15 +50,15 @@ app.add_middleware(
 | 
			
		||||
    CORSMiddleware,
 | 
			
		||||
    allow_origins=CORS_ORIGINS,
 | 
			
		||||
    allow_credentials=True,
 | 
			
		||||
    allow_methods=["*"],
 | 
			
		||||
    allow_headers=["*"],
 | 
			
		||||
    allow_methods=['*'],
 | 
			
		||||
    allow_headers=['*'],
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
logger.setLevel(logging.DEBUG if DEBUG else logging.INFO)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def get_token(request: Request) -> dict:
 | 
			
		||||
    authorization_header = request.headers['authorization']
 | 
			
		||||
    authorization_header = request.headers.get('authorization')
 | 
			
		||||
    token = authorization_header.split(' ')[1]
 | 
			
		||||
    return jwt.decode(token=token, key=jwt_decode_key, algorithms=ALGORITHMS.RS256, options={'verify_aud': False})
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										29
									
								
								app/util.py
									
									
									
									
									
								
							
							
						
						
									
										29
									
								
								app/util.py
									
									
									
									
									
								
							@@ -1,21 +1,28 @@
 | 
			
		||||
try:
 | 
			
		||||
    # Crypto | Cryptodome on Debian
 | 
			
		||||
    from Crypto.PublicKey import RSA
 | 
			
		||||
    from Crypto.PublicKey.RSA import RsaKey
 | 
			
		||||
except ModuleNotFoundError:
 | 
			
		||||
    from Cryptodome.PublicKey import RSA
 | 
			
		||||
    from Cryptodome.PublicKey.RSA import RsaKey
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def load_file(filename) -> bytes:
 | 
			
		||||
    with open(filename, 'rb') as file:
 | 
			
		||||
        content = file.read()
 | 
			
		||||
    return content
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def load_key(filename) -> RsaKey:
 | 
			
		||||
def load_key(filename) -> "RsaKey":
 | 
			
		||||
    try:
 | 
			
		||||
        # Crypto | Cryptodome on Debian
 | 
			
		||||
        from Crypto.PublicKey import RSA
 | 
			
		||||
        from Crypto.PublicKey.RSA import RsaKey
 | 
			
		||||
    except ModuleNotFoundError:
 | 
			
		||||
        from Cryptodome.PublicKey import RSA
 | 
			
		||||
        from Cryptodome.PublicKey.RSA import RsaKey
 | 
			
		||||
 | 
			
		||||
    return RSA.import_key(extern_key=load_file(filename), passphrase=None)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def generate_key() -> RsaKey:
 | 
			
		||||
def generate_key() -> "RsaKey":
 | 
			
		||||
    try:
 | 
			
		||||
        # Crypto | Cryptodome on Debian
 | 
			
		||||
        from Crypto.PublicKey import RSA
 | 
			
		||||
        from Crypto.PublicKey.RSA import RsaKey
 | 
			
		||||
    except ModuleNotFoundError:
 | 
			
		||||
        from Cryptodome.PublicKey import RSA
 | 
			
		||||
        from Cryptodome.PublicKey.RSA import RsaKey
 | 
			
		||||
 | 
			
		||||
    return RSA.generate(bits=2048)
 | 
			
		||||
 
 | 
			
		||||
@@ -16,7 +16,7 @@ sys.path.append('../')
 | 
			
		||||
sys.path.append('../app')
 | 
			
		||||
 | 
			
		||||
from app import main
 | 
			
		||||
from app.util import generate_key, load_key
 | 
			
		||||
from app.util import load_key
 | 
			
		||||
 | 
			
		||||
client = TestClient(main.app)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user