Require an explicit registry instead of defaulting to one
The shipped default named one private, internet-unreachable host, so an unconfigured install failed against a server it could never reach rather than saying what to set. - drop the registry default and make the option required - reject a non-string, empty, or non-http(s) registry with the option name and how to set it - ask for a registry only when a run has to resolve one, so clean, list, and specs with an explicit url keep working without it
This commit is contained in:
+25
-1
@@ -5,8 +5,9 @@ local spec_mod = require('arti-pack.spec')
|
||||
|
||||
local M = {}
|
||||
|
||||
-- registry has no default: it is site-specific, so any shipped value would point
|
||||
-- every install at a host it cannot reach. See M.setup.
|
||||
local DEFAULTS = {
|
||||
registry = 'https://artifactapi.k8s.syd1.au.unkin.net/api/v1/remote/github',
|
||||
plugins = {},
|
||||
auto_sync = true,
|
||||
concurrency = 4,
|
||||
@@ -42,6 +43,17 @@ local function context()
|
||||
}
|
||||
end
|
||||
|
||||
-- A spec carrying its own url never touches the registry, so only demand one
|
||||
-- when something in this run would have to be resolved against it.
|
||||
local function registry_error(specs, registry)
|
||||
for _, spec in ipairs(specs) do
|
||||
if not spec.url then
|
||||
local _, err = spec_mod.check_registry(registry)
|
||||
return err
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function installed_dir(ctx, name, opt)
|
||||
return fs.join(ctx.pack_dir, opt and 'opt' or 'start', name)
|
||||
end
|
||||
@@ -110,6 +122,11 @@ function M.sync(opts)
|
||||
return notify('everything up to date')
|
||||
end
|
||||
|
||||
local reg_err = registry_error(pending, ctx.registry)
|
||||
if reg_err then
|
||||
return notify(reg_err, vim.log.levels.ERROR)
|
||||
end
|
||||
|
||||
running = true
|
||||
notify(string.format('syncing %d plugin(s)', #pending))
|
||||
installer.run(ctx, pending, function(results)
|
||||
@@ -213,6 +230,13 @@ function M.setup(opts)
|
||||
-- a user's plugin list; the caller's list is always authoritative.
|
||||
M.config.plugins = opts.plugins or {}
|
||||
|
||||
if opts.registry ~= nil then
|
||||
local _, err = spec_mod.check_registry(opts.registry)
|
||||
if err then
|
||||
notify(err, vim.log.levels.ERROR)
|
||||
end
|
||||
end
|
||||
|
||||
local p = paths()
|
||||
fs.mkdirp(fs.join(p.pack_dir, 'start'))
|
||||
fs.mkdirp(fs.join(p.pack_dir, 'opt'))
|
||||
|
||||
+18
-3
@@ -2,6 +2,8 @@ local M = {}
|
||||
|
||||
local SOURCE_PATTERN = '^([%w%.%_%-]+)/([%w%.%_%-]+)$'
|
||||
local EXTENSIONS = { ['zip'] = true, ['tar.gz'] = true }
|
||||
local SETUP_HINT =
|
||||
"set it in require('arti-pack').setup{ registry = 'https://artifacts.example.com/artifactory/github-remote' }"
|
||||
|
||||
local function trim(s)
|
||||
return (s:gsub('^%s+', ''):gsub('%s+$', ''))
|
||||
@@ -65,16 +67,29 @@ function M.parse(entry)
|
||||
}
|
||||
end
|
||||
|
||||
-- There is no default registry: the URL is site-specific, and a wrong one only
|
||||
-- surfaces as an opaque curl failure. Returns the base with trailing slashes
|
||||
-- stripped so joining it to a path never produces "//".
|
||||
function M.check_registry(registry)
|
||||
if registry == nil then
|
||||
return nil, 'registry is not configured; ' .. SETUP_HINT
|
||||
end
|
||||
if type(registry) ~= 'string' or not registry:match('^https?://[^%s/]') then
|
||||
return nil, string.format('registry %s is not an http(s) URL; %s', vim.inspect(registry), SETUP_HINT)
|
||||
end
|
||||
return (registry:gsub('/+$', ''))
|
||||
end
|
||||
|
||||
-- Tagged source archives live at the same path shape on every GitHub-alike, so
|
||||
-- the registry is just the proxy prefix in front of "<owner>/<repo>".
|
||||
function M.url(spec, registry)
|
||||
if spec.url then
|
||||
return spec.url
|
||||
end
|
||||
if type(registry) ~= 'string' or registry == '' then
|
||||
return nil, 'registry is not configured'
|
||||
local base, err = M.check_registry(registry)
|
||||
if not base then
|
||||
return nil, err
|
||||
end
|
||||
local base = registry:gsub('/+$', '')
|
||||
return table.concat({
|
||||
base,
|
||||
spec.owner,
|
||||
|
||||
Reference in New Issue
Block a user