mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-16 21:56:25 -05:00
feat: environment variables support in configuration file (#2199)
* feat:Environment variables support in configuration file * add changeset * remove fixes typo Co-authored-by: amit <amit@enso.security>
This commit is contained in:
parent
04931c968e
commit
1810ed0d81
10 changed files with 62 additions and 26 deletions
11
.changeset/healthy-poets-compare.md
Normal file
11
.changeset/healthy-poets-compare.md
Normal file
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
'@verdaccio/config': patch
|
||||
---
|
||||
|
||||
Feature
|
||||
|
||||
- add option to set storage from environment variable VERDACCIO_STORAGE_PATH
|
||||
|
||||
#### Related tickets
|
||||
|
||||
https://github.com/verdaccio/verdaccio/issues/1681
|
|
@ -44,3 +44,7 @@ The default header to identify the protocol is `X-Forwarded-Proto`, but there ar
|
|||
```
|
||||
$ VERDACCIO_FORWARDED_PROTO=CloudFront-Forwarded-Proto verdaccio --listen 5000
|
||||
```
|
||||
|
||||
#### VERDACCIO_STORAGE_PATH
|
||||
|
||||
By default, the storage is taken from config file, but using this variable allows to set it from environment variable.
|
||||
|
|
|
@ -50,7 +50,7 @@ class Config implements AppConfig {
|
|||
|
||||
public constructor(config: ConfigRuntime) {
|
||||
const self = this;
|
||||
this.storage = config.storage;
|
||||
this.storage = process.env.VERDACCIO_STORAGE_PATH || config.storage;
|
||||
this.config_path = config.config_path;
|
||||
this.plugins = config.plugins;
|
||||
this.security = _.merge(defaultSecurity, config.security);
|
||||
|
|
|
@ -1,14 +1,7 @@
|
|||
import path from 'path';
|
||||
import { parseConfigFile } from '../src';
|
||||
import { parseConfigurationFile } from './utils';
|
||||
|
||||
describe('Package access utilities', () => {
|
||||
const parseConfigurationFile = (conf) => {
|
||||
const { name, ext } = path.parse(conf);
|
||||
const format = ext.startsWith('.') ? ext.substring(1) : 'yaml';
|
||||
|
||||
return path.join(__dirname, `./partials/config/${format}/${name}.${format}`);
|
||||
};
|
||||
|
||||
describe('JSON format', () => {
|
||||
test('parse default.json', () => {
|
||||
const config = parseConfigFile(parseConfigurationFile('default.json'));
|
||||
|
|
|
@ -10,6 +10,7 @@ import {
|
|||
ROLES,
|
||||
WEB_TITLE,
|
||||
} from '../src';
|
||||
import { parseConfigurationFile } from './utils';
|
||||
|
||||
const resolveConf = (conf) => {
|
||||
const { name, ext } = path.parse(conf);
|
||||
|
@ -80,6 +81,32 @@ describe('check basic content parsed file', () => {
|
|||
checkDefaultConfPackages(config);
|
||||
});
|
||||
|
||||
test('should set storage to value set in VERDACCIO_STORAGE_PATH environment variable', () => {
|
||||
const storageLocation = '/tmp/verdaccio';
|
||||
process.env.VERDACCIO_STORAGE_PATH = storageLocation;
|
||||
const config = new Config(parseConfigFile(resolveConf('default')));
|
||||
expect(config.storage).toBe(storageLocation);
|
||||
delete process.env.VERDACCIO_STORAGE_PATH;
|
||||
});
|
||||
|
||||
test('should set storage path to VERDACCIO_STORAGE_PATH if both config and env are set', () => {
|
||||
const storageLocation = '/tmp/verdaccio';
|
||||
process.env.VERDACCIO_STORAGE_PATH = storageLocation;
|
||||
const config = new Config(parseConfigFile(parseConfigurationFile('storage')));
|
||||
expect(config.storage).toBe(storageLocation);
|
||||
delete process.env.VERDACCIO_STORAGE_PATH;
|
||||
});
|
||||
|
||||
test('should take storage from environment variable if not exists in configs', () => {
|
||||
const storageLocation = '/tmp/verdaccio';
|
||||
process.env.VERDACCIO_STORAGE_PATH = storageLocation;
|
||||
const defaultConfig = parseConfigFile(resolveConf('default'));
|
||||
delete defaultConfig.storage;
|
||||
const config = new Config(defaultConfig);
|
||||
expect(config.storage).toBe(storageLocation);
|
||||
delete process.env.VERDACCIO_STORAGE_PATH;
|
||||
});
|
||||
|
||||
test('parse docker.yaml', () => {
|
||||
const config = new Config(parseConfigFile(resolveConf('docker')));
|
||||
checkDefaultUplink(config);
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import path from 'path';
|
||||
import _ from 'lodash';
|
||||
|
||||
import {
|
||||
|
@ -7,15 +6,9 @@ import {
|
|||
PACKAGE_ACCESS,
|
||||
} from '../src/package-access';
|
||||
import { parseConfigFile } from '../src';
|
||||
import { parseConfigurationFile } from './utils';
|
||||
|
||||
describe('Package access utilities', () => {
|
||||
const parseConfigurationFile = (conf) => {
|
||||
const { name, ext } = path.parse(conf);
|
||||
const format = ext.startsWith('.') ? ext.substring(1) : 'yaml';
|
||||
|
||||
return path.join(__dirname, `./partials/config/${format}/${name}.${format}`);
|
||||
};
|
||||
|
||||
describe('normalisePackageAccess', () => {
|
||||
test('should test basic conversion', () => {
|
||||
const { packages } = parseConfigFile(parseConfigurationFile('pkgs-basic'));
|
||||
|
|
7
packages/config/test/partials/config/yaml/storage.yaml
Normal file
7
packages/config/test/partials/config/yaml/storage.yaml
Normal file
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
storage: './storage_default_storage'
|
||||
|
||||
logs:
|
||||
- type: stdout
|
||||
format: pretty
|
||||
level: warn
|
|
@ -1,16 +1,8 @@
|
|||
import path from 'path';
|
||||
|
||||
import { hasProxyTo, sanityCheckUplinksProps, uplinkSanityCheck } from '../src/uplinks';
|
||||
import { normalisePackageAccess, parseConfigFile } from '../src';
|
||||
import { parseConfigurationFile } from './utils';
|
||||
|
||||
describe('Uplinks Utilities', () => {
|
||||
const parseConfigurationFile = (conf) => {
|
||||
const { name, ext } = path.parse(conf);
|
||||
const format = ext.startsWith('.') ? ext.substring(1) : 'yaml';
|
||||
|
||||
return path.join(__dirname, `./partials/config/${format}/${name}.${format}`);
|
||||
};
|
||||
|
||||
describe('uplinkSanityCheck', () => {
|
||||
test('should test basic conversion', () => {
|
||||
const uplinks = uplinkSanityCheck(
|
||||
|
|
1
packages/config/test/utils/index.ts
Normal file
1
packages/config/test/utils/index.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export { parseConfigurationFile } from './parse-configuration-file';
|
8
packages/config/test/utils/parse-configuration-file.ts
Normal file
8
packages/config/test/utils/parse-configuration-file.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
import path from 'path';
|
||||
|
||||
export const parseConfigurationFile = (conf: string) => {
|
||||
const { name, ext } = path.parse(conf);
|
||||
const format = ext.startsWith('.') ? ext.substring(1) : 'yaml';
|
||||
|
||||
return path.join(__dirname, `../partials/config/${format}/${name}.${format}`);
|
||||
};
|
Loading…
Reference in a new issue