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 cache = require('cp.cache')
|
||||
local constants = require('cp.constants')
|
||||
local git_credential = require('cp.git_credential')
|
||||
local logger = require('cp.log')
|
||||
local state = require('cp.state')
|
||||
|
||||
|
|
@ -40,14 +40,14 @@ local function prompt_and_login(platform, display)
|
|||
end, function(result)
|
||||
vim.schedule(function()
|
||||
if result.success then
|
||||
cache.set_credentials(platform, credentials)
|
||||
git_credential.store(platform, credentials)
|
||||
logger.log(
|
||||
display .. ' login successful',
|
||||
{ level = vim.log.levels.INFO, override = true }
|
||||
)
|
||||
else
|
||||
local err = result.error or 'unknown error'
|
||||
cache.clear_credentials(platform)
|
||||
git_credential.reject(platform, credentials)
|
||||
logger.log(
|
||||
display .. ' login failed: ' .. (constants.LOGIN_ERRORS[err] or err),
|
||||
{ level = vim.log.levels.ERROR }
|
||||
|
|
@ -73,8 +73,7 @@ function M.login(platform)
|
|||
|
||||
local display = constants.PLATFORM_DISPLAY_NAMES[platform] or platform
|
||||
|
||||
cache.load()
|
||||
local existing = cache.get_credentials(platform) or {}
|
||||
local existing = git_credential.get(platform) or {}
|
||||
|
||||
if existing.username and existing.password then
|
||||
local scraper = require('cp.scraper')
|
||||
|
|
@ -91,7 +90,7 @@ function M.login(platform)
|
|||
{ level = vim.log.levels.INFO, override = true }
|
||||
)
|
||||
else
|
||||
cache.clear_credentials(platform)
|
||||
git_credential.reject(platform, existing)
|
||||
prompt_and_login(platform, display)
|
||||
end
|
||||
end)
|
||||
|
|
@ -113,8 +112,10 @@ function M.logout(platform)
|
|||
return
|
||||
end
|
||||
local display = constants.PLATFORM_DISPLAY_NAMES[platform] or platform
|
||||
cache.load()
|
||||
cache.clear_credentials(platform)
|
||||
local existing = git_credential.get(platform)
|
||||
if existing then
|
||||
git_credential.reject(platform, existing)
|
||||
end
|
||||
local cookie_file = constants.COOKIE_FILE
|
||||
if vim.fn.filereadable(cookie_file) == 1 then
|
||||
local ok, data = pcall(vim.fn.json_decode, vim.fn.readfile(cookie_file, 'b'))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue