Skip to content

Conversation

@wking
Copy link
Contributor

@wking wking commented Sep 20, 2017

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.

  • 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 (which I'm planning on removing) and the lack of uri entries for each root (which I'm planning on adding).

@wking wking force-pushed the go-ref-engine-discovery-api branch from 726c1c7 to dc87b41 Compare September 20, 2017 20:06
@wking
Copy link
Contributor Author

wking commented Sep 20, 2017

The remaining differences are the presence of a roots indirection in the Python output (which I'm planning on removing)…

Actually, we may want to keep this. The Python implementation currently uses to pass through ref-engines-object-level casEngines. We may want to follow that lead in Go. There are alternatives, like injecting those casEngines entries into the MerkleRoot.Root object, but that gets tricky now that it's an interface{}. We can also add a new MerkleRoot.CASEngines and store the ref-engines-object-level entries (and any others we collect from other places) there.

@wking
Copy link
Contributor Author

wking commented Sep 20, 2017

The Python UI is growing the uri entries in #25.


// The Merkle root object. While this may be of any type. OCI
// tools will generally use image-spec Descriptors.
Root interface{}
Copy link
Contributor Author

@wking wking Sep 20, 2017

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.

Copy link
Contributor Author

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…

Added with 9529456bb96e49.

@wking wking force-pushed the go-ref-engine-discovery-api branch from dc87b41 to 76a7635 Compare September 21, 2017 05:48
@wking
Copy link
Contributor Author

wking commented Sep 21, 2017

Rebased around some recent changes with dc87b4176a7635. I'm still not sure what the best way is to make this go get …able after #27, but at least with these changes we can compile the executable again ;).

@wking
Copy link
Contributor Author

wking commented Sep 21, 2017

I think the vendor thing is grounds to create separe spec, lib, and CLI-tool repos. I'll work that up tomorrow.

@xiekeyang
Copy link
Owner

Sorry I am cognizant that #27 is a careless commit, which leads code structure some confusion. So I have reverted it #31 . We should figure out a better way later.

@xiekeyang
Copy link
Owner

I would help to resolve the conflicts now.

@xiekeyang
Copy link
Owner

I split commit f57ae08 to #33.

@xiekeyang xiekeyang reopened this Sep 21, 2017
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
@wking wking force-pushed the go-ref-engine-discovery-api branch from 881db73 to 9529456 Compare September 21, 2017 16:44
@wking
Copy link
Contributor Author

wking commented Sep 21, 2017

Rebased around #31 with 881db739529456. With #31, we can continue to punt on splitting this out into separate repos.

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).
@wking wking force-pushed the go-ref-engine-discovery-api branch from 9529456 to bb96e49 Compare September 21, 2017 20:14
@xiekeyang
Copy link
Owner

LGTM

@xiekeyang xiekeyang merged commit 6b9c9a5 into xiekeyang:master Sep 22, 2017
@wking wking deleted the go-ref-engine-discovery-api branch September 22, 2017 21:33
wking added a commit to wking/oci-discovery that referenced this pull request Sep 23, 2017
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.
wking added a commit to wking/oci-discovery that referenced this pull request Sep 23, 2017
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants