Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getKey and getKeyEnv silently default. #27

Open
gregwebs opened this issue Nov 25, 2014 · 4 comments
Open

getKey and getKeyEnv silently default. #27

gregwebs opened this issue Nov 25, 2014 · 4 comments

Comments

@gregwebs
Copy link
Member

There is a problem with the getKey and getKeyEnv from clientsession: they both silently default to generating a new key when one is missing.

Can we change these functions (actually add new ones) that essentially return an Either? Left would be a default, and in that case a warning can be logged for the user.

I would suggest as new function names keyFromFile and keyFromEnv.
However, this points to the fact that some kind of generic key generator is needed. Also, Either may not be descriptive enough.

data KeyGenerator = KeyGenerator { gatherKey :: IO ByteString, writeKey :: ByteString -> IO () }


data KeyInit = KeyGenerated Text Key -- ^ no key was found, generated and recorded a new one
                   | KeyFound Key -- ^ found the existing key

keyFrom :: KeyGenerator -> KeyInit
keyFromDef :: KeyGenerator -> Key
@gregwebs
Copy link
Member Author

This would also get rid of the need for to use putStrLn for generating the env key and defer that action to the library user.

@meteficha
Copy link
Member

If I understand correctly, you're suggesting that the functions should:

  • Keep their current behaviour: creating a new key out of thin air if necessary.
  • Have a variant that returns whether a key was created or not.

That sounds like a good idea.

@pbrisbin
Copy link
Member

Yup, 👍 on pushing the putStrLn to the caller.

@gregwebs
Copy link
Member Author

@meteficha yes, that is a perfect summary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants