Merge remote-tracking branch 'levy/master' into master
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
IamTheFij 2021-02-05 10:30:15 -08:00
commit 62037b9dab
2 changed files with 26 additions and 8 deletions

11
auth.go
View File

@ -68,8 +68,15 @@ func (app slackApp) listenForCode() (string, error) {
}() }()
}) })
certPath := getConfigFilePath("cert.pem") certPath, err := getConfigFilePath("cert.pem")
keyPath := getConfigFilePath("key.pem") if err != nil {
return "", err
}
keyPath, err := getConfigFilePath("key.pem")
if err != nil {
return "", err
}
if !fileExists(certPath) || !fileExists(keyPath) { if !fileExists(certPath) || !fileExists(keyPath) {
if err := generateSelfSignedCertificates(certPath, keyPath); err != nil { if err := generateSelfSignedCertificates(certPath, keyPath); err != nil {

View File

@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"os/user"
"path/filepath" "path/filepath"
) )
@ -19,22 +20,29 @@ type configData struct {
} }
// getConfigFilePath returns the path of a given file within the config folder. // getConfigFilePath returns the path of a given file within the config folder.
// The config folder will be created in ~/.local/config/slack-status-cli if it does not exist. // The config folder will be created in ~/.config/slack-status-cli if it does not exist.
func getConfigFilePath(filename string) string { func getConfigFilePath(filename string) (string, error) {
configHome := os.Getenv("XDG_CONFIG_HOME") configHome := os.Getenv("XDG_CONFIG_HOME")
if configHome == "" { if configHome == "" {
configHome = "~/.local/config" usr, err := user.Current()
if err != nil {
return "", fmt.Errorf("error getting current user information", err)
}
configHome = filepath.Join(usr.HomeDir, ".config")
} }
configDir := filepath.Join(configHome, "slack-status-cli") configDir := filepath.Join(configHome, "slack-status-cli")
_ = os.MkdirAll(configDir, 0755) _ = os.MkdirAll(configDir, 0755)
return filepath.Join(configDir, filename) return filepath.Join(configDir, filename), nil
} }
// readConfig returns the current configuration // readConfig returns the current configuration
func readConfig() (*configData, error) { func readConfig() (*configData, error) {
configPath := getConfigFilePath("config.json") configPath, err := getConfigFilePath("config.json")
if err != nil {
return nil, err
}
if !fileExists(configPath) { if !fileExists(configPath) {
return &configData{DomainTokens: map[string]string{}}, nil return &configData{DomainTokens: map[string]string{}}, nil
@ -57,7 +65,10 @@ func readConfig() (*configData, error) {
// writeConfig writes the provided config data // writeConfig writes the provided config data
func writeConfig(config configData) error { func writeConfig(config configData) error {
configPath := getConfigFilePath("config.json") configPath, err := getConfigFilePath("config.json")
if err != nil {
return err
}
contents, err := json.Marshal(config) contents, err := json.Marshal(config)
if err != nil { if err != nil {