Skip to content

Conversation

@xiekeyang
Copy link
Owner

split commit from #29.

@xiekeyang xiekeyang changed the title tools/refenginediscovery: Refactor Ref-Engine Discovery library API [Splited commit]: tools/refenginediscovery: Refactor Ref-Engine Discovery library API Sep 21, 2017
wking and others added 3 commits September 21, 2017 15:55
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 (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).
Signed-off-by: xiekeyang <[email protected]>
Signed-off-by: xiekeyang <[email protected]>
label: "manifests is not a JSON array",
response: `{"manifests": {}}`,
expected: "json: cannot unmarshal object into Go value of type []v1.Descriptor",
expected: "json: cannot unmarshal object into Go struct field Index.manifests of type []v1.Descriptor",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these are due to changing versions (I developed the tests with Go 1.7.4). We probably want to use regexps instead of fixed strings. I'll put that into a rerolled #29.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want to use regexps instead of fixed strings.

Done.

}

uri, err := url.Parse("https://example.com/.well-known/oci-host-ref-engines")
uri, err := url.Parse("https://" + host + "/.well-known/oci-host-ref-engines")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous approach avoided this unnecessary string concatenation. And once we add DNS-ancestor walking, we'll be setting uri.Host anyway.

response := &http.Response{
Request: request,
Body: ioutil.NopCloser(bytes.NewReader(bodyBytes)),
Body: ioutil.NopCloser(bytes.NewReader(bodyBytes)),
Copy link
Contributor

@wking wking Sep 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the sloppy commit. I've run go fmt … and squashed the fixes in here.

}

assert.Equal(t, err.Error(), testcase.expected)
assert.Equal(t, testcase.expected, err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Addressed this and other instances here.

@xiekeyang
Copy link
Owner Author

Closed by #29

@xiekeyang xiekeyang closed this Sep 22, 2017
@xiekeyang xiekeyang deleted the refact-api branch September 27, 2017 10:07
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.

3 participants