prevent mismatches between api versions and client versions; maximum brute force (#97)

This commit is contained in:
Michael Quigley 2022-11-21 14:02:51 -05:00
parent a9f76d1b40
commit 002fb0887d
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
2 changed files with 15 additions and 1 deletions

View File

@ -5,6 +5,8 @@ import "fmt"
var Version string
var Hash string
const Series = "v0.3"
func String() string {
if Version != "" {
return fmt.Sprintf("%v [%v]", Version, Hash)

View File

@ -4,11 +4,13 @@ import (
"github.com/go-openapi/runtime"
httptransport "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
"github.com/openziti-test-kitchen/zrok/build"
"github.com/openziti-test-kitchen/zrok/rest_client_zrok"
"github.com/pkg/errors"
"github.com/spf13/pflag"
"net/url"
"os"
"strings"
)
func AddZrokApiEndpointFlag(v *string, flags *pflag.FlagSet) {
@ -27,5 +29,15 @@ func ZrokClient(endpoint string) (*rest_client_zrok.Zrok, error) {
transport := httptransport.New(apiUrl.Host, "/api/v1", []string{apiUrl.Scheme})
transport.Producers["application/zrok.v1+json"] = runtime.JSONProducer()
transport.Consumers["application/zrok.v1+json"] = runtime.JSONConsumer()
return rest_client_zrok.New(transport, strfmt.Default), nil
zrok := rest_client_zrok.New(transport, strfmt.Default)
v, err := zrok.Metadata.Version(nil)
if err != nil {
return nil, errors.Wrapf(err, "error getting version from api endpoint '%v': %v", endpoint, err)
}
if !strings.HasPrefix(string(v.Payload), build.Series) {
return nil, errors.Errorf("expected a '%v' version, received: '%v'", build.Series, v.Payload)
}
return zrok, nil
}