cleaner endpoint type
This commit is contained in:
parent
426a74265d
commit
b4a416b996
1 changed files with 27 additions and 25 deletions
52
Lfs.hs
52
Lfs.hs
|
@ -241,38 +241,21 @@ instance ToJSON GitRef
|
||||||
|
|
||||||
type SHA256 = T.Text
|
type SHA256 = T.Text
|
||||||
|
|
||||||
-- | Adds necessary headers to a Request and makes it post the
|
-- | The endpoint of a git-lfs server.
|
||||||
-- specified TransferRequest.
|
data Endpoint
|
||||||
--
|
= EndpointRequest Url
|
||||||
-- The input Request's url should be the discovered LFS endpoint.
|
| EndpointDiscovered SshDiscoveryResponse
|
||||||
-- Since this uses the LFS batch API, it adds /objects/batch to the end of
|
|
||||||
-- that url.
|
|
||||||
startTransferRequest :: Request -> TransferRequest -> Request
|
|
||||||
startTransferRequest r tr = addLfsJsonHeaders $ r
|
|
||||||
{ path = path r <> "/objects/batch"
|
|
||||||
, method = "POST"
|
|
||||||
, requestBody = RequestBodyLBS (encode tr)
|
|
||||||
}
|
|
||||||
|
|
||||||
-- | Makes a Request using an endpoint discovered via ssh.
|
|
||||||
startTransferRequestSsh :: SshDiscoveryResponse -> TransferRequest -> Maybe Request
|
|
||||||
startTransferRequestSsh sr tr = do
|
|
||||||
basereq <- parseRequest $ T.unpack $ endpoint_href sr
|
|
||||||
let req = startTransferRequest basereq tr
|
|
||||||
let headers = map convheader $ maybe [] M.toList $ endpoint_header sr
|
|
||||||
return $ req { requestHeaders = requestHeaders req ++ headers }
|
|
||||||
where
|
|
||||||
convheader (k, v) = (CI.mk (E.encodeUtf8 k), E.encodeUtf8 v)
|
|
||||||
|
|
||||||
-- | Discovers an LFS endpoint for a git remote using ssh.
|
-- | Discovers an LFS endpoint for a git remote using ssh.
|
||||||
--
|
--
|
||||||
-- May generate console output, including error messages from ssh or the
|
-- May generate console output, including error messages from ssh or the
|
||||||
-- remote server, and ssh password prompting.
|
-- remote server, and ssh password prompting.
|
||||||
sshDiscovery :: HostUser -> FilePath -> TransferRequestOperation -> IO (Maybe SshDiscoveryResponse)
|
sshDiscoverEndpoint :: HostUser -> FilePath -> TransferRequestOperation -> IO (Maybe Endpoint)
|
||||||
sshDiscovery hostuser remotepath tro =
|
sshDiscoverEndpoint hostuser remotepath tro =
|
||||||
(try (readProcess "ssh" ps "") :: IO (Either IOError String)) >>= \case
|
(try (readProcess "ssh" ps "") :: IO (Either IOError String)) >>= \case
|
||||||
Left _err -> return Nothing
|
Left _err -> return Nothing
|
||||||
Right resp -> return $ decode $ fromString resp
|
Right resp -> return $
|
||||||
|
EndpointDiscovered <$> decode (fromString resp)
|
||||||
where
|
where
|
||||||
ps =
|
ps =
|
||||||
[ hostuser
|
[ hostuser
|
||||||
|
@ -283,6 +266,25 @@ sshDiscovery hostuser remotepath tro =
|
||||||
RequestUpload -> "upload"
|
RequestUpload -> "upload"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
-- | Makes a Request that will start the process of making a transfer to or
|
||||||
|
-- from the LFS endpoint.
|
||||||
|
startTransferRequest :: Endpoint -> TransferRequest -> Maybe Request
|
||||||
|
startTransferRequest (EndpointRequest url) tr = do
|
||||||
|
r <- parseRequest $ T.unpack url
|
||||||
|
return $ addLfsJsonHeaders $ r
|
||||||
|
-- Since this uses the LFS batch API, it adds /objects/batch
|
||||||
|
-- to the endpoint url.
|
||||||
|
{ path = path r <> "/objects/batch"
|
||||||
|
, method = "POST"
|
||||||
|
, requestBody = RequestBodyLBS (encode tr)
|
||||||
|
}
|
||||||
|
startTransferRequest (EndpointDiscovered sr) tr = do
|
||||||
|
req <- startTransferRequest (EndpointRequest (endpoint_href sr)) tr
|
||||||
|
let headers = map convheader $ maybe [] M.toList $ endpoint_header sr
|
||||||
|
return $ req { requestHeaders = requestHeaders req ++ headers }
|
||||||
|
where
|
||||||
|
convheader (k, v) = (CI.mk (E.encodeUtf8 k), E.encodeUtf8 v)
|
||||||
|
|
||||||
-- | "user@host" or just the hostname.
|
-- | "user@host" or just the hostname.
|
||||||
type HostUser = String
|
type HostUser = String
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue