webapp: Support enabling known gitlab.com remotes.

This commit is contained in:
Joey Hess 2015-07-27 16:03:22 -04:00
parent c39fb9ec2a
commit 29f3049def
3 changed files with 51 additions and 21 deletions

View file

@ -212,23 +212,26 @@ postEnableSshGitRemoteR = enableSshRemote getsshinput enableRsyncNet enablesshgi
- to prompt for its password. - to prompt for its password.
-} -}
enableSshRemote :: (RemoteConfig -> Maybe SshData) -> (SshInput -> RemoteName -> Handler Html) -> (SshData -> UUID -> Handler Html) -> UUID -> Handler Html enableSshRemote :: (RemoteConfig -> Maybe SshData) -> (SshInput -> RemoteName -> Handler Html) -> (SshData -> UUID -> Handler Html) -> UUID -> Handler Html
enableSshRemote getsshinput rsyncnetsetup genericsetup u = do enableSshRemote getsshdata rsyncnetsetup genericsetup u = do
m <- fromMaybe M.empty . M.lookup u <$> liftAnnex readRemoteLog m <- fromMaybe M.empty . M.lookup u <$> liftAnnex readRemoteLog
case (mkSshInput . unmangle <$> getsshinput m, M.lookup "name" m) of case (unmangle <$> getsshdata m, M.lookup "name" m) of
(Just sshinput, Just reponame) -> sshConfigurator $ do (Just sshdata, Just reponame)
((result, form), enctype) <- liftH $ | isGitLab sshdata -> enableGitLab sshdata
runFormPostNoToken $ renderBootstrap3 bootstrapFormLayout $ sshInputAForm textField sshinput | otherwise -> sshConfigurator $ do
case result of ((result, form), enctype) <- liftH $
FormSuccess sshinput' runFormPostNoToken $ renderBootstrap3 bootstrapFormLayout $
| isRsyncNet (inputHostname sshinput') -> sshInputAForm textField $ mkSshInput sshdata
void $ liftH $ rsyncnetsetup sshinput' reponame case result of
| otherwise -> do FormSuccess sshinput
s <- liftAssistant $ testServer sshinput' | isRsyncNet (inputHostname sshinput) ->
case s of void $ liftH $ rsyncnetsetup sshinput reponame
Left status -> showform form enctype status | otherwise -> do
Right (sshdata, _u) -> void $ liftH $ genericsetup s <- liftAssistant $ testServer sshinput
( sshdata { sshRepoName = reponame } ) u case s of
_ -> showform form enctype UntestedServer Left status -> showform form enctype status
Right (sshdata', _u) -> void $ liftH $ genericsetup
( sshdata' { sshRepoName = reponame } ) u
_ -> showform form enctype UntestedServer
_ -> redirect AddSshR _ -> redirect AddSshR
where where
unmangle sshdata = sshdata unmangle sshdata = sshdata
@ -672,7 +675,7 @@ isRsyncNet :: Maybe Text -> Bool
isRsyncNet Nothing = False isRsyncNet Nothing = False
isRsyncNet (Just host) = ".rsync.net" `T.isSuffixOf` T.toLower host isRsyncNet (Just host) = ".rsync.net" `T.isSuffixOf` T.toLower host
data GitLabUrl = GitLabUrl Text data GitLabUrl = GitLabUrl { unGitLabUrl :: Text }
badGitLabUrl :: Text badGitLabUrl :: Text
badGitLabUrl = "Bad SSH clone url. Expected something like: git@gitlab.com:yourlogin/annex.git" badGitLabUrl = "Bad SSH clone url. Expected something like: git@gitlab.com:yourlogin/annex.git"
@ -698,6 +701,18 @@ parseGitLabUrl (GitLabUrl t) =
, sshRepoUrl = Just (T.unpack t) , sshRepoUrl = Just (T.unpack t)
} }
isGitLab :: SshData -> Bool
isGitLab d = T.pack "gitlab.com" `T.isSuffixOf` (T.toLower (sshHostName d))
toGitLabUrl :: SshData -> GitLabUrl
toGitLabUrl d = GitLabUrl $ T.concat
[ fromMaybe (T.pack "git") (sshUserName d)
, T.pack "@"
, sshHostName d
, T.pack ":"
, sshDirectory d
]
{- Try to ssh into the gitlab server, verify we can access the repository, {- Try to ssh into the gitlab server, verify we can access the repository,
- and get the uuid of the repository, if it already has one. - and get the uuid of the repository, if it already has one.
- -
@ -735,8 +750,8 @@ testGitLabUrl glu = case parseGitLabUrl glu of
, Param (fromRef Annex.Branch.name) , Param (fromRef Annex.Branch.name)
] ]
gitLabUrlAForm :: AForm Handler GitLabUrl gitLabUrlAForm :: Maybe GitLabUrl -> AForm Handler GitLabUrl
gitLabUrlAForm = GitLabUrl <$> areq check_input (bfs "SSH clone url") Nothing gitLabUrlAForm defval = GitLabUrl <$> areq check_input (bfs "SSH clone url") (unGitLabUrl <$> defval)
where where
check_input = checkBool (isJust . parseGitLabUrl . GitLabUrl) check_input = checkBool (isJust . parseGitLabUrl . GitLabUrl)
badGitLabUrl textField badGitLabUrl textField
@ -744,9 +759,13 @@ gitLabUrlAForm = GitLabUrl <$> areq check_input (bfs "SSH clone url") Nothing
getAddGitLabR :: Handler Html getAddGitLabR :: Handler Html
getAddGitLabR = postAddGitLabR getAddGitLabR = postAddGitLabR
postAddGitLabR :: Handler Html postAddGitLabR :: Handler Html
postAddGitLabR = sshConfigurator $ do postAddGitLabR = promptGitLab Nothing
promptGitLab :: Maybe GitLabUrl -> Handler Html
promptGitLab defval = sshConfigurator $ do
((result, form), enctype) <- liftH $ ((result, form), enctype) <- liftH $
runFormPostNoToken $ renderBootstrap3 bootstrapFormLayout gitLabUrlAForm runFormPostNoToken $ renderBootstrap3 bootstrapFormLayout $
gitLabUrlAForm defval
case result of case result of
FormSuccess gitlaburl -> do FormSuccess gitlaburl -> do
(status, msshdata, u) <- liftAnnex $ testGitLabUrl gitlaburl (status, msshdata, u) <- liftAnnex $ testGitLabUrl gitlaburl
@ -757,3 +776,6 @@ postAddGitLabR = sshConfigurator $ do
_ -> showform form enctype UntestedServer _ -> showform form enctype UntestedServer
where where
showform form enctype status = $(widgetFile "configurators/gitlab.com/add") showform form enctype status = $(widgetFile "configurators/gitlab.com/add")
enableGitLab :: SshData -> Handler Html
enableGitLab = promptGitLab . Just . toGitLabUrl

6
debian/changelog vendored
View file

@ -1,3 +1,9 @@
git-annex (5.20150728) UNRELEASED; urgency=medium
* webapp: Support enabling known gitlab.com remotes.
-- Joey Hess <id@joeyh.name> Mon, 27 Jul 2015 15:57:07 -0400
git-annex (5.20150727) unstable; urgency=medium git-annex (5.20150727) unstable; urgency=medium
* Fix bug that prevented uploads to remotes using new-style chunking * Fix bug that prevented uploads to remotes using new-style chunking

View file

@ -4,3 +4,5 @@ work.
This is a SMOP; it needs to detect that the repo is on gitlab and use a This is a SMOP; it needs to detect that the repo is on gitlab and use a
custom enabling process and no the generic one, which doesn't work. custom enabling process and no the generic one, which doesn't work.
--[[Joey]] --[[Joey]]
> [[fixed|done]] --[[Joey]]