Skip to content

Commit

Permalink
python: lintage
Browse files Browse the repository at this point in the history
Signed-off-by: William Woodruff <william@trailofbits.com>
  • Loading branch information
woodruffw committed Dec 11, 2023
1 parent 8d8953a commit d5f4375
Show file tree
Hide file tree
Showing 13 changed files with 229 additions and 134 deletions.
21 changes: 13 additions & 8 deletions python/in_toto_attestation/predicates/link/v0/link_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 14 additions & 10 deletions python/in_toto_attestation/predicates/scai/v0/scai.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import in_toto_attestation.predicates.scai.v0.scai_pb2 as scaipb
from in_toto_attestation.v1.resource_descriptor import ResourceDescriptor

SCAI_PREDICATE_TYPE = 'https://in-toto.io/attestation/scai/attribute-report/'
SCAI_PREDICATE_VERSION = 'v0.2'
SCAI_PREDICATE_TYPE = "https://in-toto.io/attestation/scai/attribute-report/"
SCAI_PREDICATE_VERSION = "v0.2"


class AttributeAssertion:
def __init__(self, attribute, target=None, conditions=None, evidence=None) -> None:
self.pb = scaipb.AttributeAssertion()
self.pb = scaipb.AttributeAssertion() # type: ignore[attr-defined]
self.pb.attribute = attribute
if target:
self.pb.target.CopyFrom(target)
Expand All @@ -18,14 +19,14 @@ def __init__(self, attribute, target=None, conditions=None, evidence=None) -> No
self.pb.evidence.CopyFrom(evidence)

@staticmethod
def copy_from_pb(proto: type[scaipb.AttributeAssertion]) -> 'AttributeAssertion':
assertion = AttributeAssertion('tmp-attr')
def copy_from_pb(proto: type[scaipb.AttributeAssertion]) -> "AttributeAssertion": # type: ignore[name-defined]
assertion = AttributeAssertion("tmp-attr")
assertion.pb.CopyFrom(proto)
return assertion

def validate(self) -> None:
if len(self.pb.attribute) == 0:
raise ValueError('The attribute field is required')
raise ValueError("The attribute field is required")

# check any resource descriptors are valid
if self.pb.target.ByteSize() > 0:
Expand All @@ -36,22 +37,23 @@ def validate(self) -> None:
rd = ResourceDescriptor.copy_from_pb(self.pb.evidence)
rd.validate()


class AttributeReport:
def __init__(self, attributes: list, producer=None) -> None:
self.pb = scaipb.AttributeReport()
self.pb = scaipb.AttributeReport() # type: ignore[attr-defined]
self.pb.attributes.extend(attributes)
if producer:
self.pb.producer.CopyFrom(producer)

@staticmethod
def copy_from_pb(proto: type[scaipb.AttributeReport]) -> 'AttributeReport':
def copy_from_pb(proto: type[scaipb.AttributeReport]) -> "AttributeReport": # type: ignore[name-defined]
report = AttributeReport([None])
report.pb.CopyFrom(proto)
return report

def validate(self) -> None:
if len(self.pb.attributes) == 0:
raise ValueError('The attributes field is required')
raise ValueError("The attributes field is required")

# check any attribute assertions are valid
attributes = self.pb.attributes
Expand All @@ -63,7 +65,9 @@ def validate(self) -> None:
except ValueError as e:
# return index in the attributes list in case of failure:
# can't assume any other fields in attribute assertion are set
raise ValueError('Invalid attributes field (index: {0})'.format(i)) from e
raise ValueError(
"Invalid attributes field (index: {0})".format(i)
) from e

if self.pb.producer.ByteSize() > 0:
rd = ResourceDescriptor.copy_from_pb(self.pb.producer)
Expand Down
25 changes: 15 additions & 10 deletions python/in_toto_attestation/predicates/scai/v0/scai_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d5f4375

Please sign in to comment.