refactor: migrate credential consumers to git_credential
Problem: `credentials.lua`, `submit.lua`, and `scraper.lua` all routed through `cache.get/set/clear_credentials`, which no longer exists. Solution: replace all `cache` credential calls with direct `git_credential.get/store/reject` calls. Remove unused `cache` imports where applicable.
This commit is contained in:
parent
be1bc2095e
commit
d1127f3e9b
3 changed files with 15 additions and 14 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local cache = require('cp.cache')
|
|
||||||
local constants = require('cp.constants')
|
local constants = require('cp.constants')
|
||||||
|
local git_credential = require('cp.git_credential')
|
||||||
local logger = require('cp.log')
|
local logger = require('cp.log')
|
||||||
local state = require('cp.state')
|
local state = require('cp.state')
|
||||||
|
|
||||||
|
|
@ -40,14 +40,14 @@ local function prompt_and_login(platform, display)
|
||||||
end, function(result)
|
end, function(result)
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
if result.success then
|
if result.success then
|
||||||
cache.set_credentials(platform, credentials)
|
git_credential.store(platform, credentials)
|
||||||
logger.log(
|
logger.log(
|
||||||
display .. ' login successful',
|
display .. ' login successful',
|
||||||
{ level = vim.log.levels.INFO, override = true }
|
{ level = vim.log.levels.INFO, override = true }
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
local err = result.error or 'unknown error'
|
local err = result.error or 'unknown error'
|
||||||
cache.clear_credentials(platform)
|
git_credential.reject(platform, credentials)
|
||||||
logger.log(
|
logger.log(
|
||||||
display .. ' login failed: ' .. (constants.LOGIN_ERRORS[err] or err),
|
display .. ' login failed: ' .. (constants.LOGIN_ERRORS[err] or err),
|
||||||
{ level = vim.log.levels.ERROR }
|
{ level = vim.log.levels.ERROR }
|
||||||
|
|
@ -73,8 +73,7 @@ function M.login(platform)
|
||||||
|
|
||||||
local display = constants.PLATFORM_DISPLAY_NAMES[platform] or platform
|
local display = constants.PLATFORM_DISPLAY_NAMES[platform] or platform
|
||||||
|
|
||||||
cache.load()
|
local existing = git_credential.get(platform) or {}
|
||||||
local existing = cache.get_credentials(platform) or {}
|
|
||||||
|
|
||||||
if existing.username and existing.password then
|
if existing.username and existing.password then
|
||||||
local scraper = require('cp.scraper')
|
local scraper = require('cp.scraper')
|
||||||
|
|
@ -91,7 +90,7 @@ function M.login(platform)
|
||||||
{ level = vim.log.levels.INFO, override = true }
|
{ level = vim.log.levels.INFO, override = true }
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
cache.clear_credentials(platform)
|
git_credential.reject(platform, existing)
|
||||||
prompt_and_login(platform, display)
|
prompt_and_login(platform, display)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
@ -113,8 +112,10 @@ function M.logout(platform)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local display = constants.PLATFORM_DISPLAY_NAMES[platform] or platform
|
local display = constants.PLATFORM_DISPLAY_NAMES[platform] or platform
|
||||||
cache.load()
|
local existing = git_credential.get(platform)
|
||||||
cache.clear_credentials(platform)
|
if existing then
|
||||||
|
git_credential.reject(platform, existing)
|
||||||
|
end
|
||||||
local cookie_file = constants.COOKIE_FILE
|
local cookie_file = constants.COOKIE_FILE
|
||||||
if vim.fn.filereadable(cookie_file) == 1 then
|
if vim.fn.filereadable(cookie_file) == 1 then
|
||||||
local ok, data = pcall(vim.fn.json_decode, vim.fn.readfile(cookie_file, 'b'))
|
local ok, data = pcall(vim.fn.json_decode, vim.fn.readfile(cookie_file, 'b'))
|
||||||
|
|
|
||||||
|
|
@ -347,7 +347,7 @@ function M.login(platform, credentials, on_status, callback)
|
||||||
stdin = vim.json.encode(credentials),
|
stdin = vim.json.encode(credentials),
|
||||||
on_event = function(ev)
|
on_event = function(ev)
|
||||||
if ev.credentials ~= nil and next(ev.credentials) ~= nil then
|
if ev.credentials ~= nil and next(ev.credentials) ~= nil then
|
||||||
require('cp.cache').set_credentials(platform, ev.credentials)
|
require('cp.git_credential').store(platform, ev.credentials)
|
||||||
end
|
end
|
||||||
if ev.status ~= nil then
|
if ev.status ~= nil then
|
||||||
if type(on_status) == 'function' then
|
if type(on_status) == 'function' then
|
||||||
|
|
@ -395,7 +395,7 @@ function M.submit(
|
||||||
stdin = vim.json.encode(credentials),
|
stdin = vim.json.encode(credentials),
|
||||||
on_event = function(ev)
|
on_event = function(ev)
|
||||||
if ev.credentials ~= nil and next(ev.credentials) ~= nil then
|
if ev.credentials ~= nil and next(ev.credentials) ~= nil then
|
||||||
require('cp.cache').set_credentials(platform, ev.credentials)
|
require('cp.git_credential').store(platform, ev.credentials)
|
||||||
end
|
end
|
||||||
if ev.status ~= nil then
|
if ev.status ~= nil then
|
||||||
if type(on_status) == 'function' then
|
if type(on_status) == 'function' then
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local cache = require('cp.cache')
|
|
||||||
local config = require('cp.config')
|
local config = require('cp.config')
|
||||||
local constants = require('cp.constants')
|
local constants = require('cp.constants')
|
||||||
|
local git_credential = require('cp.git_credential')
|
||||||
local logger = require('cp.log')
|
local logger = require('cp.log')
|
||||||
local state = require('cp.state')
|
local state = require('cp.state')
|
||||||
|
|
||||||
|
|
@ -14,7 +14,7 @@ local STATUS_MSGS = {
|
||||||
}
|
}
|
||||||
|
|
||||||
local function prompt_credentials(platform, callback)
|
local function prompt_credentials(platform, callback)
|
||||||
local saved = cache.get_credentials(platform)
|
local saved = git_credential.get(platform)
|
||||||
if saved and saved.username and saved.password then
|
if saved and saved.username and saved.password then
|
||||||
callback(saved)
|
callback(saved)
|
||||||
return
|
return
|
||||||
|
|
@ -109,12 +109,12 @@ function M.submit(opts)
|
||||||
function(result)
|
function(result)
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
if result and result.success then
|
if result and result.success then
|
||||||
cache.set_credentials(platform, creds)
|
git_credential.store(platform, creds)
|
||||||
logger.log('Submitted successfully', { level = vim.log.levels.INFO, override = true })
|
logger.log('Submitted successfully', { level = vim.log.levels.INFO, override = true })
|
||||||
else
|
else
|
||||||
local err = result and result.error or 'unknown error'
|
local err = result and result.error or 'unknown error'
|
||||||
if err == 'bad_credentials' or err:match('^Login failed') then
|
if err == 'bad_credentials' or err:match('^Login failed') then
|
||||||
cache.clear_credentials(platform)
|
git_credential.reject(platform, creds)
|
||||||
logger.log(
|
logger.log(
|
||||||
'Submit failed: ' .. (constants.LOGIN_ERRORS[err] or err),
|
'Submit failed: ' .. (constants.LOGIN_ERRORS[err] or err),
|
||||||
{ level = vim.log.levels.ERROR }
|
{ level = vim.log.levels.ERROR }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue