Verify the existance of a JSON assets manifest
342949
def has_manifest(app, filename='manifest.json'):
    ''''''
    try:
        return pkg_resources.resource_exists(app, filename)
    except ImportError:
        return os.path.isabs(filename) and os.path.exists(filename)
380840
def validate_manifest_deployments(manifest: Dict[str, Any]) -> None:
    
    if set(("contract_types", "deployments")).issubset(manifest):
        all_contract_types = list(manifest["contract_types"].keys())
        all_deployments = list(manifest["deployments"].values())
        all_deployment_names = extract_contract_types_from_deployments(all_deployments)
        missing_contract_types = set(all_deployment_names).difference(
            all_contract_types
        )
        if missing_contract_types:
            raise ValidationError(
                f"Manifest missing references to contracts: {missing_contract_types}."
            )
1118949
def verify_manifest_main_checksum(self, manifest):
        

        # NOTE: JAR spec does not state whether there can be >1 digest used,
        # and should the validator require any or all digests to match.
        # We allow mismatching digests and require just one to be correct.
        # We see no security risk: it is the signer of the .SF file
        # who shall check, what is being signed.
        for java_digest in self.keys_with_suffix("-Digest-Manifest"):
            whole_mf_digest = b64_encoded_digest(
                manifest.get_data(),
                _get_digest(java_digest))

            # It is enough for at least one digest to be correct
            if whole_mf_digest == self.get(java_digest + "-Digest-Manifest"):
                return True

        return False
646395
function() {
      var kalaboxYaml = path.join(dest, 'kalabox.yml');
      var pkgJson = path.join(dest, 'package.json');
      return fs.existsSync(kalaboxYaml) && fs.existsSync(pkgJson);
    }
1101124
function updateManifests() {
      function updateVersion( name ) {
        var _ = grunt.util._;
        var manifest = grunt.file.readJSON(name);

        manifest = JSON.stringify(_.extend(manifest, {version: grunt.option('version')}), null, 2);
        grunt.file.write(name, manifest);
      }
      return Q.fcall(function() {
        var files = [
          path.join('./', 'package.json'),
          path.join('./', 'bower.json')
        ];
        files.forEach(function(item){
          //grunt.log.ok(item);
          if ( existsFilePath(item) ) {
            updateVersion(item);
          }
        });
      });
    }
