STACKAGE_AUTH_TOKEN environment variable

This commit is contained in:
Michael Snoyman 2015-01-11 10:08:02 +02:00
parent a143fc438d
commit fd56370e3a
4 changed files with 53 additions and 14 deletions

View File

@ -1,3 +1,8 @@
## 0.5.1
* `loadBuildConstraints`
* More command line options
## 0.5.0 ## 0.5.0
* Print "Still Alive" while checking, to avoid Travis timeouts * Print "Still Alive" while checking, to avoid Travis timeouts

View File

@ -11,6 +11,8 @@ module Stackage.BuildConstraints
, getSystemInfo , getSystemInfo
, defaultBuildConstraints , defaultBuildConstraints
, toBC , toBC
, BuildConstraintsSource (..)
, loadBuildConstraints
) where ) where
import Control.Monad.Writer.Strict (execWriter, tell) import Control.Monad.Writer.Strict (execWriter, tell)
@ -22,7 +24,7 @@ import Distribution.System (Arch, OS)
import qualified Distribution.System import qualified Distribution.System
import Distribution.Version (anyVersion) import Distribution.Version (anyVersion)
import Filesystem (isFile) import Filesystem (isFile)
import Network.HTTP.Client (Manager, httpLbs, responseBody) import Network.HTTP.Client (Manager, httpLbs, responseBody, Request)
import Stackage.CorePackages import Stackage.CorePackages
import Stackage.Prelude import Stackage.Prelude
@ -126,15 +128,32 @@ instance FromJSON PackageConstraints where
-- Checks the current directory for a build-constraints.yaml file and uses it -- Checks the current directory for a build-constraints.yaml file and uses it
-- if present. If not, downloads from Github. -- if present. If not, downloads from Github.
defaultBuildConstraints :: Manager -> IO BuildConstraints defaultBuildConstraints :: Manager -> IO BuildConstraints
defaultBuildConstraints man = do defaultBuildConstraints = loadBuildConstraints BCSDefault
e <- isFile fp
if e data BuildConstraintsSource
then decodeFileEither (fpToString fp) >>= either throwIO toBC = BCSDefault
else httpLbs req man >>= | BCSFile FilePath
either throwIO toBC . decodeEither' . toStrict . responseBody | BCSWeb Request
deriving (Show)
loadBuildConstraints :: BuildConstraintsSource -> Manager -> IO BuildConstraints
loadBuildConstraints bcs man = do
case bcs of
BCSDefault -> do
e <- isFile fp0
if e
then loadFile fp0
else loadReq req0
BCSFile fp -> loadFile fp
BCSWeb req -> loadReq req
where where
fp = "build-constraints.yaml" fp0 = "build-constraints.yaml"
req = "https://raw.githubusercontent.com/fpco/stackage/master/build-constraints.yaml" req0 = "https://raw.githubusercontent.com/fpco/stackage/master/build-constraints.yaml"
loadFile fp = decodeFileEither (fpToString fp) >>= either throwIO toBC
loadReq req = httpLbs req man >>=
either throwIO toBC . decodeEither' . toStrict . responseBody
getSystemInfo :: IO SystemInfo getSystemInfo :: IO SystemInfo
getSystemInfo = do getSystemInfo = do

View File

