Skip to content

Commit

Permalink
chore: add authorization header support to contract download requests
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanchriswhite committed Dec 8, 2022
1 parent ce8e146 commit 4a28674
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions tests/helpers/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,26 @@ def register_stake_funds(self) -> Union[None, str]:
)


def ensure_contract(name: str, url: str) -> str:
def download_contract(url: str, token: Optional[str] = None) -> bytes:
headers = None
if token is not None:
headers = {"authorization": token}

response = requests.request("get", url, headers=headers)
return response.content


def ensure_contract(name: str, url: str, token: Optional[str] = None) -> str:
contract_path = f".contract/{name}.wasm"
if not os.path.exists(".contract"):
os.mkdir(".contract")
try:
temp = open(contract_path, "rb")
temp.close()
except OSError:
contract_request = requests.get(url)
contract_content = download_contract(url, token)
with open(contract_path, "wb") as file:
file.write(contract_request.content)
file.write(contract_content)
finally:
return contract_path

Expand Down Expand Up @@ -149,6 +158,7 @@ def __init__(self, client: LedgerClient, admin: Wallet, cfg: BridgeContractConfi

class AlmanacContract(LedgerContract):
def __init__(self, client: LedgerClient, admin: Wallet, cfg: AlmanacContractConfig = DefaultAlmanacContractConfig):
token = os.environ.get("GITHUB_AUTHORIZATION_TOKEN")
url = "https://github.com/fetchai/contract-agent-almanac/releases/download/v0.1.1/contract_agent_almanac.wasm"
contract_path = ensure_contract("almanac", url)
super().__init__(contract_path, client)
Expand Down

0 comments on commit 4a28674

Please sign in to comment.