module Network.AWS.KMS.Encrypt
(
Encrypt
, encrypt
, eEncryptionContext
, eGrantTokens
, eKeyId
, ePlaintext
, EncryptResponse
, encryptResponse
, erCiphertextBlob
, erKeyId
) where
import Network.AWS.Prelude
import Network.AWS.Request.JSON
import Network.AWS.KMS.Types
import qualified GHC.Exts
data Encrypt = Encrypt
{ _eEncryptionContext :: Map Text Text
, _eGrantTokens :: List "GrantTokens" Text
, _eKeyId :: Text
, _ePlaintext :: Base64
} deriving (Eq, Show)
encrypt :: Text
-> Base64
-> Encrypt
encrypt p1 p2 = Encrypt
{ _eKeyId = p1
, _ePlaintext = p2
, _eEncryptionContext = mempty
, _eGrantTokens = mempty
}
eEncryptionContext :: Lens' Encrypt (HashMap Text Text)
eEncryptionContext =
lens _eEncryptionContext (\s a -> s { _eEncryptionContext = a })
. _Map
eGrantTokens :: Lens' Encrypt [Text]
eGrantTokens = lens _eGrantTokens (\s a -> s { _eGrantTokens = a }) . _List
eKeyId :: Lens' Encrypt Text
eKeyId = lens _eKeyId (\s a -> s { _eKeyId = a })
ePlaintext :: Lens' Encrypt Base64
ePlaintext = lens _ePlaintext (\s a -> s { _ePlaintext = a })
data EncryptResponse = EncryptResponse
{ _erCiphertextBlob :: Maybe Base64
, _erKeyId :: Maybe Text
} deriving (Eq, Show)
encryptResponse :: EncryptResponse
encryptResponse = EncryptResponse
{ _erCiphertextBlob = Nothing
, _erKeyId = Nothing
}
erCiphertextBlob :: Lens' EncryptResponse (Maybe Base64)
erCiphertextBlob = lens _erCiphertextBlob (\s a -> s { _erCiphertextBlob = a })
erKeyId :: Lens' EncryptResponse (Maybe Text)
erKeyId = lens _erKeyId (\s a -> s { _erKeyId = a })
instance ToPath Encrypt where
toPath = const "/"
instance ToQuery Encrypt where
toQuery = const mempty
instance ToHeaders Encrypt
instance ToJSON Encrypt where
toJSON Encrypt{..} = object
[ "KeyId" .= _eKeyId
, "Plaintext" .= _ePlaintext
, "EncryptionContext" .= _eEncryptionContext
, "GrantTokens" .= _eGrantTokens
]
instance AWSRequest Encrypt where
type Sv Encrypt = KMS
type Rs Encrypt = EncryptResponse
request = post "Encrypt"
response = jsonResponse
instance FromJSON EncryptResponse where
parseJSON = withObject "EncryptResponse" $ \o -> EncryptResponse
<$> o .:? "CiphertextBlob"
<*> o .:? "KeyId"