/* * Helper to load landofile */ const loadLandoFile = file => { try { return yaml.safeLoad(fs.readFileSync(file)); } catch (e) { throw new Error(`There was a problem with parsing ${file}. Ensure it is valid YAML! ${e}`); } }
_(files) // Filter if file exists .filter(fs.existsSync) // Start collecting .reduce((a, file) => exports.merge(a, yaml.safeLoad(fs.readFileSync(file))), {})
_(files) .filter(file => fs.existsSync(file)) .map(file => yaml.safeLoad(fs.readFileSync(file))) .thru(data => _.merge({}, ...data)) .thru(data => { // Set the php version // @TODO: what is the best version here? data.php = _.toString(_.get(data, 'php_version', '5.6')); // Set the webroot data.webroot = (_.get(data, 'web_docroot', false)) ? 'web' : '.'; // Set the drush version data.drush = _.toString(_.get(data, 'drush_version', '8')); // if drush version is less than 8, use 8 anyway if (data.drush < 8) data.drush = 8; // return return data; }) .value()
/** * Parses YAML text. * * @param {string} yaml YAML to parse. * @returns {Object} Object representation. */ function yamlParse(yaml) { return jsYaml.safeLoad(yaml); }
function readYAML (fp) { try { return yaml.safeLoad(fs.readFileSync(fp, 'utf8')) } catch (err) { if (err.code !== 'ENOENT') fail(err) } }
/** * Loads a yaml object from a file. * * @since 3.0.0 * @alias lando.yaml.load * @param {String} file The path to the file to be loaded * @return {Object} The loaded object * @example * // Add a string to the cache * const thing = lando.yaml.load('/tmp/myfile.yml'); */ load(file) { try { return yaml.safeLoad(fs.readFileSync(file)); } catch (e) { this.log.error('Problem parsing %s with %s', file, e.message); } }
function loadKubeconfig (cfgPath) { let cfgPaths if (!cfgPath) { cfgPaths = defaultConfigPaths() } else if (Array.isArray(cfgPath)) { cfgPaths = cfgPath } else { cfgPaths = [cfgPath] } const configs = cfgPaths.map(cfgPath => { const config = yaml.safeLoad(fs.readFileSync(cfgPath)) return mapCertificates(cfgPath, config) }) return merge.all(configs) }
// test config generation test('Should generate config file for functions', done => { // spy on console const consoleSpy = sinon.spy(console, 'log'); // execute login config({func: true}).then(() => { // first check console output expect(consoleSpy.args).toMatchSnapshot(); // then check config changes const cfg = yaml.safeLoad(fs.readFileSync(configPath, 'utf8')); expect(cfg.name).toEqual(folderName); expect(cfg.function).toEqual(true); // restore console console.log.restore(); // remove corrupted config fs.unlinkSync(configPath); done(); }); });
const manifest = yaml.safeLoad(fs.readFileSync('./integration/test/busybox-pod.yaml')) const name = manifest.metadata.name const client = await env.getClient()
describe('test-integration/basic', () => { let namespace = null beforeEach(async () => { namespace = await env.setupNamespace() }) afterEach(async () => { await env.tearDownNamespace(namespace) }) // Tests beforeEach and afterEach it('creates and deletes Namespaces', async () => { }) it('gets Pod logs', async () => { const manifest = yaml.safeLoad(fs.readFileSync('./integration/test/busybox-pod.yaml')) const client = await env.getClient() await client.api.v1.namespaces(namespace).pods.post({ body: manifest }) await waitForPod({ client, namespace, name: manifest.metadata.name }) for (let attempt = 0; attempt < 3; attempt++) { const result = await client.api.v1.namespaces(namespace).pods(manifest.metadata.name).log.get() if (result.body && result.body === 'hello\n') return await sleep(1000) } expect.fail('Did not read expected Pod log result') }) })
const cfg = yaml.safeLoad(fs.readFileSync(configPath, 'utf8')); expect(cfg.name).toEqual(configData.name); expect(cfg.restart).toEqual(configData.restart);
const manifest = yaml.safeLoad(fs.readFileSync('./integration/test/busybox-pod.yaml')) const client = await env.getClient() await client.api.v1.namespaces(namespace).pods.post({ body: manifest }) const manifest = yaml.safeLoad(fs.readFileSync('./integration/test/busybox-pod.yaml')) const client = await env.getClient() await client.api.v1.namespaces(namespace).pods.post({ body: manifest })
test('Should generate the config with parameters', done => { // spy on console const consoleSpy = sinon.spy(console, 'log'); config({ domain: 'test123.dev', port: '1234', restart: 'unless-stopped', project: 'give-project-name', name: 'test name 123', hostname: 'test123.dev', }).then(() => { expect(consoleSpy.args).toMatchSnapshot(); // then check config changes const cfg = yaml.safeLoad(fs.readFileSync(configPath, 'utf8')); expect(cfg.name).toEqual('test name 123'); expect(cfg.restart).toEqual('unless-stopped'); expect(cfg.domain).toEqual('test123.dev'); expect(cfg.port).toEqual('1234'); expect(cfg.project).toEqual('give-project-name'); expect(cfg.hostname).toEqual('test123.dev'); // restore console console.log.restore(); // remove corrupted config fs.unlinkSync(configPath); done(); }); });
const getConfig = () => yaml.safeLoad(fs.readFileSync(configPath, 'utf8'))
function parse(text) { return yaml.safeLoad(text, 'utf8'); }