Skip to content
This repository has been archived by the owner on Nov 16, 2020. It is now read-only.

Version API and CLI #500

Merged
merged 1 commit into from
Jun 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

VERSION ?= dev
GIT_VERSION = $(shell git describe --tags --dirty)
VERSION ?= $(GIT_VERSION)

GO ?= go
GOVERSIONS ?= go1.9 go1.10
OS := $(shell uname)
SHELL := /bin/bash
GIT_VERSION = $(shell git describe --tags)

.DEFAULT_GOAL := help

Expand All @@ -22,17 +22,14 @@ GO_LDFLAGS += -X $(VERSION_PACKAGE).commit=$(shell git rev-parse HEAD)
GO_LDFLAGS +="

PKGS := pkg
GIT_VERSION = $(shell git describe --tags)


# ?= cannot be used for these variables as they should be evaulated only once per Makefile
ifeq ($(PREFIX),)
PREFIX := $(shell pwd)
endif

ifeq ($(BUILD),)
BUILD := $(shell date +%s)
endif
TAG := $(VERSION)



Expand Down Expand Up @@ -122,13 +119,13 @@ images: linux ci-images

.PHONY: ci-values
ci-values:
scripts/values.sh $(BUILD)
TAG=$(TAG) scripts/values.sh

.PHONY: ci-images $(SERVICES)
ci-images: ci-values $(SERVICES)

$(SERVICES):
scripts/images.sh $@ $(BUILD)
TAG=$(TAG) scripts/images.sh $@

.PHONY: generate
generate: ## run go generate
Expand Down
1 change: 1 addition & 0 deletions charts/dispatch/charts/identity-manager/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ ingress:
# host: dispatch.vmware.com
paths:
- /v1/iam
- /v1/version
tls: {}
# Secrets must be manually created in the namespace.
# secretName: dispatch-tls
Expand Down
19 changes: 19 additions & 0 deletions pkg/api/v1/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
///////////////////////////////////////////////////////////////////////
// Copyright (c) 2018 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
///////////////////////////////////////////////////////////////////////

package v1

// NO TESTS

// Version describes version/build metadata
// swagger:model Version
type Version struct {
Version string `json:"version"`
Commit string `json:"commit"`
BuildDate string `json:"buildDate"`
GoVersion string `json:"goVersion"`
Compiler string `json:"compiler"`
Platform string `json:"platform"`
}
51 changes: 51 additions & 0 deletions pkg/client/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
///////////////////////////////////////////////////////////////////////
// Copyright (c) 2018 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
///////////////////////////////////////////////////////////////////////

package client

import (
"context"

"github.com/go-openapi/runtime"
"github.com/go-openapi/strfmt"
"github.com/pkg/errors"
"github.com/vmware/dispatch/pkg/identity-manager/gen/client/operations"

"github.com/vmware/dispatch/pkg/api/v1"
swaggerclient "github.com/vmware/dispatch/pkg/identity-manager/gen/client"
)

// VersionClient gets the version info from the API
type VersionClient interface {
// GetVersion returns either *v1.Version or error
GetVersion(ctx context.Context) (*v1.Version, error)
}

// DefaultVersionClient is the implementation of VersionClient
type DefaultVersionClient struct {
client *swaggerclient.IdentityManager
auth runtime.ClientAuthInfoWriter
}

// NewVersionClient creates an instance of *DefaultVersionClient
func NewVersionClient(host string, auth runtime.ClientAuthInfoWriter) *DefaultVersionClient {
transport := DefaultHTTPClient(host, swaggerclient.DefaultBasePath)
return &DefaultVersionClient{
client: swaggerclient.New(transport, strfmt.Default),
auth: auth,
}
}

// GetVersion returns either *v1.Version or error
func (vc *DefaultVersionClient) GetVersion(ctx context.Context) (*v1.Version, error) {
params := &operations.GetVersionParams{
Context: context.Background(),
}
resp, err := vc.client.Operations.GetVersion(params, vc.auth)
if err != nil {
return nil, errors.Wrapf(err, "error fetching version info")
}
return resp.Payload, nil
}
4 changes: 4 additions & 0 deletions pkg/dispatchcli/cmd/rest_clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,7 @@ func eventManagerClient() client.EventsClient {
func identityManagerClient() *identitymanager.IdentityManager {
return identitymanager.New(httpTransport(identitymanager.DefaultBasePath), strfmt.Default)
}

func versionClient() client.VersionClient {
return client.NewVersionClient(getDispatchHost(), GetAuthInfoWriter())
}
35 changes: 32 additions & 3 deletions pkg/dispatchcli/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,53 @@
package cmd

import (
"context"
"encoding/json"
"fmt"
"io"

"github.com/spf13/cobra"

"github.com/vmware/dispatch/pkg/api/v1"
"github.com/vmware/dispatch/pkg/dispatchcli/i18n"
"github.com/vmware/dispatch/pkg/version"
)

type versions struct {
Client *v1.Version `json:"client,omitempty"`
Server *v1.Version `json:"server,omitempty"`
}

// NewCmdVersion creates a version command for CLI
func NewCmdVersion(out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "version",
Short: i18n.T("Print Dispatch CLI version."),
Run: func(cmd *cobra.Command, args []string) {
v := version.Get()
fmt.Fprintf(out, "%s-%s\n", v.Version, v.Commit[0:7])
clientVersion := version.Get()
if dispatchConfig.JSON {
encoder := json.NewEncoder(out)
encoder.SetIndent("", " ")

serverVersion, err := getServerVersion()
CheckErr(err)

encoder.Encode(&versions{Client: clientVersion, Server: serverVersion})
return
}

fmt.Fprintf(out, "Client: %s\n", clientVersion.Version)
serverVersion, err := getServerVersion()
CheckErr(err)
fmt.Fprintf(out, "Server: %s\n", serverVersion.Version)
},
}
return cmd
}

func getServerVersion() (*v1.Version, error) {
v, err := versionClient().GetVersion(context.Background())
if err != nil {
return nil, err
}
return v, nil
}
119 changes: 119 additions & 0 deletions pkg/identity-manager/gen/client/operations/get_version_parameters.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading