packages feed

confcrypt 0.1.0.2 → 0.1.0.3

raw patch · 5 files changed

+77/−18 lines, 5 filesdep ~containersdep ~deepseqdep ~lensPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: containers, deepseq, lens

API changes (from Hackage documentation)

+ ConfCrypt.Commands: GetConfCrypt :: Text -> GetConfCrypt
+ ConfCrypt.Commands: [gName] :: GetConfCrypt -> Text
+ ConfCrypt.Commands: data GetConfCrypt
+ ConfCrypt.Commands: instance (GHC.Base.Monad m, ConfCrypt.Encryption.MonadDecrypt (ConfCrypt.Types.ConfCryptM m key) key) => ConfCrypt.Commands.Command ConfCrypt.Commands.GetConfCrypt (ConfCrypt.Types.ConfCryptM m key)
+ ConfCrypt.Commands: instance GHC.Classes.Eq ConfCrypt.Commands.GetConfCrypt
+ ConfCrypt.Commands: instance GHC.Generics.Generic ConfCrypt.Commands.GetConfCrypt
+ ConfCrypt.Commands: instance GHC.Read.Read ConfCrypt.Commands.GetConfCrypt
+ ConfCrypt.Commands: instance GHC.Show.Show ConfCrypt.Commands.GetConfCrypt
- ConfCrypt.Encryption: unpackPrivateRSAKey :: (MonadError ConfCryptError m) => ByteString -> m KeyPair
+ ConfCrypt.Encryption: unpackPrivateRSAKey :: MonadError ConfCryptError m => ByteString -> m KeyPair

Files

