MCPcopy Create free account
hub / github.com/aboutcode-org/vulnerablecode / snyk_constraints_satisfied

Function snyk_constraints_satisfied

vulntotal/vulntotal_utils.py:111–127  ·  view source on GitHub ↗

Return True or False depending on whether the given version satisfies the snyk constraint For example: >>> assert snyk_constraints_satisfied(">=4.0.0, <4.0.10.16", "4.0.10.15") == True >>> assert snyk_constraints_satisfied(" >=4.1.0, <4.4.15.7", "4.0.10.15") == False >>> assert

(snyk_constraint, version)

Source from the content-addressed store, hash-verified

109
110
111def snyk_constraints_satisfied(snyk_constraint, version):
112 """
113 Return True or False depending on whether the given version satisfies the snyk constraint
114 For example:
115 >>> assert snyk_constraints_satisfied(">=4.0.0, <4.0.10.16", "4.0.10.15") == True
116 >>> assert snyk_constraints_satisfied(" >=4.1.0, <4.4.15.7", "4.0.10.15") == False
117 >>> assert snyk_constraints_satisfied("[3.0.0,3.1.25)", "3.0.2") == True
118 """
119 snyk_constraints = snyk_constraint.strip().replace(" ", "")
120 constraints = snyk_constraints.split(",")
121 for constraint in constraints:
122 snyk_comparator, snyk_version = parse_constraint(constraint)
123 if not snyk_version:
124 continue
125 if not compare(GenericVersion(version), snyk_comparator, GenericVersion(snyk_version)):
126 return False
127 return True
128
129
130def gitlab_constraints_satisfied(gitlab_constraint, version):

Callers 1

is_purl_in_affectedFunction · 0.90

Calls 3

parse_constraintFunction · 0.85
GenericVersionClass · 0.85
compareFunction · 0.70

Tested by

no test coverage detected