From 1a7b1ee8ad79c0a164f8bae7160b55919c18c0f1 Mon Sep 17 00:00:00 2001 From: Juan Picado Date: Sat, 22 Jan 2022 10:58:04 +0100 Subject: [PATCH] feat: add new options to the web disable login and pkg managers (#2947) --- .pnp.js | 6 +++--- src/api/web/endpoint/index.ts | 5 ++++- src/api/web/html/renderHTML.ts | 6 +++++- src/lib/utils.ts | 8 +++++++- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/.pnp.js b/.pnp.js index 10e149770..2b1327e21 100755 --- a/.pnp.js +++ b/.pnp.js @@ -7840,14 +7840,14 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { ]], ["core-js", [ ["npm:2.6.9", { - "packageLocation": "./.yarn/cache/core-js-npm-2.6.9-f821bf686c-00c30207eb.zip/node_modules/core-js/", + "packageLocation": "./.yarn/unplugged/core-js-npm-2.6.9-f821bf686c/node_modules/core-js/", "packageDependencies": [ ["core-js", "npm:2.6.9"] ], "linkType": "HARD", }], ["npm:3.20.2", { - "packageLocation": "./.yarn/cache/core-js-npm-3.20.2-656ea79cc8-642927e21a.zip/node_modules/core-js/", + "packageLocation": "./.yarn/unplugged/core-js-npm-3.20.2-656ea79cc8/node_modules/core-js/", "packageDependencies": [ ["core-js", "npm:3.20.2"] ], @@ -14898,7 +14898,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { ]], ["puppeteer", [ ["npm:5.5.0", { - "packageLocation": "./.yarn/cache/puppeteer-npm-5.5.0-bba75ba998-08ba8a7da5.zip/node_modules/puppeteer/", + "packageLocation": "./.yarn/unplugged/puppeteer-npm-5.5.0-bba75ba998/node_modules/puppeteer/", "packageDependencies": [ ["puppeteer", "npm:5.5.0"], ["debug", "virtual:65523936f66795efc0bd6f7ca9a755f1be9f9bb998dc7cd39f5d823ea185c793a03b3f329f921a146569ee8bdffdd22dd15c2e08d286539b118e1cbbab91f8cf#npm:4.1.1"], diff --git a/src/api/web/endpoint/index.ts b/src/api/web/endpoint/index.ts index d5c3e77db..92ff7ca04 100644 --- a/src/api/web/endpoint/index.ts +++ b/src/api/web/endpoint/index.ts @@ -1,5 +1,6 @@ import { Response, Router } from 'express'; +import { hasLogin } from '../../../lib/utils'; import { limiter } from '../../rate-limiter'; import packageApi from './package'; import search from './search'; @@ -18,6 +19,8 @@ export default (auth, storage, config) => { route.use('/data/', packageApi(storage, auth, config)); route.use('/data/', search(storage, auth)); route.use('/sec/', limiter(config?.userRateLimit)); - route.use('/sec/', user(auth, storage)); + if (hasLogin(config)) { + route.use('/sec/', user(auth, storage)); + } return route; }; diff --git a/src/api/web/html/renderHTML.ts b/src/api/web/html/renderHTML.ts index 8f862fc8d..067742686 100644 --- a/src/api/web/html/renderHTML.ts +++ b/src/api/web/html/renderHTML.ts @@ -6,7 +6,7 @@ import { URL } from 'url'; import { HEADERS } from '@verdaccio/commons-api'; import { WEB_TITLE } from '../../../lib/constants'; -import { getPublicUrl, isHTTPProtocol } from '../../../lib/utils'; +import { getPublicUrl, hasLogin, isHTTPProtocol } from '../../../lib/utils'; import renderTemplate from './template'; const pkgJSON = require('../../../../package.json'); @@ -50,7 +50,9 @@ export default function renderHTML(config, manifest, manifestFiles, req, res) { const darkMode = config?.web?.darkMode ?? false; const title = config?.web?.title ?? WEB_TITLE; const scope = config?.web?.scope ?? ''; + const login = hasLogin(config); const logoURI = resolveLogo(config, req); + const pkgManagers = config?.web?.pkgManagers ?? ['yarn', 'pnpm', 'npm']; const version = pkgJSON.version; const primaryColor = validatePrimaryColor(config?.web?.primary_color) ?? '#4b5e40'; const { scriptsBodyAfter, metaScripts, scriptsbodyBefore } = Object.assign( @@ -69,6 +71,8 @@ export default function renderHTML(config, manifest, manifestFiles, req, res) { base, primaryColor, version, + pkgManagers, + login, logo: logoURI, title, scope, diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 03759263d..286dc2d74 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -12,7 +12,7 @@ import validator from 'validator'; // eslint-disable-next-line max-len import { getBadData, getBadRequest, getCode, getConflict, getForbidden, getInternalError, getNotFound, getServiceUnavailable, getUnauthorized } from '@verdaccio/commons-api'; import sanitizyReadme from '@verdaccio/readme'; -import { Author, Package, Version } from '@verdaccio/types'; +import { Author, Config, Package, Version } from '@verdaccio/types'; import { AuthorAvatar, StringValue } from '../../types'; import { GENERIC_AVATAR, generateGravatarUrl } from '../utils/user'; @@ -689,3 +689,9 @@ export function wrapPrefix(prefix: string | void): string { return prefix; } } + +export function hasLogin(config: Config) { + // FIXME: types are not yet on the library verdaccio/monorepo + // @ts-ignore + return _.isNil(config?.web?.login) || config?.web?.login === true; +}