Skip to content

Commit

Permalink
refactor: rename config admin functions to global
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Aug 17, 2021
1 parent 750bc16 commit bf69924
Show file tree
Hide file tree
Showing 101 changed files with 411 additions and 411 deletions.
20 changes: 10 additions & 10 deletions lib/config/admin.ts
@@ -1,9 +1,9 @@
import type { RenovateConfig, RepoAdminConfig } from './types';
import type { RenovateConfig, RepoGlobalConfig } from './types';

let adminConfig: RepoAdminConfig = {};
let repoGlobalConfig: RepoGlobalConfig = {};

// TODO: once admin config work is complete, add a test to make sure this list includes all options with admin=true (#9603)
const repoAdminOptions = [
const repoGlobalOptions = [
'allowCustomCrateRegistries',
'allowPostUpgradeCommandTemplating',
'allowScripts',
Expand All @@ -21,18 +21,18 @@ const repoAdminOptions = [
'cacheDir',
];

export function setAdminConfig(
config: RenovateConfig | RepoAdminConfig = {}
export function setGlobalConfig(
config: RenovateConfig | RepoGlobalConfig = {}
): RenovateConfig {
adminConfig = {};
repoGlobalConfig = {};
const result = { ...config };
for (const option of repoAdminOptions) {
adminConfig[option] = config[option];
for (const option of repoGlobalOptions) {
repoGlobalConfig[option] = config[option];
delete result[option]; // eslint-disable-line no-param-reassign
}
return result;
}

export function getAdminConfig(): RepoAdminConfig {
return adminConfig;
export function getGlobalConfig(): RepoGlobalConfig {
return repoGlobalConfig;
}
14 changes: 7 additions & 7 deletions lib/config/decrypt.spec.ts
@@ -1,5 +1,5 @@
import { getName, loadFixture } from '../../test/util';
import { setAdminConfig } from './admin';
import { setGlobalConfig } from './admin';
import { decryptConfig } from './decrypt';
import type { RenovateConfig } from './types';

Expand All @@ -10,7 +10,7 @@ describe(getName(), () => {
let config: RenovateConfig;
beforeEach(() => {
config = {};
setAdminConfig();
setGlobalConfig();
});
it('returns empty with no privateKey', () => {
delete config.encrypted;
Expand All @@ -25,17 +25,17 @@ describe(getName(), () => {
});
it('handles invalid encrypted type', () => {
config.encrypted = 1;
setAdminConfig({ privateKey });
setGlobalConfig({ privateKey });
const res = decryptConfig(config);
expect(res.encrypted).not.toBeDefined();
});
it('handles invalid encrypted value', () => {
config.encrypted = { a: 1 };
setAdminConfig({ privateKey });
setGlobalConfig({ privateKey });
expect(() => decryptConfig(config)).toThrow(Error('config-validation'));
});
it('replaces npm token placeholder in npmrc', () => {
setAdminConfig({ privateKey });
setGlobalConfig({ privateKey });
config.npmrc =
'//registry.npmjs.org/:_authToken=${NPM_TOKEN}\n//registry.npmjs.org/:_authToken=${NPM_TOKEN}\n'; // eslint-disable-line no-template-curly-in-string
config.encrypted = {
Expand All @@ -50,7 +50,7 @@ describe(getName(), () => {
);
});
it('appends npm token in npmrc', () => {
setAdminConfig({ privateKey });
setGlobalConfig({ privateKey });
config.npmrc = 'foo=bar\n'; // eslint-disable-line no-template-curly-in-string
config.encrypted = {
npmToken:
Expand All @@ -62,7 +62,7 @@ describe(getName(), () => {
expect(res.npmrc).toMatchSnapshot();
});
it('decrypts nested', () => {
setAdminConfig({ privateKey });
setGlobalConfig({ privateKey });
config.packageFiles = [
{
packageFile: 'package.json',
Expand Down
4 changes: 2 additions & 2 deletions lib/config/decrypt.ts
Expand Up @@ -3,13 +3,13 @@ import is from '@sindresorhus/is';
import { logger } from '../logger';
import { maskToken } from '../util/mask';
import { add } from '../util/sanitize';
import { getAdminConfig } from './admin';
import { getGlobalConfig } from './admin';
import type { RenovateConfig } from './types';

export function decryptConfig(config: RenovateConfig): RenovateConfig {
logger.trace({ config }, 'decryptConfig()');
const decryptedConfig = { ...config };
const { privateKey } = getAdminConfig();
const { privateKey } = getGlobalConfig();
for (const [key, val] of Object.entries(config)) {
if (key === 'encrypted' && is.object(val)) {
logger.debug({ config: val }, 'Found encrypted config');
Expand Down
4 changes: 2 additions & 2 deletions lib/config/migration.spec.ts
@@ -1,6 +1,6 @@
import { getName } from '../../test/util';
import { PLATFORM_TYPE_GITHUB } from '../constants/platforms';
import { setAdminConfig } from './admin';
import { setGlobalConfig } from './admin';
import { getConfig } from './defaults';
import * as configMigration from './migration';
import type {
Expand Down Expand Up @@ -707,7 +707,7 @@ describe(getName(), () => {
});
});
it('it migrates presets', () => {
setAdminConfig({
setGlobalConfig({
migratePresets: {
'@org': 'local>org/renovate-config',
'@org2/foo': '',
Expand Down
4 changes: 2 additions & 2 deletions lib/config/migration.ts
Expand Up @@ -3,7 +3,7 @@ import is from '@sindresorhus/is';
import { dequal } from 'dequal';
import { logger } from '../logger';
import { clone } from '../util/clone';
import { getAdminConfig } from './admin';
import { getGlobalConfig } from './admin';
import { getOptions } from './options';
import { removedPresets } from './presets/common';
import type {
Expand Down Expand Up @@ -56,7 +56,7 @@ export function migrateConfig(
'optionalDependencies',
'peerDependencies',
];
const { migratePresets } = getAdminConfig();
const { migratePresets } = getGlobalConfig();
for (const [key, val] of Object.entries(config)) {
if (removedOptions.includes(key)) {
delete migratedConfig[key];
Expand Down
4 changes: 2 additions & 2 deletions lib/config/presets/npm/index.spec.ts
@@ -1,6 +1,6 @@
import * as httpMock from '../../../../test/http-mock';
import { getName } from '../../../../test/util';
import { setAdminConfig } from '../../admin';
import { setGlobalConfig } from '../../admin';
import * as npm from '.';

jest.mock('registry-auth-token');
Expand All @@ -9,7 +9,7 @@ jest.mock('delay');
describe(getName(), () => {
beforeEach(() => {
jest.resetAllMocks();
setAdminConfig();
setGlobalConfig();
});
afterEach(() => {
delete process.env.RENOVATE_CACHE_NPM_MINUTES;
Expand Down
2 changes: 1 addition & 1 deletion lib/config/types.ts
Expand Up @@ -86,7 +86,7 @@ export interface GlobalOnlyConfig {

// Config options used within the repository worker, but not user configurable
// The below should contain config options where admin=true
export interface RepoAdminConfig {
export interface RepoGlobalConfig {
allowCustomCrateRegistries?: boolean;
allowPostUpgradeCommandTemplating?: boolean;
allowScripts?: boolean;
Expand Down
20 changes: 10 additions & 10 deletions lib/datasource/crate/index.spec.ts
Expand Up @@ -6,8 +6,8 @@ import { dirname, join } from 'upath';
import { getPkgReleases } from '..';
import * as httpMock from '../../../test/http-mock';
import { getName, loadFixture } from '../../../test/util';
import { setAdminConfig } from '../../config/admin';
import type { RepoAdminConfig } from '../../config/types';
import { setGlobalConfig } from '../../config/admin';
import type { RepoGlobalConfig } from '../../config/types';
import * as memCache from '../../util/cache/memory';
import { RegistryFlavor, RegistryInfo } from './types';
import { id as datasource, fetchCrateRecordsPayload, getIndexSuffix } from '.';
Expand Down Expand Up @@ -75,7 +75,7 @@ describe(getName(), () => {

describe('getReleases', () => {
let tmpDir: DirectoryResult | null;
let adminConfig: RepoAdminConfig;
let adminConfig: RepoGlobalConfig;

beforeEach(async () => {
tmpDir = await dir();
Expand All @@ -84,7 +84,7 @@ describe(getName(), () => {
localDir: join(tmpDir.path, 'local'),
cacheDir: join(tmpDir.path, 'cache'),
};
setAdminConfig(adminConfig);
setGlobalConfig(adminConfig);

simpleGit.mockReset();
memCache.init();
Expand All @@ -93,7 +93,7 @@ describe(getName(), () => {
afterEach(() => {
fs.rmdirSync(tmpDir.path, { recursive: true });
tmpDir = null;
setAdminConfig();
setGlobalConfig();
});

it('returns null for missing registry url', async () => {
Expand Down Expand Up @@ -229,7 +229,7 @@ describe(getName(), () => {
});
it('clones cloudsmith private registry', async () => {
const { mockClone } = setupGitMocks();
setAdminConfig({ ...adminConfig, allowCustomCrateRegistries: true });
setGlobalConfig({ ...adminConfig, allowCustomCrateRegistries: true });
const url = 'https://dl.cloudsmith.io/basic/myorg/myrepo/cargo/index.git';
const res = await getPkgReleases({
datasource,
Expand All @@ -243,7 +243,7 @@ describe(getName(), () => {
});
it('clones other private registry', async () => {
const { mockClone } = setupGitMocks();
setAdminConfig({ ...adminConfig, allowCustomCrateRegistries: true });
setGlobalConfig({ ...adminConfig, allowCustomCrateRegistries: true });
const url = 'https://github.com/mcorbin/testregistry';
const res = await getPkgReleases({
datasource,
Expand All @@ -257,7 +257,7 @@ describe(getName(), () => {
});
it('clones once then reuses the cache', async () => {
const { mockClone } = setupGitMocks();
setAdminConfig({ ...adminConfig, allowCustomCrateRegistries: true });
setGlobalConfig({ ...adminConfig, allowCustomCrateRegistries: true });
const url = 'https://github.com/mcorbin/othertestregistry';
await getPkgReleases({
datasource,
Expand All @@ -273,7 +273,7 @@ describe(getName(), () => {
});
it('guards against race conditions while cloning', async () => {
const { mockClone } = setupGitMocks(250);
setAdminConfig({ ...adminConfig, allowCustomCrateRegistries: true });
setGlobalConfig({ ...adminConfig, allowCustomCrateRegistries: true });
const url = 'https://github.com/mcorbin/othertestregistry';

await Promise.all([
Expand All @@ -299,7 +299,7 @@ describe(getName(), () => {
});
it('returns null when git clone fails', async () => {
setupErrorGitMock();
setAdminConfig({ ...adminConfig, allowCustomCrateRegistries: true });
setGlobalConfig({ ...adminConfig, allowCustomCrateRegistries: true });
const url = 'https://github.com/mcorbin/othertestregistry';

const result = await getPkgReleases({
Expand Down
4 changes: 2 additions & 2 deletions lib/datasource/crate/index.ts
@@ -1,7 +1,7 @@
import hasha from 'hasha';
import Git from 'simple-git';
import { join } from 'upath';
import { getAdminConfig } from '../../config/admin';
import { getGlobalConfig } from '../../config/admin';
import { logger } from '../../logger';
import { ExternalHostError } from '../../types/errors/external-host-error';
import * as memCache from '../../util/cache/memory';
Expand Down Expand Up @@ -135,7 +135,7 @@ async function fetchRegistryInfo(
};

if (flavor !== RegistryFlavor.CratesIo) {
if (!getAdminConfig().allowCustomCrateRegistries) {
if (!getGlobalConfig().allowCustomCrateRegistries) {
logger.warn(
'crate datasource: allowCustomCrateRegistries=true is required for registries other than crates.io, bailing out'
);
Expand Down
8 changes: 4 additions & 4 deletions lib/datasource/npm/index.spec.ts
Expand Up @@ -3,7 +3,7 @@ import _registryAuthToken from 'registry-auth-token';
import { getPkgReleases } from '..';
import * as httpMock from '../../../test/http-mock';
import { getName } from '../../../test/util';
import { setAdminConfig } from '../../config/admin';
import { setGlobalConfig } from '../../config/admin';
import { EXTERNAL_HOST_ERROR } from '../../constants/error-messages';
import * as hostRules from '../../util/host-rules';
import { id as datasource, getNpmrc, resetCache, setNpmrc } from '.';
Expand All @@ -18,7 +18,7 @@ let npmResponse: any;
describe(getName(), () => {
beforeEach(() => {
jest.resetAllMocks();
setAdminConfig();
setGlobalConfig();
hostRules.clear();
resetCache();
setNpmrc();
Expand Down Expand Up @@ -358,7 +358,7 @@ describe(getName(), () => {
.reply(200, npmResponse);
process.env.REGISTRY = 'https://registry.from-env.com';
process.env.RENOVATE_CACHE_NPM_MINUTES = '15';
setAdminConfig({ exposeAllEnv: true });
setGlobalConfig({ exposeAllEnv: true });
// eslint-disable-next-line no-template-curly-in-string
const npmrc = 'registry=${REGISTRY}';
const res = await getPkgReleases({ datasource, depName: 'foobar', npmrc });
Expand All @@ -367,7 +367,7 @@ describe(getName(), () => {
});

it('should throw error if necessary env var is not present', () => {
setAdminConfig({ exposeAllEnv: true });
setGlobalConfig({ exposeAllEnv: true });
// eslint-disable-next-line no-template-curly-in-string
expect(() => setNpmrc('registry=${REGISTRY_MISSING}')).toThrow(
Error('env-replace')
Expand Down
6 changes: 3 additions & 3 deletions lib/datasource/npm/npmrc.spec.ts
@@ -1,5 +1,5 @@
import { getName, mocked } from '../../../test/util';
import { setAdminConfig } from '../../config/admin';
import { setGlobalConfig } from '../../config/admin';
import * as _sanitize from '../../util/sanitize';
import { getNpmrc, setNpmrc } from './npmrc';

Expand All @@ -10,7 +10,7 @@ const sanitize = mocked(_sanitize);
describe(getName(), () => {
beforeEach(() => {
setNpmrc('');
setAdminConfig();
setGlobalConfig();
jest.resetAllMocks();
});

Expand Down Expand Up @@ -38,7 +38,7 @@ describe(getName(), () => {
});

it('sanitize _authtoken with high trust', () => {
setAdminConfig({ exposeAllEnv: true });
setGlobalConfig({ exposeAllEnv: true });
process.env.TEST_TOKEN = 'test';
setNpmrc(
// eslint-disable-next-line no-template-curly-in-string
Expand Down
4 changes: 2 additions & 2 deletions lib/datasource/npm/npmrc.ts
Expand Up @@ -3,7 +3,7 @@ import is from '@sindresorhus/is';
import ini from 'ini';
import registryAuthToken from 'registry-auth-token';
import getRegistryUrl from 'registry-auth-token/registry-url';
import { getAdminConfig } from '../../config/admin';
import { getGlobalConfig } from '../../config/admin';
import { logger } from '../../logger';
import type { OutgoingHttpHeaders } from '../../util/http/types';
import { maskToken } from '../../util/mask';
Expand Down Expand Up @@ -60,7 +60,7 @@ export function setNpmrc(input?: string): void {
npmrcRaw = input;
logger.debug('Setting npmrc');
npmrc = ini.parse(input.replace(/\\n/g, '\n'));
const { exposeAllEnv } = getAdminConfig();
const { exposeAllEnv } = getGlobalConfig();
for (const [key, val] of Object.entries(npmrc)) {
if (!exposeAllEnv) {
sanitize(key, val);
Expand Down
10 changes: 5 additions & 5 deletions lib/manager/batect/extract.spec.ts
@@ -1,6 +1,6 @@
import { getName } from '../../../test/util';
import { setAdminConfig } from '../../config/admin';
import type { RepoAdminConfig } from '../../config/types';
import { setGlobalConfig } from '../../config/admin';
import type { RepoGlobalConfig } from '../../config/types';
import { id as gitTagDatasource } from '../../datasource/git-tags';
import { id as dockerVersioning } from '../../versioning/docker';
import { id as semverVersioning } from '../../versioning/semver';
Expand All @@ -27,7 +27,7 @@ function createGitDependency(repo: string, version: string): PackageDependency {
};
}

const adminConfig: RepoAdminConfig = {
const adminConfig: RepoGlobalConfig = {
localDir: '',
};

Expand All @@ -36,11 +36,11 @@ const config: ExtractConfig = {};
describe(getName(), () => {
describe('extractPackageFile()', () => {
beforeEach(() => {
setAdminConfig(adminConfig);
setGlobalConfig(adminConfig);
});

afterEach(() => {
setAdminConfig();
setGlobalConfig();
});

it('returns empty array for empty configuration file', async () => {
Expand Down

0 comments on commit bf69924

Please sign in to comment.