Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions src/keybaseca/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,13 @@ func (ef *EnvConfig) GetKeybaseHomeDir() string {
// Get the keybase paper key for the bot account. Used if you are running a separate instance of keybase for the chatbot.
// May be empty.
func (ef *EnvConfig) GetKeybasePaperKey() string {
return os.Getenv("KEYBASE_PAPERKEY")
return shared.ReadFileOrDefault(os.Getenv("KEYBASE_PAPERKEY_PATH"), os.Getenv("KEYBASE_PAPERKEY"))
}

// Get the keybase username for the bot account. Used if you are running a separate instance of keybase for the chatbot.
// May be empty.
func (ef *EnvConfig) GetKeybaseUsername() string {
return os.Getenv("KEYBASE_USERNAME")
return shared.ReadFileOrDefault(os.Getenv("KEYBASE_USERNAME_PATH"), os.Getenv("KEYBASE_USERNAME"))
}

// Get the expiration period for signatures generated by the bot.
Expand Down
19 changes: 19 additions & 0 deletions src/shared/utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package shared

import (
"io/ioutil"
"os"
"os/user"
"path/filepath"
"strings"
Expand Down Expand Up @@ -29,3 +31,20 @@ func ExpandPathWithTilde(path string) string {
}
return path
}

// Tries to read data from a file from given path.
// If no file is found, the file read creates an error or is empty,
// the function will return the value of the `or` parameter instead.
func ReadFileOrDefault(filePath string, or string) string {
if len(filePath) <= 0 {
return or
}
if _, err := os.Stat(filePath); os.IsNotExist(err) {
return or
}
data, err := ioutil.ReadFile(filePath)
if err != nil || len(data) <= 0 {
return or
}
return string(data)
}