233951
function validate(manifest) {
  var errors = [];

  errors = validateEnum(manifest, 'dir', ENUM_DIR, errors);
  errors = validateLang(manifest, errors);

  [
    'name',
    'short_name',
    'description',
    'scope',
    'color',
    'background_color',
    'theme_color'
  ].forEach(function(member) {
    errors = validateString(manifest, member, errors);
  });

  errors = validateStartUrl(manifest, errors);
  errors = validateImages(manifest, 'icons', 'icon', errors);
  errors = validateImages(manifest, 'screenshots', 'screenshot', errors);
  errors = validateEnum(manifest, 'display', ENUM_DISPLAY, errors);
  errors = validateEnum(manifest, 'orientation', ENUM_ORIENTATION, errors);
  errors = validatePreferRelatedApplications(manifest, errors);
  errors = validatePreferredApplications(manifest, errors);

  errors = validateKnownProperties('manifest', manifest, MEMBERS, errors);

  return errors;
}
989587
def validate_asset_structure(asset_dir_path):
    
    log = logging.getLogger(mod_logger + '.validate_asset_structure')

    log.info('Validating asset directory: {d}'.format(d=asset_dir_path))

    # Ensure there is an asset.properties file
    asset_props = os.path.join(asset_dir_path, 'asset.properties')

    if not os.path.isfile(asset_props):
        raise Cons3rtAssetStructureError('Asset properties file not found: {f}'.format(f=asset_props))

    # Props to find
    install_script_rel_path = None
    doc_file_rel_path = None
    license_file_rel_path = None
    asset_type = None
    license_file_path = ''
    doc_file_path = ''
    asset_name = None

    log.info('Reading asset properties file: {f}'.format(f=asset_props))
    with open(asset_props, 'r') as f:
        for line in f:
            if line.strip().startswith('installScript='):
                install_script_name = line.strip().split('=')[1]
                install_script_rel_path = os.path.join('scripts', install_script_name)
            elif line.strip().startswith('documentationFile='):
                doc_file_rel_path = line.strip().split('=')[1]
            elif line.strip().startswith('licenseFile='):
                license_file_rel_path = line.strip().split('=')[1]
            elif line.strip().startswith('assetType='):
                asset_type = line.strip().split('=')[1]
                asset_type = asset_type.lower()
            elif line.strip().startswith('name='):
                asset_name = line.strip().split('=')[1]

    # Ensure a name was provided
    if asset_name is None:
        raise Cons3rtAssetStructureError('Required property [name] not found in asset properties file: {f}'.format(
            f=asset_props))
    if asset_name == '':
        raise Cons3rtAssetStructureError('Required property [name] found blank in asset properties file: {f}'.format(
            f=asset_props))

    # Ensure asset_type was provided
    if asset_type is None:
        raise Cons3rtAssetStructureError('Required property [asset_type] not found in asset properties '
                                         'file: {f}'.format(f=asset_props))
    if asset_type == '':
        raise Cons3rtAssetStructureError('Required property [asset_type] found blank in asset properties '
                                         'file: {f}'.format(f=asset_props))

    log.info('Found installScript={f}'.format(f=install_script_rel_path))
    log.info('Found assetType={f}'.format(f=asset_type))

    # Verify the doc file exists if specified
    if doc_file_rel_path:
        log.info('Found documentationFile={f}'.format(f=doc_file_rel_path))
        doc_file_path = os.path.join(asset_dir_path, doc_file_rel_path)
        if not os.path.isfile(doc_file_path):
            raise Cons3rtAssetStructureError('Documentation file not found: {f}'.format(f=doc_file_path))
        else:
            log.info('Verified documentation file: {f}'.format(f=doc_file_path))
    else:
        log.info('The documentationFile property was not specified in asset.properties')

    # Verify the license file exists if specified
    if license_file_rel_path:
        log.info('Found licenseFile={f}'.format(f=license_file_rel_path))
        license_file_path = os.path.join(asset_dir_path, license_file_rel_path)
        if not os.path.isfile(license_file_path):
            raise Cons3rtAssetStructureError('License file not found: {f}'.format(f=license_file_path))
        else:
            log.info('Verified license file: {f}'.format(f=license_file_path))
    else:
        log.info('The licenseFile property was not specified in asset.properties')

    if asset_type == 'software':
        if not install_script_rel_path:
            raise Cons3rtAssetStructureError('Software asset has an asset.properties missing the installScript '
                                             'prop: {f}'.format(f=asset_props))
        else:
            install_script_path = os.path.join(asset_dir_path, install_script_rel_path)
            if not os.path.isfile(install_script_path):
                raise Cons3rtAssetStructureError('Install script file not found: {f}'.format(f=install_script_path))
            else:
                log.info('Verified install script for software asset: {f}'.format(f=install_script_path))

    log.info('Checking items at the root of the asset directory...')
    for item in os.listdir(asset_dir_path):
        log.info('Checking item: {i}'.format(i=item))
        item_path = os.path.join(asset_dir_path, item)
        if item_path == license_file_path:
            continue
        elif item_path == doc_file_path:
            continue
        elif item_path == asset_props:
            continue
        elif item in ignore_items:
            continue
        elif ignore_by_extension(item_path=item_path):
            continue
        elif item in acceptable_dirs and os.path.isdir(item_path):
            continue
        else:
            if item == 'VERSION':
                os.remove(item_path)
                log.warn('Deleted file: {f}'.format(f=item_path))
            elif item == 'doc':
                raise Cons3rtAssetStructureError('Found a doc directory at the asset root, this is not allowed')
            elif item in potential_doc_files:
                if not doc_file_rel_path:
                    raise Cons3rtAssetStructureError('Documentation file found but not specified in '
                                                     'asset.properties: {f}'.format(f=item_path))
                else:
                    raise Cons3rtAssetStructureError('Extra documentation file found: {f}'.format(f=item_path))
            elif item in potential_license_files:
                if not license_file_rel_path:
                    raise Cons3rtAssetStructureError('License file found but not specified in '
                                                     'asset.properties: {f}'.format(f=item_path))
                else:
                    raise Cons3rtAssetStructureError('Extra license file found: {f}'.format(f=item_path))
            else:
                raise Cons3rtAssetStructureError('Found illegal item at the asset root dir: {i}'.format(i=item))
    log.info('Validated asset directory successfully: {d}'.format(d=asset_dir_path))
    return asset_name
1215973
function fileExists(fileName) {
        if (!fileName) {
            return false;
        }

        var filePath = PathUtils.resolveInRoot(outputFolder, fileName);
        return fs.existsSync(filePath);
    }
