Merge pull request #336 from Jeff-Ciesielski/jeffc/cache_creds
Add credential caching
This commit is contained in:
commit
82dcadeb46
2 changed files with 25 additions and 16 deletions
|
|
@ -1028,7 +1028,7 @@ proc doAction(options: Options) =
|
||||||
init(options)
|
init(options)
|
||||||
of actionPublish:
|
of actionPublish:
|
||||||
var pkgInfo = getPkgInfo(getCurrentDir(), options)
|
var pkgInfo = getPkgInfo(getCurrentDir(), options)
|
||||||
publish(pkgInfo)
|
publish(pkgInfo, options)
|
||||||
of actionDump:
|
of actionDump:
|
||||||
dump(options)
|
dump(options)
|
||||||
of actionTasks:
|
of actionTasks:
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
import system except TResult
|
import system except TResult
|
||||||
import httpclient, base64, strutils, rdstdin, json, os, browsers, times, uri
|
import httpclient, base64, strutils, rdstdin, json, os, browsers, times, uri
|
||||||
import tools, common, cli
|
import tools, common, cli, config, options
|
||||||
|
|
||||||
type
|
type
|
||||||
Auth = object
|
Auth = object
|
||||||
|
|
@ -14,6 +14,9 @@ type
|
||||||
pw: string
|
pw: string
|
||||||
token: string ## base64 encoding of user:pw
|
token: string ## base64 encoding of user:pw
|
||||||
|
|
||||||
|
const
|
||||||
|
ApiKeyFile = "api_token"
|
||||||
|
|
||||||
proc userAborted() =
|
proc userAborted() =
|
||||||
raise newException(NimbleError, "User aborted the process.")
|
raise newException(NimbleError, "User aborted the process.")
|
||||||
|
|
||||||
|
|
@ -22,18 +25,24 @@ proc createHeaders(a: Auth): string =
|
||||||
"Content-Type: application/x-www-form-urlencoded\c\L" &
|
"Content-Type: application/x-www-form-urlencoded\c\L" &
|
||||||
"Accept: */*\c\L")
|
"Accept: */*\c\L")
|
||||||
|
|
||||||
proc getGithubAuth(): Auth =
|
proc getGithubAuth(cfg: Config): Auth =
|
||||||
display("Info:", "Please create a new personal access token on Github in" &
|
|
||||||
" order to allow Nimble to fork the packages repository.",
|
try:
|
||||||
priority = HighPriority)
|
result.token = readFile(cfg.nimbleDir / ApiKeyFile)
|
||||||
display("Hint:", "Make sure to give the access token access to public repos" &
|
except IOError:
|
||||||
" (public_repo scope)!", Warning, HighPriority)
|
display("Info:", "Please create a new personal access token on Github in" &
|
||||||
sleep(5000)
|
" order to allow Nimble to fork the packages repository.",
|
||||||
display("Info:", "Your default browser should open with the following URL: " &
|
priority = HighPriority)
|
||||||
"https://github.com/settings/tokens/new", priority = HighPriority)
|
display("Hint:", "Make sure to give the access token access to public repos" &
|
||||||
sleep(3000)
|
" (public_repo scope)!", Warning, HighPriority)
|
||||||
openDefaultBrowser("https://github.com/settings/tokens/new")
|
sleep(5000)
|
||||||
result.token = promptCustom("Personal access token?", "").strip()
|
display("Info:", "Your default browser should open with the following URL: " &
|
||||||
|
"https://github.com/settings/tokens/new", priority = HighPriority)
|
||||||
|
sleep(3000)
|
||||||
|
openDefaultBrowser("https://github.com/settings/tokens/new")
|
||||||
|
result.token = promptCustom("Personal access token?", "").strip()
|
||||||
|
writeFile(cfg.nimbleDir / ApiKeyFile, result.token)
|
||||||
|
|
||||||
let resp = getContent("https://api.github.com/user",
|
let resp = getContent("https://api.github.com/user",
|
||||||
extraHeaders=createHeaders(result)).parseJson()
|
extraHeaders=createHeaders(result)).parseJson()
|
||||||
|
|
||||||
|
|
@ -131,9 +140,9 @@ proc getPackageOriginUrl(a: Auth): string =
|
||||||
result = "https://" & a.user & ':' & a.pw & '@' &
|
result = "https://" & a.user & ':' & a.pw & '@' &
|
||||||
result["https://".len .. ^1]
|
result["https://".len .. ^1]
|
||||||
|
|
||||||
proc publish*(p: PackageInfo) =
|
proc publish*(p: PackageInfo, o: Options) =
|
||||||
## Publishes the package p.
|
## Publishes the package p.
|
||||||
let auth = getGithubAuth()
|
let auth = getGithubAuth(o.config)
|
||||||
var pkgsDir = getTempDir() / "nimble-packages-fork"
|
var pkgsDir = getTempDir() / "nimble-packages-fork"
|
||||||
if not forkExists(auth):
|
if not forkExists(auth):
|
||||||
createFork(auth)
|
createFork(auth)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue