Skip to content

Commit 37a6123

Browse files
committed
A Makefile and some golint fixes
The Makefile makes it easier to build and actually substitute the version of code into the built binary in the canonical golang way. Finally. And some basic golint suggestions were adopted.
1 parent d25bae6 commit 37a6123

7 files changed

Lines changed: 26 additions & 20 deletions

File tree

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
TAG?=1.6.1
2+
VERSION := $(shell echo `git describe --tags --long --match=*.*.* --dirty` | sed s/version-//g)
3+
4+
PKG=github.com/cloudtools/ssh-cert-authority
5+
6+
test:
7+
go test ./...
8+
9+
vet:
10+
go vet ./...
11+
12+
all: test
13+
go build -ldflags "-X ${PKG}/version.Tag=${TAG} -X ${PKG}/version.BuildVersion=${VERSION}" .

client/client.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@ func (req *SigningRequest) PostToWeb(requestParameters url.Values) error {
6060
if resp.StatusCode != 200 {
6161
respBuf, _ := ioutil.ReadAll(resp.Body)
6262
return fmt.Errorf("HTTP %s: %s", resp.Status, string(respBuf))
63-
} else {
64-
return nil
6563
}
64+
return nil
6665
}
6766

6867
func (req *SigningRequest) DeleteToWeb(requestParameters url.Values) error {
@@ -81,9 +80,8 @@ func (req *SigningRequest) DeleteToWeb(requestParameters url.Values) error {
8180
if resp.StatusCode != 200 {
8281
respBuf, _ := ioutil.ReadAll(resp.Body)
8382
return fmt.Errorf("HTTP %s: %s", resp.Status, string(respBuf))
84-
} else {
85-
return nil
8683
}
84+
return nil
8785
}
8886

8987
func (req *CertRequest) SetConfig(config ssh_ca_util.RequesterConfig) error {
@@ -195,9 +193,8 @@ func (req *CertRequest) PostToWeb(requestParameters url.Values) (string, bool, e
195193
if resp.StatusCode == 201 || resp.StatusCode == 202 {
196194
signed := resp.StatusCode == 202
197195
return string(respBuf), signed, nil
198-
} else {
199-
return "", false, fmt.Errorf("Cert request rejected: %s", string(respBuf))
200196
}
197+
return "", false, fmt.Errorf("Cert request rejected: %s", string(respBuf))
201198
}
202199

203200
type SlackWebhookInput struct {
@@ -233,7 +230,6 @@ func PostToSlack(slackUrl, slackChannel, msg string) error {
233230
}
234231
if resp.StatusCode == 200 {
235232
return nil
236-
} else {
237-
return fmt.Errorf("Slack post rejected: %s", string(respBuf))
238233
}
234+
return fmt.Errorf("Slack post rejected: %s", string(respBuf))
239235
}

generate_config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func cmdGenerateConfig(c *cli.Context) error {
5454
return cli.NewExitError(fmt.Sprintf("Error getting listing of environments: %s", string(getRespBuf)), 1)
5555
}
5656

57-
environments := make([]string, 0)
57+
var environments []string
5858
json.Unmarshal(getRespBuf, &environments)
5959

6060
wholeConfig := make(map[string]ssh_ca_util.RequesterConfig, len(environments))

main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package main
22

33
import (
4-
"github.com/cloudtools/ssh-cert-authority/util"
4+
"github.com/cloudtools/ssh-cert-authority/version"
55
"github.com/codegangsta/cli"
66
"os"
77
)
@@ -10,7 +10,7 @@ func main() {
1010
app := cli.NewApp()
1111
app.Name = "ssh-cert-authority"
1212
app.EnableBashCompletion = true
13-
app.Version = ssh_ca_util.BuildVersion
13+
app.Version = version.BuildVersion
1414

1515
app.Commands = []cli.Command{
1616
{

sign_cert.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,8 @@ func signCert(c *cli.Context) error {
144144
}
145145
if err != nil {
146146
return cli.NewExitError(fmt.Sprintf("Error sending in +1: %s", err), 1)
147-
} else {
148-
fmt.Println("Signature accepted by server.")
149147
}
148+
fmt.Println("Signature accepted by server.")
150149
return nil
151150

152151
}

sign_certd.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/aws/aws-sdk-go/service/kms"
1515
"github.com/cloudtools/ssh-cert-authority/client"
1616
"github.com/cloudtools/ssh-cert-authority/util"
17+
"github.com/cloudtools/ssh-cert-authority/version"
1718
"github.com/codegangsta/cli"
1819
"github.com/gorilla/mux"
1920
"golang.org/x/crypto/ssh"
@@ -46,7 +47,7 @@ func isSupportedOption(x string) bool {
4647
}
4748

4849
func areCriticalOptionsValid(criticalOptions map[string]string) error {
49-
for optionName, _ := range criticalOptions {
50+
for optionName := range criticalOptions {
5051
if !isSupportedOption(optionName) {
5152
return fmt.Errorf("Invalid critical option name: '%s'", optionName)
5253
}
@@ -398,8 +399,8 @@ func newResponseElement(certBlob string, signed bool, numSignatures, signaturesR
398399
}
399400

400401
func (h *certRequestHandler) listEnvironments(rw http.ResponseWriter, req *http.Request) {
401-
environments := make([]string, 0)
402-
for k, _ := range h.Config {
402+
var environments []string
403+
for k := range h.Config {
403404
environments = append(environments, k)
404405
}
405406
result, err := json.Marshal(environments)
@@ -667,7 +668,7 @@ func makeCertRequestHandler(config map[string]ssh_ca_util.SignerdConfig) certReq
667668
}
668669

669670
func runSignCertd(config map[string]ssh_ca_util.SignerdConfig, addr string) error {
670-
log.Println("Server running version", ssh_ca_util.BuildVersion)
671+
log.Println("Server running version", version.BuildVersion)
671672
log.Println("Using SSH agent at", os.Getenv("SSH_AUTH_SOCK"))
672673

673674
sshAgentConn, err := net.Dial("unix", os.Getenv("SSH_AUTH_SOCK"))

util/version.go

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)