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

Plugin configuration #1226

Merged
Merged
Show file tree
Hide file tree
Changes from 8 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
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"