Skip to content

Commit

Permalink
Add client-side token validation
Browse files Browse the repository at this point in the history
Signed-off-by: Sascha Grunert <mail@saschagrunert.de>
  • Loading branch information
saschagrunert committed Jun 15, 2019
1 parent 4f9b81c commit c100d1c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
8 changes: 4 additions & 4 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
, persistent, persistent-sqlite, persistent-template, safe
, shakespeare, stdenv, tasty, tasty-hspec, tasty-quickcheck
, template-haskell, temporary, text, time, unordered-containers
, vector, wai, wai-extra, wai-logger, warp, yaml, yesod, yesod-auth
, yesod-core, yesod-form, yesod-static, yesod-test
, uuid, vector, wai, wai-extra, wai-logger, warp, yaml, yesod
, yesod-auth, yesod-core, yesod-form, yesod-static, yesod-test
}:
mkDerivation {
pname = "performabot";
Expand All @@ -23,8 +23,8 @@ mkDerivation {
hslogger http-client http-client-tls http-conduit lens megaparsec
monad-control monad-logger persistent persistent-sqlite
persistent-template safe shakespeare template-haskell temporary
text time unordered-containers vector wai wai-extra wai-logger warp
yaml yesod yesod-auth yesod-core yesod-form yesod-static
text time unordered-containers uuid vector wai wai-extra wai-logger
warp yaml yesod yesod-auth yesod-core yesod-form yesod-static
];
libraryToolDepends = [ hpack ];
executableHaskellDepends = [
Expand Down
1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ library:
- text
- time
- unordered-containers
- uuid
- vector
- wai
- wai-extra
Expand Down
3 changes: 2 additions & 1 deletion performabot.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cabal-version: 1.12
--
-- see: https://github.com/sol/hpack
--
-- hash: a6884df1b62f16200c9854fc4e7e101fbfd650b64ba7248a900764727b5ed43e
-- hash: 29443bc3901d58a1f3b9da668d25f551b3bf28ce23c282fc30300335359371ab

name: performabot
version: 0.1.0
Expand Down Expand Up @@ -91,6 +91,7 @@ library
, text
, time
, unordered-containers
, uuid
, vector
, wai
, wai-extra
Expand Down
15 changes: 13 additions & 2 deletions src/Environment.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ module Environment
) where

import Control.Lens ( (.~), (^.) )
import Control.Monad ( mapM, msum )
import Control.Monad ( mapM, msum, unless )

import Data.List ( intercalate )
import Data.Maybe ( isNothing )
import Data.Text ( Text, pack )
import qualified Data.Text as T ( null )
import Data.UUID ( fromText )

import Log ( err )
import Log ( debug, err )

import Model
( Environment, environmentBranch, environmentCommit
Expand All @@ -33,6 +35,15 @@ fillEnvironment e d = do
c <- getEnv (e ^. environmentCommit) "commit" commitEnvVars
p <- getEnv (e ^. environmentPullRequest) "pull request" pullRequestEnvVars
t <- getEnv (e ^. environmentToken) "token" tokenEnvVars

-- Validate the token
unless (T.null t) $ if isNothing (fromText t)
then do
err $ printf "Invalid token '%s' provided" t
exitFailure
else debug $ printf "Token '%s' seems to be valid" t

-- Validate the other environment variables
if not d && any T.null [ b, c, p, t ]
then exitFailure
else return $ environmentToken .~ t $ environmentPullRequest .~ p $
Expand Down

0 comments on commit c100d1c

Please sign in to comment.