def reconcile(self, dry_run: bool, state: State): name_to_id_state = state.get_all("") page_provider = self.get_page_provider() # restore component ids from state for desired in self.components: desired.component_id = name_to_id_state.get(desired.name) # delete id_to_name_state = {v: k for k, v in name_to_id_state.items()} desired_component_names = [c.name for c in self.components] for current_id in page_provider.component_ids(): # if the component is known to the state management and if it is # not known to the desired state, it was once managed by this # integration but was delete from app-interface -> delete from page name_for_current_component = id_to_name_state.get(current_id) if (name_for_current_component and name_for_current_component not in desired_component_names): LOG.info(f"delete component {name_for_current_component} " f"from page {self.name}") page_provider.delete_component(dry_run, current_id) if not dry_run: state.rm(name_for_current_component) # create and update for desired in self.components: component_id = page_provider.apply_component(dry_run, desired) if component_id and desired.component_id != component_id: self._bind_component(dry_run, desired, component_id, state)
def rm(ctx, integration, key): settings = queries.get_app_interface_settings() accounts = queries.get_aws_accounts() state = State(integration, accounts, settings=settings) state.rm(key)