Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glcon readconfig #151

Merged
merged 7 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix Minio connection check error, like was done on nabu
  • Loading branch information
valentinedwv committed Feb 7, 2023
commit a3aebea7ab612c53aed07d216cd23acfaaae9370
1 change: 1 addition & 0 deletions internal/config/minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var MinioTemplate = map[string]interface{}{
"accesskey": "",
"secretkey": "",
"bucket": "",
"ssl": "false",
},
}

Expand Down
38 changes: 16 additions & 22 deletions pkg/cli/gleaner.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package cli

import (
"errors"
"fmt"

"github.com/gleanerio/gleaner/internal/check"
"github.com/gleanerio/gleaner/internal/common"
"github.com/gleanerio/gleaner/internal/config"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -67,26 +70,17 @@ func initGleanerConfig() {
} else {
log.Fatal("error reading config file ", err)
}
//nabuViperVal = viper.New()
//if cfgFile != "" {
// // Use config file from the flag.
// nabuViperVal.SetConfigFile(cfgFile)
//} else {
// // Find home directory.
// home, err := os.UserHomeDir()
// cobra.CheckErr(err)
//
// // Search config in home directory with name ".gleaner" (without extension).
// nabuViperVal.AddConfigPath(home)
// nabuViperVal.AddConfigPath(path.Join(cfgPath, cfgName))
// nabuViperVal.SetConfigType("yaml")
// nabuViperVal.SetConfigName("nabu")
//}
//viper.AutomaticEnv() // read in environment variables that match
//
//
//if err := nabuViperVal.ReadInConfig(); err == nil {
// fmt.Fprintln(os.Stderr, "Using nabu config file:", nabuViperVal.ConfigFileUsed())
//}

// some checks
mc := common.MinioConnection(gleanerViperVal)
err := check.ConnCheck(mc)
if err != nil {
err = errors.New(err.Error() + fmt.Sprintf(" Ignore that. It's not the bucket. check config/minio: address, port, ssl. connection info: endpoint: %v ", mc.EndpointURL()))
log.Fatal("cannot connect to minio: ", err)
}

bucketVal, err = config.GetBucketName(gleanerViperVal)
if err != nil {
log.Fatal("cannot read bucketname from : %s ", err)
}
}
37 changes: 15 additions & 22 deletions pkg/cli/nabu.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package cli

import (
"errors"
"fmt"
"github.com/gleanerio/gleaner/internal/check"
"github.com/gleanerio/gleaner/internal/common"
"github.com/gleanerio/gleaner/internal/config"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -50,28 +54,6 @@ func init() {
}

func initNabuConfig() {
//
//gleanerViperVal = viper.New()
//if cfgFile != "" {
// // Use config file from the flag.
// gleanerViperVal.SetConfigFile(cfgFile)
//} else {
// // Find home directory.
// home, err := os.UserHomeDir()
// cobra.CheckErr(err)
//
// // Search config in home directory with name ".gleaner" (without extension).
// gleanerViperVal.AddConfigPath(home)
// gleanerViperVal.AddConfigPath(path.Join(cfgPath, cfgName))
// gleanerViperVal.SetConfigType("yaml")
// gleanerViperVal.SetConfigName("gleaner")
//}
//// If a config file is found, read it in.
//if err := gleanerViperVal.ReadInConfig(); err == nil {
// fmt.Fprintln(os.Stderr, "Using gleaner config file:", gleanerViperVal.ConfigFileUsed())
//} else {
// log.Fatal("error reading config file")
//}

nabuViperVal = viper.New()
if cfgFile != "" {
Expand All @@ -96,5 +78,16 @@ func initNabuConfig() {
} else {
log.Fatal("error reading config file", err)
}
// some checks
mc := common.MinioConnection(nabuViperVal)
err := check.ConnCheck(mc)
if err != nil {
err = errors.New(err.Error() + fmt.Sprintf(" Ignore that. It's not the bucket. check config/minio: address, port, ssl. connection info: endpoint: %v ", mc.EndpointURL()))
log.Fatal("cannot connect to minio: ", err)
}

bucketVal, err = config.GetBucketName(nabuViperVal)
if err != nil {
log.Fatal("cannot read bucketname from : %s ", err)
}
}
61 changes: 0 additions & 61 deletions pkg/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,70 +84,9 @@ func init() {
//rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}

//func initLogging() {
// // name the file with the date and time
// const layout = "2006-01-02-15-04-05"
// t := time.Now()
// lf := fmt.Sprintf("gleaner-%s.log", t.Format(layout))
//
// LogFile := lf // log to custom file
// logFile, err := os.OpenFile(LogFile, os.O_APPEND|os.O_RDWR|os.O_CREATE, 0644)
// if err != nil {
// log.Panic(err)
// return
// }
//
// log.SetFormatter(&log.JSONFormatter{}) // Log as JSON instead of the default ASCII formatter.
// log.SetReportCaller(true) // include file name and line number
// mw := io.MultiWriter(os.Stdout, logFile)
// log.SetOutput(mw)
// //log.SetOutput(logFile)
//}

// initConfig reads in config file and ENV variables if set.
func initConfig() {

//gleanerViperVal = viper.New()
//if cfgFile != "" {
// // Use config file from the flag.
// gleanerViperVal.SetConfigFile(cfgFile)
//} else {
// // Find home directory.
// home, err := os.UserHomeDir()
// cobra.CheckErr(err)
//
// // Search config in home directory with name ".gleaner" (without extension).
// gleanerViperVal.AddConfigPath(home)
// gleanerViperVal.AddConfigPath(path.Join(cfgPath, cfgName))
// gleanerViperVal.SetConfigType("yaml")
// gleanerViperVal.SetConfigName("gleaner")
//}
//nabuViperVal = viper.New()
//if cfgFile != "" {
// // Use config file from the flag.
// nabuViperVal.SetConfigFile(cfgFile)
//} else {
// // Find home directory.
// home, err := os.UserHomeDir()
// cobra.CheckErr(err)
//
// // Search config in home directory with name ".gleaner" (without extension).
// nabuViperVal.AddConfigPath(home)
// nabuViperVal.AddConfigPath(path.Join(cfgPath, cfgName))
// nabuViperVal.SetConfigType("yaml")
// nabuViperVal.SetConfigName("nabu")
//}
//viper.AutomaticEnv() // read in environment variables that match
//
//// If a config file is found, read it in.
//if err := gleanerViperVal.ReadInConfig(); err == nil {
// fmt.Fprintln(os.Stderr, "Using gleaner config file:", gleanerViperVal.ConfigFileUsed())
//} else {
// log.Fatal("error reading config file")
//}
//if err := nabuViperVal.ReadInConfig(); err == nil {
// fmt.Fprintln(os.Stderr, "Using nabu config file:", nabuViperVal.ConfigFileUsed())
//}
// Setup the KV store to hold a record of indexed resources
var err error
db, err = bolt.Open("gleaner.db", 0600, nil)
Expand Down