mirror of
https://github.com/certbot/certbot.git
synced 2026-06-08 00:02:14 -04:00
Clean acme module.
This commit is contained in:
parent
0fcb2a056f
commit
b5462f8f88
1 changed files with 28 additions and 12 deletions
|
|
@ -5,28 +5,44 @@ import pkg_resources
|
|||
import jsonschema
|
||||
|
||||
|
||||
schemata = {schema: json.load(open(pkg_resources.resource_filename(
|
||||
__name__, "schemata/%s.json" % schema))) for schema in [
|
||||
"authorization", "authorizationRequest", "certificate", "certificateRequest",
|
||||
"challenge", "challengeRequest", "defer", "error", "revocation",
|
||||
"revocationRequest", "statusRequest"]
|
||||
SCHEMATA = {
|
||||
schema: json.load(open(pkg_resources.resource_filename(
|
||||
__name__, "schemata/%s.json" % schema))) for schema in [
|
||||
"authorization",
|
||||
"authorizationRequest",
|
||||
"certificate",
|
||||
"certificateRequest",
|
||||
"challenge",
|
||||
"challengeRequest",
|
||||
"defer",
|
||||
"error",
|
||||
"revocation",
|
||||
"revocationRequest",
|
||||
"statusRequest"
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
def acme_object_validate(j):
|
||||
"""Validate a JSON object against the ACME protocol using JSON Schema.
|
||||
|
||||
Success will return None; failure to validate will raise a
|
||||
jsonschema.ValidationError exception describing the reason that the
|
||||
object could not be validated successfully."""
|
||||
object could not be validated successfully.
|
||||
"""
|
||||
j = json.loads(j)
|
||||
if not isinstance(j, dict):
|
||||
raise jsonschema.ValidationError("this is not a dictionary object")
|
||||
if "type" not in j:
|
||||
raise jsonschema.ValidationError("missing type field")
|
||||
if j["type"] not in schemata:
|
||||
if j["type"] not in SCHEMATA:
|
||||
raise jsonschema.ValidationError("unknown type %s" % j["type"])
|
||||
jsonschema.validate(j, schemata[j["type"]])
|
||||
jsonschema.validate(j, SCHEMATA[j["type"]])
|
||||
|
||||
def pretty(s):
|
||||
"""Return a pretty-printed version of any JSON string (useful when
|
||||
printing out protocol messages for debugging purposes."""
|
||||
return json.dumps(json.loads(s), indent=4)
|
||||
|
||||
def pretty(json_string):
|
||||
"""Return a pretty-printed version of any JSON string.
|
||||
|
||||
Useful when printing out protocol messages for debugging purposes.
|
||||
"""
|
||||
return json.dumps(json.loads(json_string), indent=4)
|
||||
|
|
|
|||
Loading…
Reference in a new issue