packages feed

copr 1.0.0 → 1.1.0

raw patch · 5 files changed

+54/−41 lines, 5 filesdep +HsOpenSSL

Dependencies added: HsOpenSSL

Files

copr.cabal view
@@ -1,5 +1,5 @@ name:                copr-version:             1.0.0+version:             1.1.0 synopsis:            Haskell interface to the Fedora Copr system description:   This provides a Haskell interface to the Fedora Copr public build system.@@ -25,6 +25,7 @@                      , bytestring >= 0.10                      , containers >= 0.5                      , http-streams >= 0.7+                     , HsOpenSSL >= 0.10                      , io-streams >= 1.1                      , semigroups >= 0.12                      , text >= 0.11
src/Fedora/Copr.hs view
@@ -17,6 +17,7 @@       module C     , CoprConfig (..)     , Username+    , ProjectName     , defaultConfig     , withConfig     , addBuild@@ -34,13 +35,15 @@ import qualified Data.ByteString as S import qualified Data.ByteString.Char8 as C8 import qualified Data.ByteString.Lazy as LS-import Data.Monoid (mappend)+import Data.Monoid ((<>)) import Network.Http.Client+import OpenSSL (withOpenSSL) import qualified System.IO.Streams.ByteString as SBS  data CoprConfig = CoprConfig {     domain :: Hostname     -- ^ The domain on which Copr is hosted.   , port   :: Port         -- ^ The port on which Copr operates.+  , ssl    :: Bool         -- ^ Should we use SSL or Plain Text?   , login  :: S.ByteString -- ^ The API login (/not/ the same as username).   , token  :: S.ByteString -- ^ The API token. } deriving (Eq, Show)@@ -51,9 +54,10 @@ defaultConfig :: CoprConfig defaultConfig = CoprConfig {     domain = "copr.fedoraproject.org"-  , port = 80-  , login = ""-  , token = ""+  , port   = 80+  , ssl    = False+  , login  = ""+  , token  = "" }  -- | A utility wrapper for calling API methods with a 'CoprConfig'.@@ -85,16 +89,26 @@ --   details being ignored, so we don't have to worry about not sending them --   in that case. apiGet :: FromJSON a => S.ByteString -> CoprConfig -> IO a-apiGet url c = do-  cnx <- openConnection (domain c) (port c)+apiGet url c = withOpenSSL $ do+  cnx <- if ssl c+         then do+           ctx <- baselineContextSSL+           openConnectionSSL ctx (domain c) (port c)+         else+           openConnection (domain c) (port c)   q <- buildRequest $ prepareRequest c GET url   sendRequest cnx q emptyBody   finishRequest cnx  -- | Perform a POST request to the API, with authentication. apiPost :: (ToJSON a, FromJSON b) => S.ByteString -> a -> CoprConfig -> IO b-apiPost url d c = do-  cnx <- openConnection (domain c) (port c)+apiPost url d c = withOpenSSL $ do+  cnx <- if ssl c+         then do+           ctx <- baselineContextSSL+           openConnectionSSL ctx (domain c) (port c)+         else+           openConnection (domain c) (port c)   q <- buildRequest $ do     prepareRequest c POST url     setContentLength $ LS.length (encode d)@@ -104,43 +118,43 @@  -- | Retrieve a list of copr projects for an individual user. -----   This makes use of the @\/api\/coprs/[username]\/@ endpoint.+--   This makes use of the @\/api\/coprs\/[username]\/@ endpoint. -----   > withConfig c $ coprs "codeblock"+--   >>> withConfig c $ coprs "codeblock" coprs :: Username   -- ^ The username of the person whose projects we want to list.       -> CoprConfig -- ^ The configuration to use.       -> IO Coprs-coprs u = apiGet ("/api/coprs/" `mappend` u `mappend` "/")+coprs u = apiGet ("/api/coprs/" <> u <> "/")  -- | Create a new copr project. -----   This makes use of the @\/api\/coprs/[username]\/new\/@ endpoint.+--   This makes use of the @\/api\/coprs\/[username]\/new\/@ endpoint. -----   > withConfig c $ new "codeblock" (CoprProject "testproject" [] [] (NEL.fromList ["fedora-20-x86_64"]))+--   >>> withConfig c $ new "codeblock" (CoprProject "testproject" [] [] (NEL.fromList ["fedora-20-x86_64"])) new :: Username       -- ^ The username of the person whose project should be created.     -> CoprProject    -- ^ The copr project to be created.     -> CoprConfig     -- ^ The configuration to use.     -> IO NewCoprResponse-new u = apiPost ("/api/coprs/" `mappend` u `mappend` "/new/")+new u = apiPost ("/api/coprs/" <> u <> "/new/")  -- | Add a build to a copr project. -- --   This makes use of the @\/api\/coprs/[username]\/[project]\/new_build\/@ endpoint. -----   > withConfig c $ addBuild "codeblock" "testproject" (CoprBuild (NEL.fromList ["http://example.com/foo-1.0.0.src.rpm"]) 2048 3600)+--   >>> withConfig c $ addBuild "codeblock" "testproject" (CoprBuild (NEL.fromList ["http://example.com/foo-1.0.0.src.rpm"]) 2048 3600) addBuild :: Username    -- ^ The username of the person who owns the copr project.          -> ProjectName -- ^ The project to add the build to.          -> CoprBuild   -- ^ A representation of the build to add.          -> CoprConfig  -- ^ The configuration to use.          -> IO CoprBuildResponse-addBuild u p = apiPost ("/api/coprs/" `mappend` u `mappend` "/" `mappend` p `mappend` "/new_build/")+addBuild u p = apiPost ("/api/coprs/" <> u <> "/" <> p <> "/new_build/") --- | Check the status of a copr build+-- | Check the status of a copr build. -----   This makes use of the @\/api\/coprs\/build_status/[build_id]\/@ endpoint.+--   This makes use of the @\/api\/coprs\/build_status\/[build_id]\/@ endpoint. -----   > withConfig c $ buildStatus 1033+--   >>> withConfig c $ buildStatus 1033 buildStatus :: Int        -- ^ The build ID number to check.             -> CoprConfig -- ^ The configuration to use.             -> IO CoprStatusResponse-buildStatus i = apiGet ("/api/coprs/build_status/" `mappend` C8.pack (show i) `mappend` "/")+buildStatus i = apiGet ("/api/coprs/build_status/" <> C8.pack (show i) <> "/")
src/Fedora/Copr/CoprBuild.hs view
@@ -7,8 +7,8 @@ import Control.Applicative import Control.Monad (mzero) import Data.Aeson-import qualified Data.ByteString as S import qualified Data.List.NonEmpty as NEL+import qualified Data.Text as T  data CoprBuildResponse = CoprBuildResponse {     output  :: String@@ -26,13 +26,13 @@   parseJSON _          = mzero  data CoprBuild = CoprBuild {-    packages :: NEL.NonEmpty S.ByteString+    packages :: NEL.NonEmpty T.Text   , memory   :: Int   , timeout  :: Int } deriving (Eq, Show)  instance ToJSON CoprBuild where-  toJSON (CoprBuild p m t) = object [ "pkgs" .= S.intercalate " " (NEL.toList p)+  toJSON (CoprBuild p m t) = object [ "pkgs" .= T.intercalate " " (NEL.toList p)                                     , "memory" .= m                                     , "timeout" .= t                                     ]
src/Fedora/Copr/CoprProject.hs view
@@ -7,8 +7,6 @@ import Control.Applicative import Control.Monad (mzero) import Data.Aeson-import qualified Data.ByteString as S-import qualified Data.ByteString.Char8 as C8 import qualified Data.List.NonEmpty as NEL import qualified Data.Text as T @@ -26,18 +24,18 @@   parseJSON _          = mzero  data CoprProject = CoprProject {-    name            :: S.ByteString-  , repos           :: [S.ByteString]-  , initialPackages :: [S.ByteString]-  , chroots         :: NEL.NonEmpty S.ByteString-  , description     :: Maybe S.ByteString-  , instructions    :: Maybe S.ByteString+    name            :: T.Text+  , repos           :: [T.Text]+  , initialPackages :: [T.Text]+  , chroots         :: NEL.NonEmpty T.Text+  , description     :: Maybe T.Text+  , instructions    :: Maybe T.Text } deriving (Eq, Show)  instance ToJSON CoprProject where   toJSON (CoprProject n r p c d i) = object $ [ "name" .= n-                                          , "repos" .= S.intercalate " " r-                                          , "initial_pkgs" .= S.intercalate " " p+                                          , "repos" .= T.intercalate " " r+                                          , "initial_pkgs" .= T.intercalate " " p                                           , "description" .= d                                           , "instructions" .= i-                                          ] ++ map (\x -> T.pack (C8.unpack x) .= C8.pack "y") (NEL.toList c)+                                          ] ++ map (\x -> x .= T.pack "y") (NEL.toList c)
src/Fedora/Copr/ListCoprs.hs view
@@ -7,8 +7,8 @@ import Control.Applicative import Control.Monad (mzero) import Data.Aeson-import qualified Data.ByteString as S import Data.Map (Map)+import qualified Data.Text as T  data Coprs = Coprs {     output :: String@@ -17,11 +17,11 @@ } deriving (Eq, Show)  data Repo = Repo {-    yumRepos        :: Map S.ByteString S.ByteString-  , additionalRepos :: S.ByteString-  , instructions    :: S.ByteString-  , name            :: S.ByteString-  , description     :: S.ByteString+    yumRepos        :: Map T.Text T.Text+  , additionalRepos :: T.Text+  , instructions    :: T.Text+  , name            :: T.Text+  , description     :: T.Text } deriving (Eq, Show)  instance FromJSON Repo where