fix: add auth headers to HTTPWriter
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
fa43080602
commit
4eda0fb5cc
@ -7,8 +7,6 @@ from typing import List
|
|||||||
# External imports
|
# External imports
|
||||||
from chainlib.chain import ChainSpec
|
from chainlib.chain import ChainSpec
|
||||||
from chainlib.cli.config import Config
|
from chainlib.cli.config import Config
|
||||||
from cic_types.ext.metadata import MetadataRequestsHandler
|
|
||||||
from cic_types.ext.metadata.signer import Signer as MetadataSigner
|
|
||||||
|
|
||||||
# Local Modules
|
# Local Modules
|
||||||
from cic.contract.components.attachment import Attachment
|
from cic.contract.components.attachment import Attachment
|
||||||
@ -19,7 +17,8 @@ from cic.contract.helpers import init_writers_from_config
|
|||||||
from cic.contract.network import Network
|
from cic.contract.network import Network
|
||||||
from cic.contract.processor import ContractProcessor
|
from cic.contract.processor import ContractProcessor
|
||||||
from cic.writers import HTTPWriter, KeyedWriterFactory, MetadataWriter
|
from cic.writers import HTTPWriter, KeyedWriterFactory, MetadataWriter
|
||||||
|
from cic_types.ext.metadata import MetadataRequestsHandler
|
||||||
|
from cic_types.ext.metadata.signer import Signer as MetadataSigner
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -149,7 +148,7 @@ def deploy_contract(
|
|||||||
|
|
||||||
metadata_endpoint = config.get("META_URL")
|
metadata_endpoint = config.get("META_URL")
|
||||||
metadata_auth_token = config.get("META_AUTH_TOKEN")
|
metadata_auth_token = config.get("META_AUTH_TOKEN")
|
||||||
|
headers = {"Authorization": f"Basic {metadata_auth_token}"}
|
||||||
if metadata_endpoint is not None:
|
if metadata_endpoint is not None:
|
||||||
MetadataRequestsHandler.base_url = metadata_endpoint
|
MetadataRequestsHandler.base_url = metadata_endpoint
|
||||||
MetadataRequestsHandler.auth_token = metadata_auth_token
|
MetadataRequestsHandler.auth_token = metadata_auth_token
|
||||||
@ -168,12 +167,12 @@ def deploy_contract(
|
|||||||
)
|
)
|
||||||
ca = Attachment(
|
ca = Attachment(
|
||||||
path=contract_directory,
|
path=contract_directory,
|
||||||
writer=writers["attachment"](path=output_writer_path_meta),
|
writer=writers["attachment"](path=output_writer_path_meta, headers=headers),
|
||||||
)
|
)
|
||||||
cp = Proof(
|
cp = Proof(
|
||||||
path=contract_directory,
|
path=contract_directory,
|
||||||
attachments=ca,
|
attachments=ca,
|
||||||
writer=writers["proof"](path=output_writer_path_meta),
|
writer=writers["proof"](path=output_writer_path_meta, headers=headers),
|
||||||
)
|
)
|
||||||
cn = Network(path=contract_directory)
|
cn = Network(path=contract_directory)
|
||||||
|
|
||||||
|
@ -84,6 +84,7 @@ class ContractProcessor:
|
|||||||
if a is None:
|
if a is None:
|
||||||
logg.debug(f'skipping missing task receiver "{task}"')
|
logg.debug(f'skipping missing task receiver "{task}"')
|
||||||
continue
|
continue
|
||||||
|
logg.debug(f'Processing "{ext}:{task}"')
|
||||||
v = a.process(
|
v = a.process(
|
||||||
token_address=token_address,
|
token_address=token_address,
|
||||||
token_symbol=token_symbol,
|
token_symbol=token_symbol,
|
||||||
|
@ -5,7 +5,7 @@ import logging
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import urllib.request
|
import urllib.request
|
||||||
from typing import Type, Union
|
from typing import Dict, Type, Union
|
||||||
|
|
||||||
from cic_types.ext.metadata import MetadataPointer, MetadataRequestsHandler
|
from cic_types.ext.metadata import MetadataPointer, MetadataRequestsHandler
|
||||||
|
|
||||||
@ -33,6 +33,7 @@ class KVWriter(OutputWriter):
|
|||||||
os.makedirs(path)
|
os.makedirs(path)
|
||||||
self.path = path
|
self.path = path
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
def write(self, k, v):
|
def write(self, k, v):
|
||||||
fp = os.path.join(self.path, str(k))
|
fp = os.path.join(self.path, str(k))
|
||||||
logg.debug(f"path write {fp} {str(v)}")
|
logg.debug(f"path write {fp} {str(v)}")
|
||||||
@ -42,16 +43,17 @@ class KVWriter(OutputWriter):
|
|||||||
|
|
||||||
|
|
||||||
class HTTPWriter(OutputWriter):
|
class HTTPWriter(OutputWriter):
|
||||||
def __init__(self, path=None, *args, **kwargs):
|
def __init__(self, path=None, headers: Dict[str, str] = None, *args, **kwargs):
|
||||||
super(HTTPWriter, self).__init__(*args, **kwargs)
|
super(HTTPWriter, self).__init__(*args, **kwargs)
|
||||||
self.path = path
|
self.path = path
|
||||||
|
self.headers = headers
|
||||||
|
|
||||||
def write(self, k, v):
|
def write(self, k, v):
|
||||||
path = self.path
|
path = self.path
|
||||||
if k is not None:
|
if k is not None:
|
||||||
path = os.path.join(path, k)
|
path = os.path.join(path, k)
|
||||||
logg.debug(f"http writer post {path} \n key: {k}, value: {v}")
|
logg.debug(f"http writer post {path} \n key: {k}, value: {v}")
|
||||||
rq = urllib.request.Request(path, method="POST", data=v)
|
rq = urllib.request.Request(path, method="POST", data=v, headers=self.headers)
|
||||||
r = urllib.request.urlopen(rq)
|
r = urllib.request.urlopen(rq)
|
||||||
logg.info(f"http writer submitted at {r.read()}")
|
logg.info(f"http writer submitted at {r.read()}")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user