packages feed

include-env (empty) → 0.1.0.0

raw patch · 6 files changed

+122/−0 lines, 6 filesdep +basedep +include-envdep +template-haskellsetup-changed

Dependencies added: base, include-env, template-haskell

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Marco Zocca (c) 2021++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Marco Zocca nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,5 @@+# include-env++[![Build Status](https://travis-ci.org/unfoldml/include-env.png)](https://travis-ci.org/unfoldml/include-env)++TODO Description.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ app/Main.hs view
@@ -0,0 +1,12 @@+{-# language TemplateHaskell #-}+module Main where++import IncludeEnv.TH (includeEnv)++$(includeEnv "SHELL" "shl")+shl :: String++main :: IO ()+main = putStrLn $ unwords ["your current shell :", shl] ++
+ include-env.cabal view
@@ -0,0 +1,35 @@+name:                include-env+version:             0.1.0.0+synopsis:            Include the value of an environment variable at compile time+description:         Embed secrets (e.g. API keys) inside production artifacts without checking them into the repository.+homepage:            https://github.com/unfoldml/include-env+license:             BSD3+license-file:        LICENSE+author:              Marco Zocca+maintainer:          example@example.com+copyright:           (c) 2021 Marco Zocca, UnfoldML AB+category:            Development+build-type:          Simple+extra-source-files:  README.md+cabal-version:       >=1.10+tested-with:         GHC == 8.6.5, GHC == 8.10.4++library+  default-language:    Haskell2010+  ghc-options:         -Wall+  hs-source-dirs:      src+  exposed-modules:     IncludeEnv.TH+  build-depends:       base >= 4.7 && < 5+                     , template-haskell >= 2.14++executable include-env+  default-language:    Haskell2010+  ghc-options:         -threaded -rtsopts -with-rtsopts=-N+  hs-source-dirs:      app+  main-is:             Main.hs+  build-depends:       base+                     , include-env++source-repository head+  type:     git+  location: https://github.com/unfoldml/include-env
+ src/IncludeEnv/TH.hs view
@@ -0,0 +1,38 @@+{-# language TemplateHaskell #-}+{-# options_ghc -Wno-unused-imports #-}+{-|+Include the value of an environment variable at compile time++== Rationale+The first use case for this library is to embed secrets (e.g. API keys) inside production artifacts without checking them into the repository.++-}+module IncludeEnv.TH (includeEnv) where++import System.Environment (lookupEnv)++-- template-haskell+import Language.Haskell.TH (runIO, runQ)+import Language.Haskell.TH.Syntax (Q, Exp(..), Dec(..), Pat(..), Name, mkName, Body(..), Lit(..))+import Language.Haskell.TH.Lib (valD)+++-- | Include the value of an environment variable at compile time+--+-- A fresh variable is declared each time this is computation is evaluated+includeEnv :: String -- ^ name of environment variable to be looked up+           -> String -- ^ name of new value+           -> Q [Dec]+includeEnv e varname = do+  mstr <- runIO $ lookupEnv e+  case mstr of+    Just str -> decl varname str+    Nothing -> error $ unwords ["Cannot find variable", e, "in the environment."]+    where+      decl :: String -> String -> Q [Dec]+      decl n x = fmap (:[]) $ pure $ ValD qpat qbody [] where+        qpat = VarP (mkName n)+        qbody = NormalB (LitE (StringL x))+++