Remove all legacy config

This commit is contained in:
2024-01-17 16:56:41 -05:00
parent 1c373ff00f
commit 4b389fca1c
13 changed files with 101 additions and 142 deletions

View File

@ -70,36 +70,43 @@ func writeConfigFile(c *config.Config, path string) {
}
func promptConfigSettings(c *config.Config) *config.Config {
var gitlabConfig *config.GitlabConfig
var gitRemote *info.RemoteInfo
// Just pick the first if we have one, considering this
// is meant to be a first-time use tool
if len(c.Gitlabs) > 0 {
gitlabConfig = &c.Gitlabs[0]
if len(c.Remotes) > 0 {
gitRemote = &c.Remotes[0]
} else {
gitlabConfig = &config.DefaultConfig.Gitlabs[0]
c.Gitlabs = append(c.Gitlabs, *gitlabConfig)
gitRemote = &config.DefaultConfig.Remotes[0]
c.Remotes = append(c.Remotes, *gitRemote)
}
if host, err := pterm.DefaultInteractiveTextInput.
WithDefaultValue(gitlabConfig.Host).
WithDefaultText("Enter gitlab URL").
WithDefaultValue(gitRemote.Host).
WithDefaultText("Enter remote URL").
Show(); err == nil {
gitlabConfig.Host = host
gitRemote.Host = host
}
if name, err := pterm.DefaultInteractiveTextInput.
WithDefaultValue(gitlabConfig.Name).
WithDefaultText("Enter gitlab name (e.g. My Private GitLab)").
WithDefaultValue(gitRemote.Name).
WithDefaultText("Enter remote name (e.g. My Private remote)").
Show(); err == nil {
gitlabConfig.Name = name
gitRemote.Name = name
}
if token, err := pterm.DefaultInteractiveTextInput.
WithMask("*").
WithDefaultValue(gitlabConfig.Token).
WithDefaultText("Enter gitlab Token").
WithDefaultValue(gitRemote.Token).
WithDefaultText("Enter remote Token").
Show(); err == nil {
gitlabConfig.Token = token
gitRemote.Token = token
}
if remoteType, err := pterm.DefaultInteractiveSelect.
WithOptions(info.RemoteTypesAll.Strings()).
WithDefaultText("Git Clone Protocol").
Show(); err == nil {
gitRemote.Type = info.GetRemoteTypeFromString(remoteType)
}
if proto, err := pterm.DefaultInteractiveSelect.
@ -107,9 +114,9 @@ func promptConfigSettings(c *config.Config) *config.Config {
WithDefaultText("Git Clone Protocol").
Show(); err == nil {
if proto == "ssh" {
gitlabConfig.CloneProto = info.CloneProtoSSH
gitRemote.CloneProto = info.CloneProtoSSH
} else {
gitlabConfig.CloneProto = info.CloneProtoHTTP
gitRemote.CloneProto = info.CloneProtoHTTP
}
}

View File

@ -21,7 +21,9 @@ func runConfigShowCmd(cmd *cobra.Command, args []string) {
showSensitive, _ := cmd.Flags().GetBool("sensitive")
if !showSensitive {
plog.Info("Sensitive fields hidden, do not use unreviewed as config")
c.GitlabToken = strings.Repeat("*", len(c.GitlabToken))
for _, r := range c.Remotes {
r.Token = strings.Repeat("*", len(r.Token))
}
} else {
plog.Warn("Displaying sensitive fields!")
}

View File

@ -10,8 +10,6 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/config"
gitearemote "gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/gitea"
gitlabremote "gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/gitlab"
)
var conf config.Config
@ -111,7 +109,6 @@ func initConfig() {
}
checkConfigPerms(viper.ConfigFileUsed()) // Abort on world-readable config
setConfigFields() // Final chance to update config struct
plog.Debug("Configuration loaded", plog.Args("conf", conf))
}
@ -133,17 +130,6 @@ func getPtermLogLevel(level string) pterm.LogLevel {
return pLevel
}
// Do any post-processing of configuration here
func setConfigFields() {
// Load Gitlabs
glRemotes := gitlabremote.GitlabRemote{}
conf.Remotes = append(conf.Remotes, glRemotes.GetInfos(conf)...)
// Load Giteas
giteaRemotes := gitearemote.GiteaRemote{}
conf.Remotes = append(conf.Remotes, giteaRemotes.GetInfos(conf)...)
}
// Don't allow world-readable configuration
func checkConfigPerms(file string) {
stat, err := os.Stat(file)

View File

@ -57,7 +57,7 @@ func getRemotes(cmd *cobra.Command) *remotes.Remotes {
for _, r := range conf.Remotes {
// Create a copy, set context
gitRemoteInfo := r
gitRemoteInfo.Ctx = cmd.Context()
gitRemoteInfo.SetContext(cmd.Context())
var gitRemote remote.Remote
var err error
switch r.Type {