-
Notifications
You must be signed in to change notification settings - Fork 501
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add decrypt and encrypt template functions
- Loading branch information
Showing
6 changed files
with
64 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package cmd | ||
|
||
func (c *Config) decryptTemplateFunc(ciphertext string) string { | ||
plaintextBytes, err := c.encryption.Decrypt([]byte(ciphertext)) | ||
if err != nil { | ||
returnTemplateError(err) | ||
return "" | ||
} | ||
return string(plaintextBytes) | ||
} | ||
|
||
func (c *Config) encryptTemplateFunc(plaintext string) string { | ||
ciphertextBytes, err := c.encryption.Encrypt([]byte(plaintext)) | ||
if err != nil { | ||
returnTemplateError(err) | ||
return "" | ||
} | ||
return string(ciphertextBytes) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[!exec:age] skip 'age not found in $PATH' | ||
|
||
mkageconfig | ||
|
||
# test encrypt template function | ||
chezmoi execute-template '{{ "plaintext" | encrypt }}' | ||
stdout '-----BEGIN AGE ENCRYPTED FILE-----' | ||
|
||
# test encrypt and decrypt template function round trip | ||
chezmoi execute-template '{{ "plaintext\n" | encrypt | decrypt }}' | ||
cmp stdout golden/plaintext | ||
|
||
[windows] stop 'remaining tests rely on UNIX path handling' # FIXME | ||
|
||
# test decrypt template function | ||
chezmoi encrypt --output=$HOME${/}ciphertext.age golden/plaintext | ||
chezmoi execute-template '{{ joinPath (env "HOME") "ciphertext.age" | include | decrypt }}' | ||
cmp stdout golden/plaintext | ||
|
||
-- golden/plaintext -- | ||
plaintext |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters