| 335 | return Infra.from_proto(registry_proto.infra) |
| 336 | |
| 337 | def apply_entity(self, entity: Entity, project: str, commit: bool = True): |
| 338 | entity.is_valid() |
| 339 | |
| 340 | now = _utc_now() |
| 341 | if not entity.created_timestamp: |
| 342 | entity.created_timestamp = now |
| 343 | entity.last_updated_timestamp = now |
| 344 | |
| 345 | entity_proto = entity.to_proto() |
| 346 | entity_proto.spec.project = project |
| 347 | self._prepare_registry_for_changes(project) |
| 348 | assert self.cached_registry_proto |
| 349 | |
| 350 | for idx, existing_entity_proto in enumerate( |
| 351 | self.cached_registry_proto.entities |
| 352 | ): |
| 353 | if ( |
| 354 | existing_entity_proto.spec.name == entity_proto.spec.name |
| 355 | and existing_entity_proto.spec.project == project |
| 356 | ): |
| 357 | entity.created_timestamp = ( |
| 358 | existing_entity_proto.meta.created_timestamp.ToDatetime() |
| 359 | ) |
| 360 | entity_proto = entity.to_proto() |
| 361 | entity_proto.spec.project = project |
| 362 | del self.cached_registry_proto.entities[idx] |
| 363 | break |
| 364 | self.cached_registry_proto.entities.append(entity_proto) |
| 365 | if commit: |
| 366 | self.commit() |
| 367 | |
| 368 | def list_entities( |
| 369 | self, |