| 1 |
======================== |
| 2 |
Writing HTTP check rules |
| 3 |
======================== |
| 4 |
|
| 5 |
oslo.policy has supported the following syntax for a while:: |
| 6 |
|
| 7 |
http:<target URL>, which delegates the check to a remote server |
| 8 |
|
| 9 |
|
| 10 |
Starting with 1.29, oslo.policy will also support https url(s) as well:: |
| 11 |
|
| 12 |
https:<target URL>, which delegates the check to a remote server |
| 13 |
|
| 14 |
|
| 15 |
Both ``http`` and ``https`` support are implemented as custom check rules. |
| 16 |
If you see the setup.cfg for oslo.policy, you can see the following |
| 17 |
entry points:: |
| 18 |
|
| 19 |
oslo.policy.rule_checks = |
| 20 |
http = oslo_policy._external:HttpCheck |
| 21 |
https = oslo_policy._external:HttpsCheck |
| 22 |
|
| 23 |
When a policy is evaluated, when the engine encounters ``https`` like in |
| 24 |
a snippet below:: |
| 25 |
|
| 26 |
{ |
| 27 |
... |
| 28 |
"target 1" : "https://foo.bar/baz", |
| 29 |
... |
| 30 |
} |
| 31 |
|
| 32 |
The engine will look for a plugin named ``https`` in the ``rule_checks`` |
| 33 |
entry point and will try to invoke that stevedore plugin. |
| 34 |
|
| 35 |
This mechanism allows anyone to write their own code, in their own library |
| 36 |
with their own custom stevedore based rule check plugins and can enhance |
| 37 |
their policies with custom checks. This would be useful for example to |
| 38 |
integrate with an in-house policy server. |
| 39 |
|
| 40 |
|
| 41 |
Example code - HttpCheck |
| 42 |
======================== |
| 43 |
|
| 44 |
.. note:: |
| 45 |
|
| •46 |
Full source located at https://opendev.org/openstack/oslo.policy/src/branch/master/oslo_policy/_external.py |
| 47 |
|
| 48 |
.. literalinclude:: ../../../oslo_policy/_external.py |
| 49 |
:language: python |
| 50 |
:linenos: |
| 51 |
:lines: 28-64 |