You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
2.4 KiB
56 lines
2.4 KiB
# Copyright (C) 2005-2024 Splunk Inc. All Rights Reserved.
|
|
import json
|
|
from ITOA.setup_logging import getLogger
|
|
import splunk.rest as rest
|
|
import splunk.bundle as bundle
|
|
import http.client
|
|
from .splunk_license_suitification_state_machine import SplunkLicenseSuitificationStateMachine
|
|
from feature_flagging.suite_content import SuiteContent
|
|
|
|
|
|
class CloudStateMaintainer(object):
|
|
"""
|
|
This class maintaines the state on cloud by keeping kvstore
|
|
in sync with changes in conf file settings
|
|
"""
|
|
|
|
def __init__(self, session_key):
|
|
self.logger = getLogger(logger_name="itsi.feature_flagging.CloudStateMaintainer")
|
|
self.session_key = session_key
|
|
|
|
def maintain_state(self):
|
|
self._validate_itsi_settings_and_markers_cloud()
|
|
|
|
def create_state_machine(self, state_name):
|
|
return SplunkLicenseSuitificationStateMachine.getCloudInstance(self.session_key, state_name)
|
|
|
|
def _validate_itsi_settings_and_markers_cloud(self):
|
|
try:
|
|
itsi_settings = bundle.getConf(confName="itsi_settings",
|
|
namespace="SA-ITOA",
|
|
owner="nobody",
|
|
sessionKey=self.session_key)
|
|
except Exception:
|
|
self.logger.exception('Failed to retrieve itsi_settings conf')
|
|
return self.create_state_machine(SuiteContent._UNRESTRICTED_SUITE)
|
|
|
|
if itsi_settings is None:
|
|
self.logger.warn("Missing itsi_settings conf")
|
|
return self.create_state_machine(SuiteContent._UNRESTRICTED_SUITE)
|
|
|
|
suite_configuration_stanza = itsi_settings.get("suite_configuration")
|
|
if suite_configuration_stanza is None:
|
|
self.logger.warn("Missing suite_configuration stanza")
|
|
return self.create_state_machine(SuiteContent._UNRESTRICTED_SUITE)
|
|
|
|
suite_level_attribute = suite_configuration_stanza.get("suite_level")
|
|
if suite_level_attribute is None:
|
|
self.logger.warn("Missing suite_level attribute")
|
|
return self.create_state_machine(SuiteContent._UNRESTRICTED_SUITE)
|
|
|
|
if not SuiteContent.is_known_suite(suite_level_attribute):
|
|
self.logger.warn("Suite {} is unknown".format(suite_level_attribute))
|
|
return self.create_state_machine(SuiteContent._UNRESTRICTED_SUITE)
|
|
|
|
return self.create_state_machine(suite_level_attribute)
|