Skip to content

Commit

Permalink
save-hackage-creds config value
Browse files Browse the repository at this point in the history
  • Loading branch information
snoyberg committed May 1, 2017
1 parent 376342e commit ca6ba8f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Other enhancements:
[Stackage no-revisions feature](http://www.snoyman.com/blog/2017/04/stackages-no-revisions-field)—as
a method to ensure PVP compliance without having to proactively fix
bounds issues for Stackage maintenance.
* Expose a `save-hackage-creds` configuration option

Bug fixes:

Expand Down
11 changes: 11 additions & 0 deletions doc/yaml_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,17 @@ in the directories it creates. Source control tools can be specified with the
templates:
scm-init: git
```

### save-hackage-creds

Controls whether, when using `stack upload`, the user's Hackage
username and password are stored in a local file. Default: true.

```yaml
save-hackage-creds: true
```

Since 1.5.0

# urls

Expand Down
1 change: 1 addition & 0 deletions src/Stack/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ configFromConfigMonoid
configAllowNewer = fromFirst False configMonoidAllowNewer
configDefaultTemplate = getFirst configMonoidDefaultTemplate
configDumpLogs = fromFirst DumpWarningLogs configMonoidDumpLogs
configSaveHackageCreds = fromFirst True configMonoidSaveHackageCreds

configAllowDifferentUser <-
case getFirst configMonoidAllowDifferentUser of
Expand Down
8 changes: 8 additions & 0 deletions src/Stack/Types/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ data Config =
,configAllowLocals :: !Bool
-- ^ Are we allowed to build local packages? The script
-- command disallows this.
,configSaveHackageCreds :: !Bool
-- ^ Should we save Hackage credentials to a file?
}

-- | Which packages do ghc-options on the command line apply to?
Expand Down Expand Up @@ -785,6 +787,8 @@ data ConfigMonoid =
-- installation.
, configMonoidDumpLogs :: !(First DumpLogs)
-- ^ See 'configDumpLogs'
, configMonoidSaveHackageCreds :: !(First Bool)
-- ^ See 'configSaveHackageCreds'
}
deriving (Show, Generic)

Expand Down Expand Up @@ -856,6 +860,7 @@ parseConfigMonoidObject rootDir obj = do
configMonoidDefaultTemplate <- First <$> obj ..:? configMonoidDefaultTemplateName
configMonoidAllowDifferentUser <- First <$> obj ..:? configMonoidAllowDifferentUserName
configMonoidDumpLogs <- First <$> obj ..:? configMonoidDumpLogsName
configMonoidSaveHackageCreds <- First <$> obj ..:? configMonoidSaveHackageCredsName

return ConfigMonoid {..}
where
Expand Down Expand Up @@ -989,6 +994,9 @@ configMonoidAllowDifferentUserName = "allow-different-user"
configMonoidDumpLogsName :: Text
configMonoidDumpLogsName = "dump-logs"

configMonoidSaveHackageCredsName :: Text
configMonoidSaveHackageCredsName = "save-hackage-creds"

data ConfigException
= ParseConfigFileException (Path Abs File) ParseException
| ParseCustomSnapshotException Text ParseException
Expand Down
5 changes: 4 additions & 1 deletion src/Stack/Upload.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Stack.Upload
import Control.Applicative
import Control.Exception.Safe (bracket, handleIO)
import qualified Control.Exception as E
import Control.Monad (void)
import Control.Monad (void, when)
import Data.Aeson (FromJSON (..),
ToJSON (..),
eitherDecode', encode,
Expand Down Expand Up @@ -99,6 +99,9 @@ loadCreds config = do
(eitherDecode' lbs)

fromPrompt fp = do
when (configSaveHackageCreds config) $ do
putStrLn "NOTE: Username and password will be saved in a local file"
putStrLn "You can modify this behavior with the save-hackage-creds config option"
putStr "Hackage username: "
hFlush stdout
username <- TIO.getLine
Expand Down

0 comments on commit ca6ba8f

Please sign in to comment.