Skip to content

Commit

Permalink
fix: removed updation of in memory account during delete
Browse files Browse the repository at this point in the history
  • Loading branch information
AvineshTripathi committed Sep 27, 2024
1 parent c8cf439 commit 7f826e4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 28 deletions.
20 changes: 5 additions & 15 deletions handlers/accounts_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"net/http"
"strconv"
"time"

"github.com/gin-gonic/gin"
Expand Down Expand Up @@ -173,22 +172,13 @@ func (handler *ApiHandler) DeleteCloudAccountHandler(c *gin.Context) {
return
}

updatedAccounts := make([]models.Account, 0)
for _, acc := range handler.accounts {
if strconv.FormatInt(res.Id, 10) != accountId {
updatedAccounts = append(updatedAccounts, acc)
} else {
err = deleteConfigAccounts(res, &handler.cfg)
if err != nil {
fmt.Println(err)
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
}
err = deleteConfigAccounts(res, &handler.cfg)
if err != nil {
fmt.Println(err)
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}

handler.accounts = updatedAccounts

err = updateConfig(handler.configPath, &handler.cfg)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
Expand Down
26 changes: 13 additions & 13 deletions handlers/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,8 @@ func populateConfigFromAccount(account models.Account, config *models.Config) er
}

func deleteConfigAccounts(account models.Account, config *models.Config) error {
switch account.Provider {
case "Aws":
switch strings.ToLower(account.Provider) {
case "aws":

updatedConfig := make([]models.AWSConfig, 0)
for _, acc := range config.AWS {
Expand All @@ -498,7 +498,7 @@ func deleteConfigAccounts(account models.Account, config *models.Config) error {
}
config.AWS = updatedConfig

case "Digitalocean":
case "digitalocean":
updatedConfig := make([]models.DigitalOceanConfig, 0)
for _, acc := range config.DigitalOcean {
if acc.Name != account.Name {
Expand All @@ -507,7 +507,7 @@ func deleteConfigAccounts(account models.Account, config *models.Config) error {
}
config.DigitalOcean = updatedConfig

case "Oci":
case "oci":
updatedConfig := make([]models.OciConfig, 0)
for _, acc := range config.Oci {
if acc.Name != account.Name {
Expand All @@ -516,7 +516,7 @@ func deleteConfigAccounts(account models.Account, config *models.Config) error {
}
config.Oci = updatedConfig

case "Civo":
case "civo":
updatedConfig := make([]models.CivoConfig, 0)
for _, acc := range config.Civo {
if acc.Name != account.Name {
Expand All @@ -525,7 +525,7 @@ func deleteConfigAccounts(account models.Account, config *models.Config) error {
}
config.Civo = updatedConfig

case "Kubernetes":
case "kubernetes":
updatedConfig := make([]models.KubernetesConfig, 0)
for _, acc := range config.Kubernetes {
if acc.Name != account.Name {
Expand All @@ -534,7 +534,7 @@ func deleteConfigAccounts(account models.Account, config *models.Config) error {
}
config.Kubernetes = updatedConfig

case "Linode":
case "linode":
updatedConfig := make([]models.LinodeConfig, 0)
for _, acc := range config.Linode {
if acc.Name != account.Name {
Expand All @@ -543,7 +543,7 @@ func deleteConfigAccounts(account models.Account, config *models.Config) error {
}
config.Linode = updatedConfig

case "Tencent":
case "tencent":
updatedConfig := make([]models.TencentConfig, 0)
for _, acc := range config.Tencent {
if acc.Name != account.Name {
Expand All @@ -552,7 +552,7 @@ func deleteConfigAccounts(account models.Account, config *models.Config) error {
}
config.Tencent = updatedConfig

case "Azure":
case "azure":
updatedConfig := make([]models.AzureConfig, 0)
for _, acc := range config.Azure {
if acc.Name != account.Name {
Expand All @@ -561,7 +561,7 @@ func deleteConfigAccounts(account models.Account, config *models.Config) error {
}
config.Azure = updatedConfig

case "Scaleway":
case "scaleway":
updatedConfig := make([]models.ScalewayConfig, 0)
for _, acc := range config.Scaleway {
if acc.Name != account.Name {
Expand All @@ -570,7 +570,7 @@ func deleteConfigAccounts(account models.Account, config *models.Config) error {
}
config.Scaleway = updatedConfig

case "Mongodb":
case "mongodb":
updatedConfig := make([]models.MongoDBAtlasConfig, 0)
for _, acc := range config.MongoDBAtlas {
if acc.Name != account.Name {
Expand All @@ -579,7 +579,7 @@ func deleteConfigAccounts(account models.Account, config *models.Config) error {
}
config.MongoDBAtlas = updatedConfig

case "Gcp":
case "gcp":
updatedConfig := make([]models.GCPConfig, 0)
for _, acc := range config.GCP {
if acc.Name != account.Name {
Expand All @@ -588,7 +588,7 @@ func deleteConfigAccounts(account models.Account, config *models.Config) error {
}
config.GCP = updatedConfig

case "Ovh":
case "ovh":
updatedConfig := make([]models.OVHConfig, 0)
for _, acc := range config.OVH {
if acc.Name != account.Name {
Expand Down

0 comments on commit 7f826e4

Please sign in to comment.