Skip to content

Commit

Permalink
Merge pull request #6 from OpenCHAMI/trcotton/read-only-config-signed
Browse files Browse the repository at this point in the history
config file read only
  • Loading branch information
alexlovelltroy committed Jan 29, 2024
2 parents efe44b9 + 8350bf4 commit 4a21559
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 31 deletions.
9 changes: 0 additions & 9 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,3 @@ func readConfig(filename string) (*Config, error) {

return c, nil
}

func writeConfig(filename string, config *Config) error {
data, err := yaml.Marshal(config)
if err != nil {
return err
}

return os.WriteFile(filename, data, 0644)
}
26 changes: 4 additions & 22 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@ import (
_ "github.com/lib/pq"
)

func generatePassword() (string, error) {
bytes := make([]byte, 16)
if _, err := rand.Read(bytes); err != nil {
return "", err
}

return hex.EncodeToString(bytes), nil
}

func connectDB(username, password, dbhost, dbname string) (*sql.DB, error) {
return connectDBWithRetry(username, password, dbhost, dbname, 2)
}
Expand Down Expand Up @@ -60,7 +51,10 @@ func execSQL(db *sql.DB, query string) error {

func main() {

config, err := readConfig("ochami.yaml")
if config_file == "" {

Check failure on line 54 in main.go

View workflow job for this annotation

GitHub Actions / build

undefined: config_file
log.Fatal("OCHAMI_CONFIG is required")
}
config, err := readConfig(config_file)

Check failure on line 57 in main.go

View workflow job for this annotation

GitHub Actions / build

undefined: config_file
if err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -98,13 +92,6 @@ func main() {
}

for _, user := range database.Users {
if user.Password == "" {
user.Password, err = generatePassword()
if err != nil {
log.Fatal(err)
}
}

err = execSQL(db, fmt.Sprintf("CREATE USER \"%s\" WITH PASSWORD '%s';", user.Name, user.Password))
if err != nil {
log.Fatal(err)
Expand All @@ -116,9 +103,4 @@ func main() {
}
}
}

err = writeConfig("ochami.yaml", config)
if err != nil {
log.Fatal(err)
}
}

0 comments on commit 4a21559

Please sign in to comment.