diff --git a/src/context/service/database/Component.py b/src/context/service/database/Component.py index 17d3cb9fffdc59fc913deaa68ddbaf3e6f4f3976..3f2776787570a85d8b090e3b20e47bd6c016e04b 100644 --- a/src/context/service/database/Component.py +++ b/src/context/service/database/Component.py @@ -40,16 +40,16 @@ def compose_components_data( dict_components : List[Dict] = list() for position,component in enumerate(components): str_kind = component.WhichOneof('config_rule') - message = (grpc_message_to_json_string(getattr(component, str_kind, {}))) - data = json.loads(message) - resource_key = data["resource_key"] + message = (grpc_message_to_json_string(getattr(component, str_kind, {}))) + data = json.loads(message) + resource_key = data["resource_key"] resource_value = data["resource_value"] if '/inventory' in resource_key: resource_value_data = json.loads(resource_value) - name = resource_value_data.pop('name', None) - type_ = resource_value_data.pop('class', None) - parent = resource_value_data.pop('parent-component-references', None) - attributes = resource_value_data.pop('attributes', {}) + name = resource_value_data.pop('name', None) + type_ = resource_value_data.pop('class', None) + parent = resource_value_data.pop('parent-component-references', None) + attributes = resource_value_data.pop('attributes', {}) if len(resource_value_data) > 0: LOGGER.warning('Discarding Component Leftovers: {:s}'.format(str(resource_value_data))) @@ -68,6 +68,5 @@ def compose_components_data( 'created_at' : now, 'updated_at' : now, } - LOGGER.debug('dict_component={:s}'.format(str(dict_component))) dict_components.append(dict_component) return dict_components diff --git a/src/context/service/database/ConfigRule.py b/src/context/service/database/ConfigRule.py index 8275a3ffe969f5c8728aaf70b7499202c57ead86..1c5a2c7d52a2ee6a98a199c9b11b6abcab2c4483 100644 --- a/src/context/service/database/ConfigRule.py +++ b/src/context/service/database/ConfigRule.py @@ -35,8 +35,6 @@ def compose_config_rules_data( dict_config_rules : List[Dict] = list() for position,config_rule in enumerate(config_rules): - #LOGGER.info("REQUEST") - #LOGGER.info(position,config_rule) str_kind = config_rule.WhichOneof('config_rule') kind = ConfigRuleKindEnum._member_map_.get(str_kind.upper()) # pylint: disable=no-member dict_config_rule = { diff --git a/src/context/service/database/models/ComponentModel.py b/src/context/service/database/models/ComponentModel.py index 964cb9bf3d2bbd28a79df76cb7c9e53b6a42e3ea..60927e944357fadc860cd9f0d98d4042939934cc 100644 --- a/src/context/service/database/models/ComponentModel.py +++ b/src/context/service/database/models/ComponentModel.py @@ -25,9 +25,9 @@ class ComponentModel(_Base): #Inherit component_uuid = Column(UUID(as_uuid=False), primary_key=True) #Unique identifier that serves as a primary key for this table device_uuid = Column(ForeignKey('device.device_uuid',ondelete='CASCADE' ), nullable=False, index=True) #Foreign Key relationship with the field device_uuid from the Device table (CASCADE' behavior for deletion, meaning when a device is deleted, its components will also be dele) name = Column(String, nullable=False) #String field that stores the name of the component - type = Column(String, nullable=False) #String field that stores the name of the component - attributes = Column(String, nullable=False) #String field that stores data about the component - parent = Column(String, nullable=False) #String field that stores data about the component + type = Column(String, nullable=False) #String field that stores the type of the component + attributes = Column(String, nullable=False) #String field that stores the attributes of the component + parent = Column(String, nullable=False) #String field that stores the parent of the component created_at = Column(DateTime, nullable=False) #Stores the creaton timestamp for the component updated_at = Column(DateTime, nullable=False) #Stores the last upadted timestamp for the component @@ -40,11 +40,12 @@ class ComponentModel(_Base): #Inherit } def dump(self) -> Dict: - data = json.loads(self.attributes) - data['component_uuid'] = {'uuid': self.component_uuid}, - data['name'] = self.name - data['type'] = self.type - data['parent'] = self.parent + data = dict() + data['attributes'] = json.loads(self.attributes) + data['component_uuid'] = {'uuid': self.component_uuid} + data['name'] = self.name + data['type'] = self.type + data['parent'] = self.parent return data def dump_name(self) -> Dict: