Skip to content

Commit 61570fc

Browse files
committed
sign packages by default
1 parent 39436cd commit 61570fc

3 files changed

Lines changed: 42 additions & 79 deletions

File tree

src/Stack/Sig.hs

Lines changed: 10 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,54 +12,18 @@ Stability : experimental
1212
Portability : POSIX
1313
-}
1414

15-
module Stack.Sig
16-
( module Sig
17-
, sigCmdName
18-
, sigSignCmdName
19-
, sigSignHackageCmdName
20-
, sigSignHackageOpts
21-
, sigSignSdistCmdName
22-
, sigSignSdistOpts
23-
)
24-
where
15+
module Stack.Sig (module Sig, signOpts) where
2516

2617
import Options.Applicative
2718
import Stack.Sig.GPG as Sig
2819
import Stack.Sig.Sign as Sig
2920

30-
-- | The command name for dealing with signatures.
31-
sigCmdName :: String
32-
sigCmdName = "sig"
33-
34-
-- | The command name for signing packages.
35-
sigSignCmdName :: String
36-
sigSignCmdName = "sign"
37-
38-
-- | The command name for signing an sdist package file.
39-
sigSignSdistCmdName :: String
40-
sigSignSdistCmdName = "sdist"
41-
42-
-- | The command name for signing all your packages from hackage.org.
43-
sigSignHackageCmdName :: String
44-
sigSignHackageCmdName = "hackage"
45-
46-
-- | The URL of the running signature service to use (sig-service)
47-
url :: Parser String
48-
url = strOption
49-
(long "url" <>
50-
short 'u' <>
51-
metavar "URL" <>
52-
showDefault <>
53-
value "https://sig.commercialhaskell.org")
54-
55-
-- | Signature sign (sdist) options
56-
sigSignSdistOpts :: Parser (String, String)
57-
sigSignSdistOpts = helper <*>
58-
((,) <$> url <*>
59-
argument str (metavar "PATH"))
60-
61-
-- | Signature sign (hackage) options
62-
sigSignHackageOpts :: Parser (String, String)
63-
sigSignHackageOpts = helper <*>
64-
((,) <$> url <*>
65-
argument str (metavar "USER"))
21+
-- | Options for commands that sign packages
22+
signOpts :: Parser (Bool, String)
23+
signOpts =
24+
(,) <$>
25+
switch (long "no-signature" <> help "Do not sign & upload signatures") <*>
26+
strOption
27+
(long "sig-server" <> metavar "URL" <> showDefault <>
28+
value "https://sig.commercialhaskell.org" <>
29+
help "URL")

src/Stack/Sig/Sign.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ signPackage url pkg filePath = do
108108
name = show n
109109
version = show v
110110
fingerprint <- GPG.verifyFile sig filePath
111-
req <-
112-
parseUrl
113-
(url <> "/upload/signature/" <> name <> "/" <> version <> "/" <>
114-
show fingerprint)
111+
let fullUrl =
112+
url <> "/upload/signature/" <> name <> "/" <> version <> "/" <>
113+
show fingerprint
114+
req <- parseUrl fullUrl
115115
let put =
116116
req
117117
{ method = methodPut
@@ -122,7 +122,7 @@ signPackage url pkg filePath = do
122122
when
123123
(responseStatus res /= status200)
124124
(throwM (GPGSignException "unable to sign & upload package"))
125-
$logInfo ("Signed successfully with key " <> (T.pack . show) fingerprint)
125+
$logInfo ("Signature uploaded to " <> T.pack fullUrl)
126126

127127
withStackWorkTempDir
128128
:: (MonadIO m, MonadMask m, MonadLogger m, MonadReader env m, HasConfig env)

src/main/Main.hs

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -276,23 +276,21 @@ commandLineHandler progName isInterpreter = complicatedOptions
276276
<> help "Clone from specified git repository"
277277
<> value "https://github.com/commercialhaskell/stack"
278278
<> showDefault ))
279-
addCommand' "upload"
280-
"Upload a package to Hackage"
281-
uploadCmd
282-
((,,,)
283-
<$> many (strArgument $ metavar "TARBALL/DIR")
284-
<*> optional pvpBoundsOption
285-
<*> ignoreCheckSwitch
286-
<*> flag False True
287-
(long "sign" <>
288-
help "GPG sign & submit signature"))
289-
addCommand' "sdist"
290-
"Create source distribution tarballs"
291-
sdistCmd
292-
((,,)
293-
<$> many (strArgument $ metavar "DIR")
294-
<*> optional pvpBoundsOption
295-
<*> ignoreCheckSwitch)
279+
addCommand'
280+
"upload"
281+
"Upload a package to Hackage"
282+
uploadCmd
283+
((,,,) <$> many (strArgument $ metavar "TARBALL/DIR") <*>
284+
optional pvpBoundsOption <*>
285+
ignoreCheckSwitch <*>
286+
Sig.signOpts)
287+
addCommand'
288+
"sdist"
289+
"Create source distribution tarballs"
290+
sdistCmd
291+
((,,,) <$> many (strArgument $ metavar "DIR") <*> optional pvpBoundsOption <*>
292+
ignoreCheckSwitch <*>
293+
Sig.signOpts)
296294
addCommand' "dot"
297295
"Visualize your project's dependency graph using Graphviz dot"
298296
dotCmd
@@ -921,9 +919,9 @@ upgradeCmd (fromGit, repo) go = withConfigAndLock go $
921919
#endif
922920