@ -27,6 +27,7 @@ import Stackage.Prelude
import Stackage.ServerBundle import Stackage.ServerBundle
import Stackage.UpdateBuildPlan import Stackage.UpdateBuildPlan
import Stackage.Upload import Stackage.Upload
import System.Environment (lookupEnv)
import System.IO (BufferMode (LineBuffering), hSetBuffering) import System.IO (BufferMode (LineBuffering), hSetBuffering)
-- | Flags passed in from the command line. -- | Flags passed in from the command line.
@ -241,12 +242,18 @@ justUploadNightly day = do
finallyUpload :: Settings -> Manager -> IO () finallyUpload :: Settings -> Manager -> IO ()
finallyUpload settings@Settings{..} man = do finallyUpload settings@Settings{..} man = do
putStrLn "Uploading bundle to Stackage Server" putStrLn "Uploading bundle to Stackage Server"
token <- readFile "/auth-token"
mtoken <- lookupEnv "STACKAGE_AUTH_TOKEN"
token <-
case mtoken of
Nothing -> decodeUtf8 <$> readFile "/auth-token"
Just token -> return $ pack token
now <- epochTime now <- epochTime
let ghcVer = display $ siGhcVersion $ bpSystemInfo plan let ghcVer = display $ siGhcVersion $ bpSystemInfo plan
(ident, mloc) <- flip uploadBundle man $ setArgs ghcVer def (ident, mloc) <- flip uploadBundle man $ setArgs ghcVer def
{ ubContents = serverBundle now (title ghcVer) slug plan { ubContents = serverBundle now (title ghcVer) slug plan
, ubAuthToken = decodeUtf8 token , ubAuthToken = token
} }
putStrLn $ "New ident: " ++ unSnapshotIdent ident putStrLn $ "New ident: " ++ unSnapshotIdent ident
forM_ mloc $ \loc -> forM_ mloc $ \loc ->
@ -257,7 +264,7 @@ finallyUpload settings@Settings{..} man = do
putStrLn "Uploading docs to Stackage Server" putStrLn "Uploading docs to Stackage Server"
res1 <- uploadDocs UploadDocs res1 <- uploadDocs UploadDocs
{ udServer = def { udServer = def
, udAuthToken = decodeUtf8 token , udAuthToken = token
, udDocs = pbDocDir pb , udDocs = pbDocDir pb
, udSnapshot = ident , udSnapshot = ident
} man } man
@ -274,7 +281,7 @@ finallyUpload settings@Settings{..} man = do
putStrLn "Uploading doc map" putStrLn "Uploading doc map"
uploadDocMap UploadDocMap uploadDocMap UploadDocMap
{ udmServer = def { udmServer = def
, udmAuthToken = decodeUtf8 token , udmAuthToken = token
, udmSnapshot = ident , udmSnapshot = ident
, udmDocDir = pbDocDir pb , udmDocDir = pbDocDir pb
, udmPlan = plan , udmPlan = plan

View File

@ -197,7 +197,7 @@ performBuild' pb@PerformBuild {..} = withBuildDir $ \builddir -> do
id id
(\db -> (("HASKELL_PACKAGE_SANDBOX", fpToString db):)) (\db -> (("HASKELL_PACKAGE_SANDBOX", fpToString db):))
(pbDatabase pb) (pbDatabase pb)
(map fixEnv env) (filter allowedEnv $ map fixEnv env)
, sbHaddockFiles = haddockFiles , sbHaddockFiles = haddockFiles
} }
@ -215,6 +215,8 @@ performBuild' pb@PerformBuild {..} = withBuildDir $ \builddir -> do
| toUpper p == "PATH" = (p, fpToString (pbBinDir pb) ++ pathSep : x) | toUpper p == "PATH" = (p, fpToString (pbBinDir pb) ++ pathSep : x)
| otherwise = (p, x) | otherwise = (p, x)
allowedEnv (k, _) = k `notMember` bannedEnvs
-- | Separate for the PATH environment variable -- | Separate for the PATH environment variable
pathSep :: Char pathSep :: Char
#ifdef mingw32_HOST_OS #ifdef mingw32_HOST_OS
@ -223,6 +225,12 @@ performBuild' pb@PerformBuild {..} = withBuildDir $ \builddir -> do
pathSep = ':' pathSep = ':'
#endif #endif
-- | Environment variables we don't allow to be passed on to child processes.
bannedEnvs :: Set String
bannedEnvs = setFromList
[ "STACKAGE_AUTH_TOKEN"
]
data SingleBuild = SingleBuild data SingleBuild = SingleBuild
{ sbSem :: TSem { sbSem :: TSem
, sbErrsVar :: TVar (Map PackageName BuildFailure) , sbErrsVar :: TVar (Map PackageName BuildFailure)