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

Commit 13ab4e0

Browse files
committed
discovery: do not set version to latest if not provided
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.
1 parent 5b7134f commit 13ab4e0

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

discovery/discovery.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ type ACIEndpoints []ACIEndpoint
4949

5050
type PublicKeys []string
5151

52-
const (
53-
defaultVersion = "latest"
54-
)
55-
5652
var (
5753
templateExpression = regexp.MustCompile(`{.*?}`)
5854
errEnough = errors.New("enough discovery information found")
@@ -134,9 +130,6 @@ func createTemplateVars(app App) []string {
134130

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

141134
_, body, err := httpsOrHTTP(pre, hostHeaders, insecure)
142135
if err != nil {

discovery/discovery_test.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,7 @@ func TestDiscoverEndpoints(t *testing.T) {
402402
[]string{"https://example.com/pubkeys.gpg"},
403403
nil,
404404
},
405-
// Test missing labels. version label should default to
406-
// "latest" and the first template should be rendered
405+
// Test missing labels. No template will render
407406
{
408407
&mockHTTPDoer{
409408
doer: fakeHTTPGet(
@@ -415,18 +414,13 @@ func TestDiscoverEndpoints(t *testing.T) {
415414
nil,
416415
),
417416
},
418-
true,
417+
false,
419418
true,
420419
App{
421420
Name: "example.com/myapp",
422421
Labels: map[types.ACIdentifier]string{},
423422
},
424-
[]ACIEndpoint{
425-
ACIEndpoint{
426-
ACI: "https://storage.example.com/example.com/myapp-latest.aci",
427-
ASC: "https://storage.example.com/example.com/myapp-latest.aci.asc",
428-
},
429-
},
423+
[]ACIEndpoint{},
430424
[]string{"https://example.com/pubkeys.gpg"},
431425
nil,
432426
},

spec/discovery.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,19 @@ Authentication during the discovery process is optional.
107107
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.
108108
For example, some implementations might only perform HTTP basic authentication over HTTPS connections.
109109

110+
111+
### Examples
112+
113+
#### Latest pattern
114+
115+
If a client wants to retrieve the latest available ACI (without knowing its version) it can provide these meta tags:
116+
117+
```html
118+
<meta name="ac-discovery" content="example.com https://storage.example.com/{os}/{arch}/{name}-{version}.{ext}">
119+
<meta name="ac-discovery" content="example.com https://storage.example.com/{os}/{arch}/{name}-latest.{ext}">
120+
```
121+
122+
When requiring a specific version, the first template will be rendered, when not requiring a _version_ label the second template will match.
123+
124+
On the http server, the "latest" url should point to the current latest ACI.
125+

0 commit comments

Comments
 (0)