-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Add spec and parser for 'containers_policy' (#3394)
* Feat: Add spec and parser for 'containers_policy' Signed-off-by: shlao <[email protected]> * Updated the class docstring Signed-off-by: shlao <[email protected]> (cherry picked from commit 6c47311)
- Loading branch information
Showing
5 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.. automodule:: insights.parsers.containers_policy | ||
:members: | ||
:show-inheritance: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
""" | ||
ContainersPolicy - file ``/etc/containers/policy.json`` | ||
======================================================= | ||
""" | ||
from insights import JSONParser, parser | ||
from insights.specs import Specs | ||
|
||
|
||
@parser(Specs.containers_policy) | ||
class ContainersPolicy(JSONParser): | ||
""" | ||
Class for converting file ``/etc/containers/policy.json`` | ||
into a dictionary that matches the JSON string in the file. | ||
Sample file content:: | ||
{ | ||
"default": [ | ||
{ | ||
"type": "insecureAcceptAnything" | ||
} | ||
], | ||
"transports": { | ||
"docker": { | ||
"registry.access.redhat.com": [ | ||
{ | ||
"type": "signedBy", | ||
"keyType": "GPGKeys", | ||
"keyPath": "/etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release" | ||
} | ||
], | ||
"registry.redhat.io/redhat/redhat-operator-index": [ | ||
{ | ||
"type": "insecureAcceptAnything" | ||
} | ||
], | ||
"registry.redhat.io": [ | ||
{ | ||
"type": "signedBy", | ||
"keyType": "GPGKeys", | ||
"keyPath": "/etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release" | ||
} | ||
] | ||
}, | ||
"docker-daemon": { | ||
"": [ | ||
{ | ||
"type": "insecureAcceptAnything" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
Examples: | ||
>>> len(containers_policy["default"]) | ||
1 | ||
""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import doctest | ||
|
||
from insights.parsers import containers_policy | ||
from insights.parsers.containers_policy import ContainersPolicy | ||
from insights.parsers.tests import skip_exception_check | ||
from insights.tests import context_wrap | ||
|
||
CONTAINERS_POLICY_FILE = ''' | ||
{ | ||
"default": [ | ||
{ | ||
"type": "insecureAcceptAnything" | ||
} | ||
], | ||
"transports": { | ||
"docker": { | ||
"registry.access.redhat.com": [ | ||
{ | ||
"type": "signedBy", | ||
"keyType": "GPGKeys", | ||
"keyPath": "/etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release" | ||
} | ||
], | ||
"registry.redhat.io/redhat/redhat-operator-index": [ | ||
{ | ||
"type": "insecureAcceptAnything" | ||
} | ||
], | ||
"registry.redhat.io": [ | ||
{ | ||
"type": "signedBy", | ||
"keyType": "GPGKeys", | ||
"keyPath": "/etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release" | ||
} | ||
] | ||
}, | ||
"docker-daemon": { | ||
"": [ | ||
{ | ||
"type": "insecureAcceptAnything" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
'''.strip() | ||
|
||
|
||
def test_doc_examples(): | ||
env = { | ||
'containers_policy': ContainersPolicy(context_wrap(CONTAINERS_POLICY_FILE)), | ||
} | ||
failed, total = doctest.testmod(containers_policy, globs=env) | ||
assert failed == 0 | ||
|
||
|
||
def test_containers_policy(): | ||
conf = ContainersPolicy(context_wrap(CONTAINERS_POLICY_FILE)) | ||
assert len(conf["default"]) == 1 | ||
assert conf["default"][0]["type"] == "insecureAcceptAnything" | ||
|
||
|
||
def test_containers_policy_empty(): | ||
assert 'Empty output.' in skip_exception_check(ContainersPolicy) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters