forked from anancarv/python-artifactory
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathartifact.py
More file actions
134 lines (90 loc) · 3.24 KB
/
Copy pathartifact.py
File metadata and controls
134 lines (90 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
"""
Definition of all artifact models.
"""
from __future__ import annotations
import hashlib
from datetime import datetime
from pathlib import Path
from typing import Any, Callable, Dict, List, Literal, Optional, Union
from pydantic import BaseModel
class Checksums(BaseModel):
"""Models a checksum."""
sha1: str
md5: str
sha256: str
@classmethod
def generate(cls, file_: Path) -> Checksums:
block_size: int = 65536
mapping: dict[str, Callable[[], Any]] = {"md5": hashlib.md5, "sha1": hashlib.sha1, "sha256": hashlib.sha256}
results = {}
for algorithm, hashing_function in mapping.items():
hasher = hashing_function()
with file_.absolute().open("rb") as fd:
buf = fd.read(block_size)
while len(buf) > 0:
hasher.update(buf)
buf = fd.read(block_size)
results[algorithm] = hasher.hexdigest()
return cls(**results)
class OriginalChecksums(BaseModel):
"""Models original checksums."""
sha256: Optional[str] = None
sha1: Optional[str] = None
md5: Optional[str] = None
class Child(BaseModel):
"""Models a child folder."""
uri: str
folder: bool
class ArtifactPropertiesResponse(BaseModel):
"""Models an artifact properties response."""
uri: str
properties: Dict[str, List[str]]
class ArtifactInfoResponseBase(BaseModel):
"""The base information available for both file and folder"""
repo: str
path: str
created: Optional[datetime] = None
createdBy: Optional[str] = None
lastModified: Optional[datetime] = None
modifiedBy: Optional[str] = None
lastUpdated: Optional[datetime] = None
uri: str
class ArtifactFolderInfoResponse(ArtifactInfoResponseBase):
"""Models an artifact folder info response."""
children: List[Child]
class ArtifactFileInfoResponse(ArtifactInfoResponseBase):
"""Models an artifact file info response."""
downloadUri: Optional[str] = None
remoteUrl: Optional[str] = None
mimeType: Optional[str] = None
size: Optional[int] = None
checksums: Optional[Checksums] = None
originalChecksums: Optional[OriginalChecksums] = None
class ArtifactListEntryResponse(BaseModel):
"""Base model for an entry in an artifact list response."""
uri: str
size: int
lastModified: datetime
folder: bool
class ArtifactListFolderResponse(ArtifactListEntryResponse):
"""Models a folder in an artifact list response."""
folder: Literal[True]
class ArtifactListFileResponse(ArtifactListEntryResponse):
"""Models a file in an artifact list response."""
folder: Literal[False]
sha1: Optional[str] = None
sha2: Optional[str] = None
class ArtifactListResponse(BaseModel):
"""Models an artifact list response."""
uri: str
created: datetime
files: List[Union[ArtifactListFileResponse, ArtifactListFolderResponse]]
class ArtifactStatsResponse(BaseModel):
"""Models an artifact statistics response."""
uri: str
downloadCount: int
lastDownloaded: int
lastDownloadedBy: Optional[str] = None
remoteDownloadCount: int
remoteLastDownloaded: int
ArtifactInfoResponse = Union[ArtifactFolderInfoResponse, ArtifactFileInfoResponse]