mirror of
https://github.com/openziti/ziti.git
synced 2026-10-12 23:32:02 +00:00
Fixed a bug with environment variables output, cleaned up environment command output, Updated tests for environment command.
Renamed edge controller port to be more clear.
This commit is contained in:
@@ -1,48 +1,6 @@
|
||||
{{ if eq .OS "windows" }}Rem {{ else }}# {{ end }}{{ .ZitiHomeVarDescription }}
|
||||
{{ if eq .OS "windows" }}SET{{ else }}export{{ end }} {{ .ZitiHomeVarName }}={{ .ZitiHome }}
|
||||
{{ if eq .OS "windows" }}Rem {{ else }}# {{ end }}{{ .ZitiCtrlNameVarDescription }}
|
||||
{{ if eq .OS "windows" }}SET{{ else }}export{{ end }} {{ .ZitiCtrlNameVarName }}={{ .Controller.Name }}
|
||||
{{ if eq .OS "windows" }}Rem {{ else }}# {{ end }}{{ .ZitiCtrlPortVarDescription }}
|
||||
{{ if eq .OS "windows" }}SET{{ else }}export{{ end }} {{ .ZitiCtrlPortVarName }}={{ .Controller.Port }}
|
||||
{{ if eq .OS "windows" }}Rem {{ else }}# {{ end }}{{ .ZitiEdgeRouterRawNameVarDescription }}
|
||||
{{ if eq .OS "windows" }}SET{{ else }}export{{ end }} {{ .ZitiEdgeRouterRawNameVarName }}={{ .Router.Edge.Hostname }}
|
||||
{{ if eq .OS "windows" }}Rem {{ else }}# {{ end }}{{ .ZitiEdgeRouterPortVarDescription }}
|
||||
{{ if eq .OS "windows" }}SET{{ else }}export{{ end }} {{ .ZitiEdgeRouterPortVarName }}={{ .Router.Edge.Port }}
|
||||
{{ if eq .OS "windows" }}Rem {{ else }}# {{ end }}{{ .ZitiCtrlListenerAddressVarDescription }}
|
||||
{{ if eq .OS "windows" }}SET{{ else }}export{{ end }} {{ .ZitiCtrlListenerAddressVarName }}={{ .Controller.ListenerAddress }}
|
||||
{{ if eq .OS "windows" }}Rem {{ else }}# {{ end }}{{ .ZitiCtrlAdvertisedAddressVarDescription }}
|
||||
{{ if eq .OS "windows" }}SET{{ else }}export{{ end }} {{ .ZitiCtrlAdvertisedAddressVarName }}={{ .Controller.AdvertisedAddress }}
|
||||
{{ if eq .OS "windows" }}Rem {{ else }}# {{ end }}{{ .ZitiEdgeCtrlIdentityCertVarDescription }}
|
||||
{{ if eq .OS "windows" }}SET{{ else }}export{{ end }} {{ .ZitiEdgeCtrlIdentityCertVarName }}={{ .Controller.Edge.IdentityCert }}
|
||||
{{ if eq .OS "windows" }}Rem {{ else }}# {{ end }}{{ .ZitiEdgeCtrlIdentityServerCertVarDescription }}
|
||||
{{ if eq .OS "windows" }}SET{{ else }}export{{ end }} {{ .ZitiEdgeCtrlIdentityServerCertVarName }}={{ .Controller.Edge.IdentityServerCert }}
|
||||
{{ if eq .OS "windows" }}Rem {{ else }}# {{ end }}{{ .ZitiEdgeCtrlIdentityKeyVarDescription }}
|
||||
{{ if eq .OS "windows" }}SET{{ else }}export{{ end }} {{ .ZitiEdgeCtrlIdentityKeyVarName }}={{ .Controller.Edge.IdentityKey }}
|
||||
{{ if eq .OS "windows" }}Rem {{ else }}# {{ end }}{{ .ZitiEdgeCtrlIdentityCAVarDescription }}
|
||||
{{ if eq .OS "windows" }}SET{{ else }}export{{ end }} {{ .ZitiEdgeCtrlIdentityCAVarName }}={{ .Controller.Edge.IdentityCA }}
|
||||
{{ if eq .OS "windows" }}Rem {{ else }}# {{ end }}{{ .ZitiEdgeCtrlPortVarDescription }}
|
||||
{{ if eq .OS "windows" }}SET{{ else }}export{{ end }} {{ .ZitiEdgeCtrlPortVarName }}={{ .Controller.Edge.Port }}
|
||||
{{ if eq .OS "windows" }}Rem {{ else }}# {{ end }}{{ .ZitiCtrlIdentityCertVarDescription }}
|
||||
{{ if eq .OS "windows" }}SET{{ else }}export{{ end }} {{ .ZitiCtrlIdentityCertVarName }}={{ .Controller.IdentityCert }}
|
||||
{{ if eq .OS "windows" }}Rem {{ else }}# {{ end }}{{ .ZitiCtrlIdentityServerCertVarDescription }}
|
||||
{{ if eq .OS "windows" }}SET{{ else }}export{{ end }} {{ .ZitiCtrlIdentityServerCertVarName }}={{ .Controller.IdentityServerCert }}
|
||||
{{ if eq .OS "windows" }}Rem {{ else }}# {{ end }}{{ .ZitiCtrlIdentityKeyVarDescription }}
|
||||
{{ if eq .OS "windows" }}SET{{ else }}export{{ end }} {{ .ZitiCtrlIdentityKeyVarName }}={{ .Controller.IdentityKey }}
|
||||
{{ if eq .OS "windows" }}Rem {{ else }}# {{ end }}{{ .ZitiCtrlIdentityCAVarDescription }}
|
||||
{{ if eq .OS "windows" }}SET{{ else }}export{{ end }} {{ .ZitiCtrlIdentityCAVarName }}={{ .Controller.IdentityCA }}
|
||||
{{ if eq .OS "windows" }}Rem {{ else }}# {{ end }}{{ .ZitiRouterIdentityCertVarDescription }}
|
||||
{{ if eq .OS "windows" }}SET{{ else }}export{{ end }} {{ .ZitiRouterIdentityCertVarName }}={{ .Router.IdentityCert }}
|
||||
{{ if eq .OS "windows" }}Rem {{ else }}# {{ end }}{{ .ZitiRouterIdentityServerCertVarDescription }}
|
||||
{{ if eq .OS "windows" }}SET{{ else }}export{{ end }} {{ .ZitiRouterIdentityServerCertVarName }}={{ .Router.IdentityServerCert }}
|
||||
{{ if eq .OS "windows" }}Rem {{ else }}# {{ end }}{{ .ZitiRouterIdentityKeyVarDescription }}
|
||||
{{ if eq .OS "windows" }}SET{{ else }}export{{ end }} {{ .ZitiRouterIdentityKeyVarName }}={{ .Router.IdentityKey }}
|
||||
{{ if eq .OS "windows" }}Rem {{ else }}# {{ end }}{{ .ZitiRouterIdentityCAVarDescription }}
|
||||
{{ if eq .OS "windows" }}SET{{ else }}export{{ end }} {{ .ZitiRouterIdentityCAVarName }}={{ .Router.IdentityCA }}
|
||||
{{ if eq .OS "windows" }}Rem {{ else }}# {{ end }}{{ .ZitiSigningCertVarDescription }}
|
||||
{{ if eq .OS "windows" }}SET{{ else }}export{{ end }} {{ .ZitiSigningCertVarName }}={{ .Controller.Edge.ZitiSigningCert }}
|
||||
{{ if eq .OS "windows" }}Rem {{ else }}# {{ end }}{{ .ZitiSigningKeyVarDescription }}
|
||||
{{ if eq .OS "windows" }}SET{{ else }}export{{ end }} {{ .ZitiSigningKeyVarName }}={{ .Controller.Edge.ZitiSigningKey }}
|
||||
{{ if eq .OS "windows" }}Rem {{ else }}# {{ end }}{{ .ZitiEdgeCtrlListenerHostPortVarDescription }}
|
||||
{{ if eq .OS "windows" }}SET{{ else }}export{{ end }} {{ .ZitiEdgeCtrlListenerHostPortVarName }}={{ .Controller.Edge.ListenerHostPort }}
|
||||
{{ if eq .OS "windows" }}Rem {{ else }}# {{ end }}{{ .ZitiEdgeCtrlAdvertisedHostPortVarDescription }}
|
||||
{{ if eq .OS "windows" }}SET{{ else }}export{{ end }} {{ .ZitiEdgeCtrlAdvertisedHostPortVarName }}={{ .Controller.Edge.AdvertisedHostPort }}
|
||||
{{ $commentPrefix := .OSCommentPrefix }}
|
||||
{{ $varDeclare := .OSVarDeclare }}
|
||||
{{- range .EnvVars}}
|
||||
{{ $commentPrefix }} {{ .Description }}
|
||||
{{ $varDeclare }} {{ .Name }}={{ .Value }}
|
||||
{{- end }}
|
||||
@@ -83,7 +83,7 @@ type ControllerTemplateValues struct {
|
||||
}
|
||||
|
||||
type EdgeControllerValues struct {
|
||||
Port string
|
||||
AdvertisedPort string
|
||||
ZitiSigningCert string
|
||||
ZitiSigningKey string
|
||||
|
||||
@@ -237,9 +237,9 @@ func (data *ConfigTemplateValues) populateEnvVars() {
|
||||
zitiEdgeCtrlAdvertisedHostPort, err := cmdhelper.GetZitiEdgeCtrlAdvertisedHostPort()
|
||||
handleVariableError(err, constants.ZitiEdgeCtrlAdvertisedHostPortVarName)
|
||||
|
||||
// Get Ziti Edge Controller Port
|
||||
zitiEdgeCtrlPort, err := cmdhelper.GetZitiEdgeCtrlPort()
|
||||
handleVariableError(err, constants.ZitiEdgeCtrlPortVarName)
|
||||
// Get Ziti Edge Controller Advertised Port
|
||||
zitiEdgeCtrlAdvertisedPort, err := cmdhelper.GetZitiEdgeCtrlAdvertisedPort()
|
||||
handleVariableError(err, constants.ZitiEdgeCtrlAdvertisedPortVarName)
|
||||
|
||||
data.ZitiHome = zitiHome
|
||||
data.Hostname = hostname
|
||||
@@ -250,7 +250,7 @@ func (data *ConfigTemplateValues) populateEnvVars() {
|
||||
data.Controller.Edge.ListenerHostPort = zitiEdgeCtrlListenerHostPort
|
||||
data.Controller.Edge.AdvertisedHostPort = zitiEdgeCtrlAdvertisedHostPort
|
||||
data.Router.Edge.Port = zitiEdgeRouterPort
|
||||
data.Controller.Edge.Port = zitiEdgeCtrlPort
|
||||
data.Controller.Edge.AdvertisedPort = zitiEdgeCtrlAdvertisedPort
|
||||
}
|
||||
|
||||
func (data *ConfigTemplateValues) populateDefaults() {
|
||||
|
||||
@@ -99,8 +99,8 @@ func TestListenerAddressWhenEdgeCtrlPortAndListenerHostPortSet(t *testing.T) {
|
||||
assert.Equal(t, expectedListenerAddress, data.Controller.Edge.ListenerHostPort)
|
||||
}
|
||||
|
||||
// Edge Ctrl Port should update the edge ctrl port to the default when ZITI_EDGE_CONTROLLER_PORT is not set
|
||||
func TestDefaultEdgeCtrlPort(t *testing.T) {
|
||||
// Edge Ctrl Advertised Port should update the edge ctrl port to the default when ZITI_EDGE_CONTROLLER_PORT is not set
|
||||
func TestDefaultEdgeCtrlAdvertisedPort(t *testing.T) {
|
||||
expectedPort := "1280" // Expecting the default port of 1280
|
||||
|
||||
// Set a custom value for the host and port
|
||||
@@ -112,11 +112,11 @@ func TestDefaultEdgeCtrlPort(t *testing.T) {
|
||||
_ = cmd.Execute()
|
||||
})
|
||||
|
||||
assert.Equal(t, expectedPort, data.Controller.Edge.Port)
|
||||
assert.Equal(t, expectedPort, data.Controller.Edge.AdvertisedPort)
|
||||
}
|
||||
|
||||
// Edge Ctrl Port should update the edge ctrl port to the custom value when ZITI_EDGE_CONTROLLER_PORT is set
|
||||
func TestEdgeCtrlPortValueWhenSet(t *testing.T) {
|
||||
// Edge Ctrl Advertised Port should update the edge ctrl port to the custom value when ZITI_EDGE_CONTROLLER_PORT is set
|
||||
func TestEdgeCtrlAdvertisedPortValueWhenSet(t *testing.T) {
|
||||
expectedPort := "1234" // Setting a custom port which is not the default value
|
||||
|
||||
// Set a custom value for the host and port
|
||||
@@ -128,5 +128,5 @@ func TestEdgeCtrlPortValueWhenSet(t *testing.T) {
|
||||
_ = cmd.Execute()
|
||||
})
|
||||
|
||||
assert.Equal(t, expectedPort, data.Controller.Edge.Port)
|
||||
assert.Equal(t, expectedPort, data.Controller.Edge.AdvertisedPort)
|
||||
}
|
||||
|
||||
@@ -32,58 +32,16 @@ import (
|
||||
"text/template"
|
||||
)
|
||||
|
||||
type EnvVariableMetaData struct {
|
||||
OS string
|
||||
ZitiHomeVarName string
|
||||
ZitiCtrlNameVarName string
|
||||
ZitiCtrlPortVarName string
|
||||
ZitiEdgeRouterRawNameVarName string
|
||||
ZitiEdgeRouterPortVarName string
|
||||
ZitiEdgeCtrlIdentityCertVarName string
|
||||
ZitiEdgeCtrlIdentityServerCertVarName string
|
||||
ZitiEdgeCtrlIdentityKeyVarName string
|
||||
ZitiEdgeCtrlIdentityCAVarName string
|
||||
ZitiCtrlIdentityCertVarName string
|
||||
ZitiCtrlIdentityServerCertVarName string
|
||||
ZitiCtrlIdentityKeyVarName string
|
||||
ZitiCtrlIdentityCAVarName string
|
||||
ZitiSigningCertVarName string
|
||||
ZitiSigningKeyVarName string
|
||||
ZitiCtrlMgmtListenerHostPortVarName string
|
||||
ZitiEdgeCtrlListenerHostPortVarName string
|
||||
ZitiEdgeCtrlAdvertisedHostPortVarName string
|
||||
ZitiRouterIdentityCertVarName string
|
||||
ZitiRouterIdentityServerCertVarName string
|
||||
ZitiRouterIdentityKeyVarName string
|
||||
ZitiRouterIdentityCAVarName string
|
||||
ZitiCtrlListenerAddressVarName string
|
||||
ZitiCtrlAdvertisedAddressVarName string
|
||||
ZitiEdgeCtrlPortVarName string
|
||||
ZitiHomeVarDescription string
|
||||
ZitiCtrlNameVarDescription string
|
||||
ZitiEdgeRouterRawNameVarDescription string
|
||||
ZitiEdgeRouterPortVarDescription string
|
||||
ZitiEdgeCtrlIdentityCertVarDescription string
|
||||
ZitiEdgeCtrlIdentityServerCertVarDescription string
|
||||
ZitiEdgeCtrlIdentityKeyVarDescription string
|
||||
ZitiEdgeCtrlIdentityCAVarDescription string
|
||||
ZitiCtrlIdentityCertVarDescription string
|
||||
ZitiCtrlIdentityServerCertVarDescription string
|
||||
ZitiCtrlIdentityKeyVarDescription string
|
||||
ZitiCtrlIdentityCAVarDescription string
|
||||
ZitiSigningCertVarDescription string
|
||||
ZitiSigningKeyVarDescription string
|
||||
ZitiCtrlPortVarDescription string
|
||||
ZitiCtrlListenerAddressVarDescription string
|
||||
ZitiCtrlAdvertisedAddressVarDescription string
|
||||
ZitiCtrlMgmtListenerHostPortVarDescription string
|
||||
ZitiEdgeCtrlListenerHostPortVarDescription string
|
||||
ZitiEdgeCtrlAdvertisedHostPortVarDescription string
|
||||
ZitiRouterIdentityCertVarDescription string
|
||||
ZitiRouterIdentityServerCertVarDescription string
|
||||
ZitiRouterIdentityKeyVarDescription string
|
||||
ZitiRouterIdentityCAVarDescription string
|
||||
ZitiEdgeCtrlPortVarDescription string
|
||||
type EnvVariableTemplateData struct {
|
||||
OSCommentPrefix string
|
||||
OSVarDeclare string
|
||||
EnvVars []EnvVar
|
||||
}
|
||||
|
||||
type EnvVar struct {
|
||||
Name string
|
||||
Description string
|
||||
Value string
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -108,68 +66,14 @@ var environmentOptions *CreateConfigEnvironmentOptions
|
||||
// CreateConfigEnvironmentOptions the options for the create environment command
|
||||
type CreateConfigEnvironmentOptions struct {
|
||||
CreateConfigOptions
|
||||
*ConfigTemplateValues
|
||||
EnvVariableMetaData
|
||||
EnvVariableTemplateData
|
||||
output string
|
||||
}
|
||||
|
||||
// NewCmdCreateConfigEnvironment creates a command object for the "environment" command
|
||||
func NewCmdCreateConfigEnvironment() *cobra.Command {
|
||||
|
||||
environmentOptions = &CreateConfigEnvironmentOptions{
|
||||
ConfigTemplateValues: data,
|
||||
EnvVariableMetaData: EnvVariableMetaData{
|
||||
OS: "Stuff",
|
||||
ZitiHomeVarName: constants.ZitiHomeVarName,
|
||||
ZitiHomeVarDescription: constants.ZitiHomeVarDescription,
|
||||
ZitiCtrlNameVarName: constants.ZitiCtrlNameVarName,
|
||||
ZitiCtrlNameVarDescription: constants.ZitiCtrlNameVarDescription,
|
||||
ZitiCtrlPortVarName: constants.ZitiCtrlPortVarName,
|
||||
ZitiCtrlPortVarDescription: constants.ZitiCtrlPortVarDescription,
|
||||
ZitiEdgeRouterRawNameVarName: constants.ZitiEdgeRouterRawNameVarName,
|
||||
ZitiEdgeRouterRawNameVarDescription: constants.ZitiEdgeRouterRawNameVarDescription,
|
||||
ZitiEdgeRouterPortVarName: constants.ZitiEdgeRouterPortVarName,
|
||||
ZitiEdgeRouterPortVarDescription: constants.ZitiEdgeRouterPortVarDescription,
|
||||
ZitiEdgeCtrlIdentityCertVarName: constants.ZitiEdgeCtrlIdentityCertVarName,
|
||||
ZitiEdgeCtrlIdentityCertVarDescription: constants.ZitiEdgeCtrlIdentityCertVarDescription,
|
||||
ZitiEdgeCtrlIdentityServerCertVarName: constants.ZitiEdgeCtrlIdentityServerCertVarName,
|
||||
ZitiEdgeCtrlIdentityServerCertVarDescription: constants.ZitiEdgeCtrlIdentityServerCertVarDescription,
|
||||
ZitiEdgeCtrlIdentityKeyVarName: constants.ZitiEdgeCtrlIdentityKeyVarName,
|
||||
ZitiEdgeCtrlIdentityKeyVarDescription: constants.ZitiEdgeCtrlIdentityKeyVarDescription,
|
||||
ZitiEdgeCtrlIdentityCAVarName: constants.ZitiEdgeCtrlIdentityCAVarName,
|
||||
ZitiEdgeCtrlIdentityCAVarDescription: constants.ZitiEdgeCtrlIdentityCAVarDescription,
|
||||
ZitiCtrlIdentityCertVarName: constants.ZitiCtrlIdentityCertVarName,
|
||||
ZitiCtrlIdentityCertVarDescription: constants.ZitiCtrlIdentityCertVarDescription,
|
||||
ZitiCtrlIdentityServerCertVarName: constants.ZitiCtrlIdentityServerCertVarName,
|
||||
ZitiCtrlIdentityServerCertVarDescription: constants.ZitiCtrlIdentityServerCertVarDescription,
|
||||
ZitiCtrlIdentityKeyVarName: constants.ZitiCtrlIdentityKeyVarName,
|
||||
ZitiCtrlIdentityKeyVarDescription: constants.ZitiCtrlIdentityKeyVarDescription,
|
||||
ZitiCtrlIdentityCAVarName: constants.ZitiCtrlIdentityCAVarName,
|
||||
ZitiCtrlIdentityCAVarDescription: constants.ZitiCtrlIdentityCAVarDescription,
|
||||
ZitiSigningCertVarName: constants.ZitiSigningCertVarName,
|
||||
ZitiSigningCertVarDescription: constants.ZitiSigningCertVarDescription,
|
||||
ZitiSigningKeyVarName: constants.ZitiSigningKeyVarName,
|
||||
ZitiSigningKeyVarDescription: constants.ZitiSigningKeyVarDescription,
|
||||
ZitiRouterIdentityCertVarName: constants.ZitiRouterIdentityCertVarName,
|
||||
ZitiRouterIdentityCertVarDescription: constants.ZitiRouterIdentityCertVarDescription,
|
||||
ZitiRouterIdentityServerCertVarName: constants.ZitiRouterIdentityServerCertVarName,
|
||||
ZitiRouterIdentityServerCertVarDescription: constants.ZitiRouterIdentityServerCertVarDescription,
|
||||
ZitiRouterIdentityKeyVarName: constants.ZitiRouterIdentityKeyVarName,
|
||||
ZitiRouterIdentityKeyVarDescription: constants.ZitiRouterIdentityKeyVarDescription,
|
||||
ZitiRouterIdentityCAVarName: constants.ZitiRouterIdentityCAVarName,
|
||||
ZitiRouterIdentityCAVarDescription: constants.ZitiRouterIdentityCAVarDescription,
|
||||
ZitiCtrlListenerAddressVarName: constants.ZitiCtrlListenerAddressVarName,
|
||||
ZitiCtrlListenerAddressVarDescription: constants.ZitiCtrlListenerAddressVarDescription,
|
||||
ZitiCtrlAdvertisedAddressVarName: constants.ZitiCtrlAdvertisedAddressVarName,
|
||||
ZitiCtrlAdvertisedAddressVarDescription: constants.ZitiCtrlAdvertisedAddressVarDescription,
|
||||
ZitiEdgeCtrlListenerHostPortVarName: constants.ZitiEdgeCtrlListenerHostPortVarName,
|
||||
ZitiEdgeCtrlListenerHostPortVarDescription: constants.ZitiEdgeCtrlListenerHostPortVarDescription,
|
||||
ZitiEdgeCtrlAdvertisedHostPortVarName: constants.ZitiEdgeCtrlAdvertisedHostPortVarName,
|
||||
ZitiEdgeCtrlAdvertisedHostPortVarDescription: constants.ZitiEdgeCtrlAdvertisedHostPortVarDescription,
|
||||
ZitiEdgeCtrlPortVarName: constants.ZitiEdgeCtrlPortVarName,
|
||||
ZitiEdgeCtrlPortVarDescription: constants.ZitiEdgeCtrlPortVarDescription,
|
||||
},
|
||||
}
|
||||
environmentOptions = &CreateConfigEnvironmentOptions{}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "environment",
|
||||
@@ -180,11 +84,50 @@ func NewCmdCreateConfigEnvironment() *cobra.Command {
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
data.populateEnvVars()
|
||||
data.populateDefaults()
|
||||
SetZitiRouterIdentity(&data.Router, data.Router.Name)
|
||||
// Set router identities
|
||||
SetZitiRouterIdentity(&data.Router, validateRouterName(""))
|
||||
// Set up other identity info
|
||||
SetControllerIdentity(&data.Controller)
|
||||
SetEdgeConfig(&data.Controller)
|
||||
SetWebConfig(&data.Controller)
|
||||
|
||||
environmentOptions.EnvVars = []EnvVar{
|
||||
{constants.ZitiHomeVarName, constants.ZitiHomeVarDescription, data.ZitiHome},
|
||||
{constants.ZitiCtrlNameVarName, constants.ZitiCtrlNameVarDescription, data.Controller.Name},
|
||||
{constants.ZitiCtrlPortVarName, constants.ZitiCtrlPortVarDescription, data.Controller.Port},
|
||||
{constants.ZitiEdgeRouterRawNameVarName, constants.ZitiEdgeRouterRawNameVarDescription, data.Router.Edge.Hostname},
|
||||
{constants.ZitiEdgeRouterPortVarName, constants.ZitiEdgeRouterPortVarDescription, data.Router.Edge.Port},
|
||||
{constants.ZitiEdgeCtrlIdentityCertVarName, constants.ZitiEdgeCtrlIdentityCertVarDescription, data.Controller.Edge.IdentityCert},
|
||||
{constants.ZitiEdgeCtrlIdentityServerCertVarName, constants.ZitiEdgeCtrlIdentityServerCertVarDescription, data.Controller.Edge.IdentityServerCert},
|
||||
{constants.ZitiEdgeCtrlIdentityKeyVarName, constants.ZitiEdgeCtrlIdentityKeyVarDescription, data.Controller.Edge.IdentityKey},
|
||||
{constants.ZitiEdgeCtrlIdentityCAVarName, constants.ZitiEdgeCtrlIdentityCAVarDescription, data.Controller.Edge.IdentityCA},
|
||||
{constants.ZitiCtrlIdentityCertVarName, constants.ZitiCtrlIdentityCertVarDescription, data.Controller.IdentityCert},
|
||||
{constants.ZitiCtrlIdentityServerCertVarName, constants.ZitiCtrlIdentityServerCertVarDescription, data.Controller.IdentityServerCert},
|
||||
{constants.ZitiCtrlIdentityKeyVarName, constants.ZitiCtrlIdentityKeyVarDescription, data.Controller.IdentityKey},
|
||||
{constants.ZitiCtrlIdentityCAVarName, constants.ZitiCtrlIdentityCAVarDescription, data.Controller.IdentityCA},
|
||||
{constants.ZitiSigningCertVarName, constants.ZitiSigningCertVarDescription, data.Controller.Edge.ZitiSigningCert},
|
||||
{constants.ZitiSigningKeyVarName, constants.ZitiSigningKeyVarDescription, data.Controller.Edge.ZitiSigningKey},
|
||||
{constants.ZitiRouterIdentityCertVarName, constants.ZitiRouterIdentityCertVarDescription, data.Router.IdentityCert},
|
||||
{constants.ZitiRouterIdentityServerCertVarName, constants.ZitiRouterIdentityServerCertVarDescription, data.Router.IdentityServerCert},
|
||||
{constants.ZitiRouterIdentityKeyVarName, constants.ZitiRouterIdentityKeyVarDescription, data.Router.IdentityKey},
|
||||
{constants.ZitiRouterIdentityCAVarName, constants.ZitiRouterIdentityCAVarDescription, data.Router.IdentityCA},
|
||||
{constants.ZitiCtrlListenerAddressVarName, constants.ZitiCtrlListenerAddressVarDescription, data.Controller.ListenerAddress},
|
||||
{constants.ZitiCtrlAdvertisedAddressVarName, constants.ZitiCtrlAdvertisedAddressVarDescription, data.Controller.AdvertisedAddress},
|
||||
{constants.ZitiEdgeCtrlListenerHostPortVarName, constants.ZitiEdgeCtrlListenerHostPortVarDescription, data.Controller.Edge.ListenerHostPort},
|
||||
{constants.ZitiEdgeCtrlAdvertisedHostPortVarName, constants.ZitiEdgeCtrlAdvertisedHostPortVarDescription, data.Controller.Edge.AdvertisedHostPort},
|
||||
{constants.ZitiEdgeCtrlAdvertisedPortVarName, constants.ZitiEdgeCtrlAdvertisedPortVarDescription, data.Controller.Edge.AdvertisedPort},
|
||||
}
|
||||
|
||||
// Setup logging
|
||||
var logOut *os.File
|
||||
environmentOptions.OS = runtime.GOOS
|
||||
// Figure out the correct comment prefix and variable declaration command
|
||||
if runtime.GOOS == "windows" {
|
||||
environmentOptions.OSCommentPrefix = "rem"
|
||||
environmentOptions.OSVarDeclare = "SET"
|
||||
} else {
|
||||
environmentOptions.OSCommentPrefix = "#"
|
||||
environmentOptions.OSVarDeclare = "export"
|
||||
}
|
||||
if environmentOptions.Verbose {
|
||||
logrus.SetLevel(logrus.DebugLevel)
|
||||
// Only print log to stdout if not printing config to stdout
|
||||
@@ -241,7 +184,7 @@ func NewCmdCreateConfigEnvironment() *cobra.Command {
|
||||
constants.ZitiCtrlListenerAddressVarName, constants.ZitiCtrlListenerAddressVarDescription, data.Controller.ListenerAddress,
|
||||
constants.ZitiEdgeCtrlListenerHostPortVarName, constants.ZitiEdgeCtrlListenerHostPortVarDescription, data.Controller.Edge.ListenerHostPort,
|
||||
constants.ZitiEdgeCtrlAdvertisedHostPortVarName, constants.ZitiEdgeCtrlAdvertisedHostPortVarDescription, data.Controller.Edge.AdvertisedHostPort,
|
||||
constants.ZitiEdgeCtrlPortVarName, constants.ZitiEdgeCtrlPortVarDescription, data.Controller.Edge.Port,
|
||||
constants.ZitiEdgeCtrlAdvertisedPortVarName, constants.ZitiEdgeCtrlAdvertisedPortVarDescription, data.Controller.Edge.AdvertisedPort,
|
||||
constants.ZitiEdgeRouterRawNameVarName, constants.ZitiEdgeRouterRawNameVarDescription, data.Router.Edge.Hostname,
|
||||
constants.ZitiEdgeRouterPortVarName, constants.ZitiEdgeRouterPortVarDescription, data.Router.Edge.Port,
|
||||
constants.ZitiRouterIdentityCertVarName, constants.ZitiRouterIdentityCertVarDescription, data.Router.IdentityCert,
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"io"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
@@ -36,77 +35,6 @@ func getZitiEnvironmentVariables() []string {
|
||||
"ZITI_CTRL_ADVERTISED_ADDRESS",
|
||||
"ZITI_CTRL_EDGE_LISTENER_HOST_PORT",
|
||||
"ZITI_EDGE_CTRL_ADVERTISED_HOST_PORT",
|
||||
"ZITI_EDGE_CONTROLLER_PORT",
|
||||
}
|
||||
}
|
||||
|
||||
// Test that all ZITI_* variables are included in the values for output
|
||||
func TestNoUnknownTemplateEnvVariablesExist(t *testing.T) {
|
||||
// Get the list of ZITI_* environment variables
|
||||
allEnvVars := getZitiEnvironmentVariables()
|
||||
|
||||
// Create a config environment command which will populate the env variable metadata
|
||||
NewCmdCreateConfigEnvironment()
|
||||
|
||||
values := reflect.ValueOf(environmentOptions.EnvVariableMetaData)
|
||||
elements := make([]interface{}, values.NumField())
|
||||
|
||||
for i := 0; i < values.NumField(); i++ {
|
||||
elements[i] = values.Field(i).Interface()
|
||||
}
|
||||
|
||||
// Check that every known environment variable is represented in the interface of values
|
||||
var unknownValues []string
|
||||
for _, value := range elements {
|
||||
strValue := fmt.Sprintf("%v", value)
|
||||
// If the value starts with ZITI_, make sure it's in the list of known environment variables
|
||||
if strings.HasPrefix(strValue, "ZITI_") {
|
||||
if !contains(allEnvVars, strValue) {
|
||||
unknownValues = append(unknownValues, strValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert.Zero(t, len(unknownValues))
|
||||
for _, value := range unknownValues {
|
||||
fmt.Printf("The variable %s was found in template values but is not a known variable. If necessary, update ZITI env variables list in test with the new variable\n", value)
|
||||
}
|
||||
}
|
||||
|
||||
// Test that all known ZITI env variables are found in the output
|
||||
func TestAllKnownEnvVariablesAreFoundInTemplate(t *testing.T) {
|
||||
// Get the list of ZITI_* environment variables
|
||||
allEnvVars := getZitiEnvironmentVariables()
|
||||
|
||||
// Create a config environment command which will populate the env variable metadata
|
||||
NewCmdCreateConfigEnvironment()
|
||||
|
||||
values := reflect.ValueOf(environmentOptions.EnvVariableMetaData)
|
||||
elements := make([]interface{}, values.NumField())
|
||||
|
||||
for i := 0; i < values.NumField(); i++ {
|
||||
elements[i] = values.Field(i).Interface()
|
||||
}
|
||||
|
||||
// Check that the interface of values doesn't have any remaining variables unaccounted for here
|
||||
var unfoundVariables []string
|
||||
for _, variable := range allEnvVars {
|
||||
found := false
|
||||
for _, value := range elements {
|
||||
strValue := fmt.Sprintf("%v", value)
|
||||
if variable == strValue {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
unfoundVariables = append(unfoundVariables, variable)
|
||||
}
|
||||
}
|
||||
|
||||
assert.Zero(t, len(unfoundVariables))
|
||||
for _, value := range unfoundVariables {
|
||||
fmt.Printf("The variable %s was not found in template values. Update ZITI env variables list in test by removing this variable if necessary\n", value)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,7 +78,7 @@ func TestNoUnknownOutputEnvVariablesExist(t *testing.T) {
|
||||
|
||||
assert.Zero(t, len(unknownValues))
|
||||
for _, value := range unknownValues {
|
||||
fmt.Printf("The variable %s was found in env file output but is not a known variable. If necessary, update ZITI env variables list in test with the new variable\n", value)
|
||||
fmt.Printf("The variable %s was found in env command output but was not expected.\n -If this is a new variable, add it to the ZITI env variables list in create_config_test.\n -If this variable was removed, remove the variable from the env command output.\n", value)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,7 +118,90 @@ func TestAllKnownEnvVariablesAreFoundInOutput(t *testing.T) {
|
||||
|
||||
assert.Zero(t, len(unfoundVariables))
|
||||
for _, value := range unfoundVariables {
|
||||
fmt.Printf("The variable %s was not found in env file output. Update ZITI env variables list in test by removing this variable if necessary\n", value)
|
||||
fmt.Printf("The variable %s was expected in env command output but was not found.\n -If this is variable was removed, remove it from the ZITI env variables list in create_config_test.\n -If this is a new variable, add it to the env command output.\n", value)
|
||||
}
|
||||
}
|
||||
|
||||
// Test that all known ZITI_* variables are included in the help output
|
||||
func TestAllKnownEnvVariablesAreFoundInHelpOutput(t *testing.T) {
|
||||
// Get the list of ZITI_* environment variables
|
||||
allEnvVars := getZitiEnvironmentVariables()
|
||||
|
||||
// Create a config environment command which will populate the env variable metadata
|
||||
NewCmdCreateConfigEnvironment()
|
||||
|
||||
// Run the environment options command and capture stdout from help
|
||||
cmd := NewCmdCreateConfigEnvironment()
|
||||
cmd.SetArgs([]string{"-h"})
|
||||
output := captureOutput(func() {
|
||||
_ = cmd.Execute()
|
||||
})
|
||||
|
||||
// Split the output on newlines
|
||||
lines := strings.Split(output, "\n")
|
||||
// Check that every known environment variable is represented in the help output
|
||||
var unfoundVariables []string
|
||||
for _, variable := range allEnvVars {
|
||||
found := false
|
||||
for _, line := range lines {
|
||||
// Check if the line contains an assignment for this env variable
|
||||
if strings.HasPrefix(line, variable) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
unfoundVariables = append(unfoundVariables, variable)
|
||||
}
|
||||
}
|
||||
|
||||
assert.Zero(t, len(unfoundVariables))
|
||||
for _, value := range unfoundVariables {
|
||||
fmt.Printf("The variable %s was expected in env command's help output but was not found.\n -If this is variable was removed, remove it from the ZITI env variables list in create_config_test.\n -If this is a new variable, add it to the env command's help output.\n", value)
|
||||
}
|
||||
}
|
||||
|
||||
// Test that all ZITI_* variables are included in the values for help output
|
||||
func TestNoUnknownHelpEnvVariablesExist(t *testing.T) {
|
||||
// Get the list of ZITI_* environment variables
|
||||
allEnvVars := getZitiEnvironmentVariables()
|
||||
|
||||
// Create a config environment command which will populate the env variable metadata
|
||||
NewCmdCreateConfigEnvironment()
|
||||
|
||||
// Run the environment options command and capture stdout from help
|
||||
cmd := NewCmdCreateConfigEnvironment()
|
||||
cmd.SetArgs([]string{"-h"})
|
||||
output := captureOutput(func() {
|
||||
_ = cmd.Execute()
|
||||
})
|
||||
|
||||
// Split the output on newlines
|
||||
lines := strings.Split(output, "\n")
|
||||
// Check that every known environment variable is represented in the env file output
|
||||
prefix := "ZITI_"
|
||||
var unknownValues []string
|
||||
for _, line := range lines {
|
||||
// Only look at lines with a ZITI_* env var
|
||||
if !strings.HasPrefix(line, prefix) {
|
||||
continue
|
||||
}
|
||||
// Strip out the variable name and see if it's a known value
|
||||
start := strings.Index(line, prefix)
|
||||
end := strings.Index(line, " ")
|
||||
if end < 0 {
|
||||
// If there's no assignment, assume a variable name was referenced in a comment and ignore
|
||||
continue
|
||||
}
|
||||
envVar := strings.TrimSpace(line[start:end])
|
||||
if !contains(allEnvVars, envVar) {
|
||||
unknownValues = append(unknownValues, envVar)
|
||||
}
|
||||
}
|
||||
|
||||
assert.Zero(t, len(unknownValues))
|
||||
for _, value := range unknownValues {
|
||||
fmt.Printf("The variable %s was found in env command's help output but was not expected.\n -If this is a new variable, add it to the ZITI env variables list in create_config_test.\n -If this variable was removed, remove the variable from the env command's help output.\n", value)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -96,9 +96,9 @@ func GetZitiEdgeRouterPort() (string, error) {
|
||||
|
||||
func GetZitiEdgeCtrlListenerHostPort() (string, error) {
|
||||
// Get the edge controller port to use as the default
|
||||
edgeCtrlPort, err := GetZitiEdgeCtrlPort()
|
||||
edgeCtrlPort, err := GetZitiEdgeCtrlAdvertisedPort()
|
||||
if err != nil {
|
||||
err := errors.Wrap(err, "Unable to get "+constants.ZitiEdgeCtrlPortVarName)
|
||||
err := errors.Wrap(err, "Unable to get "+constants.ZitiEdgeCtrlAdvertisedPortVarName)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -116,9 +116,9 @@ func GetZitiEdgeCtrlAdvertisedHostPort() (string, error) {
|
||||
}
|
||||
}
|
||||
|
||||
port, err := GetZitiEdgeCtrlPort()
|
||||
port, err := GetZitiEdgeCtrlAdvertisedPort()
|
||||
if err != nil {
|
||||
err := errors.Wrap(err, "Unable to get "+constants.ZitiEdgeCtrlPortVarName)
|
||||
err := errors.Wrap(err, "Unable to get "+constants.ZitiEdgeCtrlAdvertisedPortVarName)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -127,8 +127,8 @@ func GetZitiEdgeCtrlAdvertisedHostPort() (string, error) {
|
||||
return getValueOrSetAndGetDefault(constants.ZitiEdgeCtrlAdvertisedHostPortVarName, hostname+":"+port)
|
||||
}
|
||||
|
||||
func GetZitiEdgeCtrlPort() (string, error) {
|
||||
return getValueOrSetAndGetDefault(constants.ZitiEdgeCtrlPortVarName, constants.DefaultZitiEdgeAPIPort)
|
||||
func GetZitiEdgeCtrlAdvertisedPort() (string, error) {
|
||||
return getValueOrSetAndGetDefault(constants.ZitiEdgeCtrlAdvertisedPortVarName, constants.DefaultZitiEdgeAPIPort)
|
||||
}
|
||||
|
||||
func getValueOrSetAndGetDefault(envVarName string, defaultValue string) (string, error) {
|
||||
|
||||
@@ -285,7 +285,7 @@ func TestGetZitiEdgeCtrlPortWhenNotSet(t *testing.T) {
|
||||
_ = os.Unsetenv(varName)
|
||||
|
||||
// Check that the value matches
|
||||
actualValue, _ := GetZitiEdgeCtrlPort()
|
||||
actualValue, _ := GetZitiEdgeCtrlAdvertisedPort()
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
}
|
||||
|
||||
@@ -298,6 +298,6 @@ func TestGetZitiEdgeCtrlPortWhenSet(t *testing.T) {
|
||||
_ = os.Setenv(varName, expectedValue)
|
||||
|
||||
// Check that the value matches
|
||||
actualValue, _ := GetZitiEdgeCtrlPort()
|
||||
actualValue, _ := GetZitiEdgeCtrlAdvertisedPort()
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
}
|
||||
|
||||
@@ -97,6 +97,6 @@ const (
|
||||
ZitiEdgeCtrlListenerHostPortVarDescription = "Host and port of the Ziti Edge Controller Listener"
|
||||
ZitiEdgeCtrlAdvertisedHostPortVarName = "ZITI_EDGE_CTRL_ADVERTISED_HOST_PORT"
|
||||
ZitiEdgeCtrlAdvertisedHostPortVarDescription = "Host and port of the Ziti Edge Controller API"
|
||||
ZitiEdgeCtrlPortVarName = "ZITI_EDGE_CONTROLLER_PORT"
|
||||
ZitiEdgeCtrlPortVarDescription = "The advertised port of the edge controller"
|
||||
ZitiEdgeCtrlAdvertisedPortVarName = "ZITI_EDGE_CONTROLLER_PORT"
|
||||
ZitiEdgeCtrlAdvertisedPortVarDescription = "The advertised port of the edge controller"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user