MCPcopy Create free account
hub / github.com/dfinity/orbit / edit

Method edit

core/control-panel/impl/src/services/registry.rs:161–217  ·  view source on GitHub ↗

Updates the registry entry and returns it.

(
        &self,
        registry_id: &RegistryEntryId,
        input: RegistryEntryUpdateInput,
    )

Source from the content-addressed store, hash-verified

159
160 /// Updates the registry entry and returns it.
161 pub fn edit(
162 &self,
163 registry_id: &RegistryEntryId,
164 input: RegistryEntryUpdateInput,
165 ) -> ServiceResult<RegistryEntry> {
166 let mut entry = self.get(registry_id)?;
167
168 RegistryMapper::fill_from_update_input(&mut entry, &input);
169
170 let mut previous_artifact_id = None;
171 let mut new_artifact_id = None;
172
173 match (&input.value, &entry.value) {
174 (
175 Some(control_panel_api::RegistryEntryValueInput::WasmModule(module)),
176 RegistryValue::WasmModule(current_module),
177 ) => {
178 previous_artifact_id = Some(current_module.wasm_artifact_id);
179
180 let artifact_id = self.artifact_service.create(module.wasm_module.clone())?;
181
182 entry.value = RegistryValue::WasmModule(WasmModuleRegistryValue {
183 wasm_artifact_id: artifact_id,
184 version: module.version.clone(),
185 dependencies: module
186 .dependencies
187 .iter()
188 .map(|dep| dep.clone().into())
189 .collect(),
190 module_extra_chunks: module.module_extra_chunks.clone(),
191 });
192
193 new_artifact_id = Some(artifact_id);
194 }
195 (None, _) => (),
196 };
197
198 if let Err(err) = entry.validate() {
199 // Makes sure to remove the new artifact if the entry is invalid to avoid orphaned artifacts.
200 if let Some(artifact_id) = new_artifact_id {
201 self.artifact_service.remove_by_id(&artifact_id)?;
202 }
203
204 Err(err)?
205 }
206
207 // Remove the previous artifact if the new one is different.
208 if let Some(artifact_id) = previous_artifact_id {
209 self.artifact_service.remove_by_id(&artifact_id)?;
210 }
211
212 self.apply_single_latest_tag_across_entries(&entry);
213
214 self.registry_repository.insert(entry.id, entry.clone());
215
216 Ok(entry)
217 }
218

Callers 2

edit_registry_entryMethod · 0.45

Calls 8

mapMethod · 0.80
iterMethod · 0.80
remove_by_idMethod · 0.80
getMethod · 0.45
createMethod · 0.45
validateMethod · 0.45
insertMethod · 0.45

Tested by 1