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 468c78e
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 9 deletions.
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 468c78e

Please sign in to comment.