github_packages: use json_schemer gem.
Instead of the deprecated json-schema.
This commit is contained in:
parent
86130efd58
commit
5f31ebd8d4
6
.gitignore
vendored
6
.gitignore
vendored
@ -84,7 +84,6 @@
|
|||||||
**/vendor/bundle/ruby/*/gems/thread_safe-*/lib/thread_safe/util
|
**/vendor/bundle/ruby/*/gems/thread_safe-*/lib/thread_safe/util
|
||||||
|
|
||||||
# Ignore dependencies we don't wish to vendor
|
# Ignore dependencies we don't wish to vendor
|
||||||
**/vendor/bundle/ruby/*/gems/addressable-*/
|
|
||||||
**/vendor/bundle/ruby/*/gems/ast-*/
|
**/vendor/bundle/ruby/*/gems/ast-*/
|
||||||
**/vendor/bundle/ruby/*/gems/bootsnap-*/
|
**/vendor/bundle/ruby/*/gems/bootsnap-*/
|
||||||
**/vendor/bundle/ruby/*/gems/bundler-*/
|
**/vendor/bundle/ruby/*/gems/bundler-*/
|
||||||
@ -97,11 +96,14 @@
|
|||||||
**/vendor/bundle/ruby/*/gems/diff-lcs-*/
|
**/vendor/bundle/ruby/*/gems/diff-lcs-*/
|
||||||
**/vendor/bundle/ruby/*/gems/docile-*/
|
**/vendor/bundle/ruby/*/gems/docile-*/
|
||||||
**/vendor/bundle/ruby/*/gems/domain_name-*/
|
**/vendor/bundle/ruby/*/gems/domain_name-*/
|
||||||
|
**/vendor/bundle/ruby/*/gems/ecma-re-validator-*/
|
||||||
|
**/vendor/bundle/ruby/*/gems/hana-*/
|
||||||
**/vendor/bundle/ruby/*/gems/highline-*/
|
**/vendor/bundle/ruby/*/gems/highline-*/
|
||||||
**/vendor/bundle/ruby/*/gems/http-cookie-*/
|
**/vendor/bundle/ruby/*/gems/http-cookie-*/
|
||||||
**/vendor/bundle/ruby/*/gems/hpricot-*/
|
**/vendor/bundle/ruby/*/gems/hpricot-*/
|
||||||
**/vendor/bundle/ruby/*/gems/jaro_winkler-*/
|
**/vendor/bundle/ruby/*/gems/jaro_winkler-*/
|
||||||
**/vendor/bundle/ruby/*/gems/json-*/
|
**/vendor/bundle/ruby/*/gems/json-*/
|
||||||
|
**/vendor/bundle/ruby/*/gems/json_schemer-*/
|
||||||
**/vendor/bundle/ruby/*/gems/method_source-*/
|
**/vendor/bundle/ruby/*/gems/method_source-*/
|
||||||
**/vendor/bundle/ruby/*/gems/mime-types-data-*/
|
**/vendor/bundle/ruby/*/gems/mime-types-data-*/
|
||||||
**/vendor/bundle/ruby/*/gems/mime-types-*/
|
**/vendor/bundle/ruby/*/gems/mime-types-*/
|
||||||
@ -120,7 +122,6 @@
|
|||||||
**/vendor/bundle/ruby/*/gems/powerpack-*/
|
**/vendor/bundle/ruby/*/gems/powerpack-*/
|
||||||
**/vendor/bundle/ruby/*/gems/psych-*/
|
**/vendor/bundle/ruby/*/gems/psych-*/
|
||||||
**/vendor/bundle/ruby/*/gems/pry-*/
|
**/vendor/bundle/ruby/*/gems/pry-*/
|
||||||
**/vendor/bundle/ruby/*/gems/public_suffix-*/
|
|
||||||
**/vendor/bundle/ruby/*/gems/racc-*/
|
**/vendor/bundle/ruby/*/gems/racc-*/
|
||||||
**/vendor/bundle/ruby/*/gems/rainbow-*/
|
**/vendor/bundle/ruby/*/gems/rainbow-*/
|
||||||
**/vendor/bundle/ruby/*/gems/rdiscount-*/
|
**/vendor/bundle/ruby/*/gems/rdiscount-*/
|
||||||
@ -152,6 +153,7 @@
|
|||||||
**/vendor/bundle/ruby/*/gems/unf_ext-*/
|
**/vendor/bundle/ruby/*/gems/unf_ext-*/
|
||||||
**/vendor/bundle/ruby/*/gems/unf-*/
|
**/vendor/bundle/ruby/*/gems/unf-*/
|
||||||
**/vendor/bundle/ruby/*/gems/unicode-display_width-*/
|
**/vendor/bundle/ruby/*/gems/unicode-display_width-*/
|
||||||
|
**/vendor/bundle/ruby/*/gems/uri_template-*/
|
||||||
**/vendor/bundle/ruby/*/gems/webrobots-*/
|
**/vendor/bundle/ruby/*/gems/webrobots-*/
|
||||||
|
|
||||||
# Ignore `bin` contents (again).
|
# Ignore `bin` contents (again).
|
||||||
|
|||||||
@ -46,10 +46,8 @@ class GitHubPackages
|
|||||||
end
|
end
|
||||||
|
|
||||||
# TODO: these dependencies are installed but cannot be required automatically.
|
# TODO: these dependencies are installed but cannot be required automatically.
|
||||||
Homebrew.install_gem!("public_suffix")
|
Homebrew.install_gem!("json_schemer")
|
||||||
Homebrew.install_gem!("addressable")
|
require "json_schemer"
|
||||||
Homebrew.install_gem!("json-schema")
|
|
||||||
require "json-schema"
|
|
||||||
|
|
||||||
load_schemas!
|
load_schemas!
|
||||||
|
|
||||||
@ -97,13 +95,30 @@ class GitHubPackages
|
|||||||
out, = curl_output(url)
|
out, = curl_output(url)
|
||||||
json = JSON.parse(out)
|
json = JSON.parse(out)
|
||||||
|
|
||||||
|
@schema_json ||= {}
|
||||||
Array(uris).each do |uri|
|
Array(uris).each do |uri|
|
||||||
schema = JSON::Schema.new(json, uri)
|
@schema_json[uri] = json
|
||||||
schema.uri = uri
|
|
||||||
JSON::Validator.add_schema(schema)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def schema_resolver(uri)
|
||||||
|
@schema_json[uri.to_s.gsub(/#.*/, "")]
|
||||||
|
end
|
||||||
|
|
||||||
|
def validate_schema!(schema_uri, json)
|
||||||
|
schema = JSONSchemer.schema(@schema_json[schema_uri], ref_resolver: method(:schema_resolver))
|
||||||
|
json = json.deep_stringify_keys
|
||||||
|
return if schema.valid?(json)
|
||||||
|
|
||||||
|
puts
|
||||||
|
ofail "#{Formatter.url(schema_uri)} JSON schema validation failed!"
|
||||||
|
oh1 "Errors"
|
||||||
|
pp schema.validate(json).to_a
|
||||||
|
oh1 "JSON"
|
||||||
|
pp json
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
|
||||||
def upload_bottle(user, token, skopeo, formula_name, bottle_hash)
|
def upload_bottle(user, token, skopeo, formula_name, bottle_hash)
|
||||||
_, org, repo, = *bottle_hash["bottle"]["root_url"].match(URL_REGEX)
|
_, org, repo, = *bottle_hash["bottle"]["root_url"].match(URL_REGEX)
|
||||||
|
|
||||||
@ -217,7 +232,7 @@ class GitHubPackages
|
|||||||
}],
|
}],
|
||||||
annotations: annotations_hash,
|
annotations: annotations_hash,
|
||||||
}
|
}
|
||||||
JSON::Validator.validate!(IMAGE_MANIFEST_SCHEMA_URI, image_manifest)
|
validate_schema!(IMAGE_MANIFEST_SCHEMA_URI, image_manifest)
|
||||||
manifest_json_sha256, manifest_json_size = write_hash(blobs, image_manifest)
|
manifest_json_sha256, manifest_json_size = write_hash(blobs, image_manifest)
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -244,7 +259,7 @@ class GitHubPackages
|
|||||||
|
|
||||||
def write_image_layout(root)
|
def write_image_layout(root)
|
||||||
image_layout = { imageLayoutVersion: "1.0.0" }
|
image_layout = { imageLayoutVersion: "1.0.0" }
|
||||||
JSON::Validator.validate!(IMAGE_LAYOUT_SCHEMA_URI, image_layout)
|
validate_schema!(IMAGE_LAYOUT_SCHEMA_URI, image_layout)
|
||||||
write_hash(root, image_layout, "oci-layout")
|
write_hash(root, image_layout, "oci-layout")
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -262,7 +277,7 @@ class GitHubPackages
|
|||||||
diff_ids: ["sha256:#{tar_sha256}"],
|
diff_ids: ["sha256:#{tar_sha256}"],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
JSON::Validator.validate!(IMAGE_CONFIG_SCHEMA_URI, image_config)
|
validate_schema!(IMAGE_CONFIG_SCHEMA_URI, image_config)
|
||||||
write_hash(blobs, image_config)
|
write_hash(blobs, image_config)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -272,7 +287,7 @@ class GitHubPackages
|
|||||||
manifests: manifests,
|
manifests: manifests,
|
||||||
annotations: {},
|
annotations: {},
|
||||||
}
|
}
|
||||||
JSON::Validator.validate!(IMAGE_INDEX_SCHEMA_URI, image_index)
|
validate_schema!(IMAGE_INDEX_SCHEMA_URI, image_index)
|
||||||
write_hash(blobs, image_index)
|
write_hash(blobs, image_index)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -287,7 +302,7 @@ class GitHubPackages
|
|||||||
}],
|
}],
|
||||||
annotations: {},
|
annotations: {},
|
||||||
}
|
}
|
||||||
JSON::Validator.validate!(IMAGE_INDEX_SCHEMA_URI, index_json)
|
validate_schema!(IMAGE_INDEX_SCHEMA_URI, index_json)
|
||||||
write_hash(root, index_json, "index.json")
|
write_hash(root, index_json, "index.json")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -4,8 +4,7 @@
|
|||||||
# typed: strong
|
# typed: strong
|
||||||
module ::StackProf; end
|
module ::StackProf; end
|
||||||
module DependencyCollector::Compat; end
|
module DependencyCollector::Compat; end
|
||||||
module JSON::Schema; end
|
module GitHubPackages::JSONSchemer; end
|
||||||
module JSON::Validator; end
|
|
||||||
module OS::Mac::Version::NULL; end
|
module OS::Mac::Version::NULL; end
|
||||||
module T::InterfaceWrapper::Helpers; end
|
module T::InterfaceWrapper::Helpers; end
|
||||||
module T::Private::Abstract::Hooks; end
|
module T::Private::Abstract::Hooks; end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user