Add attachment http writer

This commit is contained in:
nolash 2021-10-19 14:18:47 +02:00
parent 1269377c1f
commit 4518c8b700
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
3 changed files with 17 additions and 18 deletions

View File

@ -12,7 +12,7 @@ from cic import (
Proof, Proof,
Processor, Processor,
) )
from cic.proof import ProofWriter from cic.output import HTTPWriter
from cic.meta import ( from cic.meta import (
Meta, Meta,
MetadataWriter, MetadataWriter,
@ -66,7 +66,8 @@ def execute(config, eargs):
MetadataSigner.gpg_path = os.path.join('/tmp') MetadataSigner.gpg_path = os.path.join('/tmp')
MetadataSigner.key_file_path = '/home/lash/src/client/cic/grassrootseconomics/cic-internal-integration/apps/cic-ussd/tests/data/pgp/privatekeys_meta.asc' MetadataSigner.key_file_path = '/home/lash/src/client/cic/grassrootseconomics/cic-internal-integration/apps/cic-ussd/tests/data/pgp/privatekeys_meta.asc'
MetadataSigner.gpg_passphrase = 'merman' MetadataSigner.gpg_passphrase = 'merman'
writers['proof'] = ProofWriter writers['proof'] = HTTPWriter
writers['attachment'] = HTTPWriter
writers['meta'] = MetadataWriter writers['meta'] = MetadataWriter
output_writer_path_meta = eargs.metadata_endpoint output_writer_path_meta = eargs.metadata_endpoint

View File

@ -2,6 +2,7 @@
import os import os
import sys import sys
import logging import logging
import urllib.request
logg = logging.getLogger(__name__) logg = logging.getLogger(__name__)
@ -37,3 +38,16 @@ class KVWriter(OutputWriter):
f = open(fp, 'wb') f = open(fp, 'wb')
f.write(v) f.write(v)
f.close() f.close()
class HTTPWriter(OutputWriter):
def __init__(self, path=None, *args, **kwargs):
super(HTTPWriter, self).__init__(*args, **kwargs)
self.path = path
def write(self, k, v):
rq = urllib.request.Request(self.path, method='POST', data=v)
r = urllib.request.urlopen(rq)
logg.info('proof submited at {}'.format(r.read))

View File

@ -4,8 +4,6 @@ import json
import logging import logging
import tempfile import tempfile
import cbor2 import cbor2
import base64
import urllib.request
# external imports # external imports
from hexathon import strip_0x from hexathon import strip_0x
@ -127,17 +125,3 @@ class Proof(Data):
def __str__(self): def __str__(self):
return "description = {}\n".format(self.description) return "description = {}\n".format(self.description)
class ProofWriter(OutputWriter):
def __init__(self, path=None, *args, **kwargs):
super(ProofWriter, self).__init__(*args, **kwargs)
self.path = path
def write(self, k, v):
rq = urllib.request.Request(self.path, method='POST', data=v)
r = urllib.request.urlopen(rq)
logg.info('proof submited at {}'.format(r.read(dd)))