Yapf code formatting

This commit is contained in:
Khanh Ngo 2019-12-15 09:40:05 +07:00
parent 32236faae8
commit de581e9e1d
No known key found for this signature in database
GPG Key ID: A945965CD6351844

View File

@ -6,6 +6,7 @@ import os
from ..lib.certutil import KEY_FILE, CERT_FILE from ..lib.certutil import KEY_FILE, CERT_FILE
from ..lib.utils import urlparse from ..lib.utils import urlparse
class SAML(object): class SAML(object):
def __init__(self): def __init__(self):
if current_app.config['SAML_ENABLED']: if current_app.config['SAML_ENABLED']:
@ -34,10 +35,10 @@ class SAML(object):
'SAML: IDP Metadata initial load failed') 'SAML: IDP Metadata initial load failed')
exit(-1) exit(-1)
def get_idp_data(self): def get_idp_data(self):
lifetime = timedelta(minutes=current_app.config['SAML_METADATA_CACHE_LIFETIME']) lifetime = timedelta(
minutes=current_app.config['SAML_METADATA_CACHE_LIFETIME'])
if self.idp_timestamp + lifetime < datetime.now(): if self.idp_timestamp + lifetime < datetime.now():
background_thread = Thread(target=self.retrieve_idp_data()) background_thread = Thread(target=self.retrieve_idp_data())
@ -45,26 +46,25 @@ class SAML(object):
return self.idp_data return self.idp_data
def retrieve_idp_data(self): def retrieve_idp_data(self):
if 'SAML_IDP_SSO_BINDING' in current_app.config: if 'SAML_IDP_SSO_BINDING' in current_app.config:
new_idp_data = self.OneLogin_Saml2_IdPMetadataParser.parse_remote( new_idp_data = self.OneLogin_Saml2_IdPMetadataParser.parse_remote(
current_app.config['SAML_METADATA_URL'], current_app.config['SAML_METADATA_URL'],
entity_id=current_app.config.get('SAML_IDP_ENTITY_ID', None), entity_id=current_app.config.get('SAML_IDP_ENTITY_ID', None),
required_sso_binding=current_app.config['SAML_IDP_SSO_BINDING'] required_sso_binding=current_app.config['SAML_IDP_SSO_BINDING']
) )
else: else:
new_idp_data = self.OneLogin_Saml2_IdPMetadataParser.parse_remote( new_idp_data = self.OneLogin_Saml2_IdPMetadataParser.parse_remote(
current_app.config['SAML_METADATA_URL'], current_app.config['SAML_METADATA_URL'],
entity_id=current_app.config.get('SAML_IDP_ENTITY_ID', None)) entity_id=current_app.config.get('SAML_IDP_ENTITY_ID', None))
if new_idp_data is not None: if new_idp_data is not None:
self.idp_data = new_idp_data self.idp_data = new_idp_data
self.idp_timestamp = datetime.now() self.idp_timestamp = datetime.now()
current_app.logger.info( current_app.logger.info(
"SAML: IDP Metadata successfully retrieved from: " + "SAML: IDP Metadata successfully retrieved from: " +
current_app.config['SAML_METADATA_URL']) current_app.config['SAML_METADATA_URL'])
else: else:
current_app.logger.info( current_app.logger.info(
"SAML: IDP Metadata could not be retrieved") "SAML: IDP Metadata could not be retrieved")