diff --git a/bartlett.cabal b/bartlett.cabal index 7816aad..01103e8 100644 --- a/bartlett.cabal +++ b/bartlett.cabal @@ -1,5 +1,5 @@ name: bartlett -version: 1.1.0 +version: 1.1.1 synopsis: The Jenkins command-line tool to serve your needs. description: Please see README.md homepage: https://github.com/Nike-inc/bartlett diff --git a/src/Bartlett/Actions/Build.hs b/src/Bartlett/Actions/Build.hs index aafbd90..d0b5938 100644 --- a/src/Bartlett/Actions/Build.hs +++ b/src/Bartlett/Actions/Build.hs @@ -40,7 +40,7 @@ postBuild :: -> Maybe JobParameters -- ^ Optional set of job parameters to trigger with. -> IO () postBuild user base path parameters = do - resp <- execRequest "post" reqOpts reqUri Nothing + resp <- execRequest Post reqOpts reqUri Nothing BL.putStrLn . encodePretty . BU.toResponseStatus $ resp ^. responseStatus where (suffix, buildOpts) = consBuildType parameters diff --git a/src/Bartlett/Actions/Config.hs b/src/Bartlett/Actions/Config.hs index b2e9dde..eeae355 100644 --- a/src/Bartlett/Actions/Config.hs +++ b/src/Bartlett/Actions/Config.hs @@ -31,7 +31,7 @@ getConfig :: BasicAuthUser a => -> JobPath -- The Job for the given Jenkins instance to interact with. -> IO () -- The XML configuration for the given job. getConfig user base path = do - resp <- execRequest "get" reqOpts (configUri base path) Nothing + resp <- execRequest Get reqOpts (configUri base path) Nothing BL.putStrLn $ resp ^. responseBody where reqOpts = defaults & auth ?~ getBasicAuth user @@ -44,6 +44,6 @@ updateConfig :: BasicAuthUser a => -> IO () updateConfig user base path configPath = do configFile <- BL.readFile configPath - resp <- execRequest "post" reqOpts (configUri base path) (Just configFile) + resp <- execRequest Post reqOpts (configUri base path) (Just configFile) BL.putStrLn . encodePretty . toResponseStatus $ resp ^. responseStatus where reqOpts = defaults & auth ?~ getBasicAuth user diff --git a/src/Bartlett/Actions/Info.hs b/src/Bartlett/Actions/Info.hs index f509dc0..0b70db6 100644 --- a/src/Bartlett/Actions/Info.hs +++ b/src/Bartlett/Actions/Info.hs @@ -33,7 +33,7 @@ getInfo :: -> IO () getInfo user base [] = return () getInfo user base (path:paths) = do - resp <- execRequest "get" reqOpts reqUri Nothing + resp <- execRequest Get reqOpts reqUri Nothing BL.putStrLn . toPrettyJson $ resp ^. responseBody getInfo user base paths where reqOpts = defaults & auth ?~ getBasicAuth user diff --git a/src/Bartlett/Network.hs b/src/Bartlett/Network.hs index 7843aa0..5b0097a 100644 --- a/src/Bartlett/Network.hs +++ b/src/Bartlett/Network.hs @@ -18,6 +18,7 @@ module Bartlett.Network ( )where import Bartlett.Util (toResponseStatus, withForcedSSL) +import Bartlett.Types (RequestType(Get, Post)) import qualified Control.Exception as E import Data.Aeson.Encode.Pretty (encodePretty) @@ -30,7 +31,7 @@ import qualified Network.Wreq.Session as S -- | General request handler that provides basic error handling. execRequest :: - ByteString -- ^ The type of request to make (e.g. "get") + RequestType -- ^ The type of request to make -> Options -- ^ Request params to pass along with the request. -> ByteString -- ^ The uri to make the request to -> Maybe ByteString -- ^ The file to upload to the Jenkins instance. @@ -41,13 +42,13 @@ execRequest requestType opts reqUrl postBody = -- TODO Need to get a CSRF crumb -- JENKINS_URL/crumbIssuer/api/json?xpath=?xpath=concat(//crumbRequestField,":",//crumb)') -- TODO create a proper sum type for requestType - "post" -> + Post -> postSession reqUrl `E.catch` recoverableErrorHandler (postSession $ withForcedSSL reqUrl) where fileToUpload = fromMaybe "" postBody :: ByteString postSession url = S.postWith opts session (unpack url) fileToUpload - "get" -> + Get -> getSession reqUrl `E.catch` recoverableErrorHandler (getSession $ withForcedSSL reqUrl) diff --git a/src/Bartlett/Types.hs b/src/Bartlett/Types.hs index fbd0e24..a9e274a 100644 --- a/src/Bartlett/Types.hs +++ b/src/Bartlett/Types.hs @@ -10,7 +10,25 @@ Stability : stable Types and type alises used throughout Bartlett. -} -module Bartlett.Types where +module Bartlett.Types ( + -- * Type Aliases + JenkinsInstance, + Username, + Password, + JobPath, + JobParameters, + Profile, + ConfigPath, + -- * User types + BasicAuthUser(..), + User(..), + -- * Command-Line Types + Command(..), + Options(..), + -- * Network Types + StatusResponse(..), + RequestType(..) +) where import Data.Aeson (ToJSON, FromJSON) import Data.ByteString.Lazy.Char8 (ByteString, toStrict) @@ -70,3 +88,6 @@ data StatusResponse = StatusResponse { -- Derived JSON serlializers instance ToJSON StatusResponse instance FromJSON StatusResponse + +-- | Incomplete sum type for network requests +data RequestType = Get | Post