forked from openwallet-foundation/acapy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathargparse.py
1947 lines (1794 loc) · 72.1 KB
/
argparse.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""Command line option parsing."""
import abc
import json
from functools import reduce
from itertools import chain
from os import environ
from typing import Type
import deepmerge
import yaml
from configargparse import ArgumentParser, Namespace, YAMLConfigFileParser
from ..utils.tracing import trace_event
from .error import ArgsParseError
from .util import BoundedInt, ByteSize
from .plugin_settings import PLUGIN_CONFIG_KEY
CAT_PROVISION = "general"
CAT_START = "start"
CAT_UPGRADE = "upgrade"
ENDORSER_AUTHOR = "author"
ENDORSER_ENDORSER = "endorser"
ENDORSER_NONE = "none"
class ArgumentGroup(abc.ABC):
"""A class representing a group of related command line arguments."""
GROUP_NAME = None
@abc.abstractmethod
def add_arguments(self, parser: ArgumentParser):
"""Add arguments to the provided argument parser."""
@abc.abstractmethod
def get_settings(self, args: Namespace) -> dict:
"""Extract settings from the parsed arguments."""
class group:
"""Decorator for registering argument groups."""
_registered = []
def __init__(self, *categories):
"""Initialize the decorator."""
self.categories = tuple(categories)
def __call__(self, group_cls: ArgumentGroup):
"""Register a class in the given categories."""
setattr(group_cls, "CATEGORIES", self.categories)
self._registered.append((self.categories, group_cls))
return group_cls
@classmethod
def get_registered(cls, category: str = None):
"""Fetch the set of registered classes in a category."""
return (
grp
for (cats, grp) in cls._registered
if category is None or category in cats
)
def create_argument_parser(*, prog: str = None):
"""Create am instance of an arg parser, force yaml format for external config."""
return ArgumentParser(config_file_parser_class=YAMLConfigFileParser, prog=prog)
def load_argument_groups(parser: ArgumentParser, *groups: Type[ArgumentGroup]):
"""Log a set of argument groups into a parser.
Returns:
A callable to convert loaded arguments into a settings dictionary
"""
group_inst = []
for group in groups:
g_parser = parser.add_argument_group(group.GROUP_NAME)
inst = group()
inst.add_arguments(g_parser)
group_inst.append(inst)
def get_settings(args: Namespace):
settings = {}
try:
for group in group_inst:
settings.update(group.get_settings(args))
except ArgsParseError as e:
parser.print_help()
raise e
return settings
return get_settings
@group(CAT_START)
class AdminGroup(ArgumentGroup):
"""Admin server settings."""
GROUP_NAME = "Admin"
def add_arguments(self, parser: ArgumentParser):
"""Add admin-specific command line arguments to the parser."""
parser.add_argument(
"--admin",
type=str,
nargs=2,
metavar=("<host>", "<port>"),
env_var="ACAPY_ADMIN",
help=(
"Specify the host and port on which to run the administrative server. "
"If not provided, no admin server is made available."
),
)
parser.add_argument(
"--admin-api-key",
type=str,
metavar="<api-key>",
env_var="ACAPY_ADMIN_API_KEY",
help=(
"Protect all admin endpoints with the provided API key. "
"API clients (e.g. the controller) must pass the key in the HTTP "
"header using 'X-API-Key: <api key>'. Either this parameter or the "
"'--admin-insecure-mode' parameter MUST be specified."
),
)
parser.add_argument(
"--admin-insecure-mode",
action="store_true",
env_var="ACAPY_ADMIN_INSECURE_MODE",
help=(
"Run the admin web server in insecure mode. DO NOT USE FOR "
"PRODUCTION DEPLOYMENTS. The admin server will be publicly available "
"to anyone who has access to the interface. Either this parameter or "
"the '--api-key' parameter MUST be specified."
),
)
parser.add_argument(
"--no-receive-invites",
action="store_true",
env_var="ACAPY_NO_RECEIVE_INVITES",
help=(
"Prevents an agent from receiving invites by removing the "
"'/connections/receive-invite' route from the administrative "
"interface. Default: false."
),
)
parser.add_argument(
"--help-link",
type=str,
metavar="<help-url>",
env_var="ACAPY_HELP_LINK",
help=(
"A URL to an administrative interface help web page that a controller "
"user interface can get from the agent and provide as a link to users."
),
)
parser.add_argument(
"--webhook-url",
action="append",
metavar="<url#api_key>",
env_var="ACAPY_WEBHOOK_URL",
help=(
"Send webhooks containing internal state changes to the specified "
"URL. Optional API key to be passed in the request body can be "
"appended using a hash separator [#]. This is useful for a controller "
"to monitor agent events and respond to those events using the "
"admin API. If not specified, webhooks are not published by the agent."
),
)
parser.add_argument(
"--admin-client-max-request-size",
default=1,
type=BoundedInt(min=1, max=16),
env_var="ACAPY_ADMIN_CLIENT_MAX_REQUEST_SIZE",
help="Maximum client request size to admin server, in megabytes: default 1",
)
def get_settings(self, args: Namespace):
"""Extract admin settings."""
settings = {}
if args.admin:
admin_api_key = args.admin_api_key
admin_insecure_mode = args.admin_insecure_mode
if (admin_api_key and admin_insecure_mode) or not (
admin_api_key or admin_insecure_mode
):
raise ArgsParseError(
"Either --admin-api-key or --admin-insecure-mode "
"must be set but not both."
)
settings["admin.admin_api_key"] = admin_api_key
settings["admin.admin_insecure_mode"] = admin_insecure_mode
settings["admin.enabled"] = True
settings["admin.host"] = args.admin[0]
settings["admin.port"] = args.admin[1]
if args.help_link:
settings["admin.help_link"] = args.help_link
if args.no_receive_invites:
settings["admin.no_receive_invites"] = True
hook_urls = list(args.webhook_url) if args.webhook_url else []
hook_url = environ.get("WEBHOOK_URL")
if hook_url:
hook_urls.append(hook_url)
settings["admin.webhook_urls"] = hook_urls
settings["admin.admin_client_max_request_size"] = (
args.admin_client_max_request_size or 1
)
return settings
@group(CAT_START)
class DebugGroup(ArgumentGroup):
"""Debug settings."""
GROUP_NAME = "Debug"
def add_arguments(self, parser: ArgumentParser):
"""Add debug command line arguments to the parser."""
parser.add_argument(
"--debug",
action="store_true",
env_var="ACAPY_DEBUG",
help=(
"Enables a remote debugging service that can be accessed "
"using ptvsd for Visual Studio Code. The framework will wait "
"for the debugger to connect at start-up. Default: false."
),
)
parser.add_argument(
"--debug-seed",
dest="debug_seed",
type=str,
metavar="<debug-did-seed>",
env_var="ACAPY_DEBUG_SEED",
help="Specify the debug seed to use.",
)
parser.add_argument(
"--debug-connections",
action="store_true",
env_var="ACAPY_DEBUG_CONNECTIONS",
help="Enable additional logging around connections. Default: false.",
)
parser.add_argument(
"--debug-credentials",
action="store_true",
env_var="ACAPY_DEBUG_CREDENTIALS",
help=(
"Enable additional logging around credential exchanges. "
"Default: false."
),
)
parser.add_argument(
"--debug-presentations",
action="store_true",
env_var="ACAPY_DEBUG_PRESENTATIONS",
help=(
"Enable additional logging around presentation exchanges. "
"Default: false."
),
)
parser.add_argument(
"--invite",
action="store_true",
env_var="ACAPY_INVITE",
help=(
"After startup, generate and print a new out-of-band connection "
"invitation URL. Default: false."
),
)
parser.add_argument(
"--connections-invite",
action="store_true",
env_var="ACAPY_CONNECTIONS_INVITE",
help=(
"After startup, generate and print a new connections protocol "
"style invitation URL. Default: false."
),
)
parser.add_argument(
"--invite-label",
dest="invite_label",
type=str,
metavar="<label>",
env_var="ACAPY_INVITE_LABEL",
help="Specify the label of the generated invitation.",
)
parser.add_argument(
"--invite-multi-use",
action="store_true",
env_var="ACAPY_INVITE_MULTI_USE",
help="Flag specifying the generated invite should be multi-use.",
)
parser.add_argument(
"--invite-public",
action="store_true",
env_var="ACAPY_INVITE_PUBLIC",
help="Flag specifying the generated invite should be public.",
)
parser.add_argument(
"--invite-metadata-json",
type=str,
metavar="<metadata-json>",
env_var="ACAPY_INVITE_METADATA_JSON",
help="Add metadata json to invitation created with --invite argument.",
)
parser.add_argument(
"--test-suite-endpoint",
type=str,
metavar="<endpoint>",
env_var="ACAPY_TEST_SUITE_ENDPOINT",
help="URL endpoint for sending messages to the test suite agent.",
)
parser.add_argument(
"--auto-accept-invites",
action="store_true",
env_var="ACAPY_AUTO_ACCEPT_INVITES",
help=(
"Automatically accept invites without firing a webhook event or "
"waiting for an admin request. Default: false."
),
)
parser.add_argument(
"--auto-accept-requests",
action="store_true",
env_var="ACAPY_AUTO_ACCEPT_REQUESTS",
help=(
"Automatically accept connection requests without firing "
"a webhook event or waiting for an admin request. Default: false."
),
)
parser.add_argument(
"--auto-respond-messages",
action="store_true",
env_var="ACAPY_AUTO_RESPOND_MESSAGES",
help=(
"Automatically respond to basic messages indicating the message was "
"received. Default: false."
),
)
parser.add_argument(
"--auto-respond-credential-proposal",
action="store_true",
env_var="ACAPY_AUTO_RESPOND_CREDENTIAL_PROPOSAL",
help=(
"Auto-respond to credential proposals with corresponding "
"credential offers"
),
)
parser.add_argument(
"--auto-respond-credential-offer",
action="store_true",
env_var="ACAPY_AUTO_RESPOND_CREDENTIAL_OFFER",
help=(
"Automatically respond to Indy credential offers with a credential "
"request. Default: false"
),
)
parser.add_argument(
"--auto-respond-credential-request",
action="store_true",
env_var="ACAPY_AUTO_RESPOND_CREDENTIAL_REQUEST",
help="Auto-respond to credential requests with corresponding credentials",
)
parser.add_argument(
"--auto-respond-presentation-proposal",
action="store_true",
env_var="ACAPY_AUTO_RESPOND_PRESENTATION_PROPOSAL",
help=(
"Auto-respond to presentation proposals with corresponding "
"presentation requests"
),
)
parser.add_argument(
"--auto-respond-presentation-request",
action="store_true",
env_var="ACAPY_AUTO_RESPOND_PRESENTATION_REQUEST",
help=(
"Automatically respond to Indy presentation requests with a "
"constructed presentation if a corresponding credential can be "
"retrieved for every referent in the presentation request. "
"Default: false."
),
)
parser.add_argument(
"--auto-store-credential",
action="store_true",
env_var="ACAPY_AUTO_STORE_CREDENTIAL",
help=(
"Automatically store an issued credential upon receipt. "
"Default: false."
),
)
parser.add_argument(
"--auto-verify-presentation",
action="store_true",
env_var="ACAPY_AUTO_VERIFY_PRESENTATION",
help=(
"Automatically verify a presentation when it is received. "
"Default: false."
),
)
def get_settings(self, args: Namespace) -> dict:
"""Extract debug settings."""
settings = {}
if args.debug:
settings["debug.enabled"] = True
if args.debug_connections:
settings["debug.connections"] = True
if args.debug_credentials:
settings["debug.credentials"] = True
if args.debug_presentations:
settings["debug.presentations"] = True
if args.debug_seed:
settings["debug.seed"] = args.debug_seed
if args.invite:
settings["debug.print_invitation"] = True
if args.connections_invite:
settings["debug.print_connections_invitation"] = True
if args.invite_label:
settings["debug.invite_label"] = args.invite_label
if args.invite_multi_use:
settings["debug.invite_multi_use"] = True
if args.invite_public:
settings["debug.invite_public"] = True
if args.invite_metadata_json:
settings["debug.invite_metadata_json"] = args.invite_metadata_json
if args.test_suite_endpoint:
settings["debug.test_suite_endpoint"] = args.test_suite_endpoint
if args.auto_respond_credential_proposal:
settings["debug.auto_respond_credential_proposal"] = True
if args.auto_respond_credential_offer:
settings["debug.auto_respond_credential_offer"] = True
if args.auto_respond_credential_request:
settings["debug.auto_respond_credential_request"] = True
if args.auto_respond_presentation_proposal:
settings["debug.auto_respond_presentation_proposal"] = True
if args.auto_respond_presentation_request:
settings["debug.auto_respond_presentation_request"] = True
if args.auto_store_credential:
settings["debug.auto_store_credential"] = True
if args.auto_verify_presentation:
settings["debug.auto_verify_presentation"] = True
if args.auto_accept_invites:
settings["debug.auto_accept_invites"] = True
if args.auto_accept_requests:
settings["debug.auto_accept_requests"] = True
if args.auto_respond_messages:
settings["debug.auto_respond_messages"] = True
return settings
@group(CAT_START)
class DiscoverFeaturesGroup(ArgumentGroup):
"""Discover Features settings."""
GROUP_NAME = "Discover features"
def add_arguments(self, parser: ArgumentParser):
"""Add discover features specific command line arguments to the parser."""
parser.add_argument(
"--auto-disclose-features",
action="store_true",
env_var="ACAPY_AUTO_DISCLOSE_FEATURES",
help=(
"Specifies that the agent will proactively/auto disclose protocols"
" and goal-codes features on connection creation [RFC0557]."
),
)
parser.add_argument(
"--disclose-features-list",
type=str,
dest="disclose_features_list",
required=False,
env_var="ACAPY_DISCLOSE_FEATURES_LIST",
help="Load YAML file path that specifies which features to disclose.",
)
def get_settings(self, args: Namespace) -> dict:
"""Extract discover features settings."""
settings = {}
if args.auto_disclose_features:
settings["auto_disclose_features"] = True
if args.disclose_features_list:
with open(args.disclose_features_list, "r") as stream:
provided_lists = yaml.safe_load(stream)
if "protocols" in provided_lists:
settings["disclose_protocol_list"] = provided_lists.get("protocols")
if "goal-codes" in provided_lists:
settings["disclose_goal_code_list"] = provided_lists.get(
"goal-codes"
)
return settings
@group(CAT_PROVISION, CAT_START)
class GeneralGroup(ArgumentGroup):
"""General settings."""
GROUP_NAME = "General"
def add_arguments(self, parser: ArgumentParser):
"""Add general command line arguments to the parser."""
parser.add_argument(
"--arg-file",
is_config_file=True,
help=(
"Load aca-py arguments from the specified file. Note that "
"this file *must* be in YAML format."
),
)
parser.add_argument(
"--plugin",
dest="external_plugins",
type=str,
action="append",
required=False,
metavar="<module>",
env_var="ACAPY_PLUGIN",
help=(
"Load <module> as external plugin module. Multiple "
"instances of this parameter can be specified."
),
)
parser.add_argument(
"--block-plugin",
dest="blocked_plugins",
type=str,
action="append",
required=False,
metavar="<module>",
env_var="ACAPY_BLOCKED_PLUGIN",
help=(
"Block <module> plugin module from loading. Multiple "
"instances of this parameter can be specified."
),
)
parser.add_argument(
"--plugin-config",
dest="plugin_config",
type=str,
required=False,
env_var="ACAPY_PLUGIN_CONFIG",
help="Load YAML file path that defines external plugin configuration.",
)
parser.add_argument(
"-o",
"--plugin-config-value",
dest="plugin_config_values",
type=str,
nargs="+",
action="append",
required=False,
metavar="<KEY=VALUE>",
help=(
"Set an arbitrary plugin configuration option in the format "
"KEY=VALUE. Use dots in KEY to set deeply nested values, as in "
'"a.b.c=value". VALUE is parsed as yaml.'
),
)
parser.add_argument(
"--storage-type",
type=str,
metavar="<storage-type>",
env_var="ACAPY_STORAGE_TYPE",
help=(
"Specifies the type of storage provider to use for the internal "
"storage engine. This storage interface is used to store internal "
"state Supported internal storage types are 'basic' (memory) "
"and 'indy'. The default (if not specified) is 'indy' if the "
"wallet type is set to 'indy', otherwise 'basic'."
),
)
parser.add_argument(
"-e",
"--endpoint",
type=str,
nargs="+",
metavar="<endpoint>",
env_var="ACAPY_ENDPOINT",
help=(
"Specifies the endpoints to put into DIDDocs "
"to inform other agents of where they should send messages destined "
"for this agent. Each endpoint could be one of the specified inbound "
"transports for this agent, or the endpoint could be that of "
"another agent (e.g. 'https://example.com/agent-endpoint') if the "
"routing of messages to this agent by a mediator is configured. "
"The first endpoint specified will be used in invitations. "
"The endpoints are used in the formation of a connection "
"with another agent."
),
)
parser.add_argument(
"--profile-endpoint",
type=str,
metavar="<profile_endpoint>",
env_var="ACAPY_PROFILE_ENDPOINT",
help="Specifies the profile endpoint for the (public) DID.",
)
parser.add_argument(
"--read-only-ledger",
action="store_true",
env_var="ACAPY_READ_ONLY_LEDGER",
help="Sets ledger to read-only to prevent updates. Default: false.",
)
def get_settings(self, args: Namespace) -> dict:
"""Extract general settings."""
settings = {}
if args.external_plugins:
settings["external_plugins"] = args.external_plugins
if args.blocked_plugins:
settings["blocked_plugins"] = args.blocked_plugins
if args.plugin_config:
with open(args.plugin_config, "r") as stream:
settings[PLUGIN_CONFIG_KEY] = yaml.safe_load(stream)
if args.plugin_config_values:
if PLUGIN_CONFIG_KEY not in settings:
settings[PLUGIN_CONFIG_KEY] = {}
for value_str in chain(*args.plugin_config_values):
key, value = value_str.split("=", maxsplit=1)
value = yaml.safe_load(value)
deepmerge.always_merger.merge(
settings[PLUGIN_CONFIG_KEY],
reduce(lambda v, k: {k: v}, key.split(".")[::-1], value),
)
if args.storage_type:
settings["storage_type"] = args.storage_type
if args.endpoint:
settings["default_endpoint"] = args.endpoint[0]
settings["additional_endpoints"] = args.endpoint[1:]
else:
raise ArgsParseError("-e/--endpoint is required")
if args.profile_endpoint:
settings["profile_endpoint"] = args.profile_endpoint
if args.read_only_ledger:
settings["read_only_ledger"] = True
return settings
@group(CAT_START, CAT_PROVISION)
class RevocationGroup(ArgumentGroup):
"""Revocation settings."""
GROUP_NAME = "Revocation"
def add_arguments(self, parser: ArgumentParser):
"""Add revocation arguments to the parser."""
parser.add_argument(
"--tails-server-base-url",
type=str,
metavar="<tails-server-base-url>",
env_var="ACAPY_TAILS_SERVER_BASE_URL",
help="Sets the base url of the tails server in use.",
)
parser.add_argument(
"--tails-server-upload-url",
type=str,
metavar="<tails-server-upload-url>",
env_var="ACAPY_TAILS_SERVER_UPLOAD_URL",
help=(
"Sets the base url of the tails server for upload, defaulting to the "
"tails server base url."
),
)
parser.add_argument(
"--notify-revocation",
action="store_true",
env_var="ACAPY_NOTIFY_REVOCATION",
help=(
"Specifies that aca-py will notify credential recipients when "
"revoking a credential it issued."
),
)
parser.add_argument(
"--monitor-revocation-notification",
action="store_true",
env_var="ACAPY_MONITOR_REVOCATION_NOTIFICATION",
help=(
"Specifies that aca-py will emit webhooks on notification of "
"revocation received."
),
)
def get_settings(self, args: Namespace) -> dict:
"""Extract revocation settings."""
settings = {}
if args.tails_server_base_url:
settings["tails_server_base_url"] = args.tails_server_base_url
settings["tails_server_upload_url"] = args.tails_server_base_url
if args.tails_server_upload_url:
settings["tails_server_upload_url"] = args.tails_server_upload_url
if args.notify_revocation:
settings["revocation.notify"] = args.notify_revocation
if args.monitor_revocation_notification:
settings[
"revocation.monitor_notification"
] = args.monitor_revocation_notification
return settings
@group(CAT_START, CAT_PROVISION)
class LedgerGroup(ArgumentGroup):
"""Ledger settings."""
GROUP_NAME = "Ledger"
def add_arguments(self, parser: ArgumentParser):
"""Add ledger-specific command line arguments to the parser."""
parser.add_argument(
"--ledger-pool-name",
type=str,
metavar="<ledger-pool-name>",
env_var="ACAPY_LEDGER_POOL_NAME",
help=(
"Specifies the name of the indy pool to be opened. "
"This is useful if you have multiple pool configurations."
),
)
parser.add_argument(
"--genesis-transactions",
type=str,
dest="genesis_transactions",
metavar="<genesis-transactions>",
env_var="ACAPY_GENESIS_TRANSACTIONS",
help=(
"Specifies the genesis transactions to use to connect to "
"a Hyperledger Indy ledger. The transactions are provided as string "
'of JSON e.g. \'{"reqSignature":{},"txn":{"data":{"d... <snip>}}}\''
),
)
parser.add_argument(
"--genesis-file",
type=str,
dest="genesis_file",
metavar="<genesis-file>",
env_var="ACAPY_GENESIS_FILE",
help="Specifies a local file from which to read the genesis transactions.",
)
parser.add_argument(
"--genesis-url",
type=str,
dest="genesis_url",
metavar="<genesis-url>",
env_var="ACAPY_GENESIS_URL",
help=(
"Specifies the url from which to download the genesis "
"transactions. For example, if you are using 'von-network', "
"the URL might be 'http://localhost:9000/genesis'. "
"Genesis transactions URLs are available for the "
"Sovrin test/main networks."
),
)
parser.add_argument(
"--no-ledger",
action="store_true",
env_var="ACAPY_NO_LEDGER",
help=(
"Specifies that aca-py will run with no ledger configured. "
"This must be set if running in no-ledger mode. Overrides any "
"specified ledger or genesis configurations. Default: false."
),
)
parser.add_argument(
"--ledger-keepalive",
default=5,
type=BoundedInt(min=5),
env_var="ACAPY_LEDGER_KEEP_ALIVE",
help="Specifies how many seconds to keep the ledger open. Default: 5",
)
parser.add_argument(
"--ledger-socks-proxy",
type=str,
dest="ledger_socks_proxy",
metavar="<host:port>",
required=False,
env_var="ACAPY_LEDGER_SOCKS_PROXY",
help=(
"Specifies the socks proxy (NOT http proxy) hostname and port in format "
"'hostname:port'. This is an optional parameter to be passed to ledger "
"pool configuration and ZMQ in case if aca-py is running "
"in a corporate/private network behind a corporate proxy and will "
"connect to the public (outside of corporate network) ledger pool"
),
)
parser.add_argument(
"--genesis-transactions-list",
type=str,
required=False,
dest="genesis_transactions_list",
metavar="<genesis-transactions-list>",
env_var="ACAPY_GENESIS_TRANSACTIONS_LIST",
help=(
"Load YAML configuration for connecting to multiple"
" HyperLedger Indy ledgers."
),
)
parser.add_argument(
"--accept-taa",
type=str,
nargs=2,
metavar=("<acceptance-mechanism>", "<taa-version>"),
env_var="ACAPY_ACCEPT_TAA",
help=(
"Specify the acceptance mechanism and taa version for which to accept"
" the transaction author agreement. If not provided, the TAA must"
" be accepted through the TTY or the admin API."
),
)
def get_settings(self, args: Namespace) -> dict:
"""Extract ledger settings."""
settings = {}
if args.no_ledger:
settings["ledger.disabled"] = True
else:
configured = False
if args.genesis_url:
settings["ledger.genesis_url"] = args.genesis_url
configured = True
elif args.genesis_file:
settings["ledger.genesis_file"] = args.genesis_file
configured = True
elif args.genesis_transactions:
settings["ledger.genesis_transactions"] = args.genesis_transactions
configured = True
if args.genesis_transactions_list:
with open(args.genesis_transactions_list, "r") as stream:
txn_config_list = yaml.safe_load(stream)
ledger_config_list = []
for txn_config in txn_config_list:
ledger_config_list.append(txn_config)
settings["ledger.ledger_config_list"] = ledger_config_list
configured = True
if not configured:
raise ArgsParseError(
"One of --genesis-url --genesis-file, --genesis-transactions "
"or --genesis-transactions-list must be specified (unless "
"--no-ledger is specified to explicitly configure aca-py to"
" run with no ledger)."
)
if args.ledger_pool_name:
settings["ledger.pool_name"] = args.ledger_pool_name
if args.ledger_keepalive:
settings["ledger.keepalive"] = args.ledger_keepalive
if args.ledger_socks_proxy:
settings["ledger.socks_proxy"] = args.ledger_socks_proxy
if args.accept_taa:
settings["ledger.taa_acceptance_mechanism"] = args.accept_taa[0]
settings["ledger.taa_acceptance_version"] = args.accept_taa[1]
return settings
@group(CAT_PROVISION, CAT_START)
class LoggingGroup(ArgumentGroup):
"""Logging settings."""
GROUP_NAME = "Logging"
def add_arguments(self, parser: ArgumentParser):
"""Add logging-specific command line arguments to the parser."""
parser.add_argument(
"--log-config",
dest="log_config",
type=str,
metavar="<path-to-config>",
default=None,
env_var="ACAPY_LOG_CONFIG",
help="Specifies a custom logging configuration file",
)
parser.add_argument(
"--log-file",
dest="log_file",
type=str,
metavar="<log-file>",
default=None,
env_var="ACAPY_LOG_FILE",
help=(
"Overrides the output destination for the root logger (as defined "
"by the log config file) to the named <log-file>."
),
)
parser.add_argument(
"--log-level",
dest="log_level",
type=str,
metavar="<log-level>",
default=None,
env_var="ACAPY_LOG_LEVEL",
help=(
"Specifies a custom logging level as one of: "
"('debug', 'info', 'warning', 'error', 'critical')"
),
)
def get_settings(self, args: Namespace) -> dict:
"""Extract logging settings."""
settings = {}
if args.log_config:
settings["log.config"] = args.log_config
if args.log_file:
settings["log.file"] = args.log_file
if args.log_level:
settings["log.level"] = args.log_level
return settings
@group(CAT_START)
class ProtocolGroup(ArgumentGroup):
"""Protocol settings."""
GROUP_NAME = "Protocol"
def add_arguments(self, parser: ArgumentParser):
"""Add protocol-specific command line arguments to the parser."""
parser.add_argument(
"--auto-ping-connection",
action="store_true",
env_var="ACAPY_AUTO_PING_CONNECTION",
help=(
"Automatically send a trust ping immediately after a "
"connection response is accepted. Some agents require this before "
"marking a connection as 'active'. Default: false."
),
)
parser.add_argument(
"--auto-accept-intro-invitation-requests",
action="store_true",
env_var="ACAPY_AUTO_ACCEPT_INTRO_INVITATION_REQUESTS",
help="Automatically accept introduction invitations. Default: false.",
)
parser.add_argument(
"--invite-base-url",
type=str,
metavar="<base-url>",
env_var="ACAPY_INVITE_BASE_URL",
help=(
"Base URL to use when formatting connection invitations in URL format."
),
)
parser.add_argument(
"--monitor-ping",
action="store_true",
env_var="ACAPY_MONITOR_PING",
help="Send a webhook when a ping is sent or received.",
)
parser.add_argument(
"--monitor-forward",
action="store_true",
env_var="ACAPY_MONITOR_FORWARD",
help="Send a webhook when a forward is received.",
)
parser.add_argument(
"--public-invites",
action="store_true",
env_var="ACAPY_PUBLIC_INVITES",
help=(
"Send invitations out, and receive connection requests, "
"using the public DID for the agent. Default: false."
),
)
parser.add_argument(
"--timing",
action="store_true",
env_var="ACAPY_TIMING",
help="Include timing information in response messages.",
)
parser.add_argument(
"--timing-log",
type=str,
metavar="<log-path>",
env_var="ACAPY_TIMING_LOG",
help="Write timing information to a given log file.",
)
parser.add_argument(