diff --git a/containerm/daemon/daemon_command.go b/containerm/daemon/daemon_command.go index f21ae67..81e6568 100644 --- a/containerm/daemon/daemon_command.go +++ b/containerm/daemon/daemon_command.go @@ -14,7 +14,6 @@ package main import ( "github.com/spf13/cobra" - "github.com/spf13/pflag" ) func setupCommandFlags(cmd *cobra.Command) { @@ -111,27 +110,4 @@ func setupCommandFlags(cmd *cobra.Command) { flagSet.StringVar(&cfg.LocalConnection.Transport.RootCA, "conn-root-ca", cfg.LocalConnection.Transport.RootCA, "Specify the PEM encoded CA certificates file") flagSet.StringVar(&cfg.LocalConnection.Transport.ClientCert, "conn-client-cert", cfg.LocalConnection.Transport.ClientCert, "Specify the PEM encoded certificate file to authenticate to the MQTT server/broker") flagSet.StringVar(&cfg.LocalConnection.Transport.ClientKey, "conn-client-key", cfg.LocalConnection.Transport.ClientKey, "Specify the PEM encoded unencrypted private key file to authenticate to the MQTT server/broker") - - //TODO remove in M5 - setupDeprecatedCommandFlags(flagSet) -} - -func setupDeprecatedCommandFlags(flagSet *pflag.FlagSet) { - flagSet.StringVar(&cfg.ThingsConfig.ThingsConnectionConfig.BrokerURL, "things-conn-broker", cfg.ThingsConfig.ThingsConnectionConfig.BrokerURL, "DEPRECATED Specify the MQTT broker URL to connect to") - flagSet.Int64Var(&cfg.ThingsConfig.ThingsConnectionConfig.KeepAlive, "things-conn-keep-alive", cfg.ThingsConfig.ThingsConnectionConfig.KeepAlive, "DEPRECATED Specify the keep alive duration for the MQTT requests in milliseconds") - flagSet.Int64Var(&cfg.ThingsConfig.ThingsConnectionConfig.DisconnectTimeout, "things-conn-disconnect-timeout", cfg.ThingsConfig.ThingsConnectionConfig.DisconnectTimeout, "DEPRECATED Specify the disconnection timeout for the MQTT connection in milliseconds") - flagSet.StringVar(&cfg.ThingsConfig.ThingsConnectionConfig.ClientUsername, "things-conn-client-username", cfg.ThingsConfig.ThingsConnectionConfig.ClientUsername, "DEPRECATED Specify the MQTT client username to authenticate with") - flagSet.StringVar(&cfg.ThingsConfig.ThingsConnectionConfig.ClientPassword, "things-conn-client-password", cfg.ThingsConfig.ThingsConnectionConfig.ClientPassword, "DEPRECATED Specify the MQTT client password to authenticate with") - flagSet.Int64Var(&cfg.ThingsConfig.ThingsConnectionConfig.ConnectTimeout, "things-conn-connect-timeout", cfg.ThingsConfig.ThingsConnectionConfig.ConnectTimeout, "DEPRECATED Specify the connect timeout for the MQTT in milliseconds") - flagSet.Int64Var(&cfg.ThingsConfig.ThingsConnectionConfig.AcknowledgeTimeout, "things-conn-ack-timeout", cfg.ThingsConfig.ThingsConnectionConfig.AcknowledgeTimeout, "DEPRECATED Specify the acknowledgement timeout for the MQTT requests in milliseconds") - flagSet.Int64Var(&cfg.ThingsConfig.ThingsConnectionConfig.SubscribeTimeout, "things-conn-sub-timeout", cfg.ThingsConfig.ThingsConnectionConfig.SubscribeTimeout, "DEPRECATED Specify the subscribe timeout for the MQTT requests in milliseconds") - flagSet.Int64Var(&cfg.ThingsConfig.ThingsConnectionConfig.UnsubscribeTimeout, "things-conn-unsub-timeout", cfg.ThingsConfig.ThingsConnectionConfig.UnsubscribeTimeout, "DEPRECATED Specify the unsubscribe timeout for the MQTT requests in milliseconds") - - // init tls support - if cfg.ThingsConfig.ThingsConnectionConfig.Transport == nil { - cfg.ThingsConfig.ThingsConnectionConfig.Transport = &tlsConfig{} - } - flagSet.StringVar(&cfg.ThingsConfig.ThingsConnectionConfig.Transport.RootCA, "things-conn-root-ca", cfg.ThingsConfig.ThingsConnectionConfig.Transport.RootCA, "DEPRECATED Specify the PEM encoded CA certificates file") - flagSet.StringVar(&cfg.ThingsConfig.ThingsConnectionConfig.Transport.ClientCert, "things-conn-client-cert", cfg.ThingsConfig.ThingsConnectionConfig.Transport.ClientCert, "DEPRECATED Specify the PEM encoded certificate file to authenticate to the MQTT server/broker") - flagSet.StringVar(&cfg.ThingsConfig.ThingsConnectionConfig.Transport.ClientKey, "things-conn-client-key", cfg.ThingsConfig.ThingsConnectionConfig.Transport.ClientKey, "DEPRECATED Specify the PEM encoded unencrypted private key file to authenticate to the MQTT server/broker") } diff --git a/containerm/daemon/daemon_config.go b/containerm/daemon/daemon_config.go index 5b46359..7862bba 100644 --- a/containerm/daemon/daemon_config.go +++ b/containerm/daemon/daemon_config.go @@ -178,10 +178,9 @@ type grpcServerConfig struct { // things client configuration type thingsConfig struct { - ThingsEnable bool `json:"enable,omitempty"` - ThingsMetaPath string `json:"home_dir,omitempty"` - Features []string `json:"features,omitempty"` - ThingsConnectionConfig *thingsConnectionConfig `json:"connection,omitempty"` + ThingsEnable bool `json:"enable,omitempty"` + ThingsMetaPath string `json:"home_dir,omitempty"` + Features []string `json:"features,omitempty"` } // things client configuration @@ -206,21 +205,6 @@ type localConnectionConfig struct { Transport *tlsConfig `json:"transport,omitempty"` } -// TODO Remove in M5 -// things service connection config -type thingsConnectionConfig struct { - BrokerURL string `json:"broker_url,omitempty"` - KeepAlive int64 `json:"keep_alive,omitempty"` - DisconnectTimeout int64 `json:"disconnect_timeout,omitempty"` - ClientUsername string `json:"client_username,omitempty"` - ClientPassword string `json:"client_password,omitempty"` - ConnectTimeout int64 `json:"connect_timeout,omitempty"` - AcknowledgeTimeout int64 `json:"acknowledge_timeout,omitempty"` - SubscribeTimeout int64 `json:"subscribe_timeout,omitempty"` - UnsubscribeTimeout int64 `json:"unsubscribe_timeout,omitempty"` - Transport *tlsConfig `json:"transport,omitempty"` -} - // verifierConfig is alias used as flag value type verifierConfig map[string]string diff --git a/containerm/daemon/daemon_config_default.go b/containerm/daemon/daemon_config_default.go index d121c85..05cb426 100644 --- a/containerm/daemon/daemon_config_default.go +++ b/containerm/daemon/daemon_config_default.go @@ -167,17 +167,6 @@ func getDefaultInstance() *config { ThingsEnable: thingsEnableDefault, ThingsMetaPath: thingsMetaPathDefault, Features: thingsServiceFeaturesDefault, - ThingsConnectionConfig: &thingsConnectionConfig{ - BrokerURL: connectionBrokerURLDefault, - KeepAlive: 20000, - DisconnectTimeout: 250, - ClientUsername: connectionClientUsername, - ClientPassword: connectionClientPassword, - ConnectTimeout: 30000, - AcknowledgeTimeout: 15000, - SubscribeTimeout: 15000, - UnsubscribeTimeout: 5000, - }, }, DeploymentManagerConfig: &deploymentManagerConfig{ DeploymentEnable: deploymentEnableDefault, diff --git a/containerm/daemon/daemon_config_util.go b/containerm/daemon/daemon_config_util.go index b36fd5b..0dde8db 100644 --- a/containerm/daemon/daemon_config_util.go +++ b/containerm/daemon/daemon_config_util.go @@ -17,7 +17,6 @@ import ( "fmt" "io/ioutil" "os" - "reflect" "strconv" "time" @@ -103,42 +102,21 @@ func extractGrpcOptions(daemonConfig *config) []server.GrpcServerOpt { func extractThingsOptions(daemonConfig *config) []things.ContainerThingsManagerOpt { thingsOpts := []things.ContainerThingsManagerOpt{} - // TODO Remove in M5 - lcc := daemonConfig.LocalConnection - dtcc := getDefaultInstance().ThingsConfig.ThingsConnectionConfig - dtcc.Transport = &tlsConfig{} - if !reflect.DeepEqual(daemonConfig.ThingsConfig.ThingsConnectionConfig, dtcc) { - fmt.Println("DEPRECATED: Things connection settings are now deprecated and will be removed in future release. Use the global connection settings instead!") - log.Warn("DEPRECATED: Things connection settings are now deprecated and will be removed in future release. Use the global connection settings instead!") - lcc = &localConnectionConfig{ - BrokerURL: daemonConfig.ThingsConfig.ThingsConnectionConfig.BrokerURL, - KeepAlive: fmt.Sprintf("%dms", daemonConfig.ThingsConfig.ThingsConnectionConfig.KeepAlive), - DisconnectTimeout: fmt.Sprintf("%dms", daemonConfig.ThingsConfig.ThingsConnectionConfig.DisconnectTimeout), - ClientUsername: daemonConfig.ThingsConfig.ThingsConnectionConfig.ClientUsername, - ClientPassword: daemonConfig.ThingsConfig.ThingsConnectionConfig.ClientPassword, - ConnectTimeout: fmt.Sprintf("%dms", daemonConfig.ThingsConfig.ThingsConnectionConfig.ConnectTimeout), - AcknowledgeTimeout: fmt.Sprintf("%dms", daemonConfig.ThingsConfig.ThingsConnectionConfig.AcknowledgeTimeout), - SubscribeTimeout: fmt.Sprintf("%dms", daemonConfig.ThingsConfig.ThingsConnectionConfig.SubscribeTimeout), - UnsubscribeTimeout: fmt.Sprintf("%dms", daemonConfig.ThingsConfig.ThingsConnectionConfig.UnsubscribeTimeout), - Transport: daemonConfig.ThingsConfig.ThingsConnectionConfig.Transport, - } - } - thingsOpts = append(thingsOpts, things.WithMetaPath(daemonConfig.ThingsConfig.ThingsMetaPath), things.WithFeatures(daemonConfig.ThingsConfig.Features), - things.WithConnectionBroker(lcc.BrokerURL), - things.WithConnectionKeepAlive(parseDuration(lcc.KeepAlive, lcc.KeepAlive)), - things.WithConnectionDisconnectTimeout(parseDuration(lcc.DisconnectTimeout, lcc.DisconnectTimeout)), - things.WithConnectionClientUsername(lcc.ClientUsername), - things.WithConnectionClientPassword(lcc.ClientPassword), - things.WithConnectionConnectTimeout(parseDuration(lcc.ConnectTimeout, lcc.ConnectTimeout)), - things.WithConnectionAcknowledgeTimeout(parseDuration(lcc.AcknowledgeTimeout, lcc.AcknowledgeTimeout)), - things.WithConnectionSubscribeTimeout(parseDuration(lcc.SubscribeTimeout, lcc.SubscribeTimeout)), - things.WithConnectionUnsubscribeTimeout(parseDuration(lcc.UnsubscribeTimeout, lcc.UnsubscribeTimeout)), + things.WithConnectionBroker(daemonConfig.LocalConnection.BrokerURL), + things.WithConnectionKeepAlive(parseDuration(daemonConfig.LocalConnection.KeepAlive, daemonConfig.LocalConnection.KeepAlive)), + things.WithConnectionDisconnectTimeout(parseDuration(daemonConfig.LocalConnection.DisconnectTimeout, daemonConfig.LocalConnection.DisconnectTimeout)), + things.WithConnectionClientUsername(daemonConfig.LocalConnection.ClientUsername), + things.WithConnectionClientPassword(daemonConfig.LocalConnection.ClientPassword), + things.WithConnectionConnectTimeout(parseDuration(daemonConfig.LocalConnection.ConnectTimeout, daemonConfig.LocalConnection.ConnectTimeout)), + things.WithConnectionAcknowledgeTimeout(parseDuration(daemonConfig.LocalConnection.AcknowledgeTimeout, daemonConfig.LocalConnection.AcknowledgeTimeout)), + things.WithConnectionSubscribeTimeout(parseDuration(daemonConfig.LocalConnection.SubscribeTimeout, daemonConfig.LocalConnection.SubscribeTimeout)), + things.WithConnectionUnsubscribeTimeout(parseDuration(daemonConfig.LocalConnection.UnsubscribeTimeout, daemonConfig.LocalConnection.UnsubscribeTimeout)), ) - if lcc.Transport != nil { - thingsOpts = append(thingsOpts, things.WithTLSConfig(lcc.Transport.RootCA, lcc.Transport.ClientCert, lcc.Transport.ClientKey)) + if daemonConfig.LocalConnection.Transport != nil { + thingsOpts = append(thingsOpts, things.WithTLSConfig(daemonConfig.LocalConnection.Transport.RootCA, daemonConfig.LocalConnection.Transport.ClientCert, daemonConfig.LocalConnection.Transport.ClientKey)) } return thingsOpts } @@ -344,20 +322,6 @@ func dumpThingsClient(configInstance *config) { if configInstance.ThingsConfig.ThingsEnable { log.Debug("[daemon_cfg][things-home-dir] : %s", configInstance.ThingsConfig.ThingsMetaPath) log.Debug("[daemon_cfg][things-features] : %s", configInstance.ThingsConfig.Features) - if configInstance.ThingsConfig.ThingsConnectionConfig != nil { - log.Debug("[daemon_cfg][things-conn-broker] : %s", configInstance.ThingsConfig.ThingsConnectionConfig.BrokerURL) - log.Debug("[daemon_cfg][things-conn-keep-alive] : %d", configInstance.ThingsConfig.ThingsConnectionConfig.KeepAlive) - log.Debug("[daemon_cfg][things-conn-disconnect-timeout] : %d", configInstance.ThingsConfig.ThingsConnectionConfig.DisconnectTimeout) - log.Debug("[daemon_cfg][things-conn-connect-timeout] : %d", configInstance.ThingsConfig.ThingsConnectionConfig.ConnectTimeout) - log.Debug("[daemon_cfg][things-conn-ack-timeout] : %d", configInstance.ThingsConfig.ThingsConnectionConfig.AcknowledgeTimeout) - log.Debug("[daemon_cfg][things-conn-sub-timeout] : %d", configInstance.ThingsConfig.ThingsConnectionConfig.SubscribeTimeout) - log.Debug("[daemon_cfg][things-conn-unsub-timeout] : %d", configInstance.ThingsConfig.ThingsConnectionConfig.UnsubscribeTimeout) - if configInstance.ThingsConfig.ThingsConnectionConfig.Transport != nil { - log.Debug("[daemon_cfg][things-conn-root-ca] : %s", configInstance.ThingsConfig.ThingsConnectionConfig.Transport.RootCA) - log.Debug("[daemon_cfg][things-conn-client-cert] : %s", configInstance.ThingsConfig.ThingsConnectionConfig.Transport.ClientCert) - log.Debug("[daemon_cfg][things-conn-client-key] : %s", configInstance.ThingsConfig.ThingsConnectionConfig.Transport.ClientKey) - } - } } } } diff --git a/containerm/daemon/daemon_test.go b/containerm/daemon/daemon_test.go index 046b2b4..a5a992a 100644 --- a/containerm/daemon/daemon_test.go +++ b/containerm/daemon/daemon_test.go @@ -90,7 +90,7 @@ func TestThingsServiceFeaturesConfig(t *testing.T) { func TestThingsTLSConfig(t *testing.T) { local := &config{} _ = loadLocalConfig("../pkg/testutil/config/daemon-things-tls-config.json", local) - testutil.AssertEqual(t, &tlsConfig{RootCA: "ca.crt", ClientCert: "client.crt", ClientKey: "client.key"}, local.ThingsConfig.ThingsConnectionConfig.Transport) + testutil.AssertEqual(t, &tlsConfig{RootCA: "ca.crt", ClientCert: "client.crt", ClientKey: "client.key"}, local.LocalConnection.Transport) } func TestMgrDefaultCtrsStopTimeoutConfig(t *testing.T) { @@ -364,54 +364,6 @@ func TestSetCommandFlags(t *testing.T) { flag: "things-features", expectedType: "stringSlice", }, - "test_flags_things-conn-broker": { - flag: "things-conn-broker", - expectedType: reflect.String.String(), - }, - "test_flags_things-conn-keep-alive": { - flag: "things-conn-keep-alive", - expectedType: reflect.Int64.String(), - }, - "test_flags_things-conn-disconnect-timeout": { - flag: "things-conn-disconnect-timeout", - expectedType: reflect.Int64.String(), - }, - "test_flags_things-conn-client-username": { - flag: "things-conn-client-username", - expectedType: reflect.String.String(), - }, - "test_flags_things-conn-client-password": { - flag: "things-conn-client-password", - expectedType: reflect.String.String(), - }, - "test_flags_things-conn-connect-timeout": { - flag: "things-conn-connect-timeout", - expectedType: reflect.Int64.String(), - }, - "test_flags_things-conn-ack-timeout": { - flag: "things-conn-ack-timeout", - expectedType: reflect.Int64.String(), - }, - "test_flags_things-conn-sub-timeout": { - flag: "things-conn-sub-timeout", - expectedType: reflect.Int64.String(), - }, - "test_flags_things-conn-unsub-timeout": { - flag: "things-conn-unsub-timeout", - expectedType: reflect.Int64.String(), - }, - "test_flags_things-conn-root-ca": { - flag: "things-conn-root-ca", - expectedType: reflect.String.String(), - }, - "test_flags_things-conn-client-cert": { - flag: "things-conn-client-cert", - expectedType: reflect.String.String(), - }, - "test_flags_things-conn-client-key": { - flag: "things-conn-client-key", - expectedType: reflect.String.String(), - }, "test_flags_deployment-enable": { flag: "deployment-enable", expectedType: reflect.Bool.String(), diff --git a/containerm/pkg/testutil/config/daemon-config-image-verifier.json b/containerm/pkg/testutil/config/daemon-config-image-verifier.json index 04d24b9..c247bdf 100644 --- a/containerm/pkg/testutil/config/daemon-config-image-verifier.json +++ b/containerm/pkg/testutil/config/daemon-config-image-verifier.json @@ -56,18 +56,7 @@ "ContainerFactory", "SoftwareUpdatable", "Metrics" - ], - "connection": { - "broker_url": "tcp://localhost:1883", - "keep_alive": 20000, - "disconnect_timeout": 250, - "client_username": "", - "client_password": "", - "connect_timeout": 30000, - "acknowledge_timeout": 15000, - "subscribe_timeout": 15000, - "unsubscribe_timeout": 5000 - } + ] }, "deployment": { "enable": true, diff --git a/containerm/pkg/testutil/config/daemon-config-insecure-registries.json b/containerm/pkg/testutil/config/daemon-config-insecure-registries.json index d694094..48a7e9a 100644 --- a/containerm/pkg/testutil/config/daemon-config-insecure-registries.json +++ b/containerm/pkg/testutil/config/daemon-config-insecure-registries.json @@ -60,11 +60,6 @@ }, "things": { "enable": true, - "home_dir": "/var/lib/container-management", - "connection": { - "broker_url": "tcp://localhost:1883", - "keep_alive": 20000, - "disconnect_timeout": 250 - } + "home_dir": "/var/lib/container-management" } } \ No newline at end of file diff --git a/containerm/pkg/testutil/config/daemon-config.json b/containerm/pkg/testutil/config/daemon-config.json index 538e97b..8b468e9 100644 --- a/containerm/pkg/testutil/config/daemon-config.json +++ b/containerm/pkg/testutil/config/daemon-config.json @@ -52,18 +52,7 @@ "ContainerFactory", "SoftwareUpdatable", "Metrics" - ], - "connection": { - "broker_url": "tcp://localhost:1883", - "keep_alive": 20000, - "disconnect_timeout": 250, - "client_username": "", - "client_password": "", - "connect_timeout": 30000, - "acknowledge_timeout": 15000, - "subscribe_timeout": 15000, - "unsubscribe_timeout": 5000 - } + ] }, "deployment": { "enable": true, diff --git a/containerm/pkg/testutil/config/daemon-things-tls-config.json b/containerm/pkg/testutil/config/daemon-things-tls-config.json index fc570a4..a979979 100644 --- a/containerm/pkg/testutil/config/daemon-things-tls-config.json +++ b/containerm/pkg/testutil/config/daemon-things-tls-config.json @@ -1,11 +1,9 @@ { - "things": { - "connection": { + "connection": { "transport": { "root_ca": "ca.crt", "client_cert": "client.crt", "client_key": "client.key" } - } } } \ No newline at end of file