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 Apr 12, 2016
1 parent 5b7134f commit 13ab4e0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
7 changes: 0 additions & 7 deletions discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ type ACIEndpoints []ACIEndpoint

type PublicKeys []string

const (
defaultVersion = "latest"
)

var (
templateExpression = regexp.MustCompile(`{.*?}`)
errEnough = errors.New("enough discovery information found")
Expand Down Expand Up @@ -134,9 +130,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
12 changes: 3 additions & 9 deletions discovery/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,7 @@ 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 labels. No template will render
{
&mockHTTPDoer{
doer: fakeHTTPGet(
Expand All @@ -415,18 +414,13 @@ func TestDiscoverEndpoints(t *testing.T) {
nil,
),
},
true,
false,
true,
App{
Name: "example.com/myapp",
Labels: map[types.ACIdentifier]string{},
},
[]ACIEndpoint{
ACIEndpoint{
ACI: "https://storage.example.com/example.com/myapp-latest.aci",
ASC: "https://storage.example.com/example.com/myapp-latest.aci.asc",
},
},
[]ACIEndpoint{},
[]string{"https://example.com/pubkeys.gpg"},
nil,
},
Expand Down
16 changes: 16 additions & 0 deletions spec/discovery.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,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 13ab4e0

Please sign in to comment.