mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-08-31 22:36:38 -04:00
Implement initial entry adding (partial, missing notes support)
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
// AddFolder creates a new directory at targetLocation
|
||||
func AddFolder(targetLocation string) {
|
||||
// create the directory specified by targetLocation
|
||||
err := os.Mkdir(targetLocation, 0700)
|
||||
@@ -20,3 +21,13 @@ func AddFolder(targetLocation string) {
|
||||
// TODO If in online mode, create the directory on the server
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// WriteEntry writes entryData to an encrypted file at targetLocation
|
||||
func WriteEntry(targetLocation string, entryData []string) {
|
||||
encryptedBytes := EncryptGPG(entryData)
|
||||
err := os.WriteFile(targetLocation, encryptedBytes, 0600)
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Failed to write to file: " + err.Error() + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,3 +24,16 @@ func DecryptGPG(targetLocation string) []string {
|
||||
}
|
||||
return outputSlice
|
||||
}
|
||||
|
||||
// EncryptGPG encrypts a slice of strings using GPG and returns the encrypted data as a byte slice
|
||||
func EncryptGPG(input []string) []byte {
|
||||
ReadConfig()
|
||||
cmd := exec.Command("gpg", "-q", "-r", Config["gpgID"].(string), "-e")
|
||||
writeToStdin(cmd, strings.Join(input, "\n"))
|
||||
encryptedBytes, err := cmd.Output()
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Failed to encrypt data - ensure that your GPG key is valid and that you have a valid GPG ID set in libmutton.ini" + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
return encryptedBytes
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user