Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert config files to yaml and force yaml formal for config files #748

Merged
merged 4 commits into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions aries_cloudagent/commands/provision.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from typing import Sequence

from ..config import argparse as arg
from ..config.base import BaseError
from ..config.default_context import DefaultContextBuilder
from ..config.base import BaseError
from ..config.ledger import ledger_config
from ..config.util import common_config
from ..config.wallet import wallet_config
Expand Down Expand Up @@ -41,7 +41,7 @@ async def provision(settings: dict):

def execute(argv: Sequence[str] = None):
"""Entrypoint."""
parser = ArgumentParser()
parser = arg.create_argument_parser()
parser.prog += " provision"
get_settings = init_argument_parser(parser)
args = parser.parse_args(argv)
Expand Down
2 changes: 1 addition & 1 deletion aries_cloudagent/commands/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def init_argument_parser(parser: ArgumentParser):

def execute(argv: Sequence[str] = None):
"""Entrypoint."""
parser = ArgumentParser()
parser = arg.create_argument_parser()
parser.prog += " start"
get_settings = init_argument_parser(parser)
args = parser.parse_args(argv)
Expand Down
10 changes: 8 additions & 2 deletions aries_cloudagent/config/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import abc
from os import environ

from configargparse import ArgumentParser, Namespace
from configargparse import ArgumentParser, Namespace, YAMLConfigFileParser
from typing import Type

from .error import ArgsParseError
Expand Down Expand Up @@ -53,6 +53,11 @@ def get_registered(cls, category: str = None):
)


def create_argument_parser():
"""Create am instance of an arg parser, force yaml format for external config."""
return ArgumentParser(config_file_parser_class=YAMLConfigFileParser)


