How to use the js-yaml.safeLoadAll function in js-yaml

To help you get started, we’ve selected a few js-yaml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yann-yinn / nuxt-gustave / lib / yaml.js View on Github external
// boolean. Interpret includes from https://www.npmjs.com/package/yaml-include
    includes: false,
    // parse multiple documents
    multiple: false
  }
  options = { ...defaultOptions, ...options }
  try {
    let yamlOptions = {}
    if (options.includes === true) {
      yamlOptions = {
        schema: yamlinc.YAML_INCLUDE_SCHEMA
      }
    }
    let resource = null
    if (options.multiple) {
      resource = yaml.safeLoadAll(
        fs.readFileSync(filepath, 'utf8'),
        yamlOptions
      )

      resource = resource.map(r => {
        if (r) {
          r.$filename = path.basename(filepath)
          return r
        }
        return r
      })
    } else {
      resource = yaml.safeLoad(fs.readFileSync(filepath, 'utf8'), yamlOptions)
      resource.$filename = path.basename(filepath)
    }
    //console.log('filename', resource.$filename)
github IBM / kui / plugins / plugin-k8s / src / lib / controller / status.ts View on Github external
} else {
        return {
          headerRow: headerRow({ title: file }, file),
          entities: kubeEntities
        }
      }
    } else {
      // then the user has pointed us to a yaml file
      debug('status by file', file)

      // handle !spec
      const passedAsParameter = !isURL && filepath.match(/\/(!.*$)/)

      const { fetchFileString } = await import('../util/fetch-file')
      const specs: IKubeResource[] = (passedAsParameter
        ? parseYAML(execOptions.parameters[passedAsParameter[1].slice(1)]) // yaml given programatically
        : flatten((await fetchFileString(file)).map(_ => parseYAML(_))))
        .filter(_ => _) // in case there are empty paragraphs;
      debug('specs', specs)

      const kubeEntities = Promise.all(specs.map(spec => {
        return repl.qexec(`kubectl get "${spec.kind}" "${spec.metadata.name}" ${ns(spec)} -o json`,
          undefined, undefined, raw)
          .catch(errorEntity(execOptions, spec, namespace))
      }))

      // make a table where the rows are the paragraphs in the yaml file
      if (execOptions.raw) {
        return kubeEntities
      } else {
        debug('kubeEntities', await kubeEntities)
        return {
github appcelerator / titanium_mobile / build / scons-removals.js View on Github external
async function checkFile(file) {
	const contents = await fs.readFile(file, 'utf8');
	// remove comments
	contents.replace(/\w*#.*/, '');
	const doc = await yaml.safeLoadAll(contents);
	const types = Array.isArray(doc) ? doc : [ doc ];
	// go through the types in the document, for each one, check top-level for deprecated
	// then check each property, event, method
	const arr = await Promise.all(types.map(t => checkType(t)));
	const flattened = [].concat(...arr);
	return flattened;
}
github Adjective-Object / markdown-live / server / document-types / structured-document.js View on Github external
function loadDocs(data) {
  // load handlebars template
  const docs = [];
  yaml.safeLoadAll(data, function pushDoc(doc) {
    docs.push(doc);
  });
  return docs;
}
github appcelerator / titanium_mobile / build / scons-deprecations.js View on Github external
async function checkFile(file) {
	const contents = await fs.readFile(file, 'utf8');
	// remove comments
	contents.replace(/\w*#.*/, '');
	const doc = await yaml.safeLoadAll(contents);
	const types = Array.isArray(doc) ? doc : [ doc ];
	// go through the types in the document, for each one, check top-level for deprecated
	// then check each property, event, method
	const arr = await Promise.all(types.map(t => checkType(t)));
	const flattened = [].concat(...arr);
	return flattened;
}
github Azure / vscode-kubernetes-tools / src / extension.ts View on Github external
function findKindNamesForText(text: string): Errorable {
    try {
        const objs: {}[] = yaml.safeLoadAll(text);
        if (objs.some((o) => !isKubernetesResource(o))) {
            if (objs.length === 1) {
                return { succeeded: false, error: ['the open document is not a Kubernetes resource'] };
            }
            return { succeeded: false, error: ['the open document contains an item which is not a Kubernetes resource'] };
        }
        const kindNames = objs
            .map((o) => o as KubernetesResource)
            .map((obj) => ({
                kind: obj.kind.toLowerCase(),
                resourceName: obj.metadata.name,
                namespace: obj.metadata.namespace
            }));
        return { succeeded: true, result: kindNames };
    } catch (ex) {
        console.log(ex);
github atomist / sdm-core / lib / goal / container / repositoryDrivenContainer.ts View on Github external
public async plan(pli: PushListenerInvocation, goals: Goals): Promise {
        const configYamls = (await pli.project.getFiles(".atomist/*goals.{yml,yaml}"))
            .sort((f1, f2) => f1.path.localeCompare(f2.path));

        const plan: PlannedGoals = {};
        for (const configYaml of configYamls) {
            const configs = yaml.safeLoadAll(await configYaml.getContent());

            for (const config of configs) {

                for (const k in config) {

                    if (config.hasOwnProperty(k)) {
                        const value = config[k];
                        const v = camelcaseKeys(value, { deep: true }) as any;
                        const test = and(...toArray(await mapTests(v.test, this.tests, {})));
                        if (await test.mapping(pli)) {
                            const plannedGoals = toArray(mapGoals(v.goals, {}));
                            plan[k] = {
                                goals: plannedGoals,
                                dependsOn: v.dependsOn,
                            };
                        }
github Azure / k8s-actions / k8s-deploy / src / run.ts View on Github external
manifests.forEach((manifest) => {
        let content = fs.readFileSync(manifest).toString();
        yaml.safeLoadAll(content, async function (inputObject: any) {
            if (!!inputObject.kind && !!inputObject.metadata && !!inputObject.metadata.name) {
                let kind: string = inputObject.kind;
                switch (kind.toLowerCase()) {
                    case 'deployment':
                    case 'daemonset':
                    case 'statefulset':
                        await checkRolloutStatus(inputObject.metadata.name, kind, namespace);
                        break;
                    default:
                        core.debug(`No rollout check for kind: ${inputObject.kind}`)
                }
            }
        });
    });
}
github replicatedhq / ship / web / init / src / components / kustomize / kustomize_overlay / KustomizeOverlay.jsx View on Github external
createOverlay = () => {
    const { selectedFile } = this.state;
    let file = find(this.props.fileContents, ["key", selectedFile]);
    if (!file) return;
    const files = yaml.safeLoadAll(file.baseContent);
    let overlayFields = map(files, (file) => {
      return pick(file, "apiVersion", "kind", "metadata.name")
    });
    if (files.length === 1) {
      overlayFields = overlayFields[0];
    }
    const overlay = yaml.safeDump(overlayFields);
    this.setState({ patch: `--- \n${overlay}` });
  }