Revert "Connecting Mizu to the application (#313)" (#316)

This commit is contained in:
RoyUP9
2021-10-06 10:41:23 +03:00
committed by GitHub
parent d2d4ed5aee
commit 9c98a4c2b1
15 changed files with 35 additions and 286 deletions

View File

@@ -54,30 +54,16 @@ func InitConfig(cmd *cobra.Command) error {
return nil
}
func GetConfigWithDefaults() (*ConfigStruct, error) {
func GetConfigWithDefaults() (string, error) {
defaultConf := ConfigStruct{}
if err := defaults.Set(&defaultConf); err != nil {
return nil, err
return "", err
}
configElem := reflect.ValueOf(&defaultConf).Elem()
setZeroForReadonlyFields(configElem)
return &defaultConf, nil
}
func WriteConfig(config *ConfigStruct) error {
template, err := uiUtils.PrettyYaml(config)
if err != nil {
return fmt.Errorf("failed converting config to yaml, err: %v", err)
}
data := []byte(template)
if err := ioutil.WriteFile(Config.ConfigFilePath, data, 0644); err != nil {
return fmt.Errorf("failed writing config, err: %v", err)
}
return nil
return uiUtils.PrettyYaml(defaultConf)
}
func mergeConfigFile(configFilePath string) error {

View File

@@ -21,7 +21,6 @@ type ConfigStruct struct {
Version configStructs.VersionConfig `yaml:"version"`
View configStructs.ViewConfig `yaml:"view"`
Logs configStructs.LogsConfig `yaml:"logs"`
Auth configStructs.AuthConfig `yaml:"auth"`
Config configStructs.ConfigConfig `yaml:"config,omitempty"`
AgentImage string `yaml:"agent-image,omitempty" readonly:""`
ImagePullPolicyStr string `yaml:"image-pull-policy" default:"Always"`

View File

@@ -1,6 +0,0 @@
package configStructs
type AuthConfig struct {
EnvName string `yaml:"env-name" default:"up9.app"`
Token string `yaml:"token"`
}

View File

@@ -3,7 +3,6 @@ package config_test
import (
"fmt"
"github.com/up9inc/mizu/cli/config"
"gopkg.in/yaml.v3"
"reflect"
"strings"
"testing"
@@ -16,11 +15,10 @@ func TestConfigWriteIgnoresReadonlyFields(t *testing.T) {
getFieldsWithReadonlyTag(configElem, &readonlyFields)
configWithDefaults, _ := config.GetConfigWithDefaults()
configWithDefaultsBytes, _ := yaml.Marshal(configWithDefaults)
for _, readonlyField := range readonlyFields {
t.Run(readonlyField, func(t *testing.T) {
readonlyFieldToCheck := fmt.Sprintf(" %s:", readonlyField)
if strings.Contains(string(configWithDefaultsBytes), readonlyFieldToCheck) {
readonlyFieldToCheck := fmt.Sprintf("\n%s:", readonlyField)
if strings.Contains(configWithDefaults, readonlyFieldToCheck) {
t.Errorf("unexpected result - readonly field: %v, config: %v", readonlyField, configWithDefaults)
}
})