mirror of
https://github.com/openziti/zrok.git
synced 2024-11-25 17:43:53 +01:00
prevent mismatches between api versions and client versions; maximum brute force (#97)
This commit is contained in:
parent
a9f76d1b40
commit
002fb0887d
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user