From 845f1497cbb7e2e4fbbfb61e573ceb52656c7471 Mon Sep 17 00:00:00 2001 From: Mauricio Vasquez B Date: Thu, 30 May 2019 10:26:39 -0500 Subject: [PATCH] polycubectl: remove hardcoded version logic Some time ago we had two kind of services, so the cli has to be aware of that. The last service to be updated is pcn-bridge, so now all services are aligned. We don't expect to handle this case in the future, so remove this logic. Signed-off-by: Mauricio Vasquez B --- src/polycubectl/cliargs/cliargs.go | 6 +-- src/polycubectl/config/config.go | 14 ------ src/polycubectl/hardcodedversion.go | 75 ----------------------------- src/polycubectl/main.go | 7 --- 4 files changed, 1 insertion(+), 101 deletions(-) delete mode 100644 src/polycubectl/hardcodedversion.go diff --git a/src/polycubectl/cliargs/cliargs.go b/src/polycubectl/cliargs/cliargs.go index eea4b7ddd..46f77d9d0 100644 --- a/src/polycubectl/cliargs/cliargs.go +++ b/src/polycubectl/cliargs/cliargs.go @@ -404,11 +404,7 @@ func (cli *CLIArgs) getRequestMethod() string { } else if cli.Command == AddCommand || cli.Command == "" { return httprequest.PostStr } else if cli.Command == SetCommand { - if config.GetConfig().Version == "1" { - return httprequest.PutStr - } else { - return httprequest.PatchStr - } + return httprequest.PatchStr } else if cli.Command == ShowCommand { return httprequest.GetStr } else if cli.Command == DelCommand { diff --git a/src/polycubectl/config/config.go b/src/polycubectl/config/config.go index 382fdb706..a56872eb6 100644 --- a/src/polycubectl/config/config.go +++ b/src/polycubectl/config/config.go @@ -38,9 +38,6 @@ type Config struct { Debug bool `yaml:"debug"` Expert bool `yaml:"expert"` Url string `yaml:"url"` - Version string `yaml:"version"` - // get version to be used according to service name - HardCodedVersionEnabled bool // enables Workaround for urls (e.g. set peer=veth1 PUT /peer/ "veth1") SingleParameterWorkaround bool @@ -58,8 +55,6 @@ func NewDefaultConfig() Config { Debug: false, Expert: true, Url: "http://localhost:9000/polycube/v1/", - Version: "2", - HardCodedVersionEnabled: true, SingleParameterWorkaround: true, } @@ -78,7 +73,6 @@ func saveConfig(config Config) error { `# debug: shows http method/url and body of the response # expert: enables the possibility to add new services # url: is the base url to contact the rest server -# version: (1) uses PUT method, (2) uses PATCH method # cacert: path to certification authority certificate to validate polycubed identity # cert: path to certificate to present to polycubed for validate polycubectl identity # key: path to private key for polycubectl @@ -131,10 +125,6 @@ func LoadConfig() (error) { return fmt.Errorf("error decoding config file: %s", err.Error()) } - if config.Version != "" && config.Version != "1" && config.Version != "2" { - return fmt.Errorf("%s if not a valid version, please check the config file. %s", config.Version) - } - if os.Getenv("POLYCUBECTL_URL") != "" { config.Url = os.Getenv("POLYCUBECTL_URL") } @@ -153,10 +143,6 @@ func LoadConfig() (error) { } } - if os.Getenv("POLYCUBECTL_VERSION") != "" { - config.Version = os.Getenv("POLYCUBECTL_VERSION") - } - if os.Getenv("POLYCUBECTL_CACERT") != "" { config.CACert = os.Getenv("POLYCUBECTL_CACERT") } diff --git a/src/polycubectl/hardcodedversion.go b/src/polycubectl/hardcodedversion.go deleted file mode 100644 index 99b0f1366..000000000 --- a/src/polycubectl/hardcodedversion.go +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2018 The Polycube Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package main - -import ( - "github.com/polycube-network/polycube/src/polycubectl/httprequest" -) - -var versionMap map[string]string - -// by default CLI uses version provided in configuration file. -// this is a way to force CLI to use a specific version for specific services - -func init() { - versionMap = make(map[string]string) - - // MODIFY CONFIGURATION HERE: - - versionMap["bridge"] = "1" - versionMap["firewall"] = "2" - versionMap["ddosmitigator"] = "2" - versionMap["lbrp"] = "2" - versionMap["lbdsr"] = "2" - versionMap["helloworld"] = "2" - versionMap["pbforwarder"] = "2" - versionMap["simpleforwarder"] = "2" - versionMap["kubenat"] = "2" - versionMap["nat"] = "2" - versionMap["router"] = "2" - versionMap["simplebridge"] = "2" - - // other services uses default option provided in config file -} - -func GetHardCodedVersion(args []string) string { - if len(args) > 0 { - v, ok := versionMap[args[0]] - if ok { - return v - } - } - - return "" -} - -// some services are using v2 of cli -// this implies that set method is PATCH instead of PUT -// connect command has to know the SetMethod (PATCH/PUT) -// given a specific service -func GetSetMethodFromServiceName(service string) string { - v, ok := versionMap[service] - if ok { - if v == "2" { - return httprequest.PatchStr - } - if v == "1" { - return httprequest.PutStr - } - } - return httprequest.PatchStr -} diff --git a/src/polycubectl/main.go b/src/polycubectl/main.go index 161e3db19..661c14185 100644 --- a/src/polycubectl/main.go +++ b/src/polycubectl/main.go @@ -49,13 +49,6 @@ func main() { os.Exit(1) } - if config.GetConfig().HardCodedVersionEnabled { - v := GetHardCodedVersion(os.Args[1:]) - if v != "" { - config.GetConfig().Version = v - } - } - LogCommand(os.Args) cliArgs, err := cliargs.ParseCLIArgs(os.Args[1:])