From bae836fc91873329d054991f74a4ae6cec6777c8 Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Thu, 7 Jan 2021 12:38:50 -0500 Subject: [PATCH 1/3] Add install instructions --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 7d7d054..746286f 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,16 @@ Here's how to do that on [Firefox](https://support.mozilla.org/en-US/kb/error-co 2. Run the command! On first run, you will be asked to authenticate and install the app in your workspace +## Setup + + 1. Install the app into your Slack workspace + +Add to Slack + + 2. Install the command from the Releases tab + + 3. Run the command! On first run, you will be asked to authenticate + ## Example usage Login (it will store it in `~/.config/slack-status-cli` or your `$XDG_CONFIG_HOME` dir From 9a03c1da008170e2f1ef8bec97571be75a9bf116 Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Thu, 7 Jan 2021 12:38:50 -0500 Subject: [PATCH 2/3] Update install instructions --- README.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 746286f..6effbc7 100644 --- a/README.md +++ b/README.md @@ -18,13 +18,9 @@ Here's how to do that on [Firefox](https://support.mozilla.org/en-US/kb/error-co ## Setup - 1. Install the app into your Slack workspace + 1. Install the command from the Releases tab -Add to Slack - - 2. Install the command from the Releases tab - - 3. Run the command! On first run, you will be asked to authenticate + 2. Run the command! On first run, you will be asked to authenticate and install the app in your workspace ## Example usage From aba5a5b6eb41621c215f63c169c2489443a23ad7 Mon Sep 17 00:00:00 2001 From: Alex Levy Date: Fri, 5 Feb 2021 10:22:17 -0800 Subject: [PATCH 3/3] Use home dir if XDG_CONFIG_HOME unset --- auth.go | 11 +++++++++-- config.go | 23 +++++++++++++++++------ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/auth.go b/auth.go index 252d014..00973c3 100644 --- a/auth.go +++ b/auth.go @@ -68,8 +68,15 @@ func (app slackApp) listenForCode() (string, error) { }() }) - certPath := getConfigFilePath("cert.pem") - keyPath := getConfigFilePath("key.pem") + certPath, err := getConfigFilePath("cert.pem") + if err != nil { + return "", err + } + + keyPath, err := getConfigFilePath("key.pem") + if err != nil { + return "", err + } if !fileExists(certPath) || !fileExists(keyPath) { if err := generateSelfSignedCertificates(certPath, keyPath); err != nil { diff --git a/config.go b/config.go index a2676f6..63fcc79 100644 --- a/config.go +++ b/config.go @@ -6,6 +6,7 @@ import ( "fmt" "io/ioutil" "os" + "os/user" "path/filepath" ) @@ -19,22 +20,29 @@ type configData struct { } // 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. -func getConfigFilePath(filename string) string { +// The config folder will be created in ~/.config/slack-status-cli if it does not exist. +func getConfigFilePath(filename string) (string, error) { configHome := os.Getenv("XDG_CONFIG_HOME") 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") _ = os.MkdirAll(configDir, 0755) - return filepath.Join(configDir, filename) + return filepath.Join(configDir, filename), nil } // readConfig returns the current configuration func readConfig() (*configData, error) { - configPath := getConfigFilePath("config.json") + configPath, err := getConfigFilePath("config.json") + if err != nil { + return nil, err + } if !fileExists(configPath) { return &configData{DomainTokens: map[string]string{}}, nil @@ -57,7 +65,10 @@ func readConfig() (*configData, error) { // writeConfig writes the provided config data func writeConfig(config configData) error { - configPath := getConfigFilePath("config.json") + configPath, err := getConfigFilePath("config.json") + if err != nil { + return err + } contents, err := json.Marshal(config) if err != nil {