Skip to content

Commit

Permalink
Merge pull request #1226 from sicpa-dlab/feature/plugin-config-by-file
Browse files Browse the repository at this point in the history
Plugin configuration
  • Loading branch information
dbluhm authored Jun 8, 2021
2 parents 6b979b3 + 48abba1 commit d11bb8c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
20 changes: 20 additions & 0 deletions aries_cloudagent/config/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import abc
from os import environ

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

Expand Down Expand Up @@ -477,6 +478,20 @@ def add_arguments(self, parser: ArgumentParser):
"instances of this parameter can be specified."
),
)

parser.add_argument(
"--plugin-config",
dest="plugin_config",
type=str,
required=False,
env_var="ACAPY_PLUGINS_CONFIG",
help="Load YAML file path that defines external plugins configuration. "
"The plugin should be loaded first by --plugin arg. "
"Then the config file must be a key-value mapping. "
"The key is the plugin argument and "
"the value of the specific configuration for that plugin.",
)

parser.add_argument(
"--storage-type",
type=str,
Expand Down Expand Up @@ -545,6 +560,11 @@ def get_settings(self, args: Namespace) -> dict:
settings = {}
if args.external_plugins:
settings["external_plugins"] = args.external_plugins

if args.plugin_config:
with open(args.plugin_config, "r") as stream:
settings["plugin_config"] = yaml.safe_load(stream)

if args.storage_type:
settings["storage_type"] = args.storage_type

Expand Down
28 changes: 28 additions & 0 deletions aries_cloudagent/config/tests/test_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from asynctest import TestCase as AsyncTestCase, mock as async_mock

from .. import argparse
from ..error import ArgsParseError
from ..util import BoundedInt, ByteSize


Expand Down Expand Up @@ -173,6 +174,33 @@ async def test_general_settings_file(self):
assert settings.get("external_plugins") == ["foo"]
assert settings.get("storage_type") == "bar"

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

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

result = parser.parse_args(
[
"--endpoint",
"localhost",
"--plugin-config",
"./aries_cloudagent/config/tests/test_plugins_config.yaml",
]
)

assert (
result.plugin_config
== "./aries_cloudagent/config/tests/test_plugins_config.yaml"
)

settings = group.get_settings(result)

assert settings.get("plugin_config").get("mock_resolver") == {
"methods": ["sov", "btcr"]
}

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

Expand Down
4 changes: 4 additions & 0 deletions aries_cloudagent/config/tests/test_plugins_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mock_resolver:
methods:
- "sov"
- "btcr"

0 comments on commit d11bb8c

Please sign in to comment.