-
Notifications
You must be signed in to change notification settings - Fork 5
/
configuration.rst
1842 lines (1248 loc) · 81 KB
/
configuration.rst
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
.. include:: references.rst
.. _configuration:
Configuration
=============
At startup, `Magpie` application will load multiple configuration files to define various behaviours or setup
operations. These are defined through the configuration settings presented in below sections.
All generic `Magpie` configuration settings can be defined through either the `magpie.ini`_ file or environment
variables. Values defined in `magpie.ini`_ are expected to follow the ``magpie.[variable_name]`` format, and
corresponding ``MAGPIE_[VARIABLE_NAME]`` format is used for environment variables. Both of these alternatives match
the constants defined in `constants.py`_ and can be used interchangeably.
.. versionchanged:: 1.1
Order of resolution will prioritize *setting configurations* over *environment variables* in case of duplicates
resulting into different values. Environment variables will not override already specified setting values.
Previous versions of `Magpie` would instead prioritize environment variables, but this behaviour was deemed as
counter intuitive. This is attributed to the global scope nature of environment variables that often made it hard
to understand why some custom INI file would not behave as intended since those variable would inconsistently take
precedence whether or not they were defined. Using a common configuration file makes it easier to maintain and
understand the applied settings, and is therefore preferable.
Configuration Files
-------------------
.. _config_magpie_ini:
File: magpie.ini
~~~~~~~~~~~~~~~~~~~
This is the base configuration file that defines most of `Magpie`'s lower level configuration. A basic example is
provided in `magpie.ini`_ which should allow any user to run the application locally. Furthermore, this file
is used by default in each tagged Docker image. If you want to provide different configuration, the file should be
overridden in the Docker image using a volume mount parameter, or by specifying an alternative path through the
environment variable :envvar:`MAGPIE_INI_FILE_PATH`.
.. _config_magpie_env:
File: magpie.env
~~~~~~~~~~~~~~~~~~~
By default, `Magpie` will try to load a ``magpie.env`` file which can define further environment variable definitions
used to setup the application (see :envvar:`MAGPIE_ENV_FILE` setting further below). An example of expected format and
common variables for this file is presented in `magpie.env.example`_.
.. warning::
If ``magpie.env`` cannot be found (e.g.: using setting :envvar:`MAGPIE_ENV_FILE`) but `magpie.env.example`_ is
available after resolving any previously set :envvar:`MAGPIE_ENV_DIR` variable, this example file will be used to
make a copy saved as ``magpie.env`` and will be used as the base ``.env`` file to load its contained environment
variables. This behaviour is intended to reduce initial configuration and preparation of `Magpie` for a new user.
When loading variables from the ``.env`` file, any conflicting environment variable will **NOT** be overridden.
Therefore, only *missing but required* values will be added to the environment to ensure proper setup of `Magpie`.
.. _config_postgres_env:
File: postgres.env
~~~~~~~~~~~~~~~~~~~
This file behaves exactly in the same manner as for ``magpie.env`` above, but for specific variables definition
employed to setup the `PostgreSQL`_ database connection (see :envvar:`MAGPIE_POSTGRES_ENV_FILE` setting below).
File `postgres.env.example`_ and auto-resolution of missing ``postgres.env`` is identical to ``magpie.env``
case.
.. _config_providers:
File: providers.cfg
~~~~~~~~~~~~~~~~~~~
This configuration file allows automatically registering :term:`Service` definitions in `Magpie` at startup. When the
application starts, it will look for corresponding services and add them to the database as required. It will also
look for mismatches between the :term:`Service` name and URL with the corresponding entry in the database to update it
to the desired URL. See :envvar:`MAGPIE_PROVIDERS_CONFIG_PATH` setting below to setup alternate references to this type
of configuration. Please refer to the comment header of sample file `providers.cfg`_ for specific format and parameter
details.
.. versionchanged:: 3.1
Some services, such as :ref:`ServiceTHREDDS` for instance, can take additional parameters to customize some of
their behaviour. Please refer to :ref:`Services` chapter for specific configuration supported.
.. _config_permissions:
File: permissions.cfg
~~~~~~~~~~~~~~~~~~~~~~
This configuration file allows automatically registering or cleaning :term:`Permission` definitions in `Magpie` at
startup. Each specified update operation is applied for the corresponding :term:`User` and/or :term:`Group` onto the
specific :term:`Service` or :term:`Resource`. This file is processed after `providers.cfg`_ in order to allow
permissions to be applied on freshly registered services. Furthermore, sub-resources are automatically created if they
can be iteratively resolved with provided parameters of the corresponding permission entry. Resources should be defined
using tree-path in this case, as described by format in
:func:`magpie.api.management.resources.resources_utils.get_resource_path` or in example `permissions.cfg`_.
See :envvar:`MAGPIE_PERMISSIONS_CONFIG_PATH` setting below to setup alternate references to this type of configuration.
Please refer to the comment header of sample file `permissions.cfg`_ for specific format details as well as specific
behaviour of each parameter according to encountered use cases.
.. _config_formats:
Configuration File Formats
~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. versionchanged:: 1.9.2
Any file represented in the :ref:`Configuration` chapter using any of the extension ``.cfg``, ``.json``, ``.yaml`` or
``.yml`` will be accepted interchangeably if provided. Both parsing as JSON and YAML will be attempted for backward
compatibility of each resolved file path.
It is not mandatory for the name of each file to also match the employed name in the documentation, provided
the paths can be resolved to valid files, though there is special handling of default ``.example`` extensions with
matching file names when no other alternative configurations can be found. Again, this is mostly for backward
compatibility.
.. _config_file:
Combined Configuration File
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. versionadded:: 2.0
Since contents of all different configurations files (`providers.cfg`_, `permissions.cfg`_) reside under distinct
top-level objects, it is actually possible to use an unique file to define everything. For example, one could define
a combined configuration as follows.
.. code-block:: YAML
# inside 'config.yml'
providers:
some-service:
url: http://${HOSTNAME}:8000
title: Some Service
public: true
c4i: false
type: api
hooks: [] # see 'Service Hooks' section below for more details
groups:
- name: my-group
description: My Custom Group
discoverable: false
users:
- username: my-user
group: my-group # will reference above group
permissions:
- service: api
resource: /resource/user-resource # will create both resources respecting children relationship
type: route # not mandatory here since service type 'api' only allows this type, but useful for other cases
permission: read
user: my-user # will reference above user
action: create
- service: api
resource: /groups
permission: read
group: my-group # will reference above group
action: create
webhooks: # see 'Webhook Configuration' below for more details
- name: <webhook_name>
action: <webhook_action>
method: GET | HEAD | POST | PUT | PATCH | DELETE
url: <location>
payload:
<param_raw>: "value" # some literal value that will be added to the payload as is
<param_subst>: "{<param_value>}" # <param_value> will be substituted (must be available for that action)
...
For backward compatibility reasons, `Magpie` will first look for separate files to load each section individually.
To enforce using a combined file as above *instead of the separate files*, either provide
``MAGPIE_CONFIG_PATH = <path>/config.yml``, or ensure that both environment variable
:envvar:`MAGPIE_PROVIDERS_CONFIG_PATH` and :envvar:`MAGPIE_PERMISSIONS_CONFIG_PATH` specifically
refer to this same YAML file. For all of these variables, ``magpie.[variable_name]`` formatted settings are also
supported through definitions within ``magpie.ini``.
When loading configurations from a combined file, the order of resolution of each section is the same as when loading
definitions from multiple files, meaning that ``providers`` are first registered, followed by individual
``permissions``, with the dynamic creation of any missing ``user`` or ``group`` during this process. If an explicit
``user`` or ``group`` definition can be found under the relevant sections, additional parameters are employed for their
creation. Otherwise defaults are assumed and only the specified user or group name are employed. Please refer to files
`providers.cfg`_ and `permissions.cfg`_ for further details about specific formatting and behaviour of each available
field.
.. versionadded:: 3.6
The ``webhook`` section allows to define external connectors to which `Magpie` should send requests following
certain events. These are described in further details in :ref:`config_webhook` section.
.. versionadded:: 3.12
Variable :envvar:`MAGPIE_WEBHOOKS_CONFIG_PATH` was added and will act in a similar fashion as their providers and
permissions counterparts, to load definitions from multiple configuration files.
.. _config_service_hooks:
Service Hooks
~~~~~~~~~~~~~~~~~~~~~~
.. versionadded:: 3.25
.. warning::
Requires `Twitcher`_ version ``0.7.0`` minimally to use this feature. Versions ``0.6.x`` of `Twitcher`_ remain
compatible but will not call the adapter hooks as the feature did not exist at that point.
Under each :term:`Service` within `providers.cfg`_ or the :ref:`config_file`, it is possible to provide a section
named ``hooks`` that lists additional pre/post request/response processing operations to apply when matched against
the given request filter conditions. These hooks are plugin-based Python scripts that can modify the proxied request
and response when `Magpie` and `Twitcher`_ work together using the :ref:`utilities_adapter<Magpie Adapter>`.
Each :term:`Service Hook` must be configured using the following parameters.
.. list-table:: :term:`Service Hook` configuration
:header-rows: 1
:stub-columns: 1
:widths: 10,10,80
* - Field
- Requirement
- Description
* - ``type``
- **required**
- Literal string ``{ request | response }`` of the desired instance where to invoke the hook.
* - ``path``
- **required**
- :term:`Service`-specific request path or regular expression pattern to be matched for invoking the hook.
Path starts after `Twitcher`_ proxy prefix path and :term:`Service` name (i.e.: path as if there was no proxy).
* - ``method``
- *optional*
- Literal string ``{ HEAD | GET | POST | PUT | PATCH | DELETE | * }`` (default: ``*`` representing any method).
HTTP method that must be matched for invoking the hook.
* - ``query``
- *optional*
- Request query string or regular expression pattern to be matched for invoking the hook (default: ``.*``).
Matches anything if not specified. To match explicitly no-query condition, provide an empty string (``""``).
* - ``target``
- **required**
- Location of the function that will handle hook processing when request matching conditions are met.
Path should be absolute or relative to :envvar:`MAGPIE_ROOT` and must be a valid Python file.
Path should include the function name using format: ``some/path/script.py:func``.
More specifically, when a :term:`Service` or children :term:`Resource` is accessed, triggering a proxied request
through `Twitcher`_, the authenticated and authorized request goes through ``hooks`` processing chain that can adjust
certain request and response parameters (e.g.: add headers, filter the body, etc.), or even substitute the request
definition entirely based on ``target`` implementations. Hooks are applied in the same order as they are defined in
the configuration when they match the inbound request, propagating the request/response across each :term:`Service Hook`
call. Plugin scripts can therefore apply some advanced logic to improve the synergy between the protected services.
They can also be employed to apply some :term:`Service` specific operations such as filtering protected contents
that `Magpie` and `Twitcher`_ cannot themselves process evidently. :term:`Service Hook` are applied *after*
authentication and authorization of the request, just before sending the request to the real protected :term:`Service`
(in case of ``request`` hook), and just after receiving its response (in case of ``response`` hook.
Permitted signatures of :term:`Service Hook` functions are as presented below.
The first argument (``request`` or ``response`` respectively) is **always required**. Its modified definition must be
returned as well. The other parameters (``service``, ``hook``, ``context``) are all optional. They represent the
specific configurations that triggered the ``target`` call. Optional arguments can be specified in any order or
combination, but **MUST** use the exact argument names indicated below.
.. versionchanged:: 3.26.0
Added the ``context`` parameter.
.. code-block:: python
def request_hook(request: pyramid.request.Request) -> pyramid.request.Request: ...
def request_hook(request: pyramid.request.Request,
service: magpie.typedefs.ServiceConfigItem,
hook: magpie.typedefs.ServiceHookConfigItem,
context: magpie.adapter.HookContext,
) -> pyramid.request.Request: ...
def response_hook(response: pyramid.response.Response) -> pyramid.response.Response: ...
def response_hook(response: pyramid.response.Response,
service: magpie.typedefs.ServiceConfigItem,
hook: magpie.typedefs.ServiceHookConfigItem,
context: magpie.adapter.HookContext,
) -> pyramid.response.Response: ...
.. list-table:: :term:`Service Hook` function parameters
:header-rows: 1
:stub-columns: 1
:widths: 10,20,70
* - Parameter
- Type
- Description
* - ``request``/``response``
- :class:`pyramid.request.Request` / :class:`pyramid.response.Response`
- Applicable instance to be modified by the hook according to ``type`` definition.
* - ``service``
- :class:`magpie.typedefs.ServiceConfigItem`
- Definition of the :term:`Service` as specified in the original configuration file.
* - ``hook``
- :class:`magpie.typedefs.ServiceHookConfigItem`
- Specific hook entry (under the above ``service`` definition), that was matched to call the ``target`` function.
* - ``context``
- :class:`magpie.adapter.HookContext`
- Attribute holder with internal handlers and references that were used for processing the current ``request``.
This offers precomputed accessors to :class:`magpie.adapter.MagpieAdapter`, the contextual :term:`Service`
involved in the current transaction (i.e.: specific :class:`magpie.services.ServiceInterface` implementation),
as well as the underlying database reference :class:`magpie.models.Resource` that represents the accessed
:term:`Service`. Using those definitions, it is possible for a :term:`Service Hook` to perform further
:term:`Permission` verifications for manipulating the ``request`` or ``response`` (e.g.: filtering content).
.. warning::
When using the ``context`` parameter, it is important to consider that any operation performed that could involve
additional database queries or :ref:`perm_resolution` steps could slow down the observed response speed from the
protected :term:`Service`. Optimizing or caching the result of such operations could become critical if the request
that triggers the corresponding :term:`Service Hook` require high demands.
.. seealso::
File `providers.cfg`_ presents contextual information and location of the ``hooks`` schema under
example provider definitions.
File |test-hooks|_ presents some examples of hook ``target`` functions with common operations to
update request and response parameters.
.. |test-hooks| replace:: tests/hooks/request_hooks.py
.. _test-hooks: https://github.com/Ouranosinc/Magpie/blob/master/tests/hooks/request_hooks.py
.. _config_constants:
Settings and Constants
----------------------
.. _constant:
.. |constant| replace:: ``constant``
Environment variables can be used to define all following configurations (unless mentioned otherwise with
[|constant|_] keyword). Most values are parsed as plain strings, unless they refer to an
activatable setting (e.g.: ``True`` or ``False``), or when specified with more specific ``[<type>]`` notation.
Configuration variables will be used by `Magpie` on startup unless prior definition is found within `magpie.ini`_.
All variables (i.e.: non-|constant|_ parameters) can also be specified by their ``magpie.[variable_name]`` setting
counterpart as described at the start of the :ref:`configuration` section.
.. _config_load_settings:
Loading Settings
~~~~~~~~~~~~~~~~~
These settings can be used to specify where to find other settings through custom configuration files.
.. envvar:: MAGPIE_MODULE_DIR
[|constant|_]
Path to the top level :mod:`magpie` module (i.e.: source code).
.. envvar:: MAGPIE_ROOT
[|constant|_]
Path to the containing directory of `Magpie`. This corresponds to the directory where the repository was cloned
or where the package was installed.
.. envvar:: MAGPIE_CONFIG_DIR
(Default: ``${MAGPIE_ROOT}/config``)
Configuration directory where to look for ``providers.cfg`` and ``permissions.cfg`` files.
If more than one file for any of those individual type of configuration needs to be loaded from a directory, the
:envvar:`MAGPIE_PROVIDERS_CONFIG_PATH` and :envvar:`MAGPIE_PERMISSIONS_CONFIG_PATH` must be employed instead.
Setting this variable will only look for files named *exactly* as above, unless the more explicit definitions
of ``MAGPIE_<type>_CONFIG_PATH`` variables are also provided.
.. warning::
This setting is ignored if :envvar:`MAGPIE_CONFIG_PATH` is specified.
.. envvar:: MAGPIE_PROVIDERS_CONFIG_PATH
(Default: ``${MAGPIE_CONFIG_DIR}/providers.cfg``)
Path where to find a `providers.cfg`_ file. Can also be a directory path, where all contained configuration files
will be parsed for ``providers`` section and will be loaded sequentially.
Please refer to `providers.cfg`_ for specific format details and parameters.
.. note::
If a directory path is specified, the order of loaded configuration files is alphabetical.
Matching :term:`Service` will be overridden by files loaded last.
.. versionchanged:: 1.7.4
Loading order of multiple files was **NOT** guaranteed prior to this version.
This could lead to some entries to be loaded in inconsistent order.
.. warning::
This setting is ignored if :envvar:`MAGPIE_CONFIG_PATH` is specified.
.. envvar:: MAGPIE_PROVIDERS_HOOKS_PATH
(Default: :envvar:`MAGPIE_ROOT`)
Defines the root directory were to look for ``target`` references in :ref:`config_service_hooks` when the
provided path is relative.
.. note::
When using the :ref:`Docker <usage_docker>` image, the default :envvar:`MAGPIE_ROOT` corresponds to the
source location. When using the installed :ref:`package <usage_package>` (unless ``-e`` was provided to
``pip`` for development installation), this :envvar:`MAGPIE_ROOT` will be located in site-packages of the
target `Python` environment.
.. envvar:: MAGPIE_PERMISSIONS_CONFIG_PATH
(Default: ``${MAGPIE_CONFIG_DIR}/permissions.cfg``)
Path where to find `permissions.cfg`_ file. Can also be a directory path, where all contained configuration files
will be parsed for ``permissions`` section and will be loaded sequentially.
Please refer to `permissions.cfg`_ for specific format details of the various parameters.
.. note::
If a directory path is specified, the order of loaded configuration files is alphabetical.
.. versionchanged:: 1.7.4
Loading order of multiple files was **NOT** guaranteed prior to this version.
With older versions, cross-file references to services or resources should be avoided to ensure that,
for example, any parent resource dependency won't be missing because it was specified in a
second file loaded after the first. Corresponding references can be duplicated across files
and these conflicts will be correctly handled according to configuration loading methodology.
Later versions are safe to assume alphabetical loading order.
.. warning::
This setting is ignored if :envvar:`MAGPIE_CONFIG_PATH` is specified.
.. envvar:: MAGPIE_WEBHOOKS_CONFIG_PATH
(Default: ``None``)
.. versionadded:: 3.12
Path where to find a file or a directory of multiple configuration files where ``webhooks`` section(s) that
provide definitions for :ref:`config_webhook` can be loaded from.
Examples of such configuration section is presented in the example :ref:`config_file`.
When multiple files are available from a directory path, they are loaded by name alphabetically.
.. warning::
This setting is ignored if :envvar:`MAGPIE_CONFIG_PATH` is specified.
.. envvar:: MAGPIE_CONFIG_PATH
Path where to find a combined YAML configuration file which can include ``providers``, ``permissions``, ``users``
and ``groups`` sections to sequentially process registration or removal of items at `Magpie` startup.
See :ref:`config_file` for further details and an example of its structure.
.. versionchanged:: 3.6
The configuration can also contain a ``webhooks`` section, as described in :ref:`config_webhook` and
presented in the sample :ref:`config_file`.
.. warning::
When this setting is defined, all other combinations of :envvar:`MAGPIE_CONFIG_DIR`,
:envvar:`MAGPIE_PERMISSIONS_CONFIG_PATH`, :envvar:`MAGPIE_PROVIDERS_CONFIG_PATH` and
:envvar:`MAGPIE_WEBHOOKS_CONFIG_PATH` are effectively ignored in favour of definitions in this file.
It is not possible to employ the single :ref:`config_file` at the same time as multi-configuration file
loading strategy from a directory.
.. envvar:: MAGPIE_INI_FILE_PATH
Specifies where to find the initialization file to run `Magpie` application.
.. note::
This variable ignores the setting/env-var resolution order since settings cannot be defined without
firstly loading the file referenced by its value.
.. seealso::
`config_magpie_ini`_
.. envvar:: MAGPIE_ENV_DIR
(Default: ``"${MAGPIE_ROOT}/env"``)
Directory path where to look for ``.env`` files. This variable can be useful to load specific test environment
configurations or to specify a local path while the actual `Magpie` code is located in a Python `site-packages`
directory (``.env`` files are not installed to avoid hard-to-resolve settings loaded from an install location).
.. envvar:: MAGPIE_ENV_FILE
(Default: ``"${MAGPIE_ENV_DIR}/magpie.env"``)
File path to ``magpie.env`` file with additional environment variables to configure the application.
.. seealso::
:ref:`config_magpie_env`
.. envvar:: MAGPIE_POSTGRES_ENV_FILE
(Default: ``"${MAGPIE_ENV_DIR}/postgres.env"``)
File path to ``postgres.env`` file with additional environment variables to configure the `postgres` connection.
.. seealso::
:ref:`config_postgres_env`
.. _config_app_settings:
Application Settings
~~~~~~~~~~~~~~~~~~~~~
Following configuration parameters are used to define values that are employed by `Magpie` after loading
the `Loading Settings`_. All ``magpie.[variable_name]`` counterpart definitions are also available as described
at the start of the :ref:`Configuration` section.
.. envvar:: MAGPIE_URL
(Default: ``"http://localhost:2001"``)
Full hostname URL to use so that `Magpie` can resolve his own running instance location.
.. note::
If the value is not set, `Magpie` will attempt to retrieve this critical information through other variables
such as :envvar:`MAGPIE_HOST`, :envvar:`MAGPIE_PORT`, :envvar:`MAGPIE_SCHEME` and :envvar:`HOSTNAME`. Modifying
any of these variables partially is permitted but will force `Magpie` to attempt building the full URL as best
as possible from the individual parts. The result of these parts (potential using corresponding defaults) will
have the following format: ``"${MAGPIE_SCHEME}//:${MAGPIE_HOST}:${MAGPIE_PORT}"``.
.. note::
The definition of :envvar:`MAGPIE_URL` or any of its parts to reconstruct it must not be confused with
parameters defined in the ``[server:main]`` section of the provided `magpie.ini`_ configuration. The purpose
of variable :envvar:`MAGPIE_URL` is to define where the *exposed* application is located, often representing
the server endpoint for which the `Magpie` instance is employed. The values of ``host`` and ``port``, or
``bind`` defined in ``[server:main]`` instead correspond to how the WSGI application is exposed (e.g.: through
`Gunicorn`_), and so represents a *local* web application that must be mapped one way or another to the server
when running within the :ref:`usage_docker`.
.. envvar:: MAGPIE_SCHEME
(Default: ``"http"``)
Protocol scheme URL part of `Magpie` application to rebuild the full :envvar:`MAGPIE_URL`.
.. envvar:: MAGPIE_HOST
(Default: ``"localhost"``)
Domain host URL part of `Magpie` application to rebuild the full :envvar:`MAGPIE_URL`.
.. envvar:: MAGPIE_PORT
[:class:`int`]
(Default: ``2001``)
Port URL part of `Magpie` application to rebuild the full :envvar:`MAGPIE_URL`.
.. envvar:: MAGPIE_CRON_LOG
(Default: ``"~/magpie-cron.log"``)
Path that the ``cron`` operation should use for logging.
.. envvar:: MAGPIE_LOG_LEVEL
(Default: ``INFO``)
Logging level of operations. `Magpie` will first use the complete logging configuration found in
`magpie.ini`_ in order to define logging formatters and handler referencing to the ``logger_magpie`` section.
If this configuration fail to retrieve an explicit logging level, this configuration variable is used instead to
prepare a basic logger, after checking if a corresponding ``magpie.log_level`` setting was instead specified.
.. warning::
When setting ``DEBUG`` level or lower, `Magpie` will potentially dump some sensitive information in logs such
as access tokens. It is important to avoid this setting for production systems.
.. envvar:: MAGPIE_LOG_PRINT
[:class:`bool`]
(Default: ``False``)
Specifies whether `Magpie` logging should also **enforce** printing the details to the console when using
:ref:`cli_helpers`.
Otherwise, the configured logging methodology in `magpie.ini`_ is used (which can also define a console handler).
.. envvar:: MAGPIE_LOG_REQUEST
[:class:`bool`]
(Default: ``True``)
Specifies whether `Magpie` should log incoming request details.
.. note::
This can make `Magpie` quite verbose if large quantity of requests are accomplished.
.. envvar:: MAGPIE_LOG_EXCEPTION
[:class:`bool`]
(Default: ``True``)
Specifies whether `Magpie` should log a raised exception during a process execution.
.. envvar:: MAGPIE_SMTP_USER
(Default: ``"Magpie"``)
.. versionadded:: 3.13
Display name employed as sending user of notification emails.
If explicitly overridden by an empty string, the :envvar:`MAGPIE_SMTP_FROM` is used as replacement.
.. envvar:: MAGPIE_SMTP_FROM
(Default: ``None``)
.. versionadded:: 3.13
Email that identifies the sender of notification emails by the application.
This value is also employed to run the authentication step to the SMTP server in combination with
:envvar:`MAGPIE_SMTP_PASSWORD` if it is also provided. Furthermore, if the value is provided while
:envvar:`MAGPIE_SMTP_USER` is empty, the default email sender (display name) will revert to this value.
.. envvar:: MAGPIE_SMTP_PASSWORD
(Default: ``None``)
.. versionadded:: 3.13
Authentication password to use in combination with :envvar:`MAGPIE_SMTP_FROM` to connect the server
specified by :envvar:`MAGPIE_SMTP_HOST` as required.
Leave blank if SMTP server does not require or should not execute authentication step.
.. envvar:: MAGPIE_SMTP_HOST
.. versionadded:: 3.13
Host of the SMTP server to employ for sending notification emails.
.. envvar:: MAGPIE_SMTP_PORT
[:class:`int`]
(Default: ``465``)
.. versionadded:: 3.13
Port of the outgoing notification emails from the SMTP server.
In case of doubt, port value ``25`` (an sometimes ``587``) is employed for non-encrypted emails.
For secure TLS, ``587`` is the usual choice, and ``465`` when using SSL.
Other ports based on the functionalities offered by targeted :envvar:`MAGPIE_SMTP_HOST` could be available.
Note that :envvar:`MAGPIE_SMTP_SSL` should be set accordingly when using those standard values.
It is strongly recommended to employ an encrypted email since transferred details by `Magpie` can potentially
contain some sensible details.
.. envvar:: MAGPIE_SMTP_SSL
[:class:`bool`]
(Default: ``True``)
.. versionadded:: 3.13
Specifies if SSL should be employed for sending email.
If not enabled, `Magpie` will first attempt to establish a TLS connection if the targeted SMTP server
supports it to use encrypted emails. If it is not supported by that server, it falls back to unencrypted
emails since no other alternatives exist.
.. envvar:: MAGPIE_TOKEN_EXPIRE
[:class:`int`]
(Default: ``86400`` seconds)
.. versionadded:: 3.7
Duration for which temporary URL tokens will remain valid until automatically removed.
These tokens can be used for many different applications within `Magpie`, but are notably employed for handling
callback URL operations in tandem with a given :term:`Webhook` (see also: :ref:`config_webhook_actions`).
.. envvar:: MAGPIE_UI_ENABLED
[:class:`bool`]
(Default: ``True``)
Specifies whether `Magpie` graphical user interface should be available with the started instance. If disabled,
all routes that normally refer to the UI will return ``404``, except the frontpage that will return a simple JSON
description as it is normally the default entrypoint of the application.
.. envvar:: MAGPIE_UI_THEME
(Default: ``"blue"``)
Specifies the adjustable theme to apply `Magpie` UI pages. This theme consist principally of the applied color for
generic interface items, but could be extended at a later date. The value must be one of the CSS file names located
within the `themes`_ subdirectory.
.. _config_security:
Security Settings
~~~~~~~~~~~~~~~~~~~~~
Following configuration parameters are used to define specific values that are related to security configurations.
Again, the `Loading Settings`_ will be processed beforehand and all ``magpie.[variable_name]`` setting definitions
remain available as described at the start of the :ref:`Configuration` section.
.. envvar:: MAGPIE_SECRET
.. no default since explicit value is now required
Secret value employed to encrypt user authentication tokens.
.. warning::
Changing this value at a later time will cause previously created user tokens from passwords to be invalidated.
This value **MUST** be defined before starting the application in order to move on to user accounts and
permissions creation in your `Magpie` instance. The application will quit with an error if this value cannot
be found.
.. versionchanged:: 2.0
Prior to this version, a default value was employed if this setting not provided. Later `Magpie` version now
require an explicit definition of this parameter to avoid weak default configuration making the protected system
prone to easier breaches. This also avoids incorrect initial setup of special :term:`User`s with that temporary
weak secret that would need recreation to regenerate passwords.
.. envvar:: MAGPIE_COOKIE_NAME
(Default: ``"auth_tkt"``)
Identifier of the cookie that will be used for reading and writing in the requests from login and for
:term:`User` authentication operations.
.. seealso::
:ref:`auth_methods`
.. envvar:: MAGPIE_COOKIE_EXPIRE
[:class:`int`]
(Default: ``None``)
Lifetime duration in seconds of the cookies. Tokens become invalid after this duration is elapsed.
When no value is provided, the cookies will have an infinite duration (never expire).
When a valid integer value is provided, their reissue time (how long until a new token is regenerated) is a factor
of 10 from this expiration time. For example, tokens are reissued after 360 seconds if their expiration is 3600.
.. envvar:: MAGPIE_ADMIN_USER
.. no default since explicit value is now required
Name of the default 'administrator' generated by the application.
.. seealso::
:envvar:`MAGPIE_ADMIN_PASSWORD`
This :term:`User` is required for initial launch of the application to avoid being 'locked out' as routes for
creating new users require administrative access rights. It should be used as a first login method to setup other
accounts. It is afterwards recommended to employ other user accounts with :envvar:`MAGPIE_ADMIN_GROUP` membership
to accomplish administrative management operations.
If this :term:`User` is missing, it is automatically recreated on following application start. The best way to
invalidate its credentials is therefore to completely remove its entry from the database so it gets regenerated
from updated configuration values. Note also that modifying the value in the configuration without restarting the
application so that the administrator user entry in the database can also be updated could cause other operations
to fail drastically since this special user would be output of sync when employed by other `Magpie` operations such
as :ref:`Service Synchronization` and :term:`Permission` setup during the application startup.
.. versionchanged:: 2.0
Prior to this version, a default value was employed if this setting was not provided. Later `Magpie` version
now require an explicit definition of this parameter to avoid weak default configuration making the protected
system prone to easier breaches. This value **MUST** be defined before starting the application in order to
resume to any other operation in your `Magpie` instance. The application will quit with an error if this value
cannot be found. It is recommended that the developer configures every new instance with server-specific and
strong credentials.
Prior versions also allowed modification of this value from the API and UI, which increased chances of having
out-of-sync definitions between the database and :term:`Configuration` files. This is not permitted anymore.
Changing this value should be accomplished by updating the :term:`Configuration` file and restarting the
:ref:`usage_webapp` or calling the :ref:`cli_helpers` to register changes.
.. envvar:: MAGPIE_ADMIN_PASSWORD
.. no default since explicit value is now required
Password of the default *administrator* :term:`User` generated by the application.
.. seealso::
:envvar:`MAGPIE_ADMIN_USER`
.. versionchanged:: 2.0
Default values definition and update during runtime for this parameter was modified to avoid problematic
configuration synchronization problems. See corresponding change details in above :envvar:`MAGPIE_ADMIN_USER`.
.. versionchanged:: 3.8
Prior to this version, changing only the :envvar:`MAGPIE_ADMIN_PASSWORD` without modification of
:envvar:`MAGPIE_ADMIN_USER` was not handled. Following versions applies any password modification on restart
to update credentials.
.. warning::
Note that if the password is modified in later versions, its new value will require to fulfill validation
against standard password format requirements, such as :envvar:`MAGPIE_PASSWORD_MIN_LENGTH`. Older passwords
will remain effective only if left untouched for backward compatibility, but will be flagged as potential
security risk.
.. envvar:: MAGPIE_ADMIN_EMAIL
(Default: ``"${MAGPIE_ADMIN_USER}@mail.com"``)
Email of the default *administrator* generated by the application.
.. envvar:: MAGPIE_ADMIN_GROUP
(Default: ``"administrators"``)
Name of the default *administrator* :term:`Group` generated by the application.
.. note::
To simplify configuration of future administrators of the application, all their :ref:`Inherited Permissions`
are shared through this :term:`Group` instead of setting individual permissions on each :term:`User`. It is
recommended to keep defining such higher level permissions on this :term:`Group` to ease the management process
of granted access to all their members, or in other words, to allow multiple administrators to manage `Magpie`
resources with their respective accounts.
.. envvar:: MAGPIE_ADMIN_PERMISSION
[|constant|_]
(Value: ``"admin"``)
Name of the :term:`Permission` used to represent highest administration privilege in the application. It is one of
the special :term:`Access Permission` known by the application (see also :ref:`Route Access` section).
.. envvar:: MAGPIE_LOGGED_PERMISSION
[|constant|_]
(Value: ``"MAGPIE_LOGGED_USER"``)
.. versionadded:: 2.0
Defines a special condition of :term:`Access Permission` related to the :term:`Logged User` session and the
targeted :term:`User` by the request. See details in :ref:`Route Access` for when it applies.
.. envvar:: MAGPIE_LOGGED_USER
[|constant|_]
(Value: ``"current"``)
Keyword used to define route resolution using the currently :term:`Logged User`. This value allows, for example,
retrieving the user details of the logged user with ``GET /users/${MAGPIE_LOGGED_USER}`` instead of having to
find explicitly the ``GET /users/<my-user-id>`` variant. User resolution is done using the authentication cookie
found in the request. If no cookie can be found, it defaults to the :envvar:`MAGPIE_ANONYMOUS_USER` value.
.. note::
Because the :term:`Logged User` executing the request with this keyword is effectively the authenticated user,
the behaviour of some specific paths can be slightly different than their literal ``user_name`` counterpart.
For example, :term:`User` details will be accessible to the :term:`Logged User` (he can view his own
information) but this same user will receive a forbidden response if using is ID in the path if he doesn't
have required privileges.
.. versionchanged:: 2.0
Even without administrative access rights, the :term:`Logged User` is allowed to obtain some additional details
about the targeted :term:`User` of the request path if it corresponds to itself.
See :envvar:`MAGPIE_LOGGED_PERMISSION` and :ref:`Route Access` for further details.
.. envvar:: MAGPIE_ANONYMOUS_USER
(Default: ``"anonymous"``)
Name of the default :term:`User` that represents non logged-in user (ie: invalid or no :term:`Authentication`
token provided). This :term:`User` is used to manage :term:`Public` access to :term:`Service` and :term:`Resource`.
.. envvar:: MAGPIE_ANONYMOUS_PASSWORD
[|constant|_]
(Value: ``${MAGPIE_ANONYMOUS_USER}``)
Password of the default unauthenticated :term:`User`.
This value is not modifiable directly and is available only for preparation of the default user on startup.
.. envvar:: MAGPIE_ANONYMOUS_EMAIL
(Default: ``"${MAGPIE_ANONYMOUS_USER}@mail.com"``)
Email of the default unauthenticated :term:`User`.
.. envvar:: MAGPIE_ANONYMOUS_GROUP
[|constant|_]
(Value: ``${MAGPIE_ANONYMOUS_USER}``)
Special :term:`Group` name that defines :ref:`Public Access` functionalities. All users are automatically member
of this :term:`Public` :term:`Group` to obtain :ref:`Inherited Permissions`.
This parameter is enforced to be equal to :envvar:`MAGPIE_ANONYMOUS_USER`. It is preserved for backward
compatibility of migration scripts and external libraries that specifically refer to this parameter.
.. versionchanged:: 2.0
The :term:`Group` generated by this configuration cannot be modified to remove :term:`User` memberships or
change other metadata associated to it.
.. warning::
To set :term:`Public` permissions, one should always set them on this :term:`Group` instead of directly on
:envvar:`MAGPIE_ANONYMOUS_USER` as setting them directly on that :term:`User` will cause unexpected behaviours.
See :ref:`Public Access` section for full explanation.
.. envvar:: MAGPIE_EDITOR_GROUP
(Default: ``"editors"``)
*Unused for the moment.*
.. envvar:: MAGPIE_USERS_GROUP
(Default: ``"users"``)
Name of a generic :term:`Group` created to associate registered :term:`User` memberships in the application.
.. versionchanged:: 2.0
New :term:`User` are **NOT** automatically added to this :term:`Group` anymore. This :term:`Group` remains
available for testing and backward compatibility reasons, but doesn't have any special connotation and can be
modified just as any other normal :term:`Group`.
Prior versions of `Magpie` were adding every new :term:`User` to that :term:`Group` which made it no
different than the behaviour fulfilled by :envvar:`MAGPIE_ANONYMOUS_GROUP` which they are also member of.
Since :envvar:`MAGPIE_USERS_GROUP` has no special meaning and is modifiable at any time (e.g.: users could be
removed from it), it could not even be employed to ensure provision of permissions applied to all users
(its original purpose), which is also equivalent to functionalities provided with :term:`Public` permissions
inherited by :envvar:`MAGPIE_ANONYMOUS_GROUP` that is more specifically handled by `Magpie` for this purpose.
.. envvar:: MAGPIE_GROUP_NAME_MAX_LENGTH
[|constant|_, :class:`int`]
(Value: ``64``)
Maximum length to consider a :term:`Group` name as valid.
Any name specified during creation will be forbidden if longer.
.. envvar:: MAGPIE_USER_NAME_MAX_LENGTH
[|constant|_, :class:`int`]
(Value: ``64``)
Maximum length to consider a :term:`User` name as valid.
Any name specified during creation will be forbidden if longer.
.. warning::
This value **MUST NOT** be greater than the token length used to identify a :term:`User` to preserve internal
functionalities.
.. envvar:: MAGPIE_USER_NAME_EXTRA_REGEX
(Default: ``None``)
.. versionadded:: 3.37
A case sensitive (python3 syntax) regular expression used to validate a ``user_name`` when creating or updating a
:term:`User`.
For example, if ``MAGPIE_USER_NAME_EXTRA_REGEX='^\w+$'``, then a :term:`User` can have ``userA`` as a ``user_name``
but not ``user.A`` or ``user-A``.
Note that `Magpie` enforces other restrictions that must also be met for a ``user_name`` to be considered valid.
This creates an additional restriction, it does not replace an existing restriction on the ``user_name``.
If this variable is empty or unset, then no additional ``user_name`` validations will be performed.
.. envvar:: MAGPIE_PASSWORD_MIN_LENGTH
[:class:`int`]
(Default: ``12``)
.. versionadded:: 2.0
Minimum length of the password for :term:`User` creation or update.
.. note::
For backward-compatibility requirements, passwords are not enforced this condition during login procedure
as shorter passwords could have been used and not yet updated for older accounts. Fulfilling this requirement
will be mandatory for new password updates and new :term:`User` account creations.
.. envvar:: MAGPIE_DEFAULT_PROVIDER
[|constant|_]
(Value: ``"ziggurat"``)
Name of the :term:`Provider` used for login. This represents the identifier that is set to define how to
differentiate between a local sign-in procedure and a dispatched one some known :ref:`authn_providers`.
.. _config_phoenix:
Phoenix Settings
~~~~~~~~~~~~~~~~~~~~~
Following settings provide some integration support for `Phoenix`_ in order to synchronize its service definitions with
`Magpie` services.
.. warning::
Support of `Phoenix`_ is fairly minimal. It is preserved for historical and backward compatibility but is
not actively tested. Please submit an `issue`_ if you use it and some unexpected behaviour is encountered.