Skip to content
Permalink
Browse files

add manifest index schema and validation step in generate.py

Signed-off-by: Daniel Nurmi <nurmi@anchore.com>
  • Loading branch information...
nurmi committed May 10, 2019
1 parent 62eecf7 commit a408dc283c8bf6f59e8628a1ea79f4c3569639bb
Showing with 123 additions and 2 deletions.
  1. +10 −2 generate.py
  2. +113 −0 schemas/hub-index.json
@@ -56,6 +56,9 @@ def process_bundles(source_dir=None, target_dir=None):

def populate_target(source_dir=None, target_dir=None, bundles={}):

with open("./schemas/hub-index.json", 'r') as FH:
manifestschema = jsonref.loads(FH.read())

# create the manifest
manifest = {
'metadata': {
@@ -68,6 +71,11 @@ def populate_target(source_dir=None, target_dir=None, bundles={}):
digest = "{}:{}".format('sha256', hashlib.sha256(json.dumps(manifest['content'], sort_keys=True, indent=4).encode('utf8')).hexdigest())
manifest['metadata']['digest'] = digest

# validate the index manifest before proceeding
print ("\tValidating generated manifest index ...", end='')
jsonschema.validate(manifest, manifestschema)
print ("done!")

# prep the target location
if not target_dir or not source_dir:
raise Exception("empty target_dir({}) or source_dir({}) passed in".format(target_dir, source_dir))
@@ -126,9 +134,9 @@ def populate_target(source_dir=None, target_dir=None, bundles={}):

# generate target and populate
try:
print ("Populating target...", end='')
print ("Populating target...")
rc = populate_target(source_dir=config.get("ANCHORE_HUB_SOURCEDIR"), target_dir=config.get("ANCHORE_HUB_TARGETDIR"), bundles=bundles)
print ("done!")
print ("Populating target done!")
except Exception as err:
raise Exception("ERROR during target population")

@@ -0,0 +1,113 @@
{
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://example.com/root.json",
"type": "object",
"title": "Root Schema",
"required": [
"content",
"metadata"
],
"properties": {
"content": {
"$id": "#/properties/content",
"type": "array",
"title": "Content Schema",
"items": {
"$id": "#/properties/content/items",
"type": "object",
"title": "Items Schema",
"required": [
"description",
"digest",
"location",
"name",
"type"
],
"properties": {
"description": {
"$id": "#/properties/content/items/properties/description",
"type": "string",
"title": "Description Schema",
"default": "",
"examples": [
"Anchore DoD Security Docker image content checks"
],
"pattern": "^(.*)$"
},
"digest": {
"$id": "#/properties/content/items/properties/digest",
"type": "string",
"title": "Digest Schema",
"default": "",
"examples": [
"sha256:9a24a59a88cdd79fd9f6408f73207d592b10bd8e362fa277d2608b5d42b6436b"
],
"pattern": "^sha256:[A-Fa-f0-9]{64}$"
},
"location": {
"$id": "#/properties/content/items/properties/location",
"type": "string",
"title": "Location Schema",
"default": "",
"examples": [
"bundles/anchore_dod_security_policies_v2/sha256:9a24a59a88cdd79fd9f6408f73207d592b10bd8e362fa277d2608b5d42b6436b.json"
],
"pattern": "^(.*)$"
},
"name": {
"$id": "#/properties/content/items/properties/name",
"type": "string",
"title": "Name Schema",
"default": "",
"examples": [
"anchore_dod_security_policies_v2"
],
"pattern": "^(.*)$"
},
"type": {
"$id": "#/properties/content/items/properties/type",
"type": "string",
"title": "Type Schema",
"default": "",
"examples": [
"bundle"
],
"pattern": "^bundle$"
}
}
}
},
"metadata": {
"$id": "#/properties/metadata",
"type": "object",
"title": "Metadata Schema",
"required": [
"digest",
"last_updated"
],
"properties": {
"digest": {
"$id": "#/properties/metadata/properties/digest",
"type": "string",
"title": "Digest Schema",
"default": "",
"examples": [
"sha256:ecd7f53a1d5a980ca96e3cb47df3cde18a07a774b29f19c54eb81dac81574a59"
],
"pattern": "^sha256:[A-Fa-f0-9]{64}$"
},
"last_updated": {
"$id": "#/properties/metadata/properties/last_updated",
"type": "string",
"title": "Last_updated Schema",
"default": "",
"examples": [
"2019-04-24T23:46:14.356161"
],
"pattern": "^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(.[0-9]+)?(Z)?$"
}
}
}
}
}

0 comments on commit a408dc2

Please sign in to comment.
You can’t perform that action at this time.