mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-27 10:47:35 +00:00
version/updates: start of version updates policy package
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
0fa1da2d1b
commit
d39e972e59
38
version/updates/rules.json
Normal file
38
version/updates/rules.json
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
{
|
||||||
|
"tests": [
|
||||||
|
{
|
||||||
|
"os": "linux",
|
||||||
|
"distro": "synology",
|
||||||
|
"ver": "1.14.5",
|
||||||
|
"want": "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"os": "windows",
|
||||||
|
"ver": "1.2.1",
|
||||||
|
"want": "update/security",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"rules": [
|
||||||
|
{
|
||||||
|
"ver": "1.12.3",
|
||||||
|
"os": "linux",
|
||||||
|
"distro": "synology",
|
||||||
|
"then": "stop",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"os": "windows",
|
||||||
|
"thenRules": [],
|
||||||
|
"elseRules": [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ver": "<1.2.3",
|
||||||
|
"os": "windows",
|
||||||
|
"then": "update/security: some notes",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ver": "<1.14",
|
||||||
|
"now": ">=2020-09-29",
|
||||||
|
"then": "update",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
50
version/updates/updates.go
Normal file
50
version/updates/updates.go
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
// Copyright (c) 2021 Tailscale Inc & AUTHORS All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// Packate updates is an evalator for a update policy file that controls
|
||||||
|
// when users get update available notifications (and which types).
|
||||||
|
//
|
||||||
|
// It's used and hot reloaded by several servers. It permits us to
|
||||||
|
// centralize and test the update policy.
|
||||||
|
package updates
|
||||||
|
|
||||||
|
type Policy struct {
|
||||||
|
Tests []*Test
|
||||||
|
Rules []*Rule
|
||||||
|
}
|
||||||
|
|
||||||
|
type Test struct {
|
||||||
|
OS string
|
||||||
|
Distro string // "synology" on Linux
|
||||||
|
Ver string // "1.2.3-tXXXX-gXXX"
|
||||||
|
Want string // "", "update", "update/security"
|
||||||
|
}
|
||||||
|
|
||||||
|
type Rule struct {
|
||||||
|
// Ver, if non-empty, matches the version number.
|
||||||
|
// If it begins with an operator ("<", "<=", then the comparison
|
||||||
|
// is done semantically based on semver, not lexically.
|
||||||
|
Ver string
|
||||||
|
|
||||||
|
// OS, if non-empty, matches the node operating system.
|
||||||
|
// Possible values: "linux", "windows", "macOS", "iOS", or
|
||||||
|
// else a runtime.GOOS value (except not "darwin" or "ios").
|
||||||
|
OS string
|
||||||
|
|
||||||
|
// Package, if non-empty, matches the packaging variant.
|
||||||
|
// Possible values: "choco", "appstore", "macsys", "tailscaled".
|
||||||
|
Package string
|
||||||
|
|
||||||
|
// Distro, if non-empty, matches the node's distro.
|
||||||
|
// Possible values: "synology".
|
||||||
|
Distro string
|
||||||
|
|
||||||
|
// Now, if non-empty, matches based on the current date in UTC.
|
||||||
|
// e.g. ">=2021-10-07".
|
||||||
|
Now string
|
||||||
|
|
||||||
|
Then string // "stop", "update", "update/security", "update: note"
|
||||||
|
ThenRules []*Rule
|
||||||
|
ElseRules []*Rule
|
||||||
|
}
|
28
version/updates/updates_test.go
Normal file
28
version/updates/updates_test.go
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// Copyright (c) 2021 Tailscale Inc & AUTHORS All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package updates
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/tailscale/hujson"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestParse(t *testing.T) {
|
||||||
|
rulesJSON, err := os.ReadFile("rules.json")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
d := hujson.NewDecoder(bytes.NewReader(rulesJSON))
|
||||||
|
d.DisallowUnknownFields()
|
||||||
|
|
||||||
|
var p Policy
|
||||||
|
if err := d.Decode(&p); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user