{-# LANGUAGE OverloadedStrings, RecordWildCards #-}
module Network.AWS.CloudFront.SignedCookies.CLI.Sign
( main, mainOpts, Opts (..), optsParser, mainParserInfo
) where
import Network.AWS.CloudFront.SignedCookies
import Network.AWS.CloudFront.SignedCookies.CLI.Internal
import Data.Coerce (Coercible, coerce)
import Data.Foldable (for_)
import Data.Semigroup ((<>))
import qualified Options.Applicative as Opt
import qualified Data.Text as Text
import qualified Data.Text.IO as Text
import Data.Time.Clock (nominalDay)
main :: IO ()
main = do
opts <- Opt.execParser $ Opt.info (Opt.helper <*> optsParser) infoMod
mainOpts opts
mainOpts :: Opts -> IO ()
mainOpts Opts{..} = do
policy <- simplePolicy opt_resource opt_lifespan
key <- readPrivateKeyPemFile opt_pemFilePath
cookies <- createSignedCookies opt_keyPairId key policy
(Text.putStr . renderCookiesText) cookies
data Opts =
Opts
{ opt_pemFilePath :: PemFilePath
, opt_keyPairId :: KeyPairId
, opt_resource :: Resource
, opt_lifespan :: Lifespan
}
optsParser :: Opt.Parser Opts
optsParser =
Opts
<$> text "pem-file" "Location in the filesystem where a .pem file \
\containing an RSA secret key can be found"
<*> text "key-pair-id" "CloudFront key pair ID for the key pair that \
\you are using to generate signature"
<*> text "resource" "URL that the policy will grant access to, \
\optionally containing asterisks for wildcards"
<*> days "days" "Integer number of days until the policy expires"
mainParserInfo :: Opt.ParserInfo (IO ())
mainParserInfo =
mainOpts <$> Opt.info optsParser infoMod
infoMod :: Opt.InfoMod a
infoMod =
Opt.header "Generate signed cookies for AWS CloudFront"