Skip to content

Commit

Permalink
Revert "Revert "OS-9 | Use new cmd pattern and better testing" (#2)" (#4
Browse files Browse the repository at this point in the history
)

This reverts commit 2c168b6.
  • Loading branch information
Hakan Kurtulus authored Jun 4, 2021
1 parent 2c168b6 commit 62341a8
Show file tree
Hide file tree
Showing 25 changed files with 1,831 additions and 686 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: Code Check
name: Test

on:
push:
pull_request:

jobs:
Expand All @@ -21,6 +20,7 @@ jobs:
- name: Get dependencies
run: |
go get -v -t -d ./...
- name: go test
run: go test -v -covermode=count -coverprofile=coverage.out ./...

Expand All @@ -32,6 +32,7 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: coverage.lcov
flag-name: Unit Test

vet:
name: go vet and lint
Expand Down Expand Up @@ -66,4 +67,4 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.37.0
version: v1.40.1
71 changes: 11 additions & 60 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ run:
linters-settings:
goimports:
local-prefixes: github.com/omegion/go-vault-ssh
golint:
min-confidence: 0
gci:
local-prefixes: github.com/omegion/go-vault-ssh
govet:
check-shadowing: true
misspell:
Expand All @@ -18,6 +18,8 @@ linters-settings:
allow-unused: false
require-explanation: true
require-specific: false
funlen:
lines: 80

issues:
exclude-rules:
Expand All @@ -29,64 +31,13 @@ issues:
- gosec
- dupl
- funlen
- scopelint
- testpackage
- ifshort
- paralleltest

linters:
disable-all: true
enable:
- deadcode
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- structcheck
- typecheck
- unused
- varcheck
- asciicheck
- bodyclose
- depguard
- dogsled
- dupl
- exportloopref
- funlen
- gochecknoglobals
- gochecknoinits
- gocognit
- goconst
- gocritic
- gocyclo
- godot
- godox
- goerr113
- gofmt
- gofumpt
- goimports
- golint
- gomnd
- gomodguard
- goprintffuncname
- gosec
- interfacer
- lll
- maligned
- misspell
- nakedret
- nestif
- noctx
- nolintlint
- prealloc
- rowserrcheck
- scopelint
- sqlclosecheck
- stylecheck
- unconvert
- unparam
- whitespace
- wsl
- tparallel
# don't enable:
# - go-header
# - testpackage
disable-all: false
enable-all: true
disable:
- exhaustivestruct
- wrapcheck
11 changes: 7 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
ARG GO_VERSION=1.16-alpine3.12
ARG FROM_IMAGE=alpine:3.12

FROM golang:${GO_VERSION} AS builder
FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS builder

ARG TARGETOS
ARG TARGETARCH

LABEL org.opencontainers.image.source="https://github.com/omegion/vault-ssh"

Expand All @@ -10,15 +13,15 @@ WORKDIR /app
COPY ./ /app

