Page MenuHomeDevCentral

D1875.id4736.diff
No OneTemporary

D1875.id4736.diff

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()
+ }
}
/* -------------------------------------------------------------
@@ -159,6 +173,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,17 @@
.get_all_repositories()
.into_json_response()
}
+
+#[get("/repository/findByLayer/<hash>")]
+pub fn find_repository_by_layer(hash: String) -> ApiJsonResponse<Vec<Repository>> {
+ 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>> {
+ Registry::with_default_location()
+ .get_repositories_by_image_hash(&hash)
+ .into_json_response()
+}

File Metadata

Mime Type
text/plain
Expires
Tue, Nov 26, 23:14 (20 h, 22 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2265224
Default Alt Text
D1875.id4736.diff (2 KB)

Event Timeline