How to use the safety.errors.InvalidKeyError function in safety

To help you get started, we’ve selected a few safety 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 pyupio / safety / safety / cli.py View on Github external
vulns = safety.check(packages=packages, key=key, db_mirror=db, cached=cache, ignore_ids=ignore, proxy=proxy_dictionary)
        output_report = report(vulns=vulns, 
                               full=full_report, 
                               json_report=json, 
                               bare_report=bare,
                               checked_packages=len(packages), 
                               db=db, 
                               key=key)

        if output:
            with open(output, 'w+') as output_file:
                output_file.write(output_report)
        else:
            click.secho(output_report, nl=False if bare and not vulns else True)
        sys.exit(-1 if vulns else 0)
    except InvalidKeyError:
        click.secho("Your API Key '{key}' is invalid. See {link}".format(
            key=key, link='https://goo.gl/O7Y1rS'),
            fg="red",
            file=sys.stderr)
        sys.exit(-1)
    except DatabaseFileNotFoundError:
        click.secho("Unable to load vulnerability database from {db}".format(db=db), fg="red", file=sys.stderr)
        sys.exit(-1)
    except DatabaseFetchError:
        click.secho("Unable to load vulnerability database", fg="red", file=sys.stderr)
        sys.exit(-1)
github pypa / pipenv / pipenv / patched / safety / cli.py View on Github external
vulns = safety.check(packages=packages, key=key, db_mirror=db, cached=cache, ignore_ids=ignore, proxy=proxy_dictionary)
        output_report = report(vulns=vulns, 
                               full=full_report, 
                               json_report=json, 
                               bare_report=bare,
                               checked_packages=len(packages), 
                               db=db, 
                               key=key)

        if output:
            with open(output, 'w+') as output_file:
                output_file.write(output_report)
        else:
            click.secho(output_report, nl=False if bare and not vulns else True)
        sys.exit(-1 if vulns else 0)
    except InvalidKeyError:
        click.secho("Your API Key '{key}' is invalid. See {link}".format(
            key=key, link='https://goo.gl/O7Y1rS'),
            fg="red",
            file=sys.stderr)
        sys.exit(-1)
    except DatabaseFileNotFoundError:
        click.secho("Unable to load vulnerability database from {db}".format(db=db), fg="red", file=sys.stderr)
        sys.exit(-1)
    except DatabaseFetchError:
        click.secho("Unable to load vulnerability database", fg="red", file=sys.stderr)
        sys.exit(-1)
github pyupio / pyup / pyup / requirements.py View on Github external
def changelog(self):
        if self._changelog is None:
            self._changelog = OrderedDict()
            if settings.api_key:
                r = requests.get(
                    "https://pyup.io/api/v1/changelogs/{}/".format(self.key),
                    headers={"X-Api-Key": settings.api_key}
                )
                if r.status_code == 403:
                    raise InvalidKeyError
                if r.status_code == 200:
                    data = r.json()
                    if data:
                        # sort the changelog by release
                        sorted_log = sorted(
                            data.items(), key=lambda v: parse_version(v[0]), reverse=True)
                        # go over each release and add it to the log if it's within the "upgrade
                        # range" e.g. update from 1.2 to 1.3 includes a changelog for 1.2.1 but
                        # not for 0.4.
                        for version, log in sorted_log:
                            parsed_version = parse_version(version)
                            if self.is_pinned and parsed_version > parse_version(
                                self.version) and parsed_version <= parse_version(
                                    self.latest_version_within_specs):
                                self._changelog[version] = log
                            elif not self.is_pinned and parsed_version <= parse_version(
github pyupio / safety / safety / safety.py View on Github external
if key:
        headers["X-Api-Key"] = key

    if cached:
        cached_data = get_from_cache(db_name=db_name)
        if cached_data:
            return cached_data
    url = mirror + db_name
    r = requests.get(url=url, timeout=REQUEST_TIMEOUT, headers=headers, proxies=proxy)
    if r.status_code == 200:
        data = r.json()
        if cached:
            write_to_cache(db_name, data)
        return data
    elif r.status_code == 403:
        raise InvalidKeyError()