923921
-- | Upload to Hackage
924-
uploadCmd :: ([String], Maybe PvpBounds, Bool, Bool) -> GlobalOpts -> IO ()
922+
uploadCmd :: ([String], Maybe PvpBounds, Bool, (Bool,String)) -> GlobalOpts -> IO ()
925923
uploadCmd ([], _, _, _) _ = error "To upload the current package, please run 'stack upload .'"
926-
uploadCmd (args, mpvpBounds, ignoreCheck, shouldSign) go = do
924+
uploadCmd (args, mpvpBounds, ignoreCheck, (dontSign, sigServerUrl)) go = do
927925
let partitionM _ [] = return ([], [])
928926
partitionM f (x:xs) = do
929927
r <- f x
@@ -942,7 +940,6 @@ uploadCmd (args, mpvpBounds, ignoreCheck, shouldSign) go = do
942940
let uploadSettings =
943941
Upload.setGetManager (return manager) Upload.defaultUploadSettings
944942
liftIO $ Upload.mkUploader config uploadSettings
945-
sigServiceUrl = "https://sig.commercialhaskell.org/"
946943
withBuildConfigAndLock go $ \_ -> do
947944
uploader <- getUploader
948945
unless ignoreCheck $
@@ -953,11 +950,11 @@ uploadCmd (args, mpvpBounds, ignoreCheck, shouldSign) go = do
953950
do tarFile <- resolveFile' file
954951
liftIO
955952
(Upload.upload uploader (toFilePath tarFile))
956-
when
957-
shouldSign
953+
unless
954+
dontSign
958955
(Sig.sign
959956
(lcProjectRoot lc)
960-
sigServiceUrl
957+
sigServerUrl
961958
tarFile))
962959
unless (null dirs) $
963960
forM_ dirs $ \dir -> do
@@ -966,16 +963,16 @@ uploadCmd (args, mpvpBounds, ignoreCheck, shouldSign) go = do
966963
unless ignoreCheck $ checkSDistTarball' tarName tarBytes
967964
liftIO $ Upload.uploadBytes uploader tarName tarBytes
968965
tarPath <- parseRelFile tarName
969-
when
970-
shouldSign
966+
unless
967+
dontSign
971968
(Sig.signTarBytes
972969
(lcProjectRoot lc)
973-
sigServiceUrl
970+
sigServerUrl
974971
tarPath
975972
tarBytes)
976973

977-
sdistCmd :: ([String], Maybe PvpBounds, Bool) -> GlobalOpts -> IO ()
978-
sdistCmd (dirs, mpvpBounds, ignoreCheck) go =
974+
sdistCmd :: ([String], Maybe PvpBounds, Bool, (Bool,String)) -> GlobalOpts -> IO ()
975+
sdistCmd (dirs, mpvpBounds, ignoreCheck, (dontSign,sigServerUrl)) go =
979976
withBuildConfig go $ do -- No locking needed.
980977
-- If no directories are specified, build all sdist tarballs.
981978
dirs' <- if null dirs
@@ -989,6 +986,8 @@ sdistCmd (dirs, mpvpBounds, ignoreCheck) go =
989986
liftIO $ L.writeFile (toFilePath tarPath) tarBytes
990987
unless ignoreCheck (checkSDistTarball tarPath)
991988
$logInfo $ "Wrote sdist tarball to " <> T.pack (toFilePath tarPath)
989+
(_,lc) <- liftIO $ loadConfigWithOpts go
990+
unless dontSign (Sig.sign (lcProjectRoot lc) sigServerUrl tarPath)
992991

993992
-- | Execute a command.
994993
execCmd :: ExecOpts -> GlobalOpts -> IO ()

0 commit comments

Comments
 (0)