# Copyright (C) 2005-2024 Splunk Inc. All Rights Reserved. from ITOA.itoa_object import ItoaObject from itsi.content_packs.constants import ContentPackFields class ItsiContentPackStatus(ItoaObject): ''' Implements ITSI Content Pack Status ''' log_prefix = '[ITSI Content Pack Status Update] ' collection_name = 'itsi_content_pack_status' def __init__(self, session_key, current_user_name): super(ItsiContentPackStatus, self).__init__(session_key, current_user_name, 'content_pack_status', collection_name=self.collection_name, title_validation_required=False) def update_content_pack_status(self, content_pack_key, version): """ Creates an entry for the specified content pack key if one does not exist. Otherwise, tries to update the installed_versions object in the existing entry. @param content_pack_key: key of the content pack being installed @type basestring @param version: version of the content pack being installed @type basestring :return: list of installed_versions """ content_pack = self.get('nobody', content_pack_key) if not content_pack: new_content_status = { ContentPackFields.VERSION_INSTALLED: [version], '_key': content_pack_key } self.save_batch( 'nobody', data_list=[new_content_status], validate_names=False ) return [version] else: if version not in content_pack[ContentPackFields.VERSION_INSTALLED]: content_pack[ContentPackFields.VERSION_INSTALLED].append(version) self.save_batch( 'nobody', data_list=[content_pack], is_partial_data=True, validate_names=False ) return content_pack[ContentPackFields.VERSION_INSTALLED]