-
Notifications
You must be signed in to change notification settings - Fork 1
tools/refenginediscovery: Refactor Ref-Engine Discovery library API #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tools/refenginediscovery: Refactor Ref-Engine Discovery library API #29
Conversation
726c1c7 to
dc87b41
Compare
Actually, we may want to keep this. The Python implementation currently uses to pass through ref-engines-object-level |
|
The Python UI is growing the |
|
|
||
| // The Merkle root object. While this may be of any type. OCI | ||
| // tools will generally use image-spec Descriptors. | ||
| Root interface{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may want a MediaType string property on MerkleRoot so we don't lose typing information in any JSON output. We still have Go typing information without it, because callers can use reflection and/or casting to determine if Root is backed by a type they understand. But having an explicit media type stores that information in a way that will survive JSON serialization. I can add that to this commit, or make it part of follow-up work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dc87b41 to
76a7635
Compare
|
I think the vendor thing is grounds to create separe spec, lib, and CLI-tool repos. I'll work that up tomorrow. |
|
I would help to resolve the conflicts now. |
The order is (expected, actual, ...) [1]. Reported by Keyang in [2]. [1]: https://godoc.org/github.com/stretchr/testify/assert#Equal [2]: xiekeyang@9139cfd#diff-79f54ccc4674abcf6ef6ae61d5dba64bL322
The old strings are what Go 1.7.4 generated, but Keyang reports another Go version generating more specific strings [1]. [1]: xiekeyang@9139cfd#diff-79f54ccc4674abcf6ef6ae61d5dba64bL298
881db73 to
9529456
Compare
Pull the UI portions of this out into tools/cmd, because the library
API should not depend on urfave/cli.
The new refenginediscovery API is based on a per-configured-ref-engine
callback, which gives callers lots of flexibility in how they want to
handle each ref-engine and if/when they want to abort the
protocol/host iteration.
I've also adjusted the ref-engine interface to return a new MerkleRoot
type. This improves on the old Descriptor returns by:
* Being less opinionated about the root object, to stay in keeping
with ref-engine-discovery.md's:
The Merkle root may be a descriptor (media type
application/vnd.oci.descriptor.v1+json), or it may have a
different media type.
The new MediaType parameter provides guidance for tools that need to
consume the otherwise-opaque Root data. Go tools can use reflection
and/or casting to determine if Root is a type they support, but the
mediaType JSON entry will preserve that information through JSON
serialization. It's also as convenient as reflection without
requiring a 'reflect' import, and it's much more convenient than
iterating through casts to known types.
* Including the retrieval URI, which may be needed to expand
references in the root object (e.g. if the root has a casEngines
configuration which includes a relative reference).
These changes bring the API and output of the 'oci-discovery resolve
...' command much closer to the current Python module. The remaining
differences are the presence of a 'roots' indirection in the Python
output (currently used to pass through ref-engines-object-level
casEngines entries) and the lack of 'uri' entries for each root (which
I'm planning on adding).
9529456 to
bb96e49
Compare
|
LGTM |
Previously these were not provided in the output JSON. To store the data during resolution, create a new resolvedName type. That type extends the usual MerkleRoot JSON with a new 'casEngines' property that is a sibling of MerkleRoot's 'root' and 'uri' properties. To get the sibling serialization, we need a little MarshalJSON wrapper for resolvedName, but we don't need to bother with UnmarshalJSON because this isn't a public library type. Rename 'allRoots' to 'resolvedNames', because each key in the map is an image name. Each value in the map may contain several roots (resolveNames), so 'allRoots' wasn't particularly clear. Move refenginediscovery.ResolvedCASEngine to engine.Reference. This gives us a shorter name, and lets us recycle some code via the new (private) (*Config).unmarshalInterface. That lets us get the same config serialization in Reference without the wash through bytes that I use in resolvedName.MarshalJSON. Washing through bytes is an acceptable hack for command-line-specific code, but it's nice to avoid it in the library code. While we're at it, cleanup the MerkleRoot JSON handling, dropping the tag from MediaType (redundant because our JSON helpers don't use reflection) and adding comments for the public methods. Alphabetizing the root entries in the oci-discovery README example probably should have happened back in bb96e49 (tools/refenginediscovery: Refactor Ref-Engine Discovery library API, 2017-09-20, xiekeyang#29), since that's when we started using a map[string]interface{} in MerkleRoot.MarshalJSON.
Previously these were not provided in the output JSON. To store the data during resolution, create a new resolvedName type. That type extends the usual MerkleRoot JSON with a new 'casEngines' property that is a sibling of MerkleRoot's 'root' and 'uri' properties. To get the sibling serialization, we need a little MarshalJSON wrapper for resolvedName, but we don't need to bother with UnmarshalJSON because this isn't a public library type. Rename 'allRoots' to 'resolvedNames', because each key in the map is an image name. Each value in the map may contain several roots (resolveNames), so 'allRoots' wasn't particularly clear. Move refenginediscovery.ResolvedCASEngine to engine.Reference. This gives us a shorter name, and lets us recycle some code via the new (private) (*Config).unmarshalInterface. That lets us get the same config serialization in Reference without the wash through bytes that I use in resolvedName.MarshalJSON. Washing through bytes is an acceptable hack for command-line-specific code, but it's nice to avoid it in the library code. While we're at it, clean up the MerkleRoot JSON handling, dropping the tag from MediaType (redundant because our JSON helpers don't use reflection) and adding comments for the public methods. Alphabetizing the root entries in the oci-discovery README example probably should have happened back in bb96e49 (tools/refenginediscovery: Refactor Ref-Engine Discovery library API, 2017-09-20, xiekeyang#29), since that's when we started using a map[string]interface{} in MerkleRoot.MarshalJSON.
Pull the UI portions of this out into
tools/cmd, because the library API should not depend onurfave/cli.The new
refenginediscoveryAPI is based on a per-configured-ref-engine callback, which gives callers lots of flexibility in how they want to handle each ref-engine and if/when they want to abort the protocol/host iteration.I've also adjusted the ref-engine interface to return a new
MerkleRoottype. This improves on the oldDescriptorreturns by:Being less opinionated about the root object, to stay in keeping with
ref-engine-discovery.md's:Including the retrieval URI, which may be needed to expand references in the root object (e.g. if the root has a
casEnginesconfiguration which includes a relative reference).These changes bring the API and output of the
oci-discovery resolve …command much closer to the current Python module. The remaining differences are the presence of arootsindirection in the Python output (which I'm planning on removing) and the lack ofurientries for each root (which I'm planning on adding).