def sync(model): """Syncs the model with the QGIS data base""" kwargs = { 'signal': post_delete, 'receiver': sync_auth_delete, 'sender': QgisAuth, 'dispatch_uid': None } with temp_disconnect_signal(**kwargs): kwargs = { 'signal': pre_delete, 'receiver': check_layer_dependencies, 'sender': QgisAuth, 'dispatch_uid': None } with temp_disconnect_signal(**kwargs): model._objects.all().delete() am = QgsApplication.instance().authManager() kwargs = { 'signal': post_save, 'receiver': sync_auth_save, 'sender': QgisAuth, 'dispatch_uid': None } with temp_disconnect_signal(**kwargs): for authcfg in sorted(am.configIds()): c = QgsAuthMethodConfig() am.loadAuthenticationConfig(authcfg, c, True) model._objects.create(id=c.id(), name=c.name(), config=c.configMap( ), uri=c.uri(), version=c.version(), method=c.method())
def populatePKITestCerts(): """ Populate AuthManager with test certificates. heavily based on testqgsauthmanager.cpp. """ global AUTHM global AUTHCFGID global AUTHTYPE assert (AUTHM is not None) if AUTHCFGID: removePKITestCerts() assert (AUTHCFGID is None) # set alice PKI data p_config = QgsAuthMethodConfig() p_config.setName("alice") p_config.setMethod("PKI-Paths") p_config.setUri("http://example.com") p_config.setConfig("certpath", os.path.join(PKIDATA, 'alice-cert.pem')) p_config.setConfig("keypath", os.path.join(PKIDATA, 'alice-key.pem')) assert p_config.isValid() # add authorities cacerts = QSslCertificate.fromPath( os.path.join(PKIDATA, 'subissuer-issuer-root-ca_issuer-2-root-2-ca_chains.pem')) assert cacerts is not None AUTHM.storeCertAuthorities(cacerts) AUTHM.rebuildCaCertsCache() AUTHM.rebuildTrustedCaCertsCache() # add alice cert # boundle = QgsPkiBundle.fromPemPaths(os.path.join(PKIDATA, 'alice-cert.pem'), # os.path.join(PKIDATA, 'alice-key_w-pass.pem'), # 'password', # cacerts) # assert boundle is not None # assert boundle.isValid() # register alice data in auth AUTHM.storeAuthenticationConfig(p_config) AUTHCFGID = p_config.id() assert (AUTHCFGID is not None) assert (AUTHCFGID != '') AUTHTYPE = p_config.method()
def populatePKITestCerts(): """ Populate AuthManager with test certificates. heavily based on testqgsauthmanager.cpp. """ global AUTHM global AUTHCFGID global AUTHTYPE assert (AUTHM is not None) if AUTHCFGID: removePKITestCerts() assert (AUTHCFGID is None) # set alice PKI data p_config = QgsAuthMethodConfig() p_config.setName("alice") p_config.setMethod("PKI-Paths") p_config.setUri("http://example.com") p_config.setConfig("certpath", os.path.join(PKIDATA, 'alice-cert.pem')) p_config.setConfig("keypath", os.path.join(PKIDATA, 'alice-key.pem')) assert p_config.isValid() # add authorities cacerts = QSslCertificate.fromPath(os.path.join(PKIDATA, 'subissuer-issuer-root-ca_issuer-2-root-2-ca_chains.pem')) assert cacerts is not None AUTHM.storeCertAuthorities(cacerts) AUTHM.rebuildCaCertsCache() AUTHM.rebuildTrustedCaCertsCache() # add alice cert # boundle = QgsPkiBundle.fromPemPaths(os.path.join(PKIDATA, 'alice-cert.pem'), # os.path.join(PKIDATA, 'alice-key_w-pass.pem'), # 'password', # cacerts) # assert boundle is not None # assert boundle.isValid() # register alice data in auth AUTHM.storeAuthenticationConfig(p_config) AUTHCFGID = p_config.id() assert (AUTHCFGID is not None) assert (AUTHCFGID != '') AUTHTYPE = p_config.method()