Skip to content

Commit 0743711

Browse files
Set installCerts value in config.ini if certicates are manually installed
1 parent b281453 commit 0743711

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

config/config.go

+18
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
"github.com/arduino/go-paths-helper"
2424
log "github.com/sirupsen/logrus"
25+
"gopkg.in/ini.v1"
2526
)
2627

2728
// GetCertificatesDir return the directory where SSL certificates are saved
@@ -124,3 +125,20 @@ func GenerateConfig(destDir *paths.Path) *paths.Path {
124125
log.Infof("generated config in %s", configPath)
125126
return configPath
126127
}
128+
129+
// SetInstallCertsIni sets installCerts value to true in the config
130+
func SetInstallCertsIni(filename string) error {
131+
cfg, err := ini.LoadSources(ini.LoadOptions{IgnoreInlineComment: false, AllowPythonMultilineValues: true}, filename)
132+
if err != nil {
133+
return err
134+
}
135+
_, err = cfg.Section("").NewKey("installCerts", "true")
136+
if err != nil {
137+
return err
138+
}
139+
err = cfg.SaveTo(filename)
140+
if err != nil {
141+
return err
142+
}
143+
return nil
144+
}

main.go

+1-17
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ func loop() {
227227
if value, err := valueIni(configPath.String()); err != nil {
228228
log.Panicf("config.ini cannot be parsed: %s", err)
229229
} else if !value && cert.PromptInstallCertsSafari() {
230-
err = modifyIni(configPath.String())
230+
err = config.SetInstallCertsIni(configPath.String())
231231
if err != nil {
232232
log.Panicf("config.ini cannot be parsed: %s", err)
233233
}
@@ -517,22 +517,6 @@ func parseIni(filename string) (args []string, err error) {
517517
return args, nil
518518
}
519519

520-
func modifyIni(filename string) error {
521-
cfg, err := ini.LoadSources(ini.LoadOptions{IgnoreInlineComment: false, AllowPythonMultilineValues: true}, filename)
522-
if err != nil {
523-
return err
524-
}
525-
_, err = cfg.Section("").NewKey("installCerts", "true")
526-
if err != nil {
527-
return err
528-
}
529-
err = cfg.SaveTo(filename)
530-
if err != nil {
531-
return err
532-
}
533-
return nil
534-
}
535-
536520
func valueIni(filename string) (bool, error) {
537521
cfg, err := ini.LoadSources(ini.LoadOptions{IgnoreInlineComment: false, AllowPythonMultilineValues: true}, filename)
538522
if err != nil {

systray/systray_real.go

+4
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ func (s *Systray) start() {
108108
log.Errorf("cannot install certificates something went wrong: %s", err)
109109
cert.DeleteCertificates(certDir)
110110
}
111+
err = config.SetInstallCertsIni(s.currentConfigFilePath.String())
112+
if err != nil {
113+
log.Errorf("cannot set installCerts value in config.ini: %s", err)
114+
}
111115
s.Restart()
112116
case <-mRemoveCerts.ClickedCh:
113117
err := cert.UninstallCertificates()

0 commit comments

Comments
 (0)