File: GetAuth.hs

package info (click to toggle)
github-backup 1.20200721-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 560 kB
  • sloc: haskell: 3,730; makefile: 27; sh: 9
file content (30 lines) | stat: -rw-r--r-- 776 bytes parent folder | download
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
28
29
30
module Github.GetAuth where

import Utility.Env
import Data.Maybe
import System.IO

import Common
import qualified GitHub.Auth as Github
import qualified Data.ByteString.UTF8 as B

getAuth :: IO (Maybe Github.Auth)
getAuth = do
	oauthtoken <- getEnv "GITHUB_OAUTH_TOKEN"
	case oauthtoken of
		Just t -> return $ Just $ Github.OAuth (B.fromString t)
		Nothing -> do
			checkDeprecatedVars
			return Nothing

checkDeprecatedVars :: IO ()
checkDeprecatedVars = do
	user <- getEnv "GITHUB_USER"
	password <- getEnv "GITHUB_PASSWORD"
	when (isJust user && isJust password) $
		hPutStrLn stderr $ unwords
			[ "GITHUB_USER and GITHUB_PASSWORD are no longer"
			, "supported, because Github is removing that"
			, "authentication method."
			, "Set GITHUB_OAUTH_TOKEN instead."
			]