local multi_token_manager = require('sql-cli.multi_token_manager')
multi_token_manager.setup({
JWT_TOKEN = {
command = "powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -File " .. vim.fn.expand("~/dev/sql-cli/GetUatToken.ps1"),
refresh_interval = 840, auto_refresh = true,
debug = false, },
JWT_TOKEN_PROD = {
command = "powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -File " .. vim.fn.expand("~/dev/sql-cli/GetProdToken.ps1"),
refresh_interval = 840, auto_refresh = true,
debug = false,
},
})
multi_token_manager.create_commands()
vim.notify("Multi-Token Manager configured for JWT_TOKEN and JWT_TOKEN_PROD", vim.log.levels.INFO)
vim.notify("Commands: :TokenStatus, :TokenRefreshAll, :TokenRefresh [name]", vim.log.levels.INFO)
vim.api.nvim_create_autocmd("FileType", {
pattern = "sql",
callback = function()
local old_expand = vim.b.sql_template_expand
if old_expand then
vim.b.sql_template_expand = function(text)
local expanded = text
expanded = expanded:gsub("${JWT_TOKEN}", function()
return multi_token_manager.get_token("JWT_TOKEN") or ""
end)
expanded = expanded:gsub("${JWT_TOKEN_PROD}", function()
return multi_token_manager.get_token("JWT_TOKEN_PROD") or ""
end)
if old_expand then
return old_expand(expanded)
end
return expanded
end
end
end
})