versioncontrol: add new version schema (#2991)

This commit is contained in:
Michal Niewrzal 2019-09-11 07:01:36 -07:00 committed by GitHub
parent b9e5331193
commit 40ff56f6c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 70 additions and 23 deletions

View File

@ -51,28 +51,6 @@ var (
binaryLocation string
)
// Response response from version server.
type Response struct {
Processes Processes `json:"processes"`
}
// Processes describes versions for each binary.
type Processes struct {
Storagenode Process `json:"storagenode"`
}
// Process versions for specific binary.
type Process struct {
Minimum Version `json:"minimum"`
Suggested Version `json:"suggested"`
}
// Version represents version and download URL for binary.
type Version struct {
Version string `json:"version"`
URL string `json:"url"`
}
func init() {
rootCmd.AddCommand(runCmd)
@ -183,7 +161,7 @@ func suggestedVersion() (ver version.SemVer, url string, err error) {
return ver, url, err
}
var response Response
var response version.AllowedVersions
err = json.Unmarshal(body, &response)
if err != nil {
return ver, url, err

View File

@ -58,6 +58,30 @@ type AllowedVersions struct {
Uplink SemVer
Gateway SemVer
Identity SemVer
Processes Processes `json:"processes"`
}
// Processes describes versions for each binary.
type Processes struct {
Bootstrap Process `json:"bootstrap"`
Satellite Process `json:"satellite"`
Storagenode Process `json:"storagenode"`
Uplink Process `json:"uplink"`
Gateway Process `json:"gateway"`
Identity Process `json:"identity"`
}
// Process versions for specific binary.
type Process struct {
Minimum Version `json:"minimum"`
Suggested Version `json:"suggested"`
}
// Version represents version and download URL for binary.
type Version struct {
Version string `json:"version"`
URL string `json:"url"`
}
// SemVerRegex is the regular expression used to parse a semantic version.

View File

@ -21,6 +21,8 @@ import (
type Config struct {
Address string `user:"true" help:"public address to listen on" default:":8080"`
Versions ServiceVersions
Binary Versions
}
// ServiceVersions provides a list of allowed Versions per Service
@ -33,6 +35,28 @@ type ServiceVersions struct {
Identity string `user:"true" help:"Allowed Identity Versions" default:"v0.0.1"`
}
// Versions represents versions for all binaries
type Versions struct {
Bootstrap Binary
Satellite Binary
Storagenode Binary
Uplink Binary
Gateway Binary
Identity Binary
}
// Binary represents versions for single binary
type Binary struct {
Minimum Version
Suggested Version
}
// Version single version
type Version struct {
Version string `user:"true" help:"peer version" default:"v0.0.1"`
URL string `user:"true" help:"URL for specific binary" default:""`
}
// Peer is the representation of a VersionControl Server.
type Peer struct {
// core dependencies
@ -107,6 +131,14 @@ func New(log *zap.Logger, config *Config) (peer *Peer, err error) {
return &Peer{}, err
}
peer.Versions.Processes = version.Processes{}
peer.Versions.Processes.Bootstrap = configToProcess(config.Binary.Bootstrap)
peer.Versions.Processes.Satellite = configToProcess(config.Binary.Satellite)
peer.Versions.Processes.Storagenode = configToProcess(config.Binary.Storagenode)
peer.Versions.Processes.Uplink = configToProcess(config.Binary.Uplink)
peer.Versions.Processes.Gateway = configToProcess(config.Binary.Gateway)
peer.Versions.Processes.Identity = configToProcess(config.Binary.Identity)
peer.response, err = json.Marshal(peer.Versions)
if err != nil {
@ -153,3 +185,16 @@ func (peer *Peer) Close() (err error) {
// Addr returns the public address.
func (peer *Peer) Addr() string { return peer.Server.Listener.Addr().String() }
func configToProcess(binary Binary) version.Process {
return version.Process{
Minimum: version.Version{
Version: binary.Minimum.Version,
URL: binary.Minimum.URL,
},
Suggested: version.Version{
Version: binary.Suggested.Version,
URL: binary.Suggested.URL,
},
}
}