Skip to content

Commit

Permalink
add CLI version tag
Browse files Browse the repository at this point in the history
  • Loading branch information
skpratt committed Jun 6, 2023
1 parent f14ab2c commit cd7274c
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 14 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ jobs:
path: out/${{ env.DEB_PACKAGE }}

build-docker:
name: Docker ${{ matrix.arch }} ${{ matrix.fips }} default release build
name: Docker ${{ matrix.goarch }} ${{ matrix.fips }} default release build
needs: [get-product-version, build]
runs-on: ubuntu-latest
strategy:
Expand All @@ -258,11 +258,11 @@ jobs:
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: consul-cni_${{ needs.get-product-version.outputs.product-version }}${{ matrix.fips }}_linux_${{ matrix.arch }}.zip
path: control-plane/dist/cni/linux/${{ matrix.arch }}
name: consul-cni_${{ needs.get-product-version.outputs.product-version }}${{ matrix.fips }}_linux_${{ matrix.goarch }}.zip
path: control-plane/dist/cni/linux/${{ matrix.goarch }}
- name: extract consul-cni zip
env:
ZIP_LOCATION: control-plane/dist/cni/linux/${{ matrix.arch }}
ZIP_LOCATION: control-plane/dist/cni/linux/${{ matrix.goarch }}
run: |
cd "${ZIP_LOCATION}"
unzip -j *.zip
Expand All @@ -278,7 +278,7 @@ jobs:
echo "Test PASSED"
version: ${{ env.version }}
target: release-default
arch: ${{ matrix.arch }}
arch: ${{ matrix.goarch }}
pkg_name: consul-k8s-control-plane_${{ env.version }}
bin_name: consul-k8s-control-plane
workdir: control-plane
Expand Down
27 changes: 27 additions & 0 deletions cli/version/fips_build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//go:build fips

package version

// This validates during compilation that we are being built with a FIPS enabled go toolchain
import (
_ "crypto/tls/fipsonly"
"runtime"
"strings"
)

// IsFIPS returns true if consul-k8s is operating in FIPS-140-2 mode.
func IsFIPS() bool {
return true
}

func GetFIPSInfo() string {
str := "Enabled"
// Try to get the crypto module name
gover := strings.Split(runtime.Version(), "X:")
if len(gover) >= 2 {
gover_last := gover[len(gover)-1]
// Able to find crypto module name; add that to status string.
str = "FIPS 140-2 Enabled, crypto module " + gover_last
}
return str
}
12 changes: 12 additions & 0 deletions cli/version/non_fips_build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build !fips

package version

// IsFIPS returns true if consul-k8s is operating in FIPS-140-2 mode.
func IsFIPS() bool {
return false
}

func GetFIPSInfo() string {
return ""
}
6 changes: 5 additions & 1 deletion cli/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ func GetHumanVersion() string {
release = "dev"
}

if IsFIPS() {
version += ".fips1402"
}

if release != "" {
if !strings.HasSuffix(version, "-"+release) {
if !strings.Contains(version, "-"+release) {
// if we tagged a prerelease version then the release is in the version already
version += fmt.Sprintf("-%s", release)
}
Expand Down
4 changes: 1 addition & 3 deletions control-plane/consul/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import (
"net/http"
"time"

"github.com/hashicorp/consul-k8s/control-plane/version"
"github.com/hashicorp/consul-server-connection-manager/discovery"
capi "github.com/hashicorp/consul/api"

"github.com/hashicorp/consul-k8s/control-plane/version"
)

//go:generate mockery --name ServerConnectionManager --inpkg
Expand Down Expand Up @@ -59,7 +58,6 @@ func NewClient(config *capi.Config, consulAPITimeout time.Duration) (*capi.Clien
return nil, err
}
client.AddHeader("User-Agent", fmt.Sprintf("consul-k8s/%s", version.GetHumanVersion()))

return client, nil
}

Expand Down
10 changes: 5 additions & 5 deletions control-plane/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ func GetHumanVersion() string {
}
version = fmt.Sprintf("v%s", version)

if IsFIPS() {
version = fmt.Sprintf("%s+fips", version)
}

release := VersionPrerelease
if GitDescribe == "" && release == "" {
release = "dev"
}

if IsFIPS() {
version += ".fips1402"
}

if release != "" {
if !strings.HasSuffix(version, "-"+release) {
if !strings.Contains(version, "-"+release) {
// if we tagged a prerelease version then the release is in the version already
version += fmt.Sprintf("-%s", release)
}
Expand Down

0 comments on commit cd7274c

Please sign in to comment.