Skip to content
This repository has been archived by the owner on Apr 6, 2021. It is now read-only.

Commit

Permalink
0.2.0-beta is out
Browse files Browse the repository at this point in the history
- Simplified build process
- Automated cross-platform builds
- Switched to HTTP redirect vs DIY JSON redirects
  • Loading branch information
kontsevoy committed Sep 5, 2016
1 parent 4646546 commit 54c8bdd
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 48 deletions.
26 changes: 4 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,44 +1,26 @@
# To create a new release of Teleconsole:
# - make your changes
# - bump VERSION variable in this Makefile
# - run 'make version'
# - commit & push to git
# - run `make release` to create git tags
# - run 'make'
# - THEN commit & push to git
# - run `make release` to create and push the new git tag

# To bump the version, edit this variable and run `make version`
export VERSION=0.1.1-beta

export VERSION=0.2.0-beta
OUT=out/teleconsole
GOSRC=$(shell find -name "*.go" -print)
TELEPORT=$(shell find ../../gravitational/teleport/lib -name "*.go" -print)
TARBALL="teleconsole-v$(VERSION)-`go env GOOS`-`go env GOARCH`.tar.bz2"

# Default target: out/teleconsole
$(OUT): $(GOSRC) Makefile
$(MAKE) -C version
go build -i -ldflags -w -o $(OUT)

# Runs teleconsole against a server hosted in a local VM running
# as 'teleconsole.local'
.PHONY:dev
dev: clean
$(MAKE) $(OUT)
$(MAKE) -C ../telecast clean
$(MAKE) -C ../telecast dev
sleep 3
out/teleconsole -s teleconsole.local:5000 -insecure

# Makes a new release (pushes tags to Github)
.PHONY:release
release: version
git tag -f $(VERSION)
git push --tags --force

# Make version bumps the version
.PHONY:version
version:
@VERSION=$(VERSION) $(MAKE) -C version

.PHONY:clean
clean:
rm -rf out
Expand Down
48 changes: 32 additions & 16 deletions clt/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,14 @@ func NewAPIClient(config *conf.Config, clientVersion string) *APIClient {
Endpoint: config.APIEndpointURL,
clientVersion: clientVersion,
}
// create cookie storage:
client.httpClient.Jar, _ = cookiejar.New(nil)

// disable automatic redirects
client.httpClient.CheckRedirect = func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
}

if config.InsecureHTTPS {
fmt.Println("\033[1mWARNING:\033[0m running in insecure mode!")
client.httpClient.Transport = &http.Transport{
Expand All @@ -53,10 +59,32 @@ func NewAPIClient(config *conf.Config, clientVersion string) *APIClient {
// Sends the version of the client to the server and receives a session
// cookie. Every new API conversation must start here
func (this *APIClient) CheckVersion() error {
resp, err := this.GET("/api/version")
if err != nil {
log.Error(err)
return trace.Wrap(err)
var (
resp *http.Response
err error
)
const maxRedirects = 2

for i := 0; i <= maxRedirects; i++ {
log.Infof("Getting version from %s", this.Endpoint)
// Request server's version (and report ours):
resp, err = this.GET("/api/version")
if err != nil {
log.Error(err)
return trace.Wrap(err)
}
// Redirect to another less busy server?
if resp.StatusCode == http.StatusTemporaryRedirect {
ep := resp.Header.Get("Location")
if ep == "" {
return trace.Errorf("Invalid redirect from the server")
}
if this.Endpoint, err = url.Parse(ep); err != nil {
return trace.Errorf("Invalid redirect from the server to '%s'", ep)
}
continue
}
break
}
// HTTP error?
if resp.StatusCode != http.StatusOK {
Expand All @@ -73,18 +101,6 @@ func (this *APIClient) CheckVersion() error {
if sv.WarningMsg != "" {
fmt.Println("\033[1mWARNING:\033[0m", sv.WarningMsg)
}
// change the endpoint if requested:
if sv.Endpoint != "" {
u := &url.URL{
Scheme: "https",
Host: this.Endpoint.Host,
Path: "/api",
}
cookies := this.httpClient.Jar.Cookies(u)
u.Host = sv.Endpoint
this.Endpoint.Host = sv.Endpoint
this.httpClient.Jar.SetCookies(u, cookies)
}
log.Infof("Connecting to https://%s", this.Endpoint.Host)
return nil
}
Expand Down
4 changes: 0 additions & 4 deletions lib/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ type ServerVersion struct {

// clients must show this warning message to users if it's not empty
WarningMsg string `json:"warn_msg"`

// server may "redirect" the client to use this endpoint
// instead:
Endpoint string `json:"endpoint"`
}

func (s *Session) GetNodeHostPort() (host string, port int, err error) {
Expand Down
6 changes: 3 additions & 3 deletions version/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ BUILDDATE=`date +%F`
GITREF=`git describe --always --tags --dirty --long`

# $(VERSION_GO) will be written to version.go
VERSION_GO="/* DO NOT EDIT THIS FILE. IT IS GENERATED BY 'make setver'*/\n\
VERSION_GO="/* DO NOT EDIT THIS FILE. IT IS GENERATED BY 'make'*/\n\
package version\n\
const( Version = \"$(VERSION)\"\n)\nvar Gitref, BuildDate string\n"

Expand All @@ -16,5 +16,5 @@ func init() { Gitref = \"$(GITREF)\"\nBuildDate= \"$(BUILDDATE)\"\n} "
#
.PHONY:setver
setver:
@printf $(VERSION_GO) > version.go
@printf $(GITREF_GO) > git.go
@printf $(VERSION_GO) | gofmt > version.go
@printf $(GITREF_GO) | gofmt > git.go
9 changes: 6 additions & 3 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/* DO NOT EDIT THIS FILE. IT IS GENERATED BY 'make setver'*/
package version
const( Version = "0.1.1-beta"
/* DO NOT EDIT THIS FILE. IT IS GENERATED BY 'make'*/
package version

const (
Version = "0.2.0-beta"
)

var Gitref, BuildDate string

0 comments on commit 54c8bdd

Please sign in to comment.