701505
def check_file_presence
      spec.icons.values.each do |path|
        fail_if_not_exist "Icon", path
      end

      if spec.browser_action
        fail_if_not_exist "Browser action popup", spec.browser_action.popup
        fail_if_not_exist "Browser action icon", spec.browser_action.icon
      end

      if spec.page_action
        fail_if_not_exist "Page action popup", spec.page_action.popup
        fail_if_not_exist "Page action icon", spec.page_action.icon
      end

      if spec.packaged_app
        fail_if_not_exist "App launch page", spec.packaged_app.page
      end

      spec.content_scripts.each do |content_script|
        content_script.javascripts.each do |script_path|
          fail_if_not_exist "Content script javascript", script_path
        end
        content_script.stylesheets.each do |style_path|
          fail_if_not_exist "Content script style", style_path
        end
      end

      spec.background_scripts.each do |script_path|
        fail_if_not_exist "Background script style", script_path
      end

      fail_if_not_exist "Background page", spec.background_page
      fail_if_not_exist "Options page", spec.options_page

      spec.web_intents.each do |web_intent|
        fail_if_not_exist "Web intent href", web_intent.href
      end

      spec.nacl_modules.each do |nacl_module|
        fail_if_not_exist "NaCl module", nacl_module.path
      end

      spec.web_accessible_resources.each do |path|
        fail_if_not_exist "Web accessible resource", path
      end
    end
815655
def is_json(self):
        
        mt = self.mimetype
        return (
            mt == "application/json"
            or mt.startswith("application/")
            and mt.endswith("+json")
        )
670747
function validateJSonStructure(filePath, cb) {
  fs.readFile(filePath, function(err, data) {
    if (err) {
      return cb(err);
    }

    try {
      var jsonObject = JSON.parse(data);
      cb(null, jsonObject);
    } catch (e) {
      cb('Invalid JSON file: ' + path.basename(filePath));
    }
  });
}
154369
function digestFromManifestStr(manifestStr) {
    assert.string(manifestStr, 'manifestStr');

    var hash = crypto.createHash('sha256');
    var digestPrefix = 'sha256:';

    var manifest;
    try {
        manifest = JSON.parse(manifestStr);
    } catch (err) {
        throw new restifyErrors.InvalidContentError(err, fmt(
            'could not parse manifest: %s', manifestStr));
    }
    if (manifest.schemaVersion === 1) {
        try {
            var manifestBuffer = Buffer(manifestStr);
            var jws = _jwsFromManifest(manifest, manifestBuffer);
            hash.update(jws.payload, 'binary');
            return digestPrefix + hash.digest('hex');
        } catch (verifyErr) {
            if (!(verifyErr instanceof restifyErrors.InvalidContentError)) {
                throw verifyErr;
            }
            // Couldn't parse (or doesn't have) the signatures section,
            // fall through.
        }
    }
    hash.update(manifestStr);
    return digestPrefix + hash.digest('hex');
}
1372222
function getJsonLicense (json) {
  var license = 'nomatch'
  if (typeof json === 'string') {
    license = matchLicense(json) || 'nomatch'
  } else {
    if (json.url) {
      license = { name: json.type, url: json.url }
    } else {
      license = matchLicense(json.type)
    }
  }
  return license
}
1080070
function jsonKeyExists(json, key) {
  var keys = key.split('.')
  var cur = json

  for (var i = 0; i < keys.length; i++) {
    try {
      cur = cur[keys[i]]
      if (cur === undefined) return false
    } catch(e) {
      return false
    }
  }

  return true
}
609207
function assetHashPath(url) {
  const parsedUrl = path.parse(url.getValue());
  const asset = manifest.getAssetValue(parsedUrl.base);
  return compiler.types.String('url("' + asset + '")');
}
150706
def _check_missing_manifests(self, segids):
    """"""
    manifest_paths = [ self._manifest_path(segid) for segid in segids ]
    with Storage(self.vol.layer_cloudpath, progress=self.vol.progress) as stor:
      exists = stor.files_exist(manifest_paths)

    dne = []
    for path, there in exists.items():
      if not there:
        (segid,) = re.search(r'(\d+):0$', path).groups()
        dne.append(segid)
    return dne
605540
function validate (rootPath) {
  var manifest;
  var webextensionManifest;

  var errors = {};

  try {
    manifest = JSON.parse(fs.readFileSync(join(rootPath, "package.json")));
  } catch (e) {
    errors.parsing = utils.getErrorMessage("COULD_NOT_PARSE") + "\n" + e.message;
    return errors;
  }

  if (!validateID(manifest)) {
    errors.id = utils.getErrorMessage("INVALID_ID");
  }

  if (!validateMain(rootPath)) {
    errors.main = utils.getErrorMessage("MAIN_DNE");
  }

  if (!validateTitle(manifest)) {
    errors.title = utils.getErrorMessage("INVALID_TITLE");
  }

  if (!validateName(manifest)) {
    errors.name = utils.getErrorMessage("INVALID_NAME");
  }

  if (!validateVersion(manifest)) {
    errors.version = utils.getErrorMessage("INVALID_VERSION");
  }

  // If both a package.json and a manifest.json files exists in the addon
  // root dir, raise an helpful error message that suggest to use web-ext instead.
  if (fs.existsSync(join(rootPath, "manifest.json"))) {
    errors.webextensionManifestFound = utils.getErrorMessage("WEBEXT_ERROR");
  }

  return errors;
}