-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from Nike-Inc/feature/config-management
Add configuration download and upload for jobs
- Loading branch information
Showing
9 changed files
with
99 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,4 @@ cabal.sandbox.config | |
.stack-work/ | ||
cabal.project.local | ||
.HTF/ | ||
ptl-pthread |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{-| | ||
Module : Config | ||
Description : Methods for executing config requests against Jenkins | ||
Copyright : (c) Nike, Inc., 2016 | ||
License : BSD3 | ||
Maintainer : fernando.freire@nike.com | ||
Stability : stable | ||
Methods for executing config requests against Jenkins. | ||
-} | ||
module Bartlett.Actions.Config where | ||
|
||
import Bartlett.Network (execRequest) | ||
import Bartlett.Types | ||
import Bartlett.Util (toResponseStatus, mkUrl) | ||
|
||
import Control.Lens ((^.), (?~), (&)) | ||
import Data.Aeson.Encode.Pretty (encodePretty) | ||
import qualified Data.ByteString.Lazy.Char8 as BL | ||
import Network.Wreq (responseStatus, responseBody, defaults, auth) | ||
|
||
-- | Construct a URL to interact with Job configurations. | ||
configUri :: JenkinsInstance -> JobPath -> BL.ByteString | ||
configUri base path = | ||
mkUrl base path "/config.xml" | ||
|
||
-- | Retrieve the XML configuration for the given job. | ||
getConfig :: BasicAuthUser a => | ||
a -- The user to authenticate with. | ||
-> JenkinsInstance -- The Jenkins instance to interact with. | ||
-> 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 | ||
BL.putStrLn $ resp ^. responseBody | ||
where reqOpts = defaults & auth ?~ getBasicAuth user | ||
|
||
-- | Update the XML configuration for the given job. | ||
updateConfig :: BasicAuthUser a => | ||
a -- The user to authenticate with. | ||
-> JenkinsInstance -- The Jenkins instance to interact with. | ||
-> JobPath -- The Job for the given Jenkins instance to interact with. | ||
-> ConfigPath -- Path to the XML configuration to upload to Jenkins. | ||
-> IO () | ||
updateConfig user base path configPath = do | ||
configFile <- BL.readFile configPath | ||
resp <- execRequest "post" reqOpts (configUri base path) (Just configFile) | ||
BL.putStrLn . encodePretty . toResponseStatus $ resp ^. responseStatus | ||
where reqOpts = defaults & auth ?~ getBasicAuth user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters