Skip to content
This repository has been archived by the owner on Oct 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #46 from flagship-io/fix/bug-concurrency
Browse files Browse the repository at this point in the history
Fix/bug concurrency
  • Loading branch information
Chadiii authored Mar 5, 2024
2 parents 56af91e + 6217fe5 commit 07d6cd5
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 168 deletions.
66 changes: 0 additions & 66 deletions .github/workflows/release-staging.yaml

This file was deleted.

2 changes: 2 additions & 0 deletions cmd/configuration/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ func TestConfigurationListCommand(t *testing.T) {

err := json.Unmarshal([]byte(output), &testConfigurationList)

assert.Nil(t, err)

byt, err := json.Marshal(mockfunction.TestConfiguration)

assert.Nil(t, err)
Expand Down
7 changes: 4 additions & 3 deletions cmd/configuration/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/flagship-io/flagship/utils/config"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var (
Expand All @@ -29,12 +30,12 @@ var createCmd = &cobra.Command{
}

if credentialsFile != "" {
conf := config.ReadCredentialsFromFile(credentialsFile)
if slices.Contains(existingConfigurationsName, conf.GetString("name")) {
config.ReadCredentialsFromFile(credentialsFile)
if slices.Contains(existingConfigurationsName, viper.GetString("name")) {
fmt.Fprintln(cmd.OutOrStdout(), "Configuration name already exists")
return
}
config.CreateConfigurationFile(conf.GetString("name"), conf.GetString("client_id"), conf.GetString("client_secret"), conf.GetString("account_id"), conf.GetString("account_environment_id"))
config.CreateConfigurationFile(viper.GetString("name"), viper.GetString("client_id"), viper.GetString("client_secret"), viper.GetString("account_id"), viper.GetString("account_environment_id"))
fmt.Fprintln(cmd.OutOrStdout(), "Configuration created successfully")
return
}
Expand Down
8 changes: 6 additions & 2 deletions cmd/configuration/current.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ var currentCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
var configurationYaml models.ConfigurationYaml
var configuration models.Configuration

var v = viper.New()

configFilepath := config.SetPathForConfigName(".cli")
v.SetConfigFile(configFilepath)
v.MergeInConfig()

err := v.MergeInConfig()
if err != nil {
log.Fatalf("error occurred: %s", err)
}

configurationName := v.GetString("current_used_configuration")

Expand Down
13 changes: 2 additions & 11 deletions cmd/configuration/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Copyright © 2022 Flagship Team [email protected]
package configuration

import (
"errors"
"fmt"
"log"
"os"
Expand All @@ -19,22 +18,14 @@ var deleteCmd = &cobra.Command{
Short: "Delete a configuration",
Long: `Delete a configuration`,
Run: func(cmd *cobra.Command, args []string) {
homeDir, err := os.UserHomeDir()
cobra.CheckErr(err)

if _, err := os.Stat(homeDir + "/.flagship/configurations"); errors.Is(err, os.ErrNotExist) {
err := os.MkdirAll(homeDir+"/.flagship/configurations", os.ModePerm)
if err != nil {
log.Fatal(err)
}
}

config.CheckFlagshipHomeDirectory()

if err := os.Remove(config.SetPathForConfigName(ConfigurationName)); err != nil {
log.Fatal(err)
}

fmt.Fprintln(cmd.OutOrStdout(), "Configuration deleted successfully")
return
},
}

Expand Down
14 changes: 7 additions & 7 deletions cmd/configuration/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/flagship-io/flagship/utils/config"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var (
Expand Down Expand Up @@ -39,22 +40,22 @@ var editCmd = &cobra.Command{
return
}

conf := config.ReadCredentialsFromFile(config.SetPathForConfigName(ConfigurationName))
config.ReadCredentialsFromFile(config.SetPathForConfigName(ConfigurationName))

if newConfigurationName == "" {
newConfigurationName = conf.GetString("name")
newConfigurationName = viper.GetString("name")
}
if ConfigurationClientID == "" {
ConfigurationClientID = conf.GetString("client_id")
ConfigurationClientID = viper.GetString("client_id")
}
if ConfigurationClientSecret == "" {
ConfigurationClientSecret = conf.GetString("client_secret")
ConfigurationClientSecret = viper.GetString("client_secret")
}
if ConfigurationAccountID == "" {
ConfigurationAccountID = conf.GetString("account_id")
ConfigurationAccountID = viper.GetString("account_id")
}
if ConfigurationAccountEnvID == "" {
ConfigurationAccountEnvID = conf.GetString("account_environment_id")
ConfigurationAccountEnvID = viper.GetString("account_environment_id")
}

if newConfigurationName == "" && ConfigurationClientID == "" && ConfigurationClientSecret == "" && ConfigurationAccountID == "" && ConfigurationAccountEnvID == "" {
Expand All @@ -65,7 +66,6 @@ var editCmd = &cobra.Command{
config.EditConfigurationFile(ConfigurationName, newConfigurationName, ConfigurationClientID, ConfigurationClientSecret, ConfigurationAccountID, ConfigurationAccountEnvID)

fmt.Fprintln(cmd.OutOrStdout(), "Configuration edited successfully")
return
},
}

Expand Down
1 change: 0 additions & 1 deletion cmd/configuration/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ var useCmd = &cobra.Command{
}

fmt.Fprintln(cmd.OutOrStdout(), "Configuration selected successfully")
return
},
}

Expand Down
20 changes: 11 additions & 9 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,17 @@ func initConfig() {
if cfgFile != "" {
// Use config file from the flag.
viper.SetConfigFile(cfgFile)
} else {
// Find home directory.
homeDir, err := os.UserHomeDir()
cobra.CheckErr(err)
// Search config in home directory with name ".flagship" (without extension).
viper.SetConfigFile(homeDir + "/.flagship/configurations/.cli.yaml")
viper.MergeInConfig()
if viper.GetString("current_used_configuration") != "" {
config.SelectConfiguration(viper.GetString("current_used_configuration"))
}
return
}
// Find home directory.
homeDir, err := os.UserHomeDir()
cobra.CheckErr(err)
// Search config in home directory with name ".flagship" (without extension).
viper.SetConfigFile(homeDir + "/.flagship/configurations/.cli.yaml")
viper.MergeInConfig()
if viper.GetString("current_used_configuration") != "" {
config.ReadConfiguration(viper.GetString("current_used_configuration"))
}

}
Loading

0 comments on commit 07d6cd5

Please sign in to comment.