RUN apk update && \
apk add ca-certificates gettext git make curl unzip && \
apk add ca-certificates gettext git make && \
rm -rf /tmp/* && \
rm -rf /var/cache/apk/* && \
rm -rf /var/tmp/*

RUN make build-for-container
RUN make build TARGETOS=$TARGETOS TARGETARCH=$TARGETARCH

FROM ${FROM_IMAGE}

COPY --from=builder /app/dist/vault-ssh-linux /bin/vault-ssh
COPY --from=builder /app/dist/vault-ssh /bin/vault-ssh

ENTRYPOINT ["vault-ssh"]
30 changes: 17 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
export PATH := $(abspath ./vendor/bin):$(PATH)

BASE_PACKAGE_NAME = github.com/omegion/vault-ssh
GIT_VERSION = $(shell git describe --tags --always 2> /dev/null || echo 0.0.0)
LDFLAGS = -ldflags "-X $(BASE_PACKAGE_NAME)/pkg/info.Version=$(GIT_VERSION)"
BUFFER := $(shell mktemp)
REPORT_DIR = dist/report
COVER_PROFILE = $(REPORT_DIR)/coverage.out
BASE_PACKAGE_NAME = github.com/omegion/vault-ssh
GIT_VERSION = $(shell git describe --tags --always 2> /dev/null || echo 0.0.0)
LDFLAGS = -ldflags "-X $(BASE_PACKAGE_NAME)/internal/info.Version=$(GIT_VERSION)"
BUFFER := $(shell mktemp)
REPORT_DIR = dist/report
COVER_PROFILE = $(REPORT_DIR)/coverage.out
TARGETOS = "darwin"
TARGETARCH = "amd64"

.PHONY: build
build:
CGO_ENABLED=0 go build $(LDFLAGS) -installsuffix cgo -o dist/vault-ssh main.go

build-for-container:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -a -installsuffix cgo -o dist/vault-ssh-linux main.go
CGO_ENABLED=0 GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) go build $(LDFLAGS) -a -installsuffix cgo -o dist/vault-ssh main.go

.PHONY: lint
lint:
@echo "Checking code style"
gofmt -l . | tee $(BUFFER)
@! test -s $(BUFFER)
go vet ./...
go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.37.1
go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.40.1
@golangci-lint --version
golangci-lint run
golangci-lint run --fix
go get -u golang.org/x/lint/golint
golint -set_exit_status ./...

Expand All @@ -40,8 +39,13 @@ cut-tag:
git push origin $(version)

.PHONY: release
release: build-for-container
release: build
@echo "Releasing $(GIT_VERSION)"
docker build -t vault-ssh .
docker tag vault-ssh:latest omegion/vault-ssh:$(GIT_VERSION)
docker push omegion/vault-ssh:$(GIT_VERSION)

.PHONY: docker-image
docker-image:
@echo "Building Docker Image"
docker buildx build -t vault-ssh --platform linux/amd64,linux/arm64 . --output=type=docker
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ vault-ssh certificate create --engine my-ssh-signer
3. Read created certificate to put on your server.

```shell
vault-ssh certificate read --engine my-ssh-signer
vault-ssh certificate get --engine my-ssh-signer
```

4. Create a role for the engine.
Expand Down
15 changes: 3 additions & 12 deletions cmd/certificate/create.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package certificate

import (
"fmt"

"github.com/omegion/vault-ssh/pkg/vault"

"github.com/omegion/vault-ssh/internal/controller"
"github.com/omegion/vault-ssh/internal/vault"
"github.com/spf13/cobra"
)

Expand All @@ -21,14 +19,7 @@ func Create() *cobra.Command {
return err
}

err = api.CreateCACertificate(engineName)
if err != nil {
return err
}

fmt.Printf("Certificate created for SSH Engine \"%s\".\n", engineName)

return nil
return controller.NewController(api).CreateCACertificate(engineName)
},
}

Expand Down
11 changes: 5 additions & 6 deletions cmd/certificate/get.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package certificate

import (
"fmt"

"github.com/omegion/vault-ssh/pkg/vault"

"github.com/omegion/vault-ssh/internal/controller"
"github.com/omegion/vault-ssh/internal/vault"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand All @@ -21,12 +20,12 @@ func Get() *cobra.Command {
return err
}

publicKey, err := api.GetCACertificate(engineName)
publicKey, err := controller.NewController(api).GetCACertificate(engineName)
if err != nil {
return err
}

fmt.Printf("%s\n", publicKey)
log.Infoln(publicKey)

return nil
},
Expand Down
22 changes: 4 additions & 18 deletions cmd/enable.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
package cmd

import (
"fmt"

"github.com/omegion/vault-ssh/pkg/vault"

"github.com/omegion/vault-ssh/internal/controller"
"github.com/omegion/vault-ssh/internal/vault"
"github.com/spf13/cobra"
)

// setupAddCommand sets default flags.
func setupGetCommand(cmd *cobra.Command) {
cmd.Flags().String("path", vault.SSHEngineDefaultName, "SSH engine path")
}

// Enable enables SSH engine.
func Enable() *cobra.Command {
cmd := &cobra.Command{
Expand All @@ -26,18 +19,11 @@ func Enable() *cobra.Command {
return err
}

err = api.EnableSSHEngine(path)
if err != nil {
return err
}

fmt.Printf("\"%s\" SSH Engine enabled.\n", path)

return nil
return controller.NewController(api).EnableSSHEngine(path)
},
}

setupGetCommand(cmd)
cmd.Flags().String("path", vault.SSHEngineDefaultName, "SSH engine path")

return cmd
}
1 change: 1 addition & 0 deletions cmd/fixtures/public-key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
X
17 changes: 0 additions & 17 deletions cmd/helpers.go

This file was deleted.

15 changes: 3 additions & 12 deletions cmd/role/create.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package role

import (
"fmt"

"github.com/omegion/vault-ssh/pkg/vault"

"github.com/omegion/vault-ssh/internal/controller"
"github.com/omegion/vault-ssh/internal/vault"
"github.com/spf13/cobra"
)

Expand All @@ -22,14 +20,7 @@ func Create() *cobra.Command {
return err
}

err = api.CreateRole(engineName, roleName)
if err != nil {
return err
}

fmt.Printf("\"%s\" created for SSH Engine \"%s\" enabled.\n", roleName, engineName)

return nil
return controller.NewController(api).CreateRole(engineName, roleName)
},
}

Expand Down
Loading

0 comments on commit 62341a8

Please sign in to comment.