packages feed

cachix-api 0.1.0.1 → 0.1.0.2

raw patch · 9 files changed

+139/−99 lines, 9 filesdep −conduit-combinatorsdep ~conduit

Dependencies removed: conduit-combinators

Dependency ranges changed: conduit

Files

ChangeLog.md view
@@ -7,6 +7,18 @@  ## [Unreleased] +## [0.1.0.2] - 2018-09-27++### Changed++- #132 Remove autogenerated cabal file from git @domenkozar+- NarC now strips the extension @domenkozar+- added `BinaryCacheAuthenticated` @domenkozar+- #118 User: add email field @domenkozar+- Update dependencies to Stackage LTS-12 @domenkozar++### Changed+ ## [0.1.0.1] - 2018-07-06  ### Changed
cachix-api.cabal view
@@ -1,11 +1,13 @@--- This file has been generated from package.yaml by hpack version 0.28.2.+cabal-version: 1.12++-- This file has been generated from package.yaml by hpack version 0.31.0. -- -- see: https://github.com/sol/hpack ----- hash: 622e58e514481a3a8c55a6b379423676d4d2157334db4c29b45ef8c0954e3bb0+-- hash: 5eaa9ab936f76cafce3bb324f6f2f2e22d928ac4a49316a827f9b859b06807d7  name:           cachix-api-version:        0.1.0.1+version:        0.1.0.2 synopsis:       Servant HTTP API specification for https://cachix.org homepage:       https://github.com/cachix/cachix#readme bug-reports:    https://github.com/cachix/cachix/issues@@ -15,10 +17,9 @@ license:        Apache-2.0 license-file:   LICENSE build-type:     Simple-cabal-version:  >= 1.10 extra-source-files:-    ChangeLog.md     README.md+    ChangeLog.md  source-repository head   type: git@@ -28,16 +29,18 @@   exposed-modules:       Cachix.Api       Cachix.Api.Signing-      Cachix.Api.Swagger       Cachix.Api.Types+      Cachix.Types.BinaryCacheAuthenticated       Cachix.Types.ContentTypes+      Cachix.Types.NarInfoCreate       Cachix.Types.Servant       Cachix.Types.Session+      Cachix.Types.SwaggerOrphans   other-modules:       Paths_cachix_api   hs-source-dirs:       src-  default-extensions: OverloadedStrings+  default-extensions: OverloadedStrings DeriveGeneric DeriveAnyClass   ghc-options: -Wall -fwarn-tabs -fwarn-unused-imports -fwarn-missing-signatures -fwarn-name-shadowing -fwarn-incomplete-patterns   build-depends:       aeson@@ -45,8 +48,7 @@     , base >=4.7 && <5     , base16-bytestring     , bytestring-    , conduit-    , conduit-combinators+    , conduit >=1.3.0     , cookie     , cryptonite     , http-api-data@@ -72,7 +74,7 @@       Paths_cachix_api   hs-source-dirs:       cachix-gen-swagger-  default-extensions: OverloadedStrings+  default-extensions: OverloadedStrings DeriveGeneric DeriveAnyClass   ghc-options: -Wall -fwarn-tabs -fwarn-unused-imports -fwarn-missing-signatures -fwarn-name-shadowing -fwarn-incomplete-patterns -threaded -rtsopts -with-rtsopts=-N   build-depends:       aeson@@ -81,8 +83,7 @@     , base16-bytestring     , bytestring     , cachix-api-    , conduit-    , conduit-combinators+    , conduit >=1.3.0     , cookie     , cryptonite     , http-api-data@@ -110,7 +111,7 @@       Paths_cachix_api   hs-source-dirs:       test-  default-extensions: OverloadedStrings+  default-extensions: OverloadedStrings DeriveGeneric DeriveAnyClass   ghc-options: -Wall -fwarn-tabs -fwarn-unused-imports -fwarn-missing-signatures -fwarn-name-shadowing -fwarn-incomplete-patterns -threaded -rtsopts -with-rtsopts=-N   build-depends:       aeson@@ -119,8 +120,7 @@     , base16-bytestring     , bytestring     , cachix-api-    , conduit-    , conduit-combinators+    , conduit >=1.3.0     , cookie     , cryptonite     , hspec
src/Cachix/Api.hs view
@@ -28,11 +28,13 @@ import Servant.Swagger.UI.Core   (SwaggerSchemaUI) import Web.Cookie                (SetCookie) +import Cachix.Types.BinaryCacheAuthenticated as BinaryCacheAuthenticated+import Cachix.Types.NarInfoCreate import Cachix.Types.ContentTypes import Cachix.Types.Servant      (Get302, Post302, Head) import Cachix.Types.Session      (Session)+import Cachix.Types.SwaggerOrphans () import Cachix.Api.Types-import Cachix.Api.Swagger        ()   type CachixAuth = Auth '[Cookie,JWT] Session@@ -99,7 +101,7 @@    , caches :: route :-        CachixAuth :>        "cache" :>-       Get '[JSON] [BinaryCache]+       Get '[JSON] [BinaryCacheAuthenticated.BinaryCacheAuthenticated]    , cache :: route :-        "cache" :>        Capture "name" Text :>
src/Cachix/Api/Signing.hs view
@@ -19,24 +19,23 @@   -- perl/lib/Nix/Manifest.pm:fingerprintPath--- TODO: Either Text ByteString: assert values -- NB: references must be sorted-fingerprint :: Text -> Text -> Int -> [Text] -> ByteString+fingerprint :: Text -> Text -> Integer -> [Text] -> ByteString fingerprint storePath narHash narSize references = toS $ T.intercalate ";"   ["1", storePath, narHash, T.pack (show narSize), T.intercalate "," references]  -- Useful sinks for streaming nars -sizeSink :: MonadIO m => Consumer ByteString m Int-sizeSink = CC.foldM (\p n -> return (p + BS.length n)) 0+sizeSink :: MonadIO m => ConduitT ByteString o m Integer+sizeSink = CC.foldM (\p n -> return (p + fromIntegral (BS.length n))) 0 -hashSink :: MonadIO m => Consumer ByteString m (Context SHA256)+hashSink :: MonadIO m => ConduitT ByteString o m (Context SHA256) hashSink = CC.foldM (\p n -> return (hashUpdate p n)) hashInit -passthroughSizeSink :: MonadIO m => IORef Int -> Conduit ByteString m ByteString+passthroughSizeSink :: MonadIO m => IORef Integer -> ConduitT ByteString ByteString m () passthroughSizeSink ioref = passthroughSink sizeSink (liftIO . writeIORef ioref) -passthroughHashSink :: MonadIO m => IORef Text -> Conduit ByteString m ByteString+passthroughHashSink :: MonadIO m => IORef Text -> ConduitT ByteString ByteString m () passthroughHashSink ioref = passthroughSink hashSink (liftIO . writeIORef ioref . transf)   where     -- TODO: use cryptonite B16 to get rid of extra dep and simplify
− src/Cachix/Api/Swagger.hs
@@ -1,44 +0,0 @@-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE TypeOperators #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE ScopedTypeVariables #-}-module Cachix.Api.Swagger-  () where--import Data.Swagger-import Data.Proxy-import Servant.API-import Servant.Swagger-import Servant.Streaming-import Servant.Auth.Swagger ()-import Web.Cookie           (SetCookie)--import Cachix.Api.Types---instance ToSchema NixCacheInfo-instance ToSchema NarInfo-instance ToSchema NarInfoCreate--instance ToSchema BinaryCache-instance ToSchema BinaryCacheCreate--instance ToSchema User--instance ToParamSchema NarC-instance ToParamSchema NarInfoC----- TODO: https://github.com/haskell-servant/servant-auth/pull/42#issuecomment-381279499-instance ToParamSchema SetCookie where-  toParamSchema _ = mempty -- TODO: cookie instances for swagger---- https://github.com/plow-technologies/servant-streaming/blob/master/servant-streaming-docs/src/Servant/Streaming/Docs/Internal.hs--- TODO: these should define the body/response content-instance (HasSwagger api) => HasSwagger (StreamBodyMonad contentTypes m :> api) where---instance (HasSwagger api) => HasSwagger (StreamBody contentTypes :> api) where-  toSwagger _ = toSwagger (Proxy :: Proxy api)--instance HasSwagger (StreamResponseGet contentTypes) where-  toSwagger _ = mempty -- TODO mkEndpointNoContent
src/Cachix/Api/Types.hs view
@@ -1,10 +1,8 @@-{-# LANGUAGE DeriveGeneric #-}-{-# LANGUAGE DeriveAnyClass #-} module Cachix.Api.Types where  import Data.Aeson           (FromJSON, ToJSON)-import Data.ByteString      (ByteString) import Data.Monoid          ((<>))+import Data.Swagger         (ToSchema, ToParamSchema) import Data.Text            (Text, takeEnd, dropEnd) import GHC.Generics         (Generic) import Servant.API@@ -14,7 +12,7 @@   { storeDir :: Text   , wantMassQuery :: Integer   , priority :: Integer-  } deriving (Generic, Show, FromJSON, ToJSON)+  } deriving (Generic, Show, FromJSON, ToJSON, ToSchema)  -- narinfo url includes storePath hash and .narinfo suffix data NarInfo = NarInfo@@ -26,7 +24,7 @@     -- ^ name of the compression algorithm, eg. xz   , fileHash :: Text     -- ^ sha256 hash of the compressed nar file-    -- NOTE: to compute use "nix-hash --type sha256 --flat --base32"+    -- NOTE: to compute use "nix-hash --type sha256 --flat"   , fileSize :: Integer     -- ^ file size of compressed nar file     -- NOTE: du -b@@ -44,46 +42,38 @@     -- NOTE: nix-store -q --deriver   , sig :: Text     -- ^ signature of fields: storePath, narHash, narSize, refs-  } deriving (Generic, Show, FromJSON, ToJSON)+  } deriving (Generic, Show, FromJSON, ToJSON, ToSchema) --- | Client create type-data NarInfoCreate = NarInfoCreate-  { cStoreHash :: Text -- ^ $storePrefix / $storeHash - $storeSuffix-  , cStoreSuffix :: Text -- ^ $storePrefix / $storeHash - $storeSuffix-  , cNarHash :: Text-  , cNarSize :: Int-  , cFileHash :: Text-  , cFileSize :: Int-  , cReferences :: [Text]-  , cDeriver :: Text-  , cSig :: Text-  } deriving (Generic, Show, FromJSON, ToJSON)  data BinaryCache = BinaryCache   { name :: Text   , uri :: Text   , publicSigningKeys :: [Text]-  } deriving (Show, Generic, FromJSON, ToJSON)+  } deriving (Show, Generic, FromJSON, ToJSON, ToSchema)  newtype BinaryCacheCreate = BinaryCacheCreate   { publicSigningKey :: Text-  } deriving (Show, Generic, FromJSON, ToJSON)+  } deriving (Show, Generic, FromJSON, ToJSON, ToSchema) --- | checksum of nar.xz file-newtype NarC = NarC Text deriving Generic+newtype BinaryCacheError = BinaryCacheError+  { error :: Text+  } deriving (Generic, FromJSON, ToJSON) --- | Store path hash-newtype NarInfoC = NarInfoC Text deriving Generic+-- | Hash of nar.xz file+newtype NarC = NarC Text deriving (Generic, ToSchema, ToParamSchema)  instance FromHttpApiData NarC where   parseUrlPiece s =     if takeEnd 7 s == ".nar.xz"-    then Right $ NarC s+    then Right $ NarC (dropEnd 7 s)     else Left ""  instance ToHttpApiData NarC where   toUrlPiece (NarC n) = n <> ".nar.xz" +-- | Store path hash+newtype NarInfoC = NarInfoC Text deriving (Generic, ToSchema, ToParamSchema)+ instance FromHttpApiData NarInfoC where   parseUrlPiece s =     if takeEnd 8 s == ".narinfo"@@ -93,12 +83,8 @@ instance ToHttpApiData NarInfoC where   toUrlPiece (NarInfoC n) = n <> ".narinfo" --newtype BinaryCacheError = BinaryCacheError-  { error :: Text-  } deriving (Generic, FromJSON, ToJSON)- data User = User   { fullname :: Text   , username :: Text-  } deriving (Generic, FromJSON, ToJSON)+  , email :: Maybe Text+  } deriving (Generic, FromJSON, ToJSON, ToSchema)
+ src/Cachix/Types/BinaryCacheAuthenticated.hs view
@@ -0,0 +1,19 @@+module Cachix.Types.BinaryCacheAuthenticated+  ( BinaryCacheAuthenticated(..)+  ) where++import           Data.Aeson                     ( FromJSON+                                                , ToJSON+                                                )+import Data.Swagger+import           Data.Text                      ( Text )+import           GHC.Generics                   ( Generic )+++-- | Binary Cache response content when user is authenticated+data BinaryCacheAuthenticated = BinaryCacheAuthenticated+  { name :: Text+  , uri :: Text+  , publicSigningKeys :: [Text]+  , totalFileSize :: Integer+  } deriving (Show, Generic, FromJSON, ToJSON, ToSchema)
+ src/Cachix/Types/NarInfoCreate.hs view
@@ -0,0 +1,37 @@+module Cachix.Types.NarInfoCreate+  ( NarInfoCreate(..)+  , NarInfoInvalid+  , isNarInfoCreateValid+  ) where++import           Control.Exception             (Exception)+import           Data.Aeson                     ( FromJSON+                                                , ToJSON+                                                )+import           Data.Swagger+import           Data.Text                      ( Text )+import           GHC.Generics                   ( Generic )++-- TODO: get rid of c prefix++-- | Client create type+data NarInfoCreate = NarInfoCreate+  { cStoreHash :: Text -- ^ $storePrefix / $storeHash - $storeSuffix+  , cStoreSuffix :: Text -- ^ $storePrefix / $storeHash - $storeSuffix+  , cNarHash :: Text+  , cNarSize :: Integer+  , cFileHash :: Text+  , cFileSize :: Integer+  , cReferences :: [Text]+  , cDeriver :: Text+  , cSig :: Text+  } deriving (Generic, Show, FromJSON, ToJSON, ToSchema)++data NarInfoInvalid =+  NarSizeIsZero+  deriving (Show, Exception)+++isNarInfoCreateValid :: NarInfoCreate -> Either NarInfoInvalid ()+isNarInfoCreateValid nic | cNarSize nic == 0 = Left NarSizeIsZero+                         | otherwise = Right ()
+ src/Cachix/Types/SwaggerOrphans.hs view
@@ -0,0 +1,29 @@+{-# OPTIONS_GHC -fno-warn-orphans #-}+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE ScopedTypeVariables #-}+module Cachix.Types.SwaggerOrphans+  () where++import Data.Proxy+import Data.Swagger (ToParamSchema(..))+import Servant.API+import Servant.Swagger+import Servant.Streaming+import Servant.Auth.Swagger ()+import Web.Cookie           (SetCookie)+++-- TODO: https://github.com/haskell-servant/servant-auth/pull/42#issuecomment-381279499+instance ToParamSchema SetCookie where+  toParamSchema _ = mempty -- TODO: cookie instances for swagger++-- https://github.com/plow-technologies/servant-streaming/blob/master/servant-streaming-docs/src/Servant/Streaming/Docs/Internal.hs+-- TODO: these should define the body/response content+instance (HasSwagger api) => HasSwagger (StreamBodyMonad contentTypes m :> api) where+  toSwagger _ = toSwagger (Proxy :: Proxy api)++instance HasSwagger (StreamResponseGet contentTypes) where+  toSwagger _ = mempty -- TODO mkEndpointNoContent