File: GetAuth.hs

package info (click to toggle)
github-backup 1.20160522-2
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 448 kB
  • ctags: 4
  • sloc: haskell: 3,813; makefile: 30; sh: 19
file content (27 lines) | stat: -rw-r--r-- 665 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
module Github.GetAuth where

import Utility.Env
import Utility.Monad

import qualified GitHub.Auth as Github
import Data.Text.Encoding (encodeUtf8)
import qualified Data.Text as T
import qualified Data.ByteString.UTF8 as B

getAuth :: IO (Maybe Github.Auth)
getAuth = getM id
	[ do
		user <- getEnv "GITHUB_USER"
		password <- getEnv "GITHUB_PASSWORD"
		return $ case (user, password) of
			(Just u, Just p) -> Just $ 
				Github.BasicAuth (tobs u) (tobs p)
			_ -> Nothing
	, do
		oauthtoken <- getEnv "GITHUB_OAUTH_TOKEN"
		return $ case oauthtoken of
			Just t -> Just $ Github.OAuth (B.fromString t)
			Nothing -> Nothing
	]
  where
	tobs = encodeUtf8 . T.pack