Skip to content
This repository has been archived by the owner on Aug 14, 2020. It is now read-only.

Commit

Permalink
discovery: do not set version to latest if not provided
Browse files Browse the repository at this point in the history
Actually, if the required discovery labels doesn't contain a version
label, it'll be set to a default of "latest". This behavior isn't
documented in the spec and can create unwanted behaviors.

This patch removes this and also adds to the spec an example on how to
obtain the latest behavior without this "hidden" default.
  • Loading branch information
sgotti committed Mar 23, 2016
1 parent d56ead8 commit 2fe5633
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 14 deletions.
7 changes: 0 additions & 7 deletions discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ func (e *discoveryData) Append(ep discoveryData) {
e.Keys = append(e.Keys, ep.Keys...)
}

const (
defaultVersion = "latest"
)

var (
templateExpression = regexp.MustCompile(`{.*?}`)
errEnough = errors.New("enough discovery information found")
Expand Down Expand Up @@ -138,9 +134,6 @@ func createTemplateVars(app App) []string {

func doDiscover(pre string, hostHeaders map[string]http.Header, app App, insecure InsecureOption) (*discoveryData, error) {
app = *app.Copy()
if app.Labels["version"] == "" {
app.Labels["version"] = defaultVersion
}

_, body, err := httpsOrHTTP(pre, hostHeaders, insecure)
if err != nil {
Expand Down
48 changes: 41 additions & 7 deletions discovery/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,14 +402,43 @@ func TestDiscoverEndpoints(t *testing.T) {
[]string{"https://example.com/pubkeys.gpg"},
nil,
},
// Test missing labels. version label should default to
// "latest" and the first template should be rendered
// Test missing version label. Only one template should match
{
&mockHTTPDoer{
doer: fakeHTTPGet(
[]meta{
{"/myapp",
"meta05.html",
"meta07.html",
},
},
nil,
),
},
true,
true,
App{
Name: "example.com/myapp",
Labels: map[types.ACIdentifier]string{
"os": "linux",
"arch": "amd64",
},
},
[]ACIEndpoint{
ACIEndpoint{
ACI: "https://storage.example.com/example.com/myapp-latest-linux-amd64.aci",
ASC: "https://storage.example.com/example.com/myapp-latest-linux-amd64.aci.asc",
},
},
[]string{"https://example.com/pubkeys.gpg"},
nil,
},
// Test with required version label. Only one template should match
{
&mockHTTPDoer{
doer: fakeHTTPGet(
[]meta{
{"/myapp",
"meta07.html",
},
},
nil,
Expand All @@ -418,18 +447,23 @@ func TestDiscoverEndpoints(t *testing.T) {
true,
true,
App{
Name: "example.com/myapp",
Labels: map[types.ACIdentifier]string{},
Name: "example.com/myapp",
Labels: map[types.ACIdentifier]string{
"version": "1.0.0",
"os": "linux",
"arch": "amd64",
},
},
[]ACIEndpoint{
ACIEndpoint{
ACI: "https://storage.example.com/example.com/myapp-latest.aci",
ASC: "https://storage.example.com/example.com/myapp-latest.aci.asc",
ACI: "https://storage.example.com/example.com/myapp-1.0.0-linux-amd64.aci",
ASC: "https://storage.example.com/example.com/myapp-1.0.0-linux-amd64.aci.asc",
},
},
[]string{"https://example.com/pubkeys.gpg"},
nil,
},

// Test with a label called "name". It should be ignored.
{
&mockHTTPDoer{
Expand Down
14 changes: 14 additions & 0 deletions discovery/testdata/meta07.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>

<html>
<head>
<title>My app</title>
<meta name="ac-discovery" content="example.com https://storage.example.com/{name}-{version}-{os}-{arch}.{ext}">
<meta name="ac-discovery" content="example.com https://storage.example.com/{name}-latest-{os}-{arch}.{ext}">
<meta name="ac-discovery-pubkeys" content="example.com https://example.com/pubkeys.gpg">
</head>

<body>
<h1>My App</h1>
</body>
</html>
16 changes: 16 additions & 0 deletions spec/discovery.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,19 @@ Authentication during the discovery process is optional.
If an attempt at fetching any resource (the initial discovery URL, an App Container Image, or signature) returns a `401 Unauthorized`, implementations should enact the authentication policy set by the operator.
For example, some implementations might only perform HTTP basic authentication over HTTPS connections.


### Examples

#### Latest pattern

If a client wants to retrieve the latest available ACI (without knowing its version) it can provide these meta tags:

```html
<meta name="ac-discovery" content="example.com https://storage.example.com/{os}/{arch}/{name}-{version}.{ext}">
<meta name="ac-discovery" content="example.com https://storage.example.com/{os}/{arch}/{name}-latest.{ext}">
```

When requiring a specific version, the first template will be rendered, when not requiring a _version_ label the second template will match.

On the http server, the "latest" url should point to the current latest ACI.

0 comments on commit 2fe5633

Please sign in to comment.