Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3934825
D1875.id4738.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D1875.id4738.diff
View Options
diff --git a/src/app.rs b/src/app.rs
--- a/src/app.rs
+++ b/src/app.rs
@@ -11,6 +11,8 @@
get_registry_stats,
get_repository_info,
get_all_repositories,
+ find_repository_by_layer,
+ find_repository_by_image,
];
MinimalApplication::start_application(routes);
diff --git a/src/registry.rs b/src/registry.rs
--- a/src/registry.rs
+++ b/src/registry.rs
@@ -100,6 +100,20 @@
.filter_map(|name| self.get_repository(&name))
.collect()
}
+
+ pub fn get_repositories_by_layer_hash(&self, hash: &str) -> Vec<Repository> {
+ self.get_all_repositories()
+ .into_iter()
+ .filter(|repo| repo.has_layer(hash))
+ .collect()
+ }
+
+ pub fn get_repositories_by_image_hash(&self, hash: &str) -> Vec<Repository> {
+ self.get_all_repositories()
+ .into_iter()
+ .filter(|repo| repo.has_image(hash))
+ .collect()
+ }
}
/* -------------------------------------------------------------
@@ -132,6 +146,14 @@
RE.is_match(name) && name.len() <= 30
}
+ pub fn is_valid_hash(hash: &str) -> bool {
+ lazy_static! {
+ static ref RE: Regex = Regex::new("^[a-f0-9]+$").unwrap();
+ }
+
+ RE.is_match(hash) && hash.len() == 64
+ }
+
pub fn update_tags(&mut self) {
let path = Path::new(&self.directory).join("_manifests/tags");
@@ -159,6 +181,22 @@
Ok(buffer)
}
+
+ pub fn has_layer (&self, layer_hash_to_seek: &str) -> bool {
+ let path = Path::new(&self.directory).join("_layers/sha256");
+
+ get_subdirectories_names(&path)
+ .iter()
+ .any(|hash| hash == layer_hash_to_seek)
+ }
+
+ pub fn has_image (&self, image_hash_to_seek: &str) -> bool {
+ let path = Path::new(&self.directory).join("_manifests/revisions/sha256");
+
+ get_subdirectories_names(&path)
+ .iter()
+ .any(|hash| hash == image_hash_to_seek)
+ }
}
/* -------------------------------------------------------------
diff --git a/src/requests.rs b/src/requests.rs
--- a/src/requests.rs
+++ b/src/requests.rs
@@ -53,3 +53,25 @@
.get_all_repositories()
.into_json_response()
}
+
+#[get("/repository/findByLayer/<hash>")]
+pub fn find_repository_by_layer(hash: String) -> ApiJsonResponse<Vec<Repository>> {
+ if !Repository::is_valid_hash(&hash) {
+ return Err(build_bad_request_response())
+ }
+
+ Registry::with_default_location()
+ .get_repositories_by_layer_hash(&hash)
+ .into_json_response()
+}
+
+#[get("/repository/findByImage/<hash>")]
+pub fn find_repository_by_image(hash: String) -> ApiJsonResponse<Vec<Repository>> {
+ if !Repository::is_valid_hash(&hash) {
+ return Err(build_bad_request_response())
+ }
+
+ Registry::with_default_location()
+ .get_repositories_by_image_hash(&hash)
+ .into_json_response()
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 24, 06:26 (18 h, 33 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2313710
Default Alt Text
D1875.id4738.diff (2 KB)
Attached To
Mode
D1875: Find repositories by layer or image
Attached
Detach File
Event Timeline
Log In to Comment