def from_artifact_path(cls: Type["ArtifactReader"],
                        artifact_path: str) -> "ArtifactReader":
     """Create an ArtifactReader based on an artifact path. This either returns a
     FileArtifactReader or an S3ArtifactReader depending on the value of artifact_path"""
     if is_s3_uri(artifact_path):
         parse_s3_uri(artifact_path)
         return S3ArtifactReader()
     return FileArtifactReader()
Beispiel #2
0
 def __post_init__(self) -> None:
     if (self.scan.single_account_mode and not self.scan.scan_sub_accounts
             and self.access.accessor.multi_hop_accessors):
         raise InvalidConfigException(
             "Accessor config not supported for single account mode")
     if is_s3_uri(self.artifact_path):
         bucket, key_prefix = parse_s3_uri(self.artifact_path)
         if key_prefix is not None:
             raise InvalidConfigException(
                 f"S3 artifact_path should be s3://<bucket>, no key - got {self.artifact_path}"
             )
Beispiel #3
0
 def from_artifact_path(cls: Type["ArtifactReader"],
                        artifact_path: str) -> "ArtifactReader":
     """Create an ArtifactReader based on an artifact path. This either returns a
     FileArtifactReader or an S3ArtifactReader depending on the value of artifact_path"""
     if is_s3_uri(artifact_path):
         _, key_prefix = parse_s3_uri(artifact_path)
         if key_prefix is not None:
             raise ValueError(
                 f"S3 artifact path should be s3://<bucket>, no key - got {artifact_path}"
             )
         return S3ArtifactReader()
     return FileArtifactReader()
Beispiel #4
0
 def from_artifact_path(cls: Type["ArtifactWriter"], artifact_path: str,
                        scan_id: str) -> "ArtifactWriter":
     """Create an ArtifactWriter based on an artifact path. This either returns a FileArtifactWriter
     or an S3ArtifactWriter depending on the value of artifact_path"""
     if is_s3_uri(artifact_path):
         bucket, key_prefix = parse_s3_uri(artifact_path)
         if key_prefix is not None:
             raise ValueError(
                 f"S3 artifact path should be s3://<bucket>, no key - got {artifact_path}"
             )
         return S3ArtifactWriter(bucket=bucket, key_prefix=scan_id)
     return FileArtifactWriter(scan_id=scan_id,
                               output_dir=Path(artifact_path))
Beispiel #5
0
 def from_artifact_path(cls: Type["ArtifactWriter"], artifact_path: str,
                        scan_id: str) -> "ArtifactWriter":
     """Create an ArtifactWriter based on an artifact path. This either returns a FileArtifactWriter
     or an S3ArtifactWriter depending on the value of artifact_path"""
     if is_s3_uri(artifact_path):
         bucket, s3_uri_key_prefix = parse_s3_uri(artifact_path)
         if s3_uri_key_prefix is not None:
             key_prefix = "/".join((s3_uri_key_prefix, scan_id))
         else:
             key_prefix = scan_id
         return S3ArtifactWriter(bucket=bucket, key_prefix=key_prefix)
     return FileArtifactWriter(scan_id=scan_id,
                               output_dir=Path(artifact_path))
Beispiel #6
0
 def from_path(cls: Type["Config"], path: str) -> "Config":
     """Load a Config from an s3 uri or a  file"""
     if is_s3_uri(path):
         return cls.from_s3(s3_uri=path)
     return cls.from_file(filepath=Path(path))
Beispiel #7
0
 def __init__(self, **data: Any):
     super().__init__(**data)
     if is_s3_uri(self.artifact_path):
         parse_s3_uri(self.artifact_path)