def load_argument_groups(parser: ArgumentParser, *groups: Type[ArgumentGroup]):
"""Log a set of argument groups into a parser.

Expand Down Expand Up @@ -394,7 +399,8 @@ def add_arguments(self, parser: ArgumentParser):
parser.add_argument(
"--arg-file",
is_config_file=True,
help="Load aca-py arguments from the specified file.",
help="Load aca-py arguments from the specified file. Note that\
this file *must* be in YAML format.",
)
parser.add_argument(
"--plugin",
Expand Down
7 changes: 0 additions & 7 deletions aries_cloudagent/config/tests/test-general-args.cfg

This file was deleted.

4 changes: 4 additions & 0 deletions aries_cloudagent/config/tests/test-general-args.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# see: https://pypi.org/project/ConfigArgParse/
plugin: foo # ... also a comment
storage-type: bar
endpoint: test_endpoint
5 changes: 5 additions & 0 deletions aries_cloudagent/config/tests/test-transport-args.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# see: https://pypi.org/project/ConfigArgParse/
inbound-transport:
- [http, 0.0.0.0, 8030]
- [ws, 0.0.0.0, 8040]
outbound-transport: http
33 changes: 27 additions & 6 deletions aries_cloudagent/config/tests/test_argparse.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import itertools
from configargparse import ArgumentParser, ArgumentTypeError
from configargparse import ArgumentParser, ArgumentTypeError, YAMLConfigFileParser

from asynctest import TestCase as AsyncTestCase, mock as async_mock

Expand All @@ -10,7 +10,7 @@
class TestArgParse(AsyncTestCase):
async def test_groups(self):
"""Test optional argument parsing."""
parser = ArgumentParser()
parser = argparse.create_argument_parser()

groups = (
g
Expand All @@ -24,7 +24,7 @@ async def test_groups(self):
async def test_transport_settings(self):
"""Test required argument parsing."""

parser = ArgumentParser()
parser = argparse.create_argument_parser()
group = argparse.TransportGroup()
group.add_arguments(parser)

Expand Down Expand Up @@ -54,10 +54,10 @@ async def test_transport_settings(self):
assert settings.get("transport.outbound_configs") == ["http"]
assert result.max_outbound_retry == 5

async def test_transport_settings_file(self):
async def test_general_settings_file(self):
"""Test file argument parsing."""

parser = ArgumentParser()
parser = argparse.create_argument_parser()
group = argparse.GeneralGroup()
group.add_arguments(parser)

Expand All @@ -68,7 +68,7 @@ async def test_transport_settings_file(self):
result = parser.parse_args(
[
"--arg-file",
"./aries_cloudagent/config/tests/test-general-args.cfg",
"./aries_cloudagent/config/tests/test-general-args.yaml",
]
)

Expand All @@ -80,6 +80,27 @@ async def test_transport_settings_file(self):
assert settings.get("external_plugins") == ["foo"]
assert settings.get("storage_type") == "bar"

async def test_transport_settings_file(self):
"""Test file argument parsing."""

parser = argparse.create_argument_parser()
group = argparse.GeneralGroup()
group.add_arguments(parser)
group = argparse.TransportGroup()
group.add_arguments(parser)

with async_mock.patch.object(parser, "exit") as exit_parser:
parser.parse_args(["-h"])
exit_parser.assert_called_once()

result = parser.parse_args(
[
"--arg-file",
"./aries_cloudagent/config/tests/test-transport-args.yaml",
]
)
# no asserts, just testing that the parser doesn't fail

def test_bytesize(self):
bs = ByteSize()
with self.assertRaises(ArgumentTypeError):
Expand Down
25 changes: 9 additions & 16 deletions demo/demo-args.cfg → demo/demo-args.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
# see: https://pypi.org/project/ConfigArgParse/ for file format overview

# this runs aca-py with a minumum set of parameters

# the following are quivalent to:
# ./bin/aca-py start -it http 0.0.0.0 8020 -ot http --endpoint http://localhost:8020 --admin-insecure-mode --admin 0.0.0.0 8021 --no-ledger

# run as:
# ./bin/aca-py start --arg-file ./demo/demo-args.cfg

inbound-transport = [[http, 0.0.0.0, 8030], [ws, 0.0.0.0, 8040]]

outbound-transport = http

endpoint = http://192.168.0.48:8030

admin-insecure-mode = true

admin = [0.0.0.0, 8031]

no-ledger = true
# ./bin/aca-py start --arg-file ./demo/demo-args.yaml
inbound-transport:
- [http, 0.0.0.0, 8030]
- [ws, 0.0.0.0, 8040]
outbound-transport: http
endpoint: http://192.168.0.48:8030
admin-insecure-mode: true
admin: [0.0.0.0, 8031]
no-ledger: true
40 changes: 17 additions & 23 deletions demo/local-indy-args.cfg → demo/local-indy-args.yaml
Original file line number Diff line number Diff line change
@@ -1,43 +1,37 @@
# see: https://pypi.org/project/ConfigArgParse/ for file format overview

# before running aca-py, run the following (the commands are embedded below, next to the related parameters):
# - run a local postgres database
# - run a local instance of von-network
# - register your did (seed) on the network

# run aca-py as:
# ACAPY_WALLET_SEED=my_seed_000000000000000000000000 ACAPY_WALLET_KEY=key ./bin/aca-py start --arg-file ./demo/local-indy-args.cfg

admin-insecure-mode = true
admin = [0.0.0.0, 8031]
label = My Indy Agent

# ACAPY_WALLET_SEED=my_seed_000000000000000000000000 ACAPY_WALLET_KEY=key ./bin/aca-py start --arg-file ./demo/local-indy-args.yaml
admin-insecure-mode: true
admin: [0.0.0.0, 8031]
label: My Indy Agent
# the following is the callback url for your controller
webhook-url = http://localhost:7000/agentcb

webhook-url: http://localhost:7000/agentcb
# assumes you are running a local von-network, like:
# cd von-network
# ./manage start <my local ip>
genesis-url = http://localhost:9000/genesis

inbound-transport = [[http, 0.0.0.0, 8030], [ws, 0.0.0.0, 8040]]
outbound-transport = http
genesis-url: http://localhost:9000/genesis
inbound-transport:
- [http, 0.0.0.0, 8030]
- [ws, 0.0.0.0, 8040]
outbound-transport: http
# the following is the public endpoint advertised by the agent
endpoint = http://192.168.0.48:8030
auto-ping-connection = true

endpoint: http://192.168.0.48:8030
auto-ping-connection: true
# register your did using (this example is for von-network):
# curl -d '{"seed":"my_seed_000000000000000000000000", "role":"TRUST_ANCHOR", "alias":"My Agent"}' -X POST http://localhost:9000/register
# note that the env var name is configured in argparse.py
# seed = comes from ACAPY_WALLET_SEED
wallet-type = indy
wallet-name = testwallet
wallet-type: indy
wallet-name: testwallet
# wallet-key = comes from ACAPY_WALLET_KEY

# run a local postgres (docker) like:
# docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d -p 5432:5432 postgres:10
wallet-storage-type = postgres_storage
wallet-storage-type: postgres_storage
# could be sent using env var ACAPY_WALLET_STORAGE_CONFIG
wallet-storage-config = {"url":"localhost:5432","max_connections":5}
wallet-storage-config: '{"url":"localhost:5432","max_connections":5}'
# could be sent using env var ACAPY_WALLET_STORAGE_CREDS
wallet-storage-creds = {"account":"postgres","password":"mysecretpassword","admin_account":"postgres","admin_password":"mysecretpassword"}
wallet-storage-creds: '{"account":"postgres","password":"mysecretpassword","admin_account":"postgres","admin_password":"mysecretpassword"}'
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ pynacl~=1.3.0
requests~=2.23.0
pyld==2.0.1
py_multicodec==0.2.1
git+https://github.com/ianco/ConfigArgParse.git#egg=ConfigArgParse
pyyaml~=5.3.1
ConfigArgParse~=1.2.3