class TestEnvoyerRequete: def __init__(self, contexte): self.callback = TestCallback(contexte, self) self.generateur = GenerateurTransaction(contexte) self.reponse = None def envoyer_message_test_alerte(self): requete = { 'requetes': [ { 'type': 'mongodb', "filtre": { "_mg-libelle": "noeud.individuel", "noeud": { "$in": ["test"] } }, "projection": { "noeud": 1, "dict_senseurs": 1 } } ], # 'retour': { # "routage": "reponse.%s" % message_dao.queue_reponse # } } # enveloppe_val = generateur.soumettre_transaction(requete, 'millegrilles.domaines.Principale.creerAlerte') enveloppe_requete = self.generateur.preparer_enveloppe(requete, 'millegrilles.domaines.SenseursPassifs.requete') self.generateur.transmettre_requete(enveloppe_requete, 'requete.millegrilles.domaines.SenseursPassifs.mongodb', Constantes.DEFAUT_MQ_EXCHANGE_NOEUDS) return enveloppe_requete
class MessagesSample(BaseCallback): def __init__(self): super().__init__(contexte) self.contexte.message_dao.register_channel_listener(self) self.generateur = GenerateurTransaction(self.contexte) self.fichier_fuuid = "39c1e1b0-b6ee-11e9-b0cd-d30e8fab842j" self.channel = None self.event_recu = Event() def on_channel_open(self, channel): # Enregistrer la reply-to queue self.channel = channel channel.queue_declare(durable=True, exclusive=True, callback=self.queue_open_local) def queue_open_local(self, queue): self.queue_name = queue.method.queue print("Queue: %s" % str(self.queue_name)) self.channel.basic_consume(self.callbackAvecAck, queue=self.queue_name, no_ack=False) self.executer() def run_ioloop(self): self.contexte.message_dao.run_ioloop() def deconnecter(self): self.contexte.message_dao.deconnecter() def traiter_message(self, ch, method, properties, body): print("Message recu, correlationId: %s" % properties.correlation_id) print(json.dumps(json.loads(body.decode('utf-8')), indent=4)) print("Channel : " + str(ch)) print("Method : " + str(method)) print("Properties : " + str(properties)) print("Channel virtual host : " + str(ch.connection.params.virtual_host)) def transmettre_transaction_lecture(self): transaction = { "avg": 1.31, "lectures": [{ "timestamp": 1597950486, "valeur": 31.4 }, { "timestamp": 1597950491, "valeur": 5.3 }, { "timestamp": 1597953581, "valeur": -0.4 }, { "timestamp": 1597953586, "valeur": 38.9 }, { "timestamp": 1597953591, "valeur": 42.2 }, { "timestamp": 1597953596, "valeur": -49.3 }], "max": 49.9, "min": -49.6, "noeud_id": "001a12f5-e89d-4ff8-b6ac-f2ee269b9516", "senseur": "dummy/temperature", "timestamp": 1597950000, "timestamp_max": 1597953596, "timestamp_min": 1597950491, "type": "temperature", "uuid_senseur": "7a2764fa-c457-4f25-af0d-0fc915439b21" } enveloppe_val = self.generateur.soumettre_transaction( transaction, 'SenseursPassifs.lecture', reply_to=self.queue_name, correlation_id='efgh') print("Envoi metadata: %s" % enveloppe_val) return enveloppe_val def transmettre_maj_noeud(self): transaction = { "noeud_id": "f9f3e995-f52c-4718-8e5c-a1efd101f402", # "securite": "2.prive", "securite": "2.prive", "blynk_host": "blynk", "blynk_port": 9444, "blynk_auth": "ciyZXHGed6Z31xtszjDpsifqPxobzEJ4" } enveloppe_val = self.generateur.soumettre_transaction( transaction, SenseursPassifsConstantes.TRANSACTION_MAJ_NOEUD, reply_to=self.queue_name, correlation_id='efgh') print("Envoi metadata: %s" % enveloppe_val) def transmettre_maj_senseur(self): transaction = { "uuid_senseur": "7a2764fa-c457-4f25-af0d-0fc915439b21", "securite": "2.prive", "senseurs": { "dummy/temperature": { "blynk_vpin": 1 }, "dummy/humidite": { "blynk_vpin": 2 }, }, } enveloppe_val = self.generateur.soumettre_transaction( transaction, SenseursPassifsConstantes.TRANSACTION_MAJ_SENSEUR, reply_to=self.queue_name, correlation_id='efgh') print("Envoi metadata: %s" % enveloppe_val) def requete_liste_noeuds(self): transaction = {} enveloppe_val = self.generateur.transmettre_requete( transaction, 'SenseursPassifs.' + SenseursPassifsConstantes.REQUETE_LISTE_NOEUDS, reply_to=self.queue_name, correlation_id='efgh') print("Envoi metadata: %s" % enveloppe_val) def requete_liste_senseurs_noeud(self): transaction = {'noeud_id': 'f9f3e995-f52c-4718-8e5c-a1efd101f402'} enveloppe_val = self.generateur.transmettre_requete( transaction, 'SenseursPassifs.' + SenseursPassifsConstantes.REQUETE_LISTE_SENSEURS_NOEUD, reply_to=self.queue_name, correlation_id='efgh') print("Envoi metadata: %s" % enveloppe_val) def executer(self): # sample.transmettre_transaction_lecture() sample.transmettre_maj_noeud()
class MessagesSample(BaseCallback): def __init__(self): super().__init__(contexte) self.contexte.message_dao.register_channel_listener(self) self.generateur = GenerateurTransaction(self.contexte) self.queue_name = None self.channel = None self.event_recu = Event() def on_channel_open(self, channel): # Enregistrer la reply-to queue self.channel = channel channel.queue_declare(durable=True, exclusive=True, callback=self.queue_open_local) def queue_open_local(self, queue): self.queue_name = queue.method.queue print("Queue: %s" % str(self.queue_name)) self.channel.basic_consume(self.callbackAvecAck, queue=self.queue_name, no_ack=False) self.executer() def run_ioloop(self): self.contexte.message_dao.run_ioloop() def deconnecter(self): self.contexte.message_dao.deconnecter() def traiter_message(self, ch, method, properties, body): print("Message recu, correlationId: %s" % properties.correlation_id) message = json.loads(str(body, 'utf-8')) print(json.dumps(message, indent=4)) def transmettre_commande_ouverture(self, idmg): commande = { 'idmg': idmg } domaine = 'commande.inter.connecter' enveloppe_val = self.generateur.transmettre_commande(commande, domaine, exchange=self.configuration.exchange_prive) print("Envoi maj fiche privee: %s" % enveloppe_val) return enveloppe_val def transmettre_requete_directe(self, idmg): requete = { 'texte': 'On va se promener plus loin' } domaine = 'donne.moi.des.fichiers' enveloppe_val = self.generateur.transmettre_requete(requete, domaine, idmg_destination=idmg, correlation_id='moimoi') print("Envoi maj fiche privee: %s" % enveloppe_val) return enveloppe_val def demander_csr(self): domaine = 'inter.genererCsr' self.generateur.transmettre_requete({}, domaine, 'abcd', self.queue_name) def executer(self): idmg = 'distant' # enveloppe = sample.transmettre_commande_ouverture(idmg) # enveloppe = sample.transmettre_requete_directe(idmg) self.demander_csr()
class MessagesSample(BaseCallback): def __init__(self): super().__init__(contexte) self.contexte.message_dao.register_channel_listener(self) self.generateur = GenerateurTransaction(self.contexte) self.channel = None self.event_recu = Event() # self.thread_ioloop = Thread(target=self.run_ioloop) self.queue_name = None self.certificat_maitredescles = None self.cert_maitredescles_recu = Event() self.mot_de_passe = 'sjdpo-1824-JWAZ' # Charger cert MaitreDesCles pour pouvoir crypter contenu a transmettre with open('/home/mathieu/mgdev/certs/pki.maitrecles.cert', 'rb') as certificat_pem: certificat_courant_pem = certificat_pem.read() cert = x509.load_pem_x509_certificate(certificat_courant_pem, backend=default_backend()) self.certificat_courant = cert self.certificat_courant_pem = certificat_courant_pem.decode('utf8') def on_channel_open(self, channel): # Enregistrer la reply-to queue self.channel = channel channel.queue_declare(durable=True, exclusive=True, callback=self.queue_open) def queue_open(self, queue): self.queue_name = queue.method.queue print("Queue: %s" % str(self.queue_name)) self.channel.basic_consume(self.callbackAvecAck, queue=self.queue_name, no_ack=False) self.executer() # def run_ioloop(self): # self.contexte.message_dao.run_ioloop() def deconnecter(self): self.contexte.message_dao.deconnecter() def traiter_message(self, ch, method, properties, body): print("Message recu, correlationId: %s" % properties.correlation_id) print(body) message_dict = json.loads(body) certificat_pem = message_dict.get('certificat') if certificat_pem is not None: cert = EnveloppeCleCert() cert.cert_from_pem_bytes(certificat_pem.encode('utf-8')) self.certificat_maitredescles = cert self.cert_maitredescles_recu.set() else: self.event_recu.set() print(json.dumps(message_dict, indent=4)) def commande_creer_millegrille_hebergee(self): enveloppe_requete = self.generateur.transmettre_commande( dict(), 'commande.%s' % ConstantesHebergement.COMMANDE_CREER_MILLEGRILLE_HEBERGEE, correlation_id='abcd-1234', reply_to=self.queue_name, exchange=Constantes.DEFAUT_MQ_EXCHANGE_NOEUDS) print("Envoi commande: %s" % enveloppe_requete) return enveloppe_requete def transaction_desactiver_millegrille_hebergee(self): enveloppe_requete = self.generateur.soumettre_transaction( {'idmg': '2zHt8UFJhAdH8XzcPfb4Evsn4kcZrvZ7fxBT97R'}, ConstantesHebergement.TRANSACTION_DESACTIVER_MILLEGRILLE_HEBERGEE, correlation_id='abcd-1234', reply_to=self.queue_name) print("Envoi commande: %s" % enveloppe_requete) return enveloppe_requete def transaction_activer_millegrille_hebergee(self): enveloppe_requete = self.generateur.soumettre_transaction( {'idmg': '2zHt8UFJhAdH8XzcPfb4Evsn4kcZrvZ7fxBT97R'}, ConstantesHebergement.TRANSACTION_ACTIVER_MILLEGRILLE_HEBERGEE, correlation_id='abcd-1234', reply_to=self.queue_name) print("Envoi commande: %s" % enveloppe_requete) return enveloppe_requete def requete_millegrilles_actives(self): enveloppe_requete = self.generateur.transmettre_requete( {}, ConstantesHebergement.REQUETE_MILLEGRILLES_ACTIVES, correlation_id='abcd-1234', reply_to=self.queue_name) self.event_recu.clear() print("Envoi requete: %s" % enveloppe_requete) return enveloppe_requete def requete_millegrilles_hebergees(self): enveloppe_requete = self.generateur.transmettre_requete( {}, ConstantesHebergement.REQUETE_MILLEGRILLES_HEBERGEES, correlation_id='abcd-1234', reply_to=self.queue_name) self.event_recu.clear() print("Envoi requete: %s" % enveloppe_requete) return enveloppe_requete def transaction_supprimer_millegrille_hebergee(self): enveloppe_requete = self.generateur.soumettre_transaction( {'idmg': '3M87pZxVVWbT1dVLeRarQnge1mvADTs4trG7Caa'}, ConstantesHebergement.TRANSACTION_SUPPRIMER_MILLEGRILLE_HEBERGEE, correlation_id='abcd-1234', reply_to=self.queue_name) print("Envoi commande: %s" % enveloppe_requete) return enveloppe_requete def executer(self): # self.commande_creer_millegrille_hebergee() # self.transaction_desactiver_millegrille_hebergee() # self.transaction_activer_millegrille_hebergee() self.requete_millegrilles_actives()
class MessagesSample(BaseCallback): def __init__(self): super().__init__(contexte) self.contexte.message_dao.register_channel_listener(self) self.generateur = GenerateurTransaction(self.contexte) self.queue_name = None self.channel = None self.event_recu = Event() def on_channel_open(self, channel): # Enregistrer la reply-to queue self.channel = channel channel.queue_declare(durable=True, exclusive=True, callback=self.queue_open_local) def queue_open_local(self, queue): self.queue_name = queue.method.queue print("Queue: %s" % str(self.queue_name)) self.channel.basic_consume(self.callbackAvecAck, queue=self.queue_name, no_ack=False) self.executer() def run_ioloop(self): self.contexte.message_dao.run_ioloop() def deconnecter(self): self.contexte.message_dao.deconnecter() def traiter_message(self, ch, method, properties, body): print("Message recu, correlationId: %s" % properties.correlation_id) message = json.loads(str(body, 'utf-8')) print(json.dumps(message, indent=4)) def requete_profil_usager(self): requete = {'nomUsager': 'test'} domaine_action = '.'.join([ ConstantesMaitreDesComptes.DOMAINE_NOM, ConstantesMaitreDesComptes.REQUETE_CHARGER_USAGER ]) enveloppe = self.generateur.transmettre_requete( requete, domaine_action, 'abcd-1234', self.queue_name) print("Envoi : %s" % enveloppe) return enveloppe def requete_info_proprietaire(self): requete = {} domaine_action = '.'.join([ ConstantesMaitreDesComptes.DOMAINE_NOM, ConstantesMaitreDesComptes.REQUETE_INFO_PROPRIETAIRE ]) enveloppe = self.generateur.transmettre_requete( requete, domaine_action, 'abcd-1234', self.queue_name) print("Envoi : %s" % enveloppe) return enveloppe def transaction_inscrire_proprietaire(self): transaction = { ConstantesMaitreDesComptes.CHAMP_CLE: { 'ma_cle': 56896, 'autre_info': 'Da da daah' }, } domaine_action = '.'.join([ ConstantesMaitreDesComptes.DOMAINE_NOM, ConstantesMaitreDesComptes.TRANSACTION_INSCRIRE_PROPRIETAIRE ]) enveloppe = self.generateur.soumettre_transaction( transaction, domaine_action, 'abcd-1234', self.queue_name) print("Envoi : %s" % enveloppe) return enveloppe def transaction_inscrire_usager(self): transaction = {'nomUsager': 'test', 'mon_info': 237} domaine_action = '.'.join([ ConstantesMaitreDesComptes.DOMAINE_NOM, ConstantesMaitreDesComptes.TRANSACTION_INSCRIRE_USAGER ]) enveloppe = self.generateur.soumettre_transaction( transaction, domaine_action, 'abcd-1234', self.queue_name) print("Envoi : %s" % enveloppe) return enveloppe def transaction_maj_motdepasse(self): transaction = { ConstantesMaitreDesComptes.CHAMP_NOM_USAGER: 'test', ConstantesMaitreDesComptes.CHAMP_MOTDEPASSE: { 'info-mot-de-passe': 1234 }, } domaine_action = '.'.join([ ConstantesMaitreDesComptes.DOMAINE_NOM, ConstantesMaitreDesComptes.TRANSACTION_MAJ_MOTDEPASSE ]) enveloppe = self.generateur.soumettre_transaction( transaction, domaine_action, 'abcd-1234', self.queue_name) print("Envoi : %s" % enveloppe) return enveloppe def transaction_maj_motdepasse_proprietaire(self): transaction = { ConstantesMaitreDesComptes.CHAMP_NOM_USAGER: 'test', ConstantesMaitreDesComptes.CHAMP_MOTDEPASSE: { 'info-mot-de-passe': 1234 }, ConstantesMaitreDesComptes.CHAMP_EST_PROPRIETAIRE: True, } domaine_action = '.'.join([ ConstantesMaitreDesComptes.DOMAINE_NOM, ConstantesMaitreDesComptes.TRANSACTION_MAJ_MOTDEPASSE ]) enveloppe = self.generateur.soumettre_transaction( transaction, domaine_action, 'abcd-1234', self.queue_name) print("Envoi : %s" % enveloppe) return enveloppe def transaction_supprimer_motdepasse(self): transaction = { ConstantesMaitreDesComptes.CHAMP_NOM_USAGER: 'test', } domaine_action = '.'.join([ ConstantesMaitreDesComptes.DOMAINE_NOM, ConstantesMaitreDesComptes.TRANSACTION_SUPPRESSION_MOTDEPASSE ]) enveloppe = self.generateur.soumettre_transaction( transaction, domaine_action, 'abcd-1234', self.queue_name) print("Envoi : %s" % enveloppe) return enveloppe def transaction_ajouter_cle(self): transaction = { ConstantesMaitreDesComptes.CHAMP_NOM_USAGER: 'test', ConstantesMaitreDesComptes.CHAMP_CLE: { 'ma_cle': 56896, 'autre_info': 'Da da daah' }, ConstantesMaitreDesComptes.CHAMP_RESET_CLES: False, } domaine_action = '.'.join([ ConstantesMaitreDesComptes.DOMAINE_NOM, ConstantesMaitreDesComptes.TRANSACTION_AJOUTER_CLE ]) enveloppe = self.generateur.soumettre_transaction( transaction, domaine_action, 'abcd-1234', self.queue_name) print("Envoi : %s" % enveloppe) return enveloppe def transaction_ajouter_cle_proprietaire(self): transaction = { ConstantesMaitreDesComptes.CHAMP_EST_PROPRIETAIRE: True, ConstantesMaitreDesComptes.CHAMP_CLE: { 'ma_cle': 56896, 'autre_info': 'Da da daah' }, ConstantesMaitreDesComptes.CHAMP_RESET_CLES: False, } domaine_action = '.'.join([ ConstantesMaitreDesComptes.DOMAINE_NOM, ConstantesMaitreDesComptes.TRANSACTION_AJOUTER_CLE ]) enveloppe = self.generateur.soumettre_transaction( transaction, domaine_action, 'abcd-1234', self.queue_name) print("Envoi : %s" % enveloppe) return enveloppe def transaction_supprimer_cles(self): transaction = { ConstantesMaitreDesComptes.CHAMP_NOM_USAGER: 'test', } domaine_action = '.'.join([ ConstantesMaitreDesComptes.DOMAINE_NOM, ConstantesMaitreDesComptes.TRANSACTION_SUPPRIMER_CLES ]) enveloppe = self.generateur.soumettre_transaction( transaction, domaine_action, 'abcd-1234', self.queue_name) print("Envoi : %s" % enveloppe) return enveloppe def transaction_supprimer_usager(self): transaction = { ConstantesMaitreDesComptes.CHAMP_NOM_USAGER: 'test', } domaine_action = '.'.join([ ConstantesMaitreDesComptes.DOMAINE_NOM, ConstantesMaitreDesComptes.TRANSACTION_SUPPRIMER_USAGER ]) enveloppe = self.generateur.soumettre_transaction( transaction, domaine_action, 'abcd-1234', self.queue_name) print("Envoi : %s" % enveloppe) return enveloppe def transaction_associer_idmg(self): transaction = { ConstantesMaitreDesComptes.CHAMP_NOM_USAGER: 'test', Constantes.CONFIG_IDMG: 'D_abcd1234EFGHI', # ConstantesMaitreDesComptes.CHAMP_CHAINE_CERTIFICAT: ['cert1', 'cert5'], # ConstantesMaitreDesComptes.CHAMP_CLE: 'Une cle chiffree 5', ConstantesMaitreDesComptes.CHAMP_RESET_CERTIFICATS: False, } domaine_action = '.'.join([ ConstantesMaitreDesComptes.DOMAINE_NOM, ConstantesMaitreDesComptes.TRANSACTION_ASSOCIER_CERTIFICAT ]) enveloppe = self.generateur.soumettre_transaction( transaction, domaine_action, 'abcd-1234', self.queue_name) print("Envoi : %s" % enveloppe) return enveloppe def transaction_ajouter_certificat_navigateur(self): transaction = { 'nomUsager': '*****@*****.**', 'idmg': 'abcd1234', 'fingerprint': 'mon_fingerprint', 'cleChiffree': 'clePriveeNavigateurChiffreePem', 'certificat': 'certNavigateurPem', 'motdepassePartiel': 'motdepassePartielServeurBuffer', 'expiration': 12345678, } domaine_action = '.'.join([ ConstantesMaitreDesComptes.DOMAINE_NOM, ConstantesMaitreDesComptes.TRANSACTION_AJOUTER_NAVIGATEUR ]) enveloppe = self.generateur.soumettre_transaction( transaction, domaine_action, 'abcd-1234', self.queue_name) print("Envoi : %s" % enveloppe) return enveloppe def transaction_maj_usager_totp(self): transaction = { "totp": { "chiffrement": "mgs1", "uuid-transaction": "ae3f9e1e-2cad-4838-ae01-c797b525abaa", "identificateurs_document": { "libelle": "proprietaire", "champ": "totp" }, "secret_chiffre": "rEfqbgEjli3zxlWIjOeTxvAEY4RQVxR9PIIuCKgWA1T+Z1gQvaEBfP4Teu0hP6SYG0Exumxdtrl5f8VjB1TPnUOV6twOmGmqXQIPaxhlwNs=" }, 'nomUsager': 'proprietaire', } domaine_action = '.'.join([ ConstantesMaitreDesComptes.DOMAINE_NOM, 'MaitreDesComptes.' + ConstantesMaitreDesComptes.TRANSACTION_MAJ_USAGER_TOTP ]) enveloppe = self.generateur.soumettre_transaction( transaction, domaine_action, 'abcd-1234', self.queue_name) print("Envoi : %s" % enveloppe) return enveloppe def executer(self): self.requete_info_proprietaire()
class MessagesSample(BaseCallback): def __init__(self): super().__init__(contexte) self.contexte.message_dao.register_channel_listener(self) self.generateur = GenerateurTransaction(self.contexte) self.channel = None self.event_recu = Event() def on_channel_open(self, channel): # Enregistrer la reply-to queue self.channel = channel channel.queue_declare(durable=True, exclusive=True, callback=self.queue_open_local) def queue_open_local(self, queue): self.queue_name = queue.method.queue print("Queue: %s" % str(self.queue_name)) self.channel.basic_consume(self.callbackAvecAck, queue=self.queue_name, no_ack=False) self.executer() def run_ioloop(self): self.contexte.message_dao.run_ioloop() def deconnecter(self): self.contexte.message_dao.deconnecter() def traiter_message(self, ch, method, properties, body): print("Message recu, correlationId: %s" % properties.correlation_id) print(json.dumps(json.loads(body.decode('utf-8')), indent=4)) print("Channel : " + str(ch)) print("Method : " + str(method)) print("Properties : " + str(properties)) print("Channel virtual host : " + str(ch.connection.params.virtual_host)) def requete_liste_domaines(self): requete = {} domaine_action = ConstantesCatalogueApplications.REQUETE_LISTE_DOMAINES enveloppe_val = self.generateur.transmettre_requete( requete, domaine_action, reply_to=self.queue_name, correlation_id='efgh') print("Envoi metadata: %s" % enveloppe_val) def requete_liste_applications(self): requete = {} domaine_action = ConstantesCatalogueApplications.REQUETE_LISTE_APPLICATIONS enveloppe_val = self.generateur.transmettre_requete( requete, domaine_action, reply_to=self.queue_name, correlation_id='efgh') print("Envoi metadata: %s" % enveloppe_val) def requete_domaine(self): requete = {'nom': 'SenseursPassifs'} domaine_action = ConstantesCatalogueApplications.REQUETE_INFO_DOMAINE enveloppe_val = self.generateur.transmettre_requete( requete, domaine_action, reply_to=self.queue_name, correlation_id='efgh') print("Envoi metadata: %s" % enveloppe_val) def requete_application(self): requete = {'nom': 'blynk'} domaine_action = ConstantesCatalogueApplications.REQUETE_INFO_APPLICATION enveloppe_val = self.generateur.transmettre_requete( requete, domaine_action, reply_to=self.queue_name, correlation_id='efgh') print("Envoi metadata: %s" % enveloppe_val) def executer(self): # sample.requete_liste_domaines() sample.requete_liste_applications()
class MessagesSample(BaseCallback): def __init__(self): super().__init__(contexte) self.contexte.message_dao.register_channel_listener(self) self.generateur = GenerateurTransaction(self.contexte) self.collection_uuid = "1383dca0-37dc-11ea-acfe-00155d011f09" self.collection_figee = "4df31516-3aea-11ea-be1a-00155d011f09" self.channel = None self.event_recu = Event() def on_channel_open(self, channel): # Enregistrer la reply-to queue self.channel = channel channel.queue_declare(durable=True, exclusive=True, callback=self.queue_open_local) def queue_open_local(self, queue): self.queue_name = queue.method.queue print("Queue: %s" % str(self.queue_name)) self.channel.basic_consume(self.callbackAvecAck, queue=self.queue_name, no_ack=False) self.executer() def run_ioloop(self): self.contexte.message_dao.run_ioloop() def deconnecter(self): self.contexte.message_dao.deconnecter() def traiter_message(self, ch, method, properties, body): print("Message recu, correlationId: %s" % properties.correlation_id) message = json.loads(body.decode('utf-8')) print(json.dumps(message, indent=2)) def set_securite_collection_prive(self): transaction = { "uuid": self.collection_uuid, "niveau_securite_destination": "2.prive", } enveloppe_val = self.generateur.soumettre_transaction( transaction, ConstantesGrosFichiers.TRANSACTION_CHANGER_SECURITE_COLLECTION, reply_to=self.queue_name, correlation_id='efgh') print("Changement securite: %s" % enveloppe_val) return enveloppe_val def set_securite_collection_public(self): transaction = { "uuid": self.collection_uuid, "niveau_securite_destination": "1.public", } enveloppe_val = self.generateur.soumettre_transaction( transaction, ConstantesGrosFichiers.TRANSACTION_CHANGER_SECURITE_COLLECTION, reply_to=self.queue_name, correlation_id='efgh') print("Changement securite: %s" % enveloppe_val) return enveloppe_val def publier_collection(self): transaction = { "uuid": self.collection_figee, "url_web": "https://localhost" } enveloppe_val = self.generateur.soumettre_transaction( transaction, ConstantesGrosFichiers.TRANSACTION_PUBLIER_COLLECTION, reply_to=self.queue_name, correlation_id='efgh') print("Publier collection figee: %s" % enveloppe_val) return enveloppe_val def creer_collection(self): transaction = { "nom_collection": 'Collection sample %s' % uuid4(), "uuid_parent": "4ea93997-3721-443d-9755-65a574126775", } enveloppe_val = self.generateur.soumettre_transaction( transaction, ConstantesGrosFichiers.TRANSACTION_NOUVELLE_COLLECTION, reply_to=self.queue_name, correlation_id='efgh') print("Publier collection : %s" % enveloppe_val) def requete_collections(self): requete = {} enveloppe_val = self.generateur.transmettre_requete( requete, ConstantesGrosFichiers.REQUETE_COLLECTIONS, reply_to=self.queue_name, correlation_id='efgh') print("Requete collections : %s" % enveloppe_val) def requete_favoris(self): requete = {} enveloppe_val = self.generateur.transmettre_requete( requete, ConstantesGrosFichiers.REQUETE_FAVORIS, reply_to=self.queue_name, correlation_id='efgh') print("Requete collections : %s" % enveloppe_val) def executer(self): # sample.set_securite_collection_prive() # sample.set_securite_collection_public() # sample.publier_collection() sample.creer_collection() # sample.requete_collections() # sample.requete_favoris() pass
class MessagesSample(BaseCallback): def __init__(self): super().__init__(contexte) self.contexte.message_dao.register_channel_listener(self) self.generateur = GenerateurTransaction(self.contexte) self.queue_name = None self.channel = None self.event_recu = Event() def on_channel_open(self, channel): # Enregistrer la reply-to queue self.channel = channel channel.queue_declare(durable=True, exclusive=True, callback=self.queue_open_local) def queue_open_local(self, queue): self.queue_name = queue.method.queue print("Queue: %s" % str(self.queue_name)) self.channel.basic_consume(self.callbackAvecAck, queue=self.queue_name, no_ack=False) self.executer() def run_ioloop(self): self.contexte.message_dao.run_ioloop() def deconnecter(self): self.contexte.message_dao.deconnecter() def traiter_message(self, ch, method, properties, body): print("Message recu, correlationId: %s" % properties.correlation_id) message = json.loads(str(body, 'utf-8')) print(json.dumps(message, indent=4)) def transmettre_commande_nouveau_torrent(self): commande = { 'nom': 'ma_collection_figee', 'securite': '1.public', # Niveau de securite global du torrent 'uuid': '7fd1c894-0f15-11ea-bb74-00155d011f09', 'uuid-fige': str(uuid.uuid1()), 'etiquettes': {}, 'commentaires': "J'aime bian les torrents", 'documents': [{ # Contenu equivalent a une transaction millegrilles.domaines.GrosFichiers.nouvelleVersion.metadata # La millegrille qui recoit ce torrent va agir de la meme facon quelle le ferait avec une nouvelle # transaction (qui sera extraite et soumise sur reception du torrent). 'uuid': '264ca437-4574-4b1d-8088-142af87a6954', # uuid fichier 'fuuid': '0b6e8fe0-0d63-11ea-80d1-bf0de6b5e47c', # 'fuuid': '50f05190-0d6b-11ea-80d1-bf0de6b5e47c', # fuuid version 'nom': 'Estheticians dont have to wax male genitalia against their will BC tribunal .pdf', 'mimetype': 'application/pdf', 'securite': '3.protege', "taille": 807264, 'sha256': '6f8378ec73a354453dec5c955c617f5295d55fe873cae3d49b3ea87aea13adbd', }], 'trackers': ['https://mg-dev3.maple.maceroc.com:3004'] } enveloppe_val = self.generateur.transmettre_commande( commande, 'commande.torrent.creerNouveau') print("Envoi commande torrent: %s" % enveloppe_val) return enveloppe_val def transmettre_demande_etat_torrent(self): requete = {} enveloppe_val = self.generateur.transmettre_requete( requete, 'torrent.etat', 'abcd', self.queue_name) print("Envoi requete etat torrent: %s" % enveloppe_val) return enveloppe_val def transmettre_supprimer_torrent(self): hashlist = ['43ca6267d3f2bfa83cff025678bba17bf6abd4bd'] commande = { 'hashlist': hashlist, } enveloppe_val = self.generateur.transmettre_commande( commande, 'commande.torrent.supprimer') print("Envoi commande torrent: %s" % enveloppe_val) return enveloppe_val def transmettre_seeder_torrent(self): commande = { 'uuid': 'f445941e-16cf-11ea-9318-00155d011f09', } enveloppe_val = self.generateur.transmettre_commande( commande, 'commande.torrent.seederTorrent') print("Envoi commande seeder torrent: %s" % enveloppe_val) return enveloppe_val def executer(self): # enveloppe = sample.transmettre_commande_nouveau_torrent() enveloppe = sample.transmettre_supprimer_torrent()
class MessagesSample(BaseCallback): def __init__(self): super().__init__(contexte) self.contexte.message_dao.register_channel_listener(self) self.generateur = GenerateurTransaction(self.contexte) self.fichier_fuuid = "39c1e1b0-b6ee-11e9-b0cd-d30e8fab842j" self.channel = None self.event_recu = Event() def on_channel_open(self, channel): # Enregistrer la reply-to queue self.channel = channel channel.queue_declare(durable=True, exclusive=True, callback=self.queue_open_local) def queue_open_local(self, queue): self.queue_name = queue.method.queue print("Queue: %s" % str(self.queue_name)) self.channel.basic_consume(self.callbackAvecAck, queue=self.queue_name, no_ack=False) self.executer() def run_ioloop(self): self.contexte.message_dao.run_ioloop() def deconnecter(self): self.contexte.message_dao.deconnecter() def traiter_message(self, ch, method, properties, body): print("Message recu, correlationId: %s" % properties.correlation_id) print(json.dumps(json.loads(body.decode('utf-8')), indent=4)) print("Channel : " + str(ch)) print("Method : " + str(method)) print("Properties : " + str(properties)) print("Channel virtual host : " + str(ch.connection.params.virtual_host)) def requete_cert_fingerprint(self): requete_cert = { 'fingerprint': 'fe4e7c9b64a4f2f31b7f8c54102573d14c8894d0' } enveloppe_requete = self.generateur.transmettre_requete( requete_cert, ConstantesPki.REQUETE_CERTIFICAT_DEMANDE, 'abcd-1234', self.queue_name, securite=Constantes.SECURITE_PROTEGE, ) print("Envoi requete: %s" % enveloppe_requete) return enveloppe_requete def requete_cert_backup(self): requete_cert = {} enveloppe_requete = self.generateur.transmettre_requete( requete_cert, '%s.%s' % (ConstantesPki.DOMAINE_NOM, ConstantesPki.REQUETE_CERTIFICAT_BACKUP), 'abcd-1234', self.queue_name, securite=Constantes.SECURITE_PROTEGE, ) print("Envoi requete: %s" % enveloppe_requete) return enveloppe_requete def renouveller_certs_docker(self): requete_cert = { 'altdomains': { "mq": 'mq.maple.maceroc.com,mg-dev3.maple.maceroc.com' }, 'roles': ['mq'], } enveloppe_requete = self.generateur.soumettre_transaction( requete_cert, ConstantesPki.TRANSACTION_RENOUVELLER_CERT_DOCKER, 'abcd-1234', self.queue_name, ) print("Envoi requete: %s" % enveloppe_requete) return enveloppe_requete def requete_certificat(self): requete = { 'fingerprint': 'sha256_b64:eju05mzQkl77M9XUJgJHMJjaxaHnSHa0moGHXCl9wxE=' } domaine_action = 'requete.Pki.' + ConstantesPki.REQUETE_CERTIFICAT self.generateur.transmettre_requete(requete, domaine_action, correlation_id='abcd', reply_to=self.queue_name) def executer(self): # self.renouveller_certs_docker() # self.requete_cert_backup() # self.requete_cert_noeuds() self.requete_certificat()
class MessagesSample(BaseCallback): def __init__(self): super().__init__(contexte) self.contexte.message_dao.register_channel_listener(self) self.generateur = GenerateurTransaction(self.contexte) self.queue_name = None self.channel = None self.event_recu = Event() def on_channel_open(self, channel): # Enregistrer la reply-to queue self.channel = channel channel.queue_declare(durable=True, exclusive=True, callback=self.queue_open_local) def queue_open_local(self, queue): self.queue_name = queue.method.queue print("Queue: %s" % str(self.queue_name)) self.channel.basic_consume(self.callbackAvecAck, queue=self.queue_name, no_ack=False) self.executer() def run_ioloop(self): self.contexte.message_dao.run_ioloop() def deconnecter(self): self.contexte.message_dao.deconnecter() def traiter_message(self, ch, method, properties, body): print("Message recu, correlationId: %s" % properties.correlation_id) message = json.loads(str(body, 'utf-8')) print(json.dumps(message, indent=4)) def transmettre_maj_fiche_privee(self): fiche = { 'usager': { 'nom': 'Dugre', 'prenom': 'Mathieu', 'courriel': '*****@*****.**' }, 'descriptif': 'Moi', 'prive_mq': ['amqps://mg-dev4.maple.maceroc.com:5673/prive'] } domaine = 'millegrilles.domaines.Annuaire.maj.fichePrivee' enveloppe_val = self.generateur.soumettre_transaction( fiche, domaine, reply_to=self.queue_name, correlation_id='abcd') print("Envoi maj fiche privee: %s" % enveloppe_val) return enveloppe_val def requete_fiche_privee(self): self.generateur.transmettre_requete( {}, 'millegrilles.domaines.Annuaire.fichePrivee', reply_to=self.queue_name, correlation_id='abcd') def requete_fiche_public(self): self.generateur.transmettre_requete( {}, 'millegrilles.domaines.Annuaire.fichePublique', reply_to=self.queue_name, correlation_id='abcd', securite=Constantes.SECURITE_PUBLIC) def lire_transaction_demande_inscription(self): with open( '/home/mathieu/PycharmProjects/MilleGrilles.consignation.python/test/messages/demande_connexion.json', 'r') as fichier: transaction = json.load(fichier) domaine = 'transaction.nouvelle' self.generateur.relayer_transaction(transaction) def lire_transaction_inscription_inscription_recue(self): with open( '/home/mathieu/PycharmProjects/millegrilles.consignation.python/test/messages/inscription_reponse.json', 'r') as fichier: transaction = json.load(fichier) domaine = 'transaction.nouvelle' self.generateur.relayer_transaction(transaction) def executer(self): # enveloppe = sample.transmettre_maj_fiche_privee() # sample.requete_fiche_privee() sample.requete_fiche_public()
class MessagesSample(BaseCallback): def __init__(self): super().__init__(contexte) self.contexte.message_dao.register_channel_listener(self) self.generateur = GenerateurTransaction(self.contexte) self.queue_name = None self.channel = None self.event_recu = Event() def on_channel_open(self, channel): # Enregistrer la reply-to queue self.channel = channel channel.queue_declare(durable=True, exclusive=True, callback=self.queue_open_local) def queue_open_local(self, queue): self.queue_name = queue.method.queue print("Queue: %s" % str(self.queue_name)) self.channel.basic_consume(self.callbackAvecAck, queue=self.queue_name, no_ack=False) self.executer() def run_ioloop(self): self.contexte.message_dao.run_ioloop() def deconnecter(self): self.contexte.message_dao.deconnecter() def traiter_message(self, ch, method, properties, body): print("Message recu, correlationId: %s" % properties.correlation_id) message = json.loads(str(body, 'utf-8')) print(json.dumps(message, indent=4)) def maj_email_smtp_avecpassword(self): email_smtp_transaction = { ConstantesParametres.DOCUMENT_CHAMP_ACTIF: True, ConstantesParametres.DOCUMENT_CHAMP_HOST: 'mg-maple.local', ConstantesParametres.DOCUMENT_CHAMP_PORT: 443, ConstantesParametres.DOCUMENT_CHAMP_COURRIEL_ORIGINE: '*****@*****.**', ConstantesParametres.DOCUMENT_CHAMP_COURRIEL_DESTINATIONS: '*****@*****.**', ConstantesParametres.DOCUMENT_CHAMP_USER: '******', Constantes.DOCUMENT_SECTION_CRYPTE: 'du contenu crypte, mot de passe, etc.', } enveloppe_val = self.generateur.soumettre_transaction( email_smtp_transaction, ConstantesParametres.TRANSACTION_MODIFIER_EMAIL_SMTP, reply_to=self.queue_name, correlation_id='efgh') print("Sent: %s" % enveloppe_val) return enveloppe_val def transmettre_cles(self, uuid): email_smtp_transaction = { 'domaine': ConstantesParametres.DOMAINE_NOM, ConstantesParametres.TRANSACTION_CHAMP_MGLIBELLE: ConstantesParametres.LIBVAL_EMAIL_SMTP, 'uuid': uuid, } routing = ConstantesParametres.TRANSACTION_CLES_RECUES enveloppe_val = self.generateur.soumettre_transaction( email_smtp_transaction, routing, reply_to=self.queue_name, correlation_id='efgh') print("Sent: %s" % enveloppe_val) return enveloppe_val def maj_email_smtp_sanspassword(self): email_smtp_transaction = { ConstantesParametres.DOCUMENT_CHAMP_ACTIF: True, ConstantesParametres.DOCUMENT_CHAMP_HOST: 'mg-maple.local', ConstantesParametres.DOCUMENT_CHAMP_PORT: 443, ConstantesParametres.DOCUMENT_CHAMP_COURRIEL_ORIGINE: '*****@*****.**', ConstantesParametres.DOCUMENT_CHAMP_COURRIEL_DESTINATIONS: '*****@*****.**', ConstantesParametres.DOCUMENT_CHAMP_USER: '******', } enveloppe_val = self.generateur.soumettre_transaction( email_smtp_transaction, ConstantesParametres.TRANSACTION_MODIFIER_EMAIL_SMTP, reply_to=self.queue_name, correlation_id='efgh') print("Sent: %s" % enveloppe_val) return enveloppe_val def maj_noeud_public(self): transaction = { ConstantesParametres.DOCUMENT_PUBLIQUE_URL_WEB: 'https://localhost', ConstantesParametres.DOCUMENT_PUBLIQUE_MENU: [ 'messages', 'fichiers', 'podcasts', 'albums', ] } domaine = ConstantesParametres.TRANSACTION_MAJ_NOEUD_PUBLIC enveloppe_val = self.generateur.soumettre_transaction( transaction, domaine, reply_to=self.queue_name, correlation_id='abcd') print("Sent: %s" % enveloppe_val) return enveloppe_val def supprimer_noeud_public(self): transaction = { ConstantesParametres.DOCUMENT_PUBLIQUE_URL_WEB: 'https://localhost', } domaine = ConstantesParametres.TRANSACTION_SUPPRIMER_NOEUD_PUBLIC enveloppe_val = self.generateur.soumettre_transaction( transaction, domaine, reply_to=self.queue_name, correlation_id='abcd') print("Sent: %s" % enveloppe_val) return enveloppe_val def requete_noeud_public(self): requete = {'url_web': 'https://localhost'} enveloppe_requete = self.generateur.transmettre_requete( requete, ConstantesParametres.REQUETE_NOEUD_PUBLIC, 'abcd-1234', self.queue_name, securite=Constantes.SECURITE_PUBLIC) print("Envoi requete: %s" % enveloppe_requete) return enveloppe_requete def executer(self): # uuid = self.maj_email_smtp_avecpassword() # enveloppe = self.transmettre_cles(uuid) self.maj_noeud_public()
class MessagesSample(BaseCallback): def __init__(self): super().__init__(contexte) self.contexte.message_dao.register_channel_listener(self) self.generateur = GenerateurTransaction(self.contexte) self.queue_name = None self.channel = None self.event_recu = Event() def on_channel_open(self, channel): # Enregistrer la reply-to queue self.channel = channel channel.queue_declare(durable=True, exclusive=True, callback=self.queue_open_local) def queue_open_local(self, queue): self.queue_name = queue.method.queue print("Queue: %s" % str(self.queue_name)) self.channel.basic_consume(self.callbackAvecAck, queue=self.queue_name, no_ack=False) self.executer() def run_ioloop(self): self.contexte.message_dao.run_ioloop() def deconnecter(self): self.contexte.message_dao.deconnecter() def traiter_message(self, ch, method, properties, body): print("Message recu, correlationId: %s" % properties.correlation_id) message = json.loads(str(body, 'utf-8')) print(json.dumps(message, indent=4)) def requete_liste(self): requete_document = { 'filtre': { Constantes.DOCUMENT_INFODOC_LIBELLE: ConstantesPlume.LIBVAL_PLUME, ConstantesPlume.LIBELLE_DOC_CATEGORIES: {'$in': ['cat1']}, }, 'sort': [(Constantes.DOCUMENT_INFODOC_DERNIERE_MODIFICATION, -1)], 'projection': { ConstantesPlume.LIBELLE_DOC_PLUME_UUID: 1, ConstantesPlume.LIBELLE_DOC_CATEGORIES: 1, ConstantesPlume.LIBELLE_DOC_TITRE: 1, ConstantesPlume.LIBELLE_DOC_SECURITE: 1, Constantes.DOCUMENT_INFODOC_DERNIERE_MODIFICATION: 1, Constantes.DOCUMENT_INFODOC_DATE_CREATION: 1, } } requetes = {'requetes': [requete_document]} enveloppe_requete = self.generateur.transmettre_requete( requetes, 'millegrilles.domaines.Plume', 'abcd-1234', self.queue_name) print("Envoi requete: %s" % enveloppe_requete) return enveloppe_requete def requete_document(self): requete_document = { 'filtre': { Constantes.DOCUMENT_INFODOC_LIBELLE: ConstantesPlume.LIBVAL_PLUME, ConstantesPlume.LIBELLE_DOC_PLUME_UUID: self.uuid, } } requetes = {'requetes': [requete_document]} enveloppe_requete = self.generateur.transmettre_requete( requetes, 'millegrilles.domaines.Plume', 'abcd-1234', self.queue_name) print("Envoi requete: %s" % enveloppe_requete) return enveloppe_requete def nouveau_document(self): document = { ConstantesPlume.LIBELLE_DOC_TITRE: 'Document Unit Test', ConstantesPlume.LIBELLE_DOC_CATEGORIES: 'cat1 cat2 Cat3', ConstantesPlume.LIBELLE_DOC_SECURITE: Constantes.SECURITE_PRIVE, ConstantesPlume.LIBELLE_DOC_QUILL_DELTA: {"ops": [{"insert": "Un document de test.\n"}]}, ConstantesPlume.LIBELLE_DOC_TEXTE: "Un document de test.\n", } enveloppe_val = self.generateur.soumettre_transaction( document, 'millegrilles.domaines.Plume.nouveauDocument', reply_to=self.queue_name, correlation_id='efgh') print("Sent: %s" % enveloppe_val) return enveloppe_val def modifier_document(self): document = { ConstantesPlume.LIBELLE_DOC_PLUME_UUID: self.uuid, ConstantesPlume.LIBELLE_DOC_TITRE: 'Document Unit Test modifie 1', ConstantesPlume.LIBELLE_DOC_CATEGORIES: 'cat1 cat4 Cat3', ConstantesPlume.LIBELLE_DOC_SECURITE: Constantes.SECURITE_PRIVE, ConstantesPlume.LIBELLE_DOC_QUILL_DELTA: {"ops": [{"insert": "Un document de test modifie 1.\n"}]}, ConstantesPlume.LIBELLE_DOC_TEXTE: "Un document de test modifie 1.\n", } enveloppe_val = self.generateur.soumettre_transaction( document, 'millegrilles.domaines.Plume.modifierDocument', reply_to=self.queue_name, correlation_id='efgh') print("Sent: %s" % enveloppe_val) return enveloppe_val def supprimer_document(self): document = { ConstantesPlume.LIBELLE_DOC_PLUME_UUID: self.uuid, } enveloppe_val = self.generateur.soumettre_transaction( document, 'millegrilles.domaines.Plume.supprimerDocument', reply_to=self.queue_name, correlation_id='efgh') print("Sent: %s" % enveloppe_val) return enveloppe_val def publier_document(self): document = { ConstantesPlume.LIBELLE_DOC_PLUME_UUID: self.uuid, } enveloppe_val = self.generateur.soumettre_transaction( document, 'millegrilles.domaines.Plume.publierDocument', reply_to=self.queue_name, correlation_id='efgh') print("Sent: %s" % enveloppe_val) return enveloppe_val def creerAnnonce(self): document = ConstantesPlume.DOCUMENT_ANNONCE.copy() document[ConstantesPlume.LIBELLE_DOC_TEXTE] = 'Une nouvelle annonce sous Plume' document[ConstantesPlume.LIBELLE_DOC_SUJET] = 'Mouaip, reussi!' enveloppe_val = self.generateur.soumettre_transaction( document, ConstantesPlume.TRANSACTION_CREER_ANNONCE, reply_to=self.queue_name, correlation_id='efgh') print("Sent: %s" % enveloppe_val) return enveloppe_val def supprimerAnnonce(self): document = { ConstantesPlume.LIBELLE_DOC_PLUME_UUID: '6b55ce50-32fc-11ea-adb2-00155d011f09' } enveloppe_val = self.generateur.soumettre_transaction( document, ConstantesPlume.TRANSACTION_SUPPRIMER_ANNONCE, reply_to=self.queue_name, correlation_id='efgh') print("Sent: %s" % enveloppe_val) return enveloppe_val def remplacerAnnonce(self): document = ConstantesPlume.DOCUMENT_ANNONCE.copy() document[ConstantesPlume.LIBELLE_DOC_TEXTE] = 'Un remplacement dans Plumeau' document[ConstantesPlume.LIBELLE_DOC_SUJET] = 'Tu es remplace' document[ConstantesPlume.LIBELLE_DOC_REMPLACE] = '974c9442-32fe-11ea-adb2-00155d011f09' enveloppe_val = self.generateur.soumettre_transaction( document, ConstantesPlume.TRANSACTION_CREER_ANNONCE, reply_to=self.queue_name, correlation_id='efgh') print("Sent: %s" % enveloppe_val) return enveloppe_val def requete_annonces_recentes(self): self.generateur.transmettre_requete( {}, ConstantesPlume.REQUETE_CHARGER_ANNONCES_RECENTES, reply_to=self.queue_name, correlation_id='abcd', securite=Constantes.SECURITE_PUBLIC ) def executer(self): self.creerAnnonce()
class MessagesSample(BaseCallback): def __init__(self): super().__init__(contexte) self.contexte.message_dao.register_channel_listener(self) self.generateur = GenerateurTransaction(self.contexte) self.queue_name = None self.channel = None self.event_recu = Event() def on_channel_open(self, channel): # Enregistrer la reply-to queue self.channel = channel channel.queue_declare(durable=True, exclusive=True, callback=self.queue_open_local) def queue_open_local(self, queue): self.queue_name = queue.method.queue print("Queue: %s" % str(self.queue_name)) self.channel.basic_consume(self.callbackAvecAck, queue=self.queue_name, no_ack=False) self.executer() def run_ioloop(self): self.contexte.message_dao.run_ioloop() def deconnecter(self): self.contexte.message_dao.deconnecter() def traiter_message(self, ch, method, properties, body): print("Message recu, correlationId: %s" % properties.correlation_id) message = json.loads(str(body, 'utf-8')) print(json.dumps(message, indent=4)) def requete_compte_usager(self): requete = {'nom_usager': '*****@*****.**'} domaine_action = '.'.join([ ConstantesMessagerie.DOMAINE_NOM, ConstantesMessagerie.REQUETE_CHARGER_COMPTE ]) enveloppe = self.generateur.transmettre_requete( requete, domaine_action, 'abcd-1234', self.queue_name) print("Envoi : %s" % enveloppe) return enveloppe def requete_messages_usager(self): requete = {'idmgs': ['29yHaJVXVZ5eCEsb7rK3iNrruDmYNh9Z2hWzNtz']} domaine_action = '.'.join([ ConstantesMessagerie.DOMAINE_NOM, ConstantesMessagerie.REQUETE_SOMMAIRE_MESSAGES_PAR_IDMG ]) enveloppe = self.generateur.transmettre_requete( requete, domaine_action, 'abcd-1234', self.queue_name) print("Envoi : %s" % enveloppe) return enveloppe def requete_messages_usager_par_source(self): requete = { 'idmgs_destination': ['29yHaJVXVZ5eCEsb7rK3iNrruDmYNh9Z2hWzNtz'], 'idmgs_source': ['XEFLEkH9vvK1zBEU8qHt2fauyfRr7CLbJEwpdTh5JWRM'], } domaine_action = '.'.join([ ConstantesMessagerie.DOMAINE_NOM, ConstantesMessagerie.REQUETE_MESSAGES_USAGER_PAR_SOURCE ]) enveloppe = self.generateur.transmettre_requete( requete, domaine_action, 'abcd-1234', self.queue_name) print("Envoi : %s" % enveloppe) return enveloppe def transaction_inscrire_proprietaire(self): transaction = { ConstantesMessagerie.CHAMP_NOM_USAGER: '*****@*****.**', ConstantesMessagerie.CHAMP_IDMGS: ['29yHaJVXVZ5eCEsb7rK3iNrruDmYNh9Z2hWzNtz'], } domaine_action = '.'.join([ ConstantesMessagerie.DOMAINE_NOM, ConstantesMessagerie.TRANSACTION_INSCRIRE_COMPTE ]) enveloppe = self.generateur.soumettre_transaction( transaction, domaine_action, 'abcd-1234', self.queue_name) print("Envoi : %s" % enveloppe) return enveloppe def transaction_envoyer_instantanne(self): transaction = { Constantes.DOCUMENT_INFODOC_SECURITE: Constantes.SECURITE_PRIVE, ConstantesMessagerie.CHAMP_IDMG_SOURCE: '29yHaJVXVZ5eCEsb7rK3iNrruDmYNh9Z2hWzNtz', ConstantesMessagerie.CHAMP_IDMG_DESTINATION: 'XEFLEkH9vvK1zBEU8qHt2fauyfRr7CLbJEwpdTh5JWRM', ConstantesMessagerie.CHAMP_MESSAGE: 'Poutine sauvage a loriginal' } domaine_action = '.'.join([ ConstantesMessagerie.DOMAINE_NOM, ConstantesMessagerie.TRANSACTION_ENVOYER_MESSAGE ]) enveloppe = self.generateur.soumettre_transaction( transaction, domaine_action, 'abcd-1234', self.queue_name) print("Envoi : %s" % enveloppe) return enveloppe def transaction_marquer_message_lu(self): transaction = { Constantes.TRANSACTION_MESSAGE_LIBELLE_UUID: '6b166694-b4d8-11ea-b31e-277b4a14dd4b', } domaine_action = '.'.join([ ConstantesMessagerie.DOMAINE_NOM, ConstantesMessagerie.TRANSACTION_MARQUER_MESSAGE_LU ]) enveloppe = self.generateur.soumettre_transaction( transaction, domaine_action, 'abcd-1234', self.queue_name) print("Envoi : %s" % enveloppe) return enveloppe def transaction_supprimer_message(self, uuid_message: str): transaction = { Constantes.TRANSACTION_MESSAGE_LIBELLE_UUID: uuid_message, } domaine_action = '.'.join([ ConstantesMessagerie.DOMAINE_NOM, ConstantesMessagerie.TRANSACTION_SUPPRIMER_MESSAGE ]) enveloppe = self.generateur.soumettre_transaction( transaction, domaine_action, 'abcd-1234', self.queue_name) print("Envoi : %s" % enveloppe) return enveloppe def transaction_modifier_contact(self): transaction = { ConstantesMessagerie.CHAMP_NOM_USAGER: '*****@*****.**', ConstantesMessagerie.CHAMP_NOM_CONTACT: '*****@*****.**', ConstantesMessagerie.CHAMP_NOM_USAGER_CONTACT: 'moi meme', ConstantesMessagerie.CHAMP_IDMGS: ['MxXNJgbQxtSVrePdMFBNqeKFtvxqDXoE8CHqD7Vkd2Vu'], ConstantesMessagerie.CHAMP_UUID_CONTACT: str(uuid.uuid4()), } domaine_action = '.'.join([ ConstantesMessagerie.DOMAINE_NOM, ConstantesMessagerie.TRANSACTION_MODIFIER_CONTACT ]) enveloppe = self.generateur.soumettre_transaction( transaction, domaine_action, 'abcd-1234', self.queue_name) print("Envoi : %s" % enveloppe) return enveloppe def transaction_supprimer_contact(self, uuid_contact): transaction = { ConstantesMessagerie.CHAMP_NOM_USAGER: '*****@*****.**', ConstantesMessagerie.CHAMP_UUID_CONTACT: uuid_contact, ConstantesMessagerie.CHAMP_SUPPRIMER: True, } domaine_action = '.'.join([ ConstantesMessagerie.DOMAINE_NOM, ConstantesMessagerie.TRANSACTION_MODIFIER_CONTACT ]) enveloppe = self.generateur.soumettre_transaction( transaction, domaine_action, 'abcd-1234', self.queue_name) print("Envoi : %s" % enveloppe) return enveloppe def executer(self): # self.requete_compte_usager() self.requete_messages_usager()
class MessagesSample(BaseCallback): def __init__(self): super().__init__(contexte) self.contexte.message_dao.register_channel_listener(self) self.generateur = GenerateurTransaction(self.contexte) self.channel = None self.event_recu = Event() def on_channel_open(self, channel): # Enregistrer la reply-to queue self.channel = channel channel.queue_declare(durable=True, exclusive=True, callback=self.queue_open_local) def queue_open_local(self, queue): self.queue_name = queue.method.queue print("Queue: %s" % str(self.queue_name)) self.channel.basic_consume(self.callbackAvecAck, queue=self.queue_name, no_ack=False) self.executer() def run_ioloop(self): self.contexte.message_dao.run_ioloop() def deconnecter(self): self.contexte.message_dao.deconnecter() def traiter_message(self, ch, method, properties, body): print("Message recu, correlationId: %s" % properties.correlation_id) print(json.dumps(json.loads(body.decode('utf-8')), indent=4)) print("Channel : " + str(ch)) print("Method : " + str(method)) print("Properties : " + str(properties)) print("Channel virtual host : " + str(ch.connection.params.virtual_host)) def requete_liste_domaines(self): requete = {} domaine_action = ConstantesTopologie.REQUETE_LISTE_DOMAINES enveloppe_val = self.generateur.transmettre_requete( requete, domaine_action, reply_to=self.queue_name, correlation_id='efgh') print("Envoi metadata: %s" % enveloppe_val) def requete_liste_noeuds(self): requete = {} domaine_action = ConstantesTopologie.REQUETE_LISTE_NOEUDS enveloppe_val = self.generateur.transmettre_requete( requete, domaine_action, reply_to=self.queue_name, correlation_id='efgh') print("Envoi metadata: %s" % enveloppe_val) def requete_liste_applications(self): requete = {'securite': '3.protege'} domaine_action = ConstantesTopologie.REQUETE_LISTE_APPLICATIONS_DEPLOYEES enveloppe_val = self.generateur.transmettre_requete( requete, domaine_action, reply_to=self.queue_name, correlation_id='efgh') print("Envoi metadata: %s" % enveloppe_val) def requete_liste_noeud_detail(self): requete = { 'noeud_id': NOEUD_ID, 'all_info': True, } domaine_action = ConstantesTopologie.REQUETE_LISTE_NOEUDS enveloppe_val = self.generateur.transmettre_requete( requete, domaine_action, reply_to=self.queue_name, correlation_id='efgh') print("Envoi metadata: %s" % enveloppe_val) def requete_info_domaine(self): requete = {'domaine': 'CatalogueApplications'} domaine_action = ConstantesTopologie.REQUETE_INFO_DOMAINE enveloppe_val = self.generateur.transmettre_requete( requete, domaine_action, reply_to=self.queue_name, correlation_id='efgh') print("Envoi metadata: %s" % enveloppe_val) def requete_info_noeud(self): requete = {'noeud_id': '5ee16193-49a3-443f-ae4e-894a65de647d'} domaine_action = ConstantesTopologie.REQUETE_INFO_NOEUD enveloppe_val = self.generateur.transmettre_requete( requete, domaine_action, reply_to=self.queue_name, correlation_id='efgh') print("Envoi metadata: %s" % enveloppe_val) def transaction_ajouter_domaine(self): requete = { 'noeud_id': '5ee16193-49a3-443f-ae4e-894a65de647d', "nom": "SenseursPassifs", "module": "millegrilles.domaines.SenseursPassifs", "classe": "GestionnaireSenseursPassifs" } domaine_action = ConstantesTopologie.TRANSACTION_AJOUTER_DOMAINE_DYNAMIQUE enveloppe_val = self.generateur.soumettre_transaction( requete, domaine_action, reply_to=self.queue_name, correlation_id='efgh') print("Envoi metadata: %s" % enveloppe_val) def transaction_supprimer_domaine(self): requete = { 'noeud_id': '5ee16193-49a3-443f-ae4e-894a65de647d', "nom": "SenseursPassifs", } domaine_action = ConstantesTopologie.TRANSACTION_SUPPRIMER_DOMAINE_DYNAMIQUE enveloppe_val = self.generateur.soumettre_transaction( requete, domaine_action, reply_to=self.queue_name, correlation_id='efgh') print("Envoi metadata: %s" % enveloppe_val) def executer(self): # sample.requete_liste_domaines() sample.requete_liste_noeuds()
class MessagesSample(BaseCallback): def __init__(self): super().__init__(contexte) self.contexte.message_dao.register_channel_listener(self) self.generateur = GenerateurTransaction(self.contexte) self.fichier_fuuid = "39c1e1b0-b6ee-11e9-b0cd-d30e8fab842j" self.channel = None self.event_recu = Event() def on_channel_open(self, channel): # Enregistrer la reply-to queue self.channel = channel channel.queue_declare(durable=True, exclusive=True, callback=self.queue_open_local) def queue_open_local(self, queue): self.queue_name = queue.method.queue print("Queue: %s" % str(self.queue_name)) self.channel.basic_consume(self.callbackAvecAck, queue=self.queue_name, no_ack=False) self.executer() def run_ioloop(self): self.contexte.message_dao.run_ioloop() def deconnecter(self): self.contexte.message_dao.deconnecter() def traiter_message(self, ch, method, properties, body): print("Message recu, correlationId: %s" % properties.correlation_id) reponse = json.loads(body.decode('utf-8')) print(json.dumps(reponse, indent=2)) def transaction_nouvelle_version_metadata(self): transaction = { 'nom_fichier': 'Bill Morneau resigns as finance minister and MP, will seek to lead OECD.pdf', 'securite': '3.protege', 'fuuid': str(uuid4()), 'mimetype': 'image/blarghs', 'taille': 1190698, 'hachage': 'sha512_b64:ONOJGqswORDLwxeB/82dewqx2kAyOD0k3YQkipbkCBt3CyYAqk6BwAPw+sAFLo8BmRmLvNGlpmnnuFPs0hAmfg==', } enveloppe_val = self.generateur.soumettre_transaction( transaction, ConstantesGrosFichiers.TRANSACTION_NOUVELLEVERSION_METADATA, reply_to=self.queue_name, correlation_id='efgh') print("Envoi metadata: %s" % enveloppe_val) return enveloppe_val def transaction_nouvelle_version_transfertcomplete(self): transaction = { "fuuid": self.fichier_fuuid, "sha256": "739291ef2f7f3e0f945712112df9a62aeb2642d3828551f9fa3c95449a415e30", } enveloppe_val = self.generateur.soumettre_transaction( transaction, 'millegrilles.domaines.GrosFichiers.nouvelleVersion.transfertComplete', reply_to=self.queue_name, correlation_id='abcd') print("Envoi transfert complete: %s" % enveloppe_val) return enveloppe_val def transaction_renommer_document(self): transaction = { "uuid": "ea1e1a37-14ef-46f4-8a75-021850e0630a", "nom": 'Bashir Bouzouka 3!.jpg', } enveloppe_val = self.generateur.soumettre_transaction( transaction, ConstantesGrosFichiers.TRANSACTION_RENOMMER_DOCUMENT, reply_to=self.queue_name, correlation_id='abcd') print("Renommer repertoire complete: %s" % enveloppe_val) return enveloppe_val def transaction_changer_etiquettes_fichier(self): transaction = { "uuid": "1385e685-0630-4372-87a0-224804dfe7fd", "etiquettes": ['efgh', '1234', 'pUBlic', '4.disseminer', 'HÉ! ayoye mé açcents'] } enveloppe_val = self.generateur.soumettre_transaction( transaction, 'millegrilles.domaines.GrosFichiers.changerEtiquettesFichier', reply_to=self.queue_name, correlation_id='abcd') print("Changer libelle complete: %s" % enveloppe_val) return enveloppe_val def transaction_decrire_fichier(self): transaction = { "uuid": "41548d46-c12b-41f6-b205-4c0ae7d64c16", # "commentaires": "J'ai un commentaire. Ye! Pis on en rajoute.", "titre": { 'en': 'Name in English', 'fr': 'Nom en francais' }, "description": { 'en': '<p>Complete description of the file</p>', 'fr': '<p>Description complete du fichier</p>', } } enveloppe_val = self.generateur.soumettre_transaction( transaction, 'GrosFichiers.' + ConstantesGrosFichiers.TRANSACTION_DECRIRE_FICHIER, reply_to=self.queue_name, correlation_id='abcd') print("Renommer repertoire complete: %s" % enveloppe_val) return enveloppe_val def transaction_decrire_collection(self): transaction = { "uuid": "201e1fb7-66bd-4901-b52a-116c65d7b0d9", # "nom_collection": "public", "commentaires": "J'ai un commentaire. Ye! Pis on en rajoute.", "titre": { 'en': 'Collection name in English', 'fr': 'Nom de collection en francais' }, "description": { 'en': '<p>Complete description of the file</p>', 'fr': '<p>Description complete du fichier</p>', }, 'securite': '1.public', } enveloppe_val = self.generateur.soumettre_transaction( transaction, 'GrosFichiers.' + ConstantesGrosFichiers.TRANSACTION_DECRIRE_COLLECTION, reply_to=self.queue_name, correlation_id='abcd') print("Renommer repertoire complete: %s" % enveloppe_val) return enveloppe_val def transaction_supprimer_fichier(self): transaction = { ConstantesGrosFichiers.DOCUMENT_LISTE_UUIDS: ["53aca732-fa3c-4e21-9462-e01e5157741a"], } enveloppe_val = self.generateur.soumettre_transaction( transaction, ConstantesGrosFichiers.TRANSACTION_SUPPRIMER_FICHIER, reply_to=self.queue_name, correlation_id='abcd') print("Renommer repertoire complete: %s" % enveloppe_val) return enveloppe_val def transaction_recuperer_fichier(self): transaction = { ConstantesGrosFichiers.DOCUMENT_LISTE_UUIDS: ["53aca732-fa3c-4e21-9462-e01e5157741a"], } enveloppe_val = self.generateur.soumettre_transaction( transaction, ConstantesGrosFichiers.TRANSACTION_RECUPERER_FICHIER, reply_to=self.queue_name, correlation_id='abcd') print("Renommer repertoire complete: %s" % enveloppe_val) return enveloppe_val def transaction_creer_collection_vide(self): transaction = {} enveloppe_val = self.generateur.soumettre_transaction( transaction, 'millegrilles.domaines.GrosFichiers.nouvelleCollection', reply_to=self.queue_name, correlation_id='abcd') print("Complete : %s" % enveloppe_val) return enveloppe_val def transaction_creer_collection_2docs(self): transaction = { "documents": [ { 'uuid': 'b63c5771-d2c8-4d5c-9db5-fdbe0a35ac36' }, { 'uuid': 'ff754f4a-6df1-4fbc-ab64-70693c7c487f' }, ] } enveloppe_val = self.generateur.soumettre_transaction( transaction, 'millegrilles.domaines.GrosFichiers.nouvelleCollection', reply_to=self.queue_name, correlation_id='abcd') print("Complete : %s" % enveloppe_val) return enveloppe_val def transaction_renommer_collection(self): transaction = { "uuid": "0fda4ce6-0ecf-11ea-bb74-00155d011f09", "nom": "sous_test_change_2", } enveloppe_val = self.generateur.soumettre_transaction( transaction, 'millegrilles.domaines.GrosFichiers.renommerCollection', reply_to=self.queue_name, correlation_id='abcd') print("Renommer repertoire complete: %s" % enveloppe_val) return enveloppe_val def transaction_supprimer_collection(self): transaction = { "uuid": "0fda4ce6-0ecf-11ea-bb74-00155d011f09", } enveloppe_val = self.generateur.soumettre_transaction( transaction, 'millegrilles.domaines.GrosFichiers.supprimerCollection', reply_to=self.queue_name, correlation_id='abcd') print("Renommer repertoire complete: %s" % enveloppe_val) return enveloppe_val def transaction_recuperer_collection(self): transaction = { "uuid": "0fda4ce6-0ecf-11ea-bb74-00155d011f09", } enveloppe_val = self.generateur.soumettre_transaction( transaction, 'millegrilles.domaines.GrosFichiers.recupererCollection', reply_to=self.queue_name, correlation_id='abcd') print("Renommer repertoire complete: %s" % enveloppe_val) return enveloppe_val def transaction_figer_collection(self): transaction = { "uuid": "a80c39cc-16ca-11ea-9318-00155d011f09", } enveloppe_val = self.generateur.soumettre_transaction( transaction, 'millegrilles.domaines.GrosFichiers.figerCollection', reply_to=self.queue_name, correlation_id='abcd') print("transaction_figer_collection: %s" % enveloppe_val) return enveloppe_val def transaction_changer_etiquettes_collection(self): transaction = { "uuid": "a80c39cc-16ca-11ea-9318-00155d011f09", "etiquettes": ['abcd', '1234'] } enveloppe_val = self.generateur.soumettre_transaction( transaction, 'millegrilles.domaines.GrosFichiers.changerEtiquettesCollection', reply_to=self.queue_name, correlation_id='abcd') print("Renommer repertoire complete: %s" % enveloppe_val) return enveloppe_val def transaction_ajouter_fichiers_collection(self): transaction = { "uuid": "5edceede-f77c-11ea-8eb7-ff28b56f498d", ConstantesGrosFichiers.DOCUMENT_COLLECTION_DOCS_UUIDS: [ 'ab13c39c-35e4-4f60-a353-ef2b63d92c54', ] } enveloppe_val = self.generateur.soumettre_transaction( transaction, 'GrosFichiers.ajouterFichiersCollection', reply_to=self.queue_name, correlation_id='abcd') print("Renommer repertoire complete: %s" % enveloppe_val) return enveloppe_val def transaction_retirer_fichiers_collection(self): transaction = { ConstantesGrosFichiers.DOCUMENT_FICHIER_UUID_DOC: "862a4348-b85a-4ab7-8021-ca26c9bb58bf", ConstantesGrosFichiers.DOCUMENT_COLLECTION_DOCS_UUIDS: [ '53aca732-fa3c-4e21-9462-e01e5157741a', ] } enveloppe_val = self.generateur.soumettre_transaction( transaction, ConstantesGrosFichiers.TRANSACTION_RETIRER_FICHIERS_COLLECTION, reply_to=self.queue_name, correlation_id='abcd') print("Renommer repertoire complete: %s" % enveloppe_val) return enveloppe_val def transaction_changer_favoris(self): transaction = { ConstantesGrosFichiers.DOCUMENT_COLLECTION_DOCS_UUIDS: { 'b212db7f-27f7-4d1e-bba2-5b2293e4d9ea': False, '2ca533be-c463-4cc3-b729-5bf34f53c623': True, } } enveloppe_val = self.generateur.soumettre_transaction( transaction, ConstantesGrosFichiers.TRANSACTION_CHANGER_FAVORIS, reply_to=self.queue_name, correlation_id='abcd') print("Ajouter favori: %s" % enveloppe_val) return enveloppe_val def requete_activite(self): requete = { 'skip': 0, 'limit': 3, } enveloppe_val = self.generateur.transmettre_requete( requete, Constantes.ConstantesGrosFichiers.REQUETE_ACTIVITE_RECENTE, reply_to=self.queue_name, correlation_id='abcd') print("Activite recente %s" % enveloppe_val) return enveloppe_val def requete_corbeille(self): requete = { 'skip': 0, 'limit': 3, } enveloppe_val = self.generateur.transmettre_requete( requete, Constantes.ConstantesGrosFichiers.REQUETE_CORBEILLE, reply_to=self.queue_name, correlation_id='abcd') print("Activite recente %s" % enveloppe_val) return enveloppe_val def requete_documents_collection(self): requete = { ConstantesGrosFichiers.DOCUMENT_FICHIER_UUID_DOC: '5edceede-f77c-11ea-8eb7-ff28b56f498d', 'skip': 1, 'limit': 2, 'sort_keys': ['nom_collection', 'nom_fichier'] } enveloppe_val = self.generateur.transmettre_requete( requete, Constantes.ConstantesGrosFichiers.REQUETE_CONTENU_COLLECTION, reply_to=self.queue_name, correlation_id='abcd') print("requete_documents_collection %s" % enveloppe_val) return enveloppe_val def requete_documents_par_uuid(self): requete = { ConstantesGrosFichiers.DOCUMENT_LISTE_UUIDS: ['5edceede-f77c-11ea-8eb7-ff28b56f498d'], } enveloppe_val = self.generateur.transmettre_requete( requete, Constantes.ConstantesGrosFichiers.REQUETE_DOCUMENTS_PAR_UUID, reply_to=self.queue_name, correlation_id='abcd') print("requete_documents_collection %s" % enveloppe_val) return enveloppe_val def transaction_associer_preview(self): transaction = { 'uuid': 'af6606b0-fac9-11ea-af1c-37323461d64a', 'fuuid': '40b268a7-2af4-4424-97ff-cb2a3610b7a1', ConstantesGrosFichiers.DOCUMENT_FICHIER_MIMETYPE_PREVIEW: 'image/blarghs', ConstantesGrosFichiers.DOCUMENT_FICHIER_FUUID_PREVIEW: str(uuid4()), } enveloppe_val = self.generateur.soumettre_transaction( transaction, ConstantesGrosFichiers.TRANSACTION_ASSOCIER_PREVIEW, reply_to=self.queue_name, correlation_id='efgh') print("Envoi metadata: %s" % enveloppe_val) return enveloppe_val def requete_decryptage_cle_fuuid(self): requete_cert_maitredescles = { 'fuuid': "ddb0d8f0-f7b4-11ea-89ec-13126005a8b0" } enveloppe_requete = self.generateur.transmettre_requete( requete_cert_maitredescles, 'MaitreDesCles.%s' % Constantes.ConstantesMaitreDesCles.REQUETE_DECRYPTAGE_GROSFICHIER, 'abcd-1234', self.queue_name) print("Envoi requete: %s" % enveloppe_requete) return enveloppe_requete def requete_permission_dechiffrage_fichier_public(self): requete_cert_maitredescles = { # 'fuuid': 'd2f5ebf0-228c-11eb-b2e0-e1493ef37733', 'fuuid': 'd0fa9123-228c-11eb-8f98-5d3582e42c8c', } enveloppe_requete = self.generateur.transmettre_requete( requete_cert_maitredescles, 'GrosFichiers.' + Constantes. ConstantesGrosFichiers.REQUETE_PERMISSION_DECHIFFRAGE_PUBLIC, 'abcd-1234', self.queue_name) print("Envoi requete: %s" % enveloppe_requete) return enveloppe_requete def requete_permission_decryptage_cle_fuuid(self): # mq_cert = self.configuration.mq_certfile # with open(mq_cert, 'r') as fichier: # mq_certfile = fichier.read() signateur = self.contexte.signateur_transactions certs = signateur.chaine_certs # certs = signateur.split_chaine_certificats(mq_certfile) requete_cert_maitredescles = { 'fuuid': "d0fa9123-228c-11eb-8f98-5d3582e42c8c", 'fuuid_preview': "d2f5ebf0-228c-11eb-b2e0-e1493ef37733", 'roles_permis': ['domaines'], } enveloppe_requete = self.generateur.transmettre_requete( requete_cert_maitredescles, 'MaitreDesCles.%s' % Constantes.ConstantesMaitreDesCles.REQUETE_DECRYPTAGE_GROSFICHIER, 'abcd-1234', self.queue_name, ajouter_certificats=True) print("Envoi requete: %s" % enveloppe_requete) return enveloppe_requete def requete_collections_publiques(self): requete = {} self.generateur.transmettre_requete( requete, 'GrosFichiers.' + Constantes.ConstantesMaitreDesCles.REQUETE_COLLECTIONS_PUBLIQUES, 'abcd-1234', self.queue_name, ajouter_certificats=True) def requete_detail_collections_publiques(self): requete = {} self.generateur.transmettre_requete( requete, 'GrosFichiers.' + Constantes.ConstantesGrosFichiers. REQUETE_DETAIL_COLLECTIONS_PUBLIQUES, 'abcd-1234', self.queue_name, ajouter_certificats=True) def commande_regenerer_previews(self): requete = {} self.generateur.transmettre_commande( requete, 'commande.GrosFichiers.' + Constantes.ConstantesGrosFichiers.COMMANDE_REGENERER_PREVIEWS, correlation_id='abcd-1234', reply_to=self.queue_name) def requete_fichier_par_fuuid(self): requete_cert_maitredescles = { 'fuuid': '3a4ad9e0-3af3-11eb-8020-63f97e3a189c', } enveloppe_requete = self.generateur.transmettre_requete( requete_cert_maitredescles, 'GrosFichiers.' + Constantes.ConstantesGrosFichiers.REQUETE_DOCUMENT_PAR_FUUID, 'abcd-1234', self.queue_name) print("Envoi requete: %s" % enveloppe_requete) return enveloppe_requete def commande_transcoder_video(self): requete = {'fuuid': '45342220-3bc6-11eb-9405-f97484a4f21f'} self.generateur.transmettre_commande( requete, 'commande.GrosFichiers.' + Constantes.ConstantesGrosFichiers.COMMANDE_TRANSCODER_VIDEO, correlation_id='abcd-1234', reply_to=self.queue_name) def executer(self): # enveloppe = sample.requete_profil_usager() # enveloppe1 = sample.transaction_nouvelle_version_metadata() # enveloppe2 = sample.transaction_nouvelle_version_transfertcomplete() # enveloppe6 = sample.transaction_renommer_fichier() # enveloppe11 = sample.transaction_commenter_fichier() # enveloppe8 = sample.transaction_changer_etiquettes_fichier() # enveloppe = sample.transaction_supprimer_fichier() # enveloppe = sample.transaction_recuperer_fichier() # enveloppe3 = sample.transaction_creer_collection_vide() # enveloppe3 = sample.transaction_creer_collection_2docs() # enveloppe4 = sample.transaction_renommer_collection() # enveloppe7 = sample.transaction_ajouter_fichiers_collection() # enveloppe7 = sample.transaction_retirer_fichiers_collection() # enveloppe = sample.transaction_changer_etiquettes_collection() # enveloppe5 = sample.transaction_figer_collection() # enveloppe5 = sample.transaction_supprimer_collection() # enveloppe5 = sample.transaction_recuperer_collection() # enveloppe = sample.transaction_changer_favoris() # enveloppe1 = sample.transaction_nouvelle_version_metadata() # enveloppe = sample.requete_activite() # enveloppe = sample.requete_corbeille() # enveloppe = sample.requete_documents_collection() # enveloppe = sample.requete_documents_par_uuid() # enveloppe = sample.transaction_associer_preview() # sample.requete_decryptage_cle_fuuid() # sample.requete_permission_decryptage_cle_fuuid() # sample.transaction_renommer_document() # sample.transaction_decrire_fichier() # sample.transaction_decrire_collection() # sample.requete_permission_dechiffrage_fichier_public() # sample.requete_collections_publiques() # sample.requete_detail_collections_publiques() # sample.commande_regenerer_previews() # sample.requete_fichier_par_fuuid() sample.commande_transcoder_video() pass
class MessagesSample(BaseCallback): def __init__(self): super().__init__(contexte) self.contexte.message_dao.register_channel_listener(self) self.generateur = GenerateurTransaction(self.contexte) self.queue_name = None self.channel = None self.event_recu = Event() def on_channel_open(self, channel): # Enregistrer la reply-to queue self.channel = channel channel.queue_declare(durable=True, exclusive=True, callback=self.queue_open_local) def queue_open_local(self, queue): self.queue_name = queue.method.queue print("Queue: %s" % str(self.queue_name)) self.channel.basic_consume(self.callbackAvecAck, queue=self.queue_name, no_ack=False) self.executer() def run_ioloop(self): self.contexte.message_dao.run_ioloop() def deconnecter(self): self.contexte.message_dao.deconnecter() def traiter_message(self, ch, method, properties, body): print("Message recu, correlationId: %s" % properties.correlation_id) message = json.loads(str(body, 'utf-8')) print(json.dumps(message, indent=4)) def transmettre_maj_profil_usager(self): fiche = { ConstantesPrincipale.LIBELLE_NOM: 'DugreAB', ConstantesPrincipale.LIBELLE_PRENOM: 'Mathieu', ConstantesPrincipale.LIBELLE_COURRIEL: '*****@*****.**', ConstantesPrincipale.LIBELLE_TWITTER: '@moi!', } domaine = ConstantesPrincipale.TRANSACTION_ACTION_MAJ_PROFILUSAGER enveloppe_val = self.generateur.soumettre_transaction( fiche, domaine, reply_to=self.queue_name, correlation_id='abcd') print("Envoi maj profil usager: %s" % enveloppe_val) return enveloppe_val def transmettre_maj_profil_millegrille(self): fiche = { ConstantesPrincipale.LIBELLE_NOM_MILLEGRILLE: 'Deux Tests', ConstantesPrincipale.LIBELLE_LANGUE_PRINCIPALE: 'fr', ConstantesPrincipale.LIBELLE_LANGUE_MULTILINGUE: False, } domaine = ConstantesPrincipale.TRANSACTION_ACTION_MAJ_PROFILMILLEGRILLE enveloppe_val = self.generateur.soumettre_transaction( fiche, domaine, reply_to=self.queue_name, correlation_id='abcd') print("Envoi maj profil usager: %s" % enveloppe_val) return enveloppe_val def requete_profil_usager(self): requete_profil = { 'filtre': { Constantes.DOCUMENT_INFODOC_LIBELLE: ConstantesPrincipale.LIBVAL_PROFIL_USAGER, } } requetes = {'requetes': [requete_profil]} enveloppe_requete = self.generateur.transmettre_requete( requetes, 'millegrilles.domaines.Principale', 'abcd-1234', self.queue_name) print("Envoi requete: %s" % enveloppe_requete) return enveloppe_requete def envoyer_empreinte(self): empreinte = {'cle': 'absfoijfdosijfds'} enveloppe_val = self.generateur.soumettre_transaction( empreinte, 'millegrilles.domaines.Principale.creerEmpreinte', reply_to=self.queue_name, correlation_id='efgh') print("Sent: %s" % enveloppe_val) return enveloppe_val def ajouter_token(self): token = {'cle': 'cle_3'} enveloppe_val = self.generateur.soumettre_transaction( token, 'millegrilles.domaines.Principale.ajouterToken', reply_to=self.queue_name, correlation_id='efgh') print("Sent: %s" % enveloppe_val) return enveloppe_val def requete_authinfo(self): requete_cert = {} enveloppe_requete = self.generateur.transmettre_requete( requete_cert, ConstantesPrincipale.REQUETE_AUTHINFO_MILLEGRILLE, 'abcd-1234', self.queue_name, securite=Constantes.SECURITE_PROTEGE, ) print("Envoi requete: %s" % enveloppe_requete) return enveloppe_requete def requete_infoproprietaire(self): requete_cert = {} enveloppe_requete = self.generateur.transmettre_requete( requete_cert, 'requete.MaitreDesComptes.infoProprietaire', 'abcd-1234', self.queue_name, securite=Constantes.SECURITE_PROTEGE, ) print("Envoi requete: %s" % enveloppe_requete) return enveloppe_requete def executer(self): # sample.transmettre_maj_profil_usager() # sample.transmettre_maj_profil_millegrille() # sample.requete_authinfo() sample.requete_infoproprietaire()
class MessagesSample(BaseCallback): def __init__(self): super().__init__(contexte) self.contexte.message_dao.register_channel_listener(self) self.generateur = GenerateurTransaction(self.contexte) self.channel = None self.event_recu = Event() # self.thread_ioloop = Thread(target=self.run_ioloop) self.certificat_maitredescles = None self.cert_maitredescles_recu = Event() self.mot_de_passe = 'sjdpo-1824-JWAZ' # Charger cert MaitreDesCles pour pouvoir crypter contenu a transmettre with open('/home/mathieu/mgdev/certs/pki.maitrecles.cert', 'rb') as certificat_pem: self.certificat_courant_pem = certificat_pem.read() self.clecert = EnveloppeCleCert() self.clecert.set_chaine_str(self.certificat_courant_pem.decode('utf-8')) self.clecert.cert_from_pem_bytes(self.certificat_courant_pem) # cert = x509.load_pem_x509_certificate( # certificat_courant_pem, # backend=default_backend() # ) self.certificat_courant = self.clecert.cert self.certificat_courant_pem = self.certificat_courant_pem.decode('utf8') with open('/home/mathieu/mgdev/certs/pki.millegrille.cert', 'rb') as certificat_pem: self.certificat_millegrille_pem = certificat_pem.read() self.clecert_millegrille = EnveloppeCleCert() self.clecert_millegrille.set_chaine_str(self.certificat_millegrille_pem.decode('utf-8')) self.clecert_millegrille.cert_from_pem_bytes(self.certificat_millegrille_pem) # cert = x509.load_pem_x509_certificate( # certificat_courant_pem, # backend=default_backend() # ) self.cert_millegrille = self.clecert_millegrille.cert self.cert_millegrille_pem = self.certificat_millegrille_pem.decode('utf8') def on_channel_open(self, channel): # Enregistrer la reply-to queue self.channel = channel channel.queue_declare(durable=True, exclusive=True, callback=self.queue_open) def queue_open(self, queue): self.queue_name = queue.method.queue print("Queue: %s" % str(self.queue_name)) self.channel.basic_consume(self.callbackAvecAck, queue=self.queue_name, no_ack=False) # self.event_recu.set() self.requete_cert_maitredescles() thread_executer = Thread(name="exec", target=self.executer) thread_executer.start() # def run_ioloop(self): # self.contexte.message_dao.run_ioloop() def deconnecter(self): self.contexte.message_dao.deconnecter() def traiter_message(self, ch, method, properties, body): print("Message recu, correlationId: %s" % properties.correlation_id) print(body) message_dict = json.loads(body) certificat_pem = message_dict.get('certificat') if certificat_pem is not None: cert = EnveloppeCleCert() try: cert.cert_from_pem_bytes(certificat_pem[0].encode('utf-8')) self.certificat_maitredescles = cert print("Recu certificat %s" % cert.fingerprint_b64) except: print("Erreur traitement certificat_pem") self.cert_maitredescles_recu.set() else: self.event_recu.set() if message_dict.get('certificats_pem'): for cert in message_dict.get('certificats_pem'): print(cert) print(json.dumps(message_dict, indent=4)) def requete_cert_maitredescles(self): requete_cert_maitredescles = { # Constantes.TRANSACTION_MESSAGE_LIBELLE_EVENEMENT: ConstantesMaitreDesCles.REQUETE_CERT_MAITREDESCLES } enveloppe_requete = self.generateur.transmettre_requete( requete_cert_maitredescles, 'MaitreDesCles.%s' % ConstantesMaitreDesCles.REQUETE_CERT_MAITREDESCLES, 'abcd-1234', self.queue_name ) print("Envoi requete: %s" % enveloppe_requete) return enveloppe_requete def requete_trousseau_hebergement(self): requete = { 'idmg': ['2aMvfBTqyfeQsMgSsYbtJuMeqUJ5TZV2iNiy2ES'] } enveloppe_requete = self.generateur.transmettre_requete( requete, 'millegrilles.domaines.MaitreDesCles.%s' % ConstantesMaitreDesCles.REQUETE_TROUSSEAU_HEBERGEMENT, 'abcd-1234', self.queue_name ) print("Envoi requete: %s" % enveloppe_requete) return enveloppe_requete def requete_decryptage_cle_fuuid(self): requete_cert_maitredescles = { 'fuuid': "ddb0d8f0-f7b4-11ea-89ec-13126005a8b0" } enveloppe_requete = self.generateur.transmettre_requete( requete_cert_maitredescles, 'MaitreDesCles.%s' % ConstantesMaitreDesCles.REQUETE_DECRYPTAGE_GROSFICHIER, 'abcd-1234', self.queue_name ) print("Envoi requete: %s" % enveloppe_requete) return enveloppe_requete def requete_cle_document(self): fingerprint = self.clecert.fingerprint requete_cert_maitredescles = { 'fingerprint': fingerprint, 'certificat': self.certificat_courant_pem, 'domaine': 'MaitreDesComptes', 'identificateurs_document': { "libelle": "proprietaire", "champ": "totp" } } print(requete_cert_maitredescles) self.generateur.transmettre_requete( requete_cert_maitredescles, 'MaitreDesCles.%s' % ConstantesMaitreDesCles.REQUETE_DECRYPTAGE_DOCUMENT, 'abcd-1234', self.queue_name ) def requete_decryptage_cle_fuuid_avecfingerprint(self): requete_cert_maitredescles = { 'fuuid': "b4ecca10-1c2b-11ea-904a-7b4d1a2d4432", 'fingerprint': '74fd5742aec60dd37f99c75df423008a10149018' } enveloppe_requete = self.generateur.transmettre_requete( requete_cert_maitredescles, 'millegrilles.domaines.MaitreDesCles.%s' % ConstantesMaitreDesCles.REQUETE_DECRYPTAGE_GROSFICHIER, 'abcd-1234', self.queue_name ) print("Envoi requete: %s" % enveloppe_requete) return enveloppe_requete def requete_cle_racine(self): # Attendre le certificat de maitre des cles pour chiffrer la cle self.cert_maitredescles_recu.wait(5) mot_de_passe_chiffre, fingerprint = self.certificat_maitredescles.chiffrage_asymmetrique(self.mot_de_passe.encode('utf-8')) requete_cle_racine = { 'fingerprint': '', 'mot_de_passe_chiffre': str(b64encode(mot_de_passe_chiffre), 'utf-8'), } enveloppe_requete = self.generateur.transmettre_requete( requete_cle_racine, 'millegrilles.domaines.MaitreDesCles.%s' % ConstantesMaitreDesCles.REQUETE_CLE_RACINE, 'abcd-1234', self.queue_name ) print("Envoi requete: %s" % enveloppe_requete) return enveloppe_requete def requete_cle_backup(self): requete_cert_maitredescles = { 'certificat': self.certificat_courant_pem, 'domaine': 'Topologie', 'identificateurs_document': { 'transactions_nomfichier': 'Topologie_transactions_2020100323_3.protege.jsonl.xz.mgs1', }, "cles": { "cGrSTYhEB19QGjiipURder6/IRc=Z": "aVA+CkgvSqP496IBrDbFa2SVP11f+BKq8oc3vJ2+8g4Ypo4u2c5ZnYvNPTFEnoAGcggGRDDQY2wkCNUGOjh2gTMnItUOdWJNq5vmjs0XNTOpiEkJpq7U5ZzPTssn2m6V1JbG0TmTu5/f24K1HAhae2lz95mlVdwufm+kQolwL5rzULOzGGV+mX8PGuaQkCHPdcletVj9IUwgkwrwYAgjYHt9qPjGUHO7Bcyiw1t7dWTUTbvt59uh41J53IB79hRqwx8BMeY7rMsWoY5ffVIWBorV//XxcsnEqiXgEOUJoC/LmQfI21FxPNV6mBIzs4hakvOgET5D2yGoAlYX4wJnxg==", "OaUo6vkTDQ26S9hbdFqeKYS3NyI=": "jYYDIgn4ShniCGkBgfJ1tIzOARRl1wBAps/SQwKBDMZnL+uH3MAhsieg6XW5vtdZyC/hh+hZ2q++2GGsgSUHAKbJlTn8YWS4WuRpUQssg4agpfCVPndkRoN1qf7QaQiN27HZJhMawqif0KDx7ZU0MsJoHF1l0X0E+frNuVg+WY+8DpHRxxc15CeHcLToSYn1V15WDiCTbrfvZ0zONEF2btie7eQ/B81prcTnUNrJe5xoHraEaQOcD4NOW1gCV0D8YfGcKZ2/by9zad3aJL5iUvGW4AeftewOaaKu4tM5bjdqSeICoeaI0fXwk7L/q2bBR2FOMM/P4so3JbabOaShHA==" }, "iv": "16ldjBWXospiToJEKEIWGw==", } print(requete_cert_maitredescles) self.generateur.transmettre_requete( requete_cert_maitredescles, 'MaitreDesCles.%s' % ConstantesMaitreDesCles.REQUETE_DECHIFFRAGE_BACKUP, 'abcd-1234', self.queue_name ) def requete_cle_backup_application(self): requete_cert_maitredescles = { 'certificat': self.certificat_courant_pem, 'identificateurs_document': { 'archive_nomfichier': 'application_mariadb_redmine_client_archive_202010101721.tar.xz.mgs1' }, } print(requete_cert_maitredescles) self.generateur.transmettre_requete( requete_cert_maitredescles, 'MaitreDesCles.%s' % ConstantesMaitreDesCles.REQUETE_DECHIFFRAGE_BACKUP, 'abcd-1234', self.queue_name ) def commande_sauvegarder_cle(self): commande = { 'domaine': 'Topologie', 'identificateurs_document': { 'transactions_nomfichier': 'Topologie_transactions_2020100325_3.protege.jsonl.xz.mgs1', }, "cles": { # "cGrSTYhEB19QGjiipURder6/IRc=Z": "aVA+CkgvSqP496IBrDbFa2SVP11f+BKq8oc3vJ2+8g4Ypo4u2c5ZnYvNPTFEnoAGcggGRDDQY2wkCNUGOjh2gTMnItUOdWJNq5vmjs0XNTOpiEkJpq7U5ZzPTssn2m6V1JbG0TmTu5/f24K1HAhae2lz95mlVdwufm+kQolwL5rzULOzGGV+mX8PGuaQkCHPdcletVj9IUwgkwrwYAgjYHt9qPjGUHO7Bcyiw1t7dWTUTbvt59uh41J53IB79hRqwx8BMeY7rMsWoY5ffVIWBorV//XxcsnEqiXgEOUJoC/LmQfI21FxPNV6mBIzs4hakvOgET5D2yGoAlYX4wJnxg==", "OaUo6vkTDQ26S9hbdFqeKYS3NyI=": "jYYDIgn4ShniCGkBgfJ1tIzOARRl1wBAps/SQwKBDMZnL+uH3MAhsieg6XW5vtdZyC/hh+hZ2q++2GGsgSUHAKbJlTn8YWS4WuRpUQssg4agpfCVPndkRoN1qf7QaQiN27HZJhMawqif0KDx7ZU0MsJoHF1l0X0E+frNuVg+WY+8DpHRxxc15CeHcLToSYn1V15WDiCTbrfvZ0zONEF2btie7eQ/B81prcTnUNrJe5xoHraEaQOcD4NOW1gCV0D8YfGcKZ2/by9zad3aJL5iUvGW4AeftewOaaKu4tM5bjdqSeICoeaI0fXwk7L/q2bBR2FOMM/P4so3JbabOaShHA==" }, "iv": "16ldjBWXospiToJEKEIWGw==", 'domaine_action_transaction': ConstantesMaitreDesCles.TRANSACTION_NOUVELLE_CLE_BACKUPTRANSACTIONS, } self.generateur.transmettre_commande( commande, 'commande.MaitreDesCles.%s' % ConstantesMaitreDesCles.COMMANDE_SAUVEGARDER_CLE, exchange=Constantes.SECURITE_SECURE, correlation_id='abcd-1234', reply_to=self.queue_name ) def commande_signer_cle_backup(self): with open ('/home/mathieu/mgdev/certs/pki.connecteur.key', 'rb') as fichier: key_bytes = fichier.read() enveloppe = EnveloppeCleCert() enveloppe.key_from_pem_bytes(key_bytes, None) public_bytes = enveloppe.public_bytes requete_cle_racine = { 'cle_publique': public_bytes.decode('utf-8'), } enveloppe_requete = self.generateur.transmettre_commande( requete_cle_racine, 'commande.millegrilles.domaines.MaitreDesCles.%s' % ConstantesMaitreDesCles.COMMANDE_SIGNER_CLE_BACKUP, correlation_id='abcd-1234', reply_to=self.queue_name ) print("Envoi requete: %s" % enveloppe_requete) return enveloppe_requete def commande_restaurer_backup_cle(self): with open ('/home/mathieu/mgdev/certs/pki.connecteur.key', 'rb') as fichier: key_bytes = fichier.read() clecert = EnveloppeCleCert() clecert.key_from_pem_bytes(key_bytes, None) clecert.password = self.mot_de_passe.encode('utf-8') key_chiffree_bytes = clecert.private_key_bytes self.cert_maitredescles_recu.wait(5) mot_de_passe_chiffre, fingerprint = self.certificat_maitredescles.chiffrage_asymmetrique(self.mot_de_passe.encode('utf-8')) enveloppe = EnveloppeCleCert() enveloppe.key_from_pem_bytes(key_bytes, None) requete_cle_racine = { 'cle_privee': key_chiffree_bytes.decode('utf-8'), 'mot_de_passe_chiffre': str(b64encode(mot_de_passe_chiffre), 'utf-8'), # 'fingerprint_base64': 'Ut/UQ5aKomoGzXB7mpUduPk4Xzg=', } enveloppe_requete = self.generateur.transmettre_commande( requete_cle_racine, 'commande.millegrilles.domaines.MaitreDesCles.%s' % ConstantesMaitreDesCles.COMMANDE_RESTAURER_BACKUP_CLES, correlation_id='abcd-1234', reply_to=self.queue_name ) print("Envoi requete: %s" % enveloppe_requete) return enveloppe_requete def commande_creer_cles_millegrille_hebergee(self): enveloppe_requete = self.generateur.transmettre_commande( dict(), 'commande.millegrilles.domaines.MaitreDesCles.%s' % ConstantesMaitreDesCles.COMMANDE_CREER_CLES_MILLEGRILLE_HEBERGEE, correlation_id='abcd-1234', reply_to=self.queue_name, exchange=Constantes.DEFAUT_MQ_EXCHANGE_MIDDLEWARE ) print("Envoi commande: %s" % enveloppe_requete) return enveloppe_requete def nouvelle_cle_grosfichiers(self): cle_secrete = 'Mon mot de passe secret' clecert_chiffrage = self.clecert_millegrille # cert_chiffrage = self.certificat_courant cert_chiffrage = clecert_chiffrage.cert fingerprint_b64 = clecert_chiffrage.fingerprint_b64 cle_secrete_encryptee = cert_chiffrage.public_key().encrypt( cle_secrete.encode('utf8'), padding.OAEP( mgf=padding.MGF1(algorithm=hashes.SHA256()), algorithm=hashes.SHA256(), label=None ) ) cle_secrete_encryptee_base64 = b64encode(cle_secrete_encryptee).decode('utf8') nouvelle_cle = { "domaine": "GrosFichiers", ConstantesMaitreDesCles.TRANSACTION_CHAMP_IDENTIFICATEURS_DOCUMENTS: { "fuuid": str(uuid4()), }, "cles": {fingerprint_b64: cle_secrete_encryptee_base64}, "iv": "gA8cRaiJE+8aN2c6/N1vTg==", "sujet": ConstantesMaitreDesCles.DOCUMENT_LIBVAL_CLES_GROSFICHIERS, } enveloppe_val = self.generateur.soumettre_transaction( nouvelle_cle, ConstantesMaitreDesCles.TRANSACTION_NOUVELLE_CLE_GROSFICHIER, reply_to=self.queue_name, correlation_id='efgh' ) print("Sent: %s" % enveloppe_val) return enveloppe_val def nouvelle_cle_document(self): fingerprint_b64 = self.clecert.fingerprint_b64 cle_secrete = 'Mon mot de passe secret' cle_secrete_encryptee = self.certificat_courant.public_key().encrypt( cle_secrete.encode('utf8'), padding.OAEP( mgf=padding.MGF1(algorithm=hashes.SHA256()), algorithm=hashes.SHA256(), label=None ) ) cle_secrete_encryptee_mime64 = b64encode(cle_secrete_encryptee).decode('utf8') nouvelle_cle = { "domaine": "MaitreDesComptes", ConstantesMaitreDesCles.TRANSACTION_CHAMP_IDENTIFICATEURS_DOCUMENTS: { "_mg-libelle": "proprietaire", "champ": 'dummy' + str(uuid4()), }, "cles": {fingerprint_b64: cle_secrete_encryptee_mime64}, "iv": "gA8cRaiJE+8aN2c6/N1vTg==", } enveloppe_val = self.generateur.soumettre_transaction( nouvelle_cle, ConstantesMaitreDesCles.TRANSACTION_NOUVELLE_CLE_DOCUMENT, reply_to=self.queue_name, correlation_id='efgh' ) print("Sent: %s" % enveloppe_val) return enveloppe_val def nouvelle_cle_backup(self): cle_secrete = 'Mon mot de passe secret' clecert_chiffrage = self.clecert_millegrille # cert_chiffrage = self.certificat_courant cert_chiffrage = clecert_chiffrage.cert fingerprint_b64 = clecert_chiffrage.fingerprint_b64 cle_secrete_encryptee = cert_chiffrage.public_key().encrypt( cle_secrete.encode('utf8'), padding.OAEP( mgf=padding.MGF1(algorithm=hashes.SHA256()), algorithm=hashes.SHA256(), label=None ) ) cle_secrete_encryptee_base64 = b64encode(cle_secrete_encryptee).decode('utf8') date_str = datetime.datetime.utcnow().strftime('%y%m%d%h%m') nouvelle_cle = { "domaine": "Topologie", ConstantesMaitreDesCles.TRANSACTION_CHAMP_IDENTIFICATEURS_DOCUMENTS: { "transactions_nomfichier": "Topologie_transactions_%s_3.protege.jsonl.xz.mgs1" % date_str, }, "cles": {fingerprint_b64: cle_secrete_encryptee_base64}, "iv": "gA8cRaiJE+8aN2c6/N1vTg==", "sujet": ConstantesMaitreDesCles.DOCUMENT_LIBVAL_CLES_BACKUPTRANSACTIONS, } enveloppe_val = self.generateur.soumettre_transaction( nouvelle_cle, ConstantesMaitreDesCles.TRANSACTION_NOUVELLE_CLE_BACKUPTRANSACTIONS, reply_to=self.queue_name, correlation_id='efgh' ) print("Sent: %s" % enveloppe_val) return enveloppe_val def transaction_declasser_grosfichier(self): transaction = { 'fuuid': '3830311b-145f-4ab2-850e-f4defdb70767' } enveloppe_val = self.generateur.soumettre_transaction( transaction, ConstantesMaitreDesCles.TRANSACTION_DECLASSER_CLE_GROSFICHIER, reply_to=self.queue_name, correlation_id='efgh' ) print("Sent: %s" % enveloppe_val) return enveloppe_val def transaction_signer_certificat_navigateur(self): public_key_str = """ -----BEGIN CERTIFICATE REQUEST----- MIICfTCCAWUCAQAwODESMBAGA1UEAxMJbm9tVXNhZ2VyMRMwEQYDVQQLEwpOYXZp Z2F0ZXVyMQ0wCwYDVQQKEwRpZG1nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB CgKCAQEAwDlWi2KJsccrDJKHq8xLYjCqndu+Oh4GNsbRypPctuu+oU6PNkwwjSIN xNuJret+ZVr2mw2MNbt9JYANriltYwvFWkF63NTIGXstaegNCkj6vqa4KdtXK7uu NREtMLEhEu+ZWYcR2hWzVEN9GyIPwEgPNYQwUjjjLADUnaZ73t9Bk+fivgll0JbJ reSw8DHqvdcmB28AnXltch6Wh34EGiYPbJqDm+NnCHHZ2EumbPRkN5/bqZTmpUDw qqt+6cTcgAtdIuzYm3sPQt/Zf3EJwDT9dBxVrdbBnNFG4js3lauy49hog78zwwNP /i3DZU3VDDCDeT4POKfEHXtwxTLF4QIDAQABoAAwDQYJKoZIhvcNAQENBQADggEB AKBdiHJamlXfevloSBhehrf5g7lRbISGEsyY5HOXvVMLbip75QcGMcz8jnEJxYFk 8mDPuxlR3VOkyDiPGpLloN9hOgk50igwtRmFXcGCENbaJX2FZdho0yyx/yS03WXR HXkje/v1Z6x1gitAxACbvvywo4qtIQoBSwP08D0JIGtD2GWPvzd1+PSgsdqQsmxz EMkpLW0RZ2y1fCZyXbXPfAI4rnCL5Lb3CW7e4sbdH2XkcV4fBPEDGo03TE8648XV 6PCY9G7vw3iPiAhicMp1nI9bx+N/IapZvWmqR8vOURfFHYB1ilnli7S3MNXpDC9Q BMz4ginADdtNs9ARr3DcwG4= -----END CERTIFICATE REQUEST----- """ commande = { 'est_proprietaire': True, 'csr': public_key_str, } enveloppe_val = self.generateur.transmettre_commande( commande, 'commande.MaitreDesCles.' + ConstantesMaitreDesCles.COMMANDE_SIGNER_NAVIGATEUR_CSR, reply_to=self.queue_name, correlation_id='efgh' ) print("Sent: %s" % enveloppe_val) return enveloppe_val def transaction_demande_inscription_tierce(self): transaction = { 'idmg': '33KRMhqcWCKvMHyY5xymMCUEbT53Kg1NqUb9AU6' } domaine = ConstantesMaitreDesCles.TRANSACTION_GENERER_DEMANDE_INSCRIPTION enveloppe_val = self.generateur.soumettre_transaction( transaction, domaine, reply_to=self.queue_name, correlation_id='efgh' ) print("Sent: %s" % enveloppe_val) return enveloppe_val def transaction_signature_inscription_tierce(self): with open('/home/mathieu/PycharmProjects/MilleGrilles.consignation.python/test/messages/demande_connexion.json') as fichier: transaction = json.load(fichier) domaine = ConstantesMaitreDesCles.TRANSACTION_GENERER_CERTIFICAT_POUR_TIERS enveloppe_val = self.generateur.soumettre_transaction( transaction, domaine, reply_to=self.queue_name, correlation_id='efgh' ) print("Sent: %s" % enveloppe_val) return enveloppe_val def transaction_supprimer_trousseau_hebergement(self): domaine = ConstantesMaitreDesCles.TRANSACTION_HEBERGEMENT_SUPPRIMER enveloppe_val = self.generateur.soumettre_transaction( {'idmg': '3M87pZxVVWbT1dVLeRarQnge1mvADTs4trG7Caa'}, domaine, reply_to=self.queue_name, correlation_id='efgh' ) print("Sent: %s" % enveloppe_val) return enveloppe_val def commande_signer_csr(self): clecert = EnveloppeCleCert() clecert.generer_private_key(generer_password=True, keysize=4096) public_key = clecert.private_key.public_key() builder = x509.CertificateSigningRequestBuilder() name = x509.Name([ x509.NameAttribute(x509.name.NameOID.ORGANIZATION_NAME, '3aeGLdmMbA1BrmRYwpPgNAZKH2WGWmSedBjKSxw'), x509.NameAttribute(x509.name.NameOID.ORGANIZATIONAL_UNIT_NAME, 'domaines'), x509.NameAttribute(x509.name.NameOID.COMMON_NAME, 'test') ]) builder = builder.subject_name(name) request = builder.sign( clecert.private_key, hashes.SHA256(), default_backend() ) request_pem = request.public_bytes(primitives.serialization.Encoding.PEM) commande = { 'liste_csr': [request_pem.decode('utf-8')], } enveloppe_requete = self.generateur.transmettre_commande( commande, 'commande.millegrilles.domaines.MaitreDesCles.%s' % ConstantesMaitreDesCles.COMMANDE_SIGNER_CSR, correlation_id='abcd-1234', reply_to=self.queue_name ) print("Envoi requete: %s" % enveloppe_requete) return enveloppe_requete def commande_signer_csr_noeud_prive(self): clecert = EnveloppeCleCert() clecert.generer_private_key(keysize=2048) public_key = clecert.private_key.public_key() builder = x509.CertificateSigningRequestBuilder() name = x509.Name([ # x509.NameAttribute(x509.name.NameOID.ORGANIZATION_NAME, '3aeGLdmMbA1BrmRYwpPgNAZKH2WGWmSedBjKSxw'), x509.NameAttribute(x509.name.NameOID.ORGANIZATIONAL_UNIT_NAME, 'intermediaire'), x509.NameAttribute(x509.name.NameOID.COMMON_NAME, str(uuid4())) ]) builder = builder.subject_name(name) request = builder.sign( clecert.private_key, hashes.SHA256(), default_backend() ) request_pem = request.public_bytes(primitives.serialization.Encoding.PEM) commande = { 'liste_csr': [request_pem.decode('utf-8')], 'role': 'prive' } enveloppe_requete = self.generateur.transmettre_commande( commande, 'commande.MaitreDesCles.%s' % ConstantesMaitreDesCles.COMMANDE_SIGNER_CSR, correlation_id='abcd-1234', reply_to=self.queue_name ) print("Envoi requete: %s" % enveloppe_requete) return enveloppe_requete def requete_cles_non_dechiffrables(self): requete_cle_racine = { 'taille': 2 } enveloppe_requete = self.generateur.transmettre_requete( requete_cle_racine, 'MaitreDesCles.%s' % ConstantesMaitreDesCles.REQUETE_CLES_NON_DECHIFFRABLES, 'abcd-1234', self.queue_name ) return enveloppe_requete def requete_cles_non_dechiffrables_verifmaitrecles(self): self.cert_maitredescles_recu.wait(5) # Attendre reception cert maitredescles # Prendre le fingerprint du cert maitre des cles - devrait retourner 0 cles non chiffrees fingerprint_maitrecles = self.certificat_maitredescles.fingerprint_b64 requete_cle_racine = { 'taille': 2, 'fingerprints_actifs': [fingerprint_maitrecles], } enveloppe_requete = self.generateur.transmettre_requete( requete_cle_racine, 'MaitreDesCles.%s' % ConstantesMaitreDesCles.REQUETE_CLES_NON_DECHIFFRABLES, 'abcd-1234', self.queue_name ) return enveloppe_requete def requete_cles_non_dechiffrables_verifcledummy(self): self.cert_maitredescles_recu.wait(5) # Attendre reception cert maitredescles # Prendre le fingerprint du cert maitre des cles - devrait retourner 0 cles non chiffrees fingerprint_maitrecles = self.certificat_maitredescles.fingerprint_b64 requete_cle_racine = { 'taille': 2, 'fingerprints_actifs': ['DUMMY'], } enveloppe_requete = self.generateur.transmettre_requete( requete_cle_racine, 'MaitreDesCles.%s' % ConstantesMaitreDesCles.REQUETE_CLES_NON_DECHIFFRABLES, 'abcd-1234', self.queue_name ) return enveloppe_requete def requete_compter_cles_non_dechiffrables_verifcledummy(self): self.cert_maitredescles_recu.wait(5) # Attendre reception cert maitredescles # Prendre le fingerprint du cert maitre des cles - devrait retourner 0 cles non chiffrees fingerprint_maitrecles = self.certificat_maitredescles.fingerprint_b64 requete_cle_racine = { # 'fingerprints_actifs': ['DUMMY'], } enveloppe_requete = self.generateur.transmettre_requete( requete_cle_racine, 'MaitreDesCles.%s' % ConstantesMaitreDesCles.REQUETE_COMPTER_CLES_NON_DECHIFFRABLES, 'abcd-1234', self.queue_name ) return enveloppe_requete def executer(self): # self.event_recu.wait(5) # self.event_recu.clear() # enveloppe = self.requete_cert_maitredescles() # self.requete_trousseau_hebergement() # for i in range(0, 2): # self.nouvelle_cle_grosfichiers() # self.nouvelle_cle_document() # self.nouvelle_cle_backup() # enveloppe = self.transaction_declasser_grosfichier() # enveloppe = self.transaction_signer_certificat_navigateur() # enveloppe = self.requete_decryptage_cle_fuuid() # enveloppe = self.requete_decryptage_cle_fuuid_avecfingerprint() # self.transaction_demande_inscription_tierce() # self.transaction_signature_inscription_tierce() # self.transaction_supprimer_trousseau_hebergement() # self.requete_cle_document() # self.requete_cle_racine() # self.commande_signer_cle_backup() # self.commande_restaurer_backup_cle() # self.commande_creer_cles_millegrille_hebergee() # self.commande_signer_csr() # self.commande_signer_csr_noeud_prive() # self.requete_cles_non_dechiffrables() # self.requete_cles_non_dechiffrables_verifmaitrecles() # self.requete_cles_non_dechiffrables_verifcledummy() self.requete_compter_cles_non_dechiffrables_verifcledummy()
class MessagesSample(BaseCallback): def __init__(self): super().__init__(contexte) self.contexte.message_dao.register_channel_listener(self) self.generateur = GenerateurTransaction(self.contexte) self.queue_name = None self.channel = None self.event_recu = Event() def on_channel_open(self, channel): # Enregistrer la reply-to queue self.channel = channel channel.queue_declare(durable=True, exclusive=True, callback=self.queue_open_local) def queue_open_local(self, queue): self.queue_name = queue.method.queue print("Queue: %s" % str(self.queue_name)) self.channel.basic_consume(self.callbackAvecAck, queue=self.queue_name, no_ack=False) self.executer() def run_ioloop(self): self.contexte.message_dao.run_ioloop() def deconnecter(self): self.contexte.message_dao.deconnecter() def traiter_message(self, ch, method, properties, body): print("Message recu, correlationId: %s" % properties.correlation_id) message = json.loads(str(body, 'utf-8')) print(json.dumps(message, indent=4)) def transmettre_reponse(self): reponse = {'resultats': [[{'label': 1234}]]} enveloppe_val = self.generateur.transmettre_reponse( reponse, 'millegrilles.domaines.GrosFichiers.processus', '5deaa316fd7b6b69f45b3b24') print("Envoi resultat parametres: %s" % enveloppe_val) return enveloppe_val def transmettre_reponse_relle(self): reponse = { "_signature": "fbCZmeVWqDJ8ZwnanHFBHs3DT5JYBlMUtzajDU34JtMxDpDXK702Wo7TEx5M9TCxZaN+0mFUTEKYa8l8EUFz9A7+rY3TeR0SV4LkHSO5DXj1HBta34Lsg5KVU86S7hLZI0vrPjFCMAIALdmcsnuwC9K6OBhxhf37HfDGVrfOmwNJdY4R8HV6U7YNPnKBV+sw0bkxZC8jU2Sw+dKhkUJunYnd81mLX29lmQ6nT2FQoRX5olF1h+zFo6C+2m0rroh2uUzgr4Kb2K6kjNdTj2/DPR4TgSw1jJtPdATjBiqp1Lbcy9dHCrJ7+WBsPwFwPxpsuOaGBv+YSvXVF2gt0kuDQg==", "en-tete": { "certificat": "8f3e528bb8c7d489b6b296b07b16db2bf76fa729", "estampille": 1575662185, "hachage-contenu": "4/RiVlGWDPBtDU3vkSacQXKmeZZL38x2mPCltxvD6a0=", "source-systeme": "mathieu/mg-dev3@mg-dev3", "uuid-transaction": "7bcc7946-1862-11ea-9318-00155d011f09", "version": 4 }, "resultats": [[{ "_id": "5dd4306e4da41cd44b2463aa", "_mg-creation": 1574187118.502, "_mg-derniere-modification": 1574187118.503, "_mg-libelle": "publique.configuration", "actif": False, "activite": [], "ipv4_externe": None, "mappings_ipv4": {}, "mappings_ipv4_demandes": {}, "noeud_docker_hostname": None, "port_http": 80, "port_https": 443, "port_mq": 5673, "status_info": None, "upnp_supporte": False, "url_mq": None, "url_web": None }]] } enveloppe_val = self.generateur.transmettre_reponse( reponse, 'millegrilles.domaines.GrosFichiers.processus', '5deaa406fd7b6b69f45b3b28') print("Envoi resultat parametres: %s" % enveloppe_val) return enveloppe_val def test_rediriger_requete(self): requete = { "requetes": [{ "filtre": { '_mg-libelle': 'publique.configuration' } }] } self.generateur.transmettre_requete( requete, 'millegrilles.domaines.Parametres', '5deaa316fd7b6b69f45b3b24', self.queue_name) def executer(self): # enveloppe = sample.transmettre_reponse() enveloppe = sample.transmettre_reponse_relle()