Skip to content

Commit

Permalink
Remove the remembered endLines when a secret is added to the list.
Browse files Browse the repository at this point in the history
  • Loading branch information
bionade24 committed Aug 20, 2024
1 parent b559f40 commit 50311da
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
1 change: 1 addition & 0 deletions histcleaner.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ library
exposed-modules:
HistCleaner
HistCleaner.Cleaner
HistCleaner.Config
HistCleaner.FileParser
HistCleaner.Hash
HistCleaner.SecretStorage
Expand Down
9 changes: 2 additions & 7 deletions src/HistCleaner/Cleaner.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ module HistCleaner.Cleaner where

import Control.Monad.State.Lazy
import Crypto.Error (CryptoFailable(..))
import Data.Base64.Types (extractBase64)
import Data.ByteString (ByteString)
import Data.ByteString.Base64
import Data.Base64.Types (extractBase64)
import qualified Data.ByteString.Char8 as C8
import Data.ByteString.UTF8 (fromString, toString)
import Data.Foldable
Expand All @@ -18,10 +18,10 @@ import System.IO
import System.Posix.Files
import System.Posix.Signals

import HistCleaner.Config
import HistCleaner.FileParser
import HistCleaner.Hash
import qualified HistCleaner.SecretStorage as St
import HistCleaner.SecretStorage (getConfigFolder)

data CleanResult
= CSuccess
Expand Down Expand Up @@ -177,11 +177,6 @@ storeEndlines filepath prevELinesInfo text = do
contLines
C8.writeFile endInfosPath $ C8.unlines $ filteredLines ++ curEndInfo

getEndInfosPath :: IO FilePath
getEndInfosPath = do
configFolderPath <- getConfigFolder
pure $ configFolderPath </> "endInfos"

dropAlreadyChecked :: [ByteString] -> [ByteString] -> [ByteString]
dropAlreadyChecked endLines allLines =

Check warning on line 181 in src/HistCleaner/Cleaner.hs

View workflow job for this annotation

GitHub Actions / build

This binding for ‘endLines’ shadows the existing binding
if length allLines < 3 || length endLines < 3
Expand Down
15 changes: 15 additions & 0 deletions src/HistCleaner/Config.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module HistCleaner.Config where

import System.Environment.XDG.BaseDir
import System.FilePath

getConfigFolder :: IO FilePath
getConfigFolder = getUserConfigDir "histcleaner"

getEndInfosPath :: IO FilePath
getEndInfosPath = do
configFolderPath <- getConfigFolder
pure $ configFolderPath </> "endInfos"

getSecretsFilepath :: IO FilePath
getSecretsFilepath = getUserConfigFile "histcleaner" "secrets"
18 changes: 7 additions & 11 deletions src/HistCleaner/SecretStorage.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import Control.DeepSeq
import Control.Exception
import Control.Monad
import Crypto.Error (CryptoFailable(..))
import Data.Base64.Types (extractBase64)
import Data.ByteString (ByteString)
import Data.ByteString.Base64
import Data.Base64.Types (extractBase64)
import qualified Data.ByteString.Char8 as C8
import System.Directory (doesDirectoryExist)
import System.Environment.XDG.BaseDir
import System.Directory (doesDirectoryExist, removeFile)
import System.Posix (ownerModes)
import System.Posix.Directory (createDirectory)

import HistCleaner.Config
import qualified HistCleaner.Hash as Hash
import System.Posix (ownerModes)

data SStorageResult
= SSuccess
Expand All @@ -37,6 +37,7 @@ storeSecret secret = do
pure $ StoreFail "Secret already stored."
else do
storeLine res
getEndInfosPath >>= removeFile
pure SSuccess

-- Storing config & hashes
Expand Down Expand Up @@ -92,7 +93,8 @@ getSecrets = do
(\(e :: IOException) -> do

Check warning on line 93 in src/HistCleaner/SecretStorage.hs

View workflow job for this annotation

GitHub Actions / build

Defined but not used: ‘e’
salt <- Hash.newSalt

Check warning on line 94 in src/HistCleaner/SecretStorage.hs

View workflow job for this annotation

GitHub Actions / build

This binding for ‘salt’ shadows the existing binding
C8.writeFile filepath $
extractBase64 (encodeBase64' salt) <> "\n----------------------------------\n"
extractBase64 (encodeBase64' salt) <>
"\n----------------------------------\n"
pure $ Vault salt [])

-- Inverts the list while decoding it
Expand All @@ -105,9 +107,3 @@ decodeSecrets input =
Left _ -> do
error "Decoding error"
Right b -> (b : decodeSecrets rest)

getConfigFolder :: IO FilePath
getConfigFolder = getUserConfigDir "histcleaner"

getSecretsFilepath :: IO FilePath
getSecretsFilepath = getUserConfigFile "histcleaner" "secrets"

0 comments on commit 50311da

Please sign in to comment.