From 91da0542caaef8c39c3c40af774a6474b93e1559 Mon Sep 17 00:00:00 2001 From: Srinandan Sridhar <13950006+srinandan@users.noreply.github.com> Date: Mon, 6 Nov 2023 21:28:28 +0100 Subject: [PATCH] feat: remove configurable proxy #326 (#328) * feat: remove configurable proxy #326 * feat: remove overrides cmd #326 * feat: remove overrides from root #326 --- cmd/env/crtenv.go | 6 +- cmd/overrides/apply.go | 119 --------------------------------- cmd/overrides/delete.go | 82 ----------------------- cmd/overrides/overrides.go | 32 --------- cmd/overrides/overridestype.go | 113 ------------------------------- cmd/root.go | 2 - internal/client/env/env.go | 9 +-- 7 files changed, 3 insertions(+), 360 deletions(-) delete mode 100644 cmd/overrides/apply.go delete mode 100644 cmd/overrides/delete.go delete mode 100644 cmd/overrides/overrides.go delete mode 100644 cmd/overrides/overridestype.go diff --git a/cmd/env/crtenv.go b/cmd/env/crtenv.go index 347f5483a..59480b402 100644 --- a/cmd/env/crtenv.go +++ b/cmd/env/crtenv.go @@ -32,19 +32,17 @@ var CreateCmd = &cobra.Command{ return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { - _, err = env.Create(deploymentType, apiProxyType) + _, err = env.Create(deploymentType) return }, } -var deploymentType, apiProxyType string +var deploymentType string func init() { CreateCmd.Flags().StringVarP(&environment, "env", "e", "", "Apigee environment name") CreateCmd.Flags().StringVarP(&deploymentType, "deptype", "d", "", "Deployment type - must be PROXY or ARCHIVE") - CreateCmd.Flags().StringVarP(&apiProxyType, "proxtype", "p", - "", "Proxy type - must be PROGRAMMABLE or CONFIGURABLE") _ = CreateCmd.MarkFlagRequired("env") } diff --git a/cmd/overrides/apply.go b/cmd/overrides/apply.go deleted file mode 100644 index b30c55121..000000000 --- a/cmd/overrides/apply.go +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright 2021 Google LLC -// -// 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 overrides - -import ( - "fmt" - - "internal/apiclient" - - "internal/clilog" - - "internal/client/env" - "internal/client/envgroups" - "internal/client/orgs" - "internal/client/sync" - - "github.com/spf13/cobra" -) - -// ApplyCmd provisions control plane entities for hybrid -var ApplyCmd = &cobra.Command{ - Use: "apply", - Short: "Apply control plane entities", - Long: "Apply control plane entities", - Args: func(cmd *cobra.Command, args []string) (err error) { - return nil - }, - RunE: func(cmd *cobra.Command, args []string) (err error) { - if err = readOverrides(overridesFile); err != nil { - return err - } - - apiclient.SetProjectID(getOrg()) - apiclient.DisableCmdPrintHttpResponse() - _ = apiclient.SetApigeeOrg(getOrg()) - - // check if the org exists - if _, err = orgs.Get(); err != nil { - if _, err = orgs.Create(getOrgRegion(), "", "HYBRID", "", "", false); err != nil { - return err - } - clilog.Info.Printf("Org %s created\n", getOrg()) - } else { - clilog.Info.Printf("Org %s already exists\n", getOrg()) - } - - // check setSyncAuth - identities := getSyncServiceAccounts() - if len(identities) > 0 { - if _, err = sync.Set(identities); err != nil { - clilog.Warning.Println("Error setting identities: ", err) - } else { - clilog.Info.Printf("Org setSync identities set: %v", identities) - } - } else { - clilog.Warning.Println("No sync identities were set in overrides") - } - - // create environments - environmentList := getEnvs() - for _, environment := range environmentList { - // check if env exists - apiclient.SetApigeeEnv(environment) - if _, err = env.Get(false); err != nil { - if _, err = env.Create("PROXY", "PROGRAMMABLE"); err != nil { - return err - } - clilog.Info.Printf("Environment %s created", environment) - } else { - clilog.Info.Printf("Environment %s already exists\n", environment) - } - } - - // create environment groups - environmentGroupList := getEnvGroups() - for i, environmentGroup := range environmentGroupList { - // check if env group exists - if _, err = envgroups.Get(environmentGroup); err != nil { - if _, err = envgroups.Create(environmentGroup, getDomainName(i)); err != nil { - return err - } - clilog.Info.Printf("Environment Group %s provisioned with a temporary domain name %s\n", - environmentGroup, getDomainName(i)) - } else { - clilog.Info.Printf("Environment Group %s already exists\n", environmentGroup) - } - } - - return err - }, -} - -var overridesFile string - -func init() { - ApplyCmd.Flags().StringVarP(&overridesFile, "overrides", "f", - "overrides.yaml", "overrides file path") - - _ = ApplyCmd.MarkFlagRequired("overrides") -} - -func getDomainName(index int) []string { - domainNames := []string{} - domainName := fmt.Sprintf("api.acme%d.com", index) - domainNames = append(domainNames, domainName) - return domainNames -} diff --git a/cmd/overrides/delete.go b/cmd/overrides/delete.go deleted file mode 100644 index d1b342c19..000000000 --- a/cmd/overrides/delete.go +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2021 Google LLC -// -// 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 overrides - -import ( - "internal/apiclient" - - "internal/clilog" - - "internal/client/env" - "internal/client/envgroups" - - "github.com/spf13/cobra" -) - -// DeleteCmd provisions control plane entities for hybrid -var DeleteCmd = &cobra.Command{ - Use: "delete", - Short: "Delete control plane entities", - Long: "Delete control plane entities", - Args: func(cmd *cobra.Command, args []string) (err error) { - return nil - }, - RunE: func(cmd *cobra.Command, args []string) (err error) { - if err = readOverrides(overridesFile); err != nil { - return err - } - apiclient.SetProjectID(getOrg()) - apiclient.DisableCmdPrintHttpResponse() - _ = apiclient.SetApigeeOrg(getOrg()) - - // delete environments - environmentList := getEnvs() - for _, environment := range environmentList { - // check if env exists - apiclient.SetApigeeEnv(environment) - if _, err = env.Get(false); err != nil { - if _, err = env.Delete(); err != nil { - return err - } - clilog.Info.Printf("Environment %s deleted", environment) - } else { - clilog.Info.Printf("Environment %s does not exist\n", environment) - } - } - - // create environment groups - environmentGroupList := getEnvGroups() - for _, environmentGroup := range environmentGroupList { - // check if env group exists - if _, err = envgroups.Get(environmentGroup); err != nil { - if _, err = envgroups.Delete(environmentGroup); err != nil { - return err - } - clilog.Info.Printf("Environment Group %s deleted\n", environmentGroup) - } else { - clilog.Info.Printf("Environment Group %s does not exist\n", environmentGroup) - } - } - - return err - }, -} - -func init() { - DeleteCmd.Flags().StringVarP(&overridesFile, "overrides", "f", - "overrides.yaml", "overrides file path") - - _ = DeleteCmd.MarkFlagRequired("overrides") -} diff --git a/cmd/overrides/overrides.go b/cmd/overrides/overrides.go deleted file mode 100644 index 4a6dc14a7..000000000 --- a/cmd/overrides/overrides.go +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2021 Google LLC -// -// 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 overrides - -import ( - "github.com/spf13/cobra" -) - -// Cmd to manage ops -var Cmd = &cobra.Command{ - Use: "overrides", - Aliases: []string{"overrides"}, - Short: "Manage Apigee hybrid through overrides", - Long: "Manage Apigee hybrid through overrides", -} - -func init() { - Cmd.AddCommand(ApplyCmd) - Cmd.AddCommand(DeleteCmd) -} diff --git a/cmd/overrides/overridestype.go b/cmd/overrides/overridestype.go deleted file mode 100644 index 38875fb34..000000000 --- a/cmd/overrides/overridestype.go +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright 2021 Google LLC -// -// 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 overrides - -import ( - "encoding/json" - "os" - - "internal/clilog" - - yaml "gopkg.in/yaml.v2" -) - -type overrides struct { - Org string `yaml:"org,omitempty"` - Gcp gcp `yaml:"gcp,omitempty"` - Envs []environment `yaml:"envs,omitempty"` - Virtualhosts []virtualhost `yaml:"virtualhosts,omitempty"` -} - -type gcp struct { - ProjectID string `yaml:"projectID,omitempty"` - Region string `yaml:"region,omitempty"` -} - -type environment struct { - Name string `yaml:"name,omitempty"` - ServiceAccountPaths *serviceAccountPaths `yaml:"serviceAccountPaths,omitempty"` -} - -type serviceAccountPaths struct { - Synchronizer string `yaml:"synchronizer,omitempty"` -} - -type virtualhost struct { - Name string `yaml:"name,omitempty"` -} - -var hybridOverrides = overrides{} - -func readOverrides(filepath string) (err error) { - source, err := os.ReadFile(filepath) - if err != nil { - return err - } - - err = yaml.Unmarshal(source, &hybridOverrides) - if err != nil { - return err - } - return err -} - -func getOrg() string { - return hybridOverrides.Org -} - -func getOrgRegion() string { - return hybridOverrides.Gcp.Region -} - -func getEnvs() []string { - environmentList := []string{} - for _, environment := range hybridOverrides.Envs { - environmentList = append(environmentList, environment.Name) - } - return environmentList -} - -func getEnvGroups() []string { - environmentGroupList := []string{} - for _, environmentGroup := range hybridOverrides.Virtualhosts { - environmentGroupList = append(environmentGroupList, environmentGroup.Name) - } - return environmentGroupList -} - -func getSyncServiceAccounts() []string { - syncIdentityList := []string{} - for _, environment := range hybridOverrides.Envs { - if environment.ServiceAccountPaths != nil && environment.ServiceAccountPaths.Synchronizer != "" { - identity, _ := getIdentity(environment.ServiceAccountPaths.Synchronizer) - syncIdentityList = append(syncIdentityList, identity) - } - } - return syncIdentityList -} - -func getIdentity(serviceAccountPath string) (string, error) { - serviceAccount := make(map[string]interface{}) - saBytes, err := os.ReadFile(serviceAccountPath) - if err != nil { - clilog.Error.Println(err) - return "", err - } - if err := json.Unmarshal(saBytes, &serviceAccount); err != nil { - clilog.Error.Println(err) - return "", err - } - return serviceAccount["client_email"].(string), nil -} diff --git a/cmd/root.go b/cmd/root.go index eee653235..2cbe48c79 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -44,7 +44,6 @@ import ( "github.com/apigee/apigeecli/cmd/kvm" "github.com/apigee/apigeecli/cmd/ops" "github.com/apigee/apigeecli/cmd/org" - "github.com/apigee/apigeecli/cmd/overrides" "github.com/apigee/apigeecli/cmd/preferences" "github.com/apigee/apigeecli/cmd/products" "github.com/apigee/apigeecli/cmd/projects" @@ -171,7 +170,6 @@ func init() { RootCmd.AddCommand(instances.Cmd) RootCmd.AddCommand(ops.Cmd) RootCmd.AddCommand(preferences.Cmd) - RootCmd.AddCommand(overrides.Cmd) RootCmd.AddCommand(eptattachment.Cmd) RootCmd.AddCommand(appgroups.Cmd) } diff --git a/internal/client/env/env.go b/internal/client/env/env.go index 872e1c8a4..64d7020b5 100644 --- a/internal/client/env/env.go +++ b/internal/client/env/env.go @@ -26,7 +26,7 @@ import ( ) // Create -func Create(deploymentType string, apiProxyType string) (respBody []byte, err error) { +func Create(deploymentType string) (respBody []byte, err error) { environment := []string{} environment = append(environment, "\"name\":\""+apiclient.GetApigeeEnv()+"\"") @@ -37,13 +37,6 @@ func Create(deploymentType string, apiProxyType string) (respBody []byte, err er environment = append(environment, "\"deployment_type\":\""+deploymentType+"\"") } - if apiProxyType != "" { - if apiProxyType != "CONFIGURABLE" && apiProxyType != "PROGRAMMABLE" { - return nil, fmt.Errorf("apiProxyType must be CONFIGURABLE or PROGRAMMABLE") - } - environment = append(environment, "\"apiProxyType\":\""+apiProxyType+"\"") - } - payload := "{" + strings.Join(environment, ",") + "}" u, _ := url.Parse(apiclient.BaseURL)