app/ConfCrypt/CLI/API.hs view
@@ -7,7 +7,7 @@ ) where  import ConfCrypt.Types (SchemaType(..))-import ConfCrypt.Commands (AddConfCrypt(..), EditConfCrypt(..), DeleteConfCrypt(..))+import ConfCrypt.Commands (GetConfCrypt(..), AddConfCrypt(..), EditConfCrypt(..), DeleteConfCrypt(..))  import Options.Applicative import qualified Data.Text as T@@ -19,6 +19,7 @@  data AnyCommand     = RC KeyAndConf+    | GC KeyAndConf GetConfCrypt     | AC KeyAndConf AddConfCrypt     | EC KeyAndConf EditConfCrypt     | DC Conf DeleteConfCrypt@@ -49,6 +50,8 @@         <>         command "read" readConf         <>+        command "get" get+        <>         command "validate" validate         <>         command "new" new@@ -72,6 +75,11 @@ readConf :: ParserInfo AnyCommand readConf = info ( RC <$> keyAndConf )            (progDesc "Read in the provided config and decrypt it with the key. Results are printed to StdOut." <>+            fullDesc)++get :: ParserInfo AnyCommand+get = info ( GC <$> keyAndConf <*> (GetConfCrypt <$> onlyName))+            (progDesc "Get a single parameter value from the configuration file." <>             fullDesc)  validate :: ParserInfo AnyCommand
app/ConfCrypt/CLI/Engine.hs view
@@ -49,6 +49,8 @@                 -- Requires Decryption                 RC KeyAndConf {key, provider} ->                     runConfCrypt parsedConfiguration $ runWithDecrypt key provider ReadConfCrypt+                GC KeyAndConf {key, provider} cmd ->+                    runConfCrypt parsedConfiguration $ runWithDecrypt key provider cmd                 VC KeyAndConf {key, provider} ->                     runConfCrypt parsedConfiguration $ runWithDecrypt key provider ValidateConfCrypt @@ -101,6 +103,7 @@  confFilePath :: AnyCommand -> FilePath confFilePath  (RC KeyAndConf {conf}) = conf+confFilePath  (GC KeyAndConf {conf} _) = conf confFilePath  (VC KeyAndConf {conf}) = conf confFilePath  (AC KeyAndConf {conf} _) = conf confFilePath  (EC KeyAndConf {conf} _) = conf
confcrypt.cabal view
@@ -1,11 +1,13 @@--- This file has been generated from package.yaml by hpack version 0.28.2.+cabal-version: 1.12++-- This file has been generated from package.yaml by hpack version 0.31.0. -- -- see: https://github.com/sol/hpack ----- hash: 5b27e134c82385faabae1c112f530f28b8bae81e65dc1700f7158d7cbef14516+-- hash: a3df760fcf44cfbf4f12aae1540474ee182d0ba30d5a4146ab63055963b6b803  name:           confcrypt-version:        0.1.0.2+version:        0.1.0.3 description:    Please see the README on GitHub at <https://github.com/CollegeVine/confcrypt#readme> homepage:       https://github.com/https://github.com/collegevine/confcrypt#readme bug-reports:    https://github.com/https://github.com/collegevine/confcrypt/issues@@ -15,10 +17,9 @@ license:        MIT license-file:   LICENSE build-type:     Simple-cabal-version:  >= 1.10 extra-source-files:-    ChangeLog.md     README.md+    ChangeLog.md  source-repository head   type: git@@ -45,12 +46,12 @@     , base64-bytestring     , bytestring >=0.10.8 && <0.11     , conduit >=1.3 && <1.4-    , containers >=0.5.11 && <0.5.12+    , containers >=0.5.11     , crypto-pubkey-openssh     , crypto-pubkey-types     , cryptonite >=0.25-    , deepseq >=1.4.3 && <1.4.4-    , lens >=4.16 && <4.17+    , deepseq >=1.4.3+    , lens >=4.16     , megaparsec >=6.5 && <6.6     , mtl >=2.2 && <2.3     , optparse-applicative >=0.14 && <0.15@@ -76,12 +77,12 @@     , bytestring >=0.10.8 && <0.11     , conduit >=1.3 && <1.4     , confcrypt-    , containers >=0.5.11 && <0.5.12+    , containers >=0.5.11     , crypto-pubkey-openssh     , crypto-pubkey-types     , cryptonite >=0.25-    , deepseq >=1.4.3 && <1.4.4-    , lens >=4.16 && <4.17+    , deepseq >=1.4.3+    , lens >=4.16     , megaparsec >=6.5 && <6.6     , mtl >=2.2 && <2.3     , optparse-applicative@@ -110,12 +111,12 @@     , bytestring >=0.10.8 && <0.11     , conduit >=1.3 && <1.4     , confcrypt-    , containers >=0.5.11 && <0.5.12+    , containers >=0.5.11     , crypto-pubkey-openssh     , crypto-pubkey-types     , cryptonite >=0.25-    , deepseq >=1.4.3 && <1.4.4-    , lens >=4.16 && <4.17+    , deepseq >=1.4.3+    , lens >=4.16     , megaparsec >=6.5 && <6.6     , memory     , mtl >=2.2 && <2.3
src/ConfCrypt/Commands.hs view
@@ -5,6 +5,7 @@      -- * Supported Commands     ReadConfCrypt(..),+    GetConfCrypt(..),     AddConfCrypt(..),     EditConfCrypt(..),     DeleteConfCrypt(..),@@ -25,14 +26,14 @@ import ConfCrypt.Providers.AWS (AWSCtx)  import Control.Arrow (second)-import Control.Monad (unless)+import Control.Monad (unless, (<=<)) import Control.Monad.Trans (lift) import Control.Monad.Reader (ask) import Control.Monad.Except (throwError, runExcept, MonadError, Except) import Control.Monad.Writer (tell, MonadWriter) import Crypto.Random (MonadRandom) import Data.Foldable (foldrM, traverse_)-import Data.List (sortOn)+import Data.List (find, sortOn) import GHC.Generics (Generic) import qualified Crypto.PubKey.RSA.Types as RSA import qualified Data.Text as T@@ -70,6 +71,17 @@                 where                 transformedLines = [(p, Edit)| p <- transformed] +-- | Used to get the decrypted value of a single encrypted config parameter+data GetConfCrypt = GetConfCrypt {gName :: T.Text}+    deriving (Eq, Read, Show, Generic)++instance (Monad m, MonadDecrypt (ConfCryptM m key) key) => Command GetConfCrypt (ConfCryptM m key) where+    evaluate (GetConfCrypt name) = do+        (ccFile, ctx) <- ask+        let mParam = find ((==name) . paramName) (parameters ccFile)+        traverse_ (decrypt ctx) mParam+        where+            decrypt ctx = tell . pure <=< decryptValue ctx . paramValue  -- | Used to add a new config parameter to the file data AddConfCrypt = AddConfCrypt {aName :: T.Text, aValue :: T.Text, aType :: SchemaType}
test/ConfCrypt/CLI/API/Tests.hs view
@@ -3,7 +3,7 @@     ) where  import ConfCrypt.CLI.API-import ConfCrypt.Commands (AddConfCrypt(..), EditConfCrypt(..), DeleteConfCrypt(..))+import ConfCrypt.Commands (GetConfCrypt(..), AddConfCrypt(..), EditConfCrypt(..), DeleteConfCrypt(..)) import ConfCrypt.Types  import ConfCrypt.Common@@ -23,6 +23,7 @@ apiTests :: TestTree apiTests = testGroup "specific cases" [     readCases,+    getCases,     addCases,     editCases,     deleteCases,@@ -60,6 +61,40 @@             Success (RC (KeyAndConf "testKey" LocalRSA "test.econf") ) -> assertBool "can't fail" True             Success a -> assertFailure ("Incorrectly parsed: "<> show a)             Failure _ -> assertFailure "Should have parsed an RC"+            CompletionInvoked _ -> assertFailure "Incorrectly triggered completion"+    ]++getCases :: TestTree+getCases = testGroup "get" [+    testCase "get requires a key" $ do+        let args = ["get", "--name", "Test", "test.econf"]+            res = execParserPure defaultPrefs cliParser args+        case res of+            Failure _ -> assertBool "can't fail" True+            Success a -> assertFailure ("Incorrectly parsed: "<> show a)+            CompletionInvoked _ -> assertFailure "Incorrectly triggered completion"+    ,testCase "get requires a config file" $ do+        let args = ["get", "--key", "testKey", "--name", "Test"]+            res = execParserPure defaultPrefs cliParser args+        case res of+            Failure _ -> assertBool "can't fail" True+            Success a -> assertFailure ("Incorrectly parsed: "<> show a)+            CompletionInvoked _ -> assertFailure "Incorrectly triggered completion"+   ,testCase "get preserves the provided key file with -k" $ do+        let args = ["get", "-k", "testKey", "--name", "Test", "test.econf"]+            res = execParserPure defaultPrefs cliParser args+        case res of+            Success (GC (KeyAndConf "testKey" LocalRSA "test.econf") (GetConfCrypt "Test")) -> assertBool "can't fail" True+            Success a -> assertFailure ("Incorrectly parsed: "<> show a)+            Failure _ -> assertFailure "Should have parsed a GC"+            CompletionInvoked _ -> assertFailure "Incorrectly triggered completion"+   ,testCase "get preserves the provided key file with --key" $ do+        let args = ["get", "--key", "testKey", "--name", "Test", "test.econf"]+            res = execParserPure defaultPrefs cliParser args+        case res of+            Success (GC (KeyAndConf "testKey" LocalRSA "test.econf") (GetConfCrypt "Test")) -> assertBool "can't fail" True+            Success a -> assertFailure ("Incorrectly parsed: "<> show a)+            Failure _ -> assertFailure "Should have parsed a GC"             CompletionInvoked _ -> assertFailure "Incorrectly triggered completion"     ]