def reprocess(self, queue, *args, **options): self.stdout.write("Starting...") cred_count = Credential.objects.count() self.stdout.write("Reprocessing {} credentials".format(cred_count)) current_cred = 0 mgr = CredentialManager() for credential in Credential.objects.all().iterator(): current_cred += 1 self.stdout.write("Processing credential id: {} ({} of {})".format( credential.id, current_cred, cred_count)) # Remove and recreate search records mgr.reprocess(credential) # Now reindex signals.post_save.send(sender=Credential, instance=credential, using=DEFAULT_DB_ALIAS)
def receive_credential(request): """ Receive a stripped-down credential and store it in the credential registry. This endpoint is for testing/debug purposes ONLY! To issue a credential: - use the */api/v2/credentialtype* endpoint to determine the _cred_def_id_, - use the */api/v2/schema* endpoint to build the _schema_id_ in the form _origin_did:id:name:version_ - add the relevant attributes in the values object, using the value name as key instead of _valN_ and the string value as its _raw_ value - call this API """ message = request.data credential_id = uuid.uuid4() raw_credential = message["raw_credential"] LOGGER.debug("Received raw-credential: {}".format(raw_credential)) credential_data = { "schema_id": raw_credential["schema_id"], "cred_def_id": raw_credential["cred_def_id"], "rev_reg_id": credential_id, # we use the same value as credential_id "attrs": raw_credential["values"], } for attr in raw_credential["values"]: credential_data["attrs"][attr] = raw_credential["values"][attr]["raw"] try: credential = Credential(credential_data, credential_id=credential_id) credential_manager = CredentialManager() credential_manager.process(credential) except Exception as e: LOGGER.error("An exception occurred while processing the credential:") LOGGER.error(str(e)) return Response({"success": False, "error": str(e)}) return Response({"success": True})
else: LOGGER.info("Callback: topic=" + topic + ", message=" + json.dumps(message)) end_time = time.perf_counter() log_timing_method(method, start_time, end_time, False) return Response("Invalid topic: " + topic, status=status.HTTP_400_BAD_REQUEST) end_time = time.perf_counter() log_timing_method(method, start_time, end_time, True) return response # create one global manager instance credential_manager = CredentialManager() def handle_credentials(state, message): """ Receives notification of a credential processing event. For example, for a greenlight registration credential: message = { "connection_id": "12345", "credential_definition_id": "6qnvgJtqwK44D8LFYnV5Yf:3:CL:25:tag", "credential_exchange_id": "666", "credential_id": "67890", "credential_offer": {}, "credential_request": {}, "credential_request_metadata": {},
def handle_register_issuer(message): """Handles the registration of a new issuing agent in the credential registry. The agent registration credential will be in the following format: { "issuer_registration_id": "string", "connection_id": "string", "issuer_registration": { "credential_types": [ { "category_labels": {"category": "label"}, "claim_descriptions": {"claim": "description"}, "claim_labels": {"claim": "label"}, "credential_def_id": "string", "schema": "string", "version": "string", "name": "string", "credential": { "effective_date": {"input": "topic_id", "from": "claim"} }, "topic": [ { "source_id": {"input": "topic_id", "from": "claim"} } ], "endpoint": "string", "cardinality_fields": ["string"], "mapping": {}, "visible_fields": ["string"], "logo_b64": "string", } ], "issuer": { "name": "string", "did": "string", "abbreviation": "string", "email": "string", "url": "string", "endpoint": "string", "logo_b64": "string" } } } """ issuer_manager = IssuerManager() updated = issuer_manager.register_issuer(message) # reset the global CredentialManager instance (to clear the CredentialType cache) global credential_manager credential_manager = CredentialManager() # update tagging policy tag_policy_updates = {} cred_types = updated.credential_types for ctype in cred_types: tag_attrs = ctype.get_tagged_attributes() if tag_attrs: tag_policy_updates[ctype.credential_def_id] = tag_attrs return Response(content_type="application/json", data={"result": updated.serialize()})