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.
53 lines
1.7 KiB
53 lines
1.7 KiB
# Copyright (C) 2005-2025 Splunk Inc. All Rights Reserved.
|
|
import sys
|
|
import time
|
|
import json
|
|
import http.client
|
|
from splunk.clilib.bundle_paths import make_splunkhome_path
|
|
|
|
import splunk.rest as rest
|
|
sys.path.append(make_splunkhome_path(['etc', 'apps', 'SA-ITOA', 'lib']))
|
|
from feature_flagging.ui_views import UIViews
|
|
|
|
from ITOA.setup_logging import getLogger
|
|
logger = getLogger(logger_name='itsi.feature_flagging.itsi_feature_compare')
|
|
|
|
|
|
class ServerInfoException(Exception):
|
|
pass
|
|
|
|
|
|
class ApiCommunicationException(Exception):
|
|
pass
|
|
|
|
|
|
class FeatureComparison(object):
|
|
"""
|
|
Class to compare features between page requested and available to license
|
|
"""
|
|
def should_render_license_upgrade_page(self, session_key, path):
|
|
rsp, content = rest.simpleRequest(
|
|
'/servicesNS/nobody/SA-ITOA/feature_flagging/features',
|
|
sessionKey=session_key,
|
|
raiseAllErrors=False,
|
|
getargs={'output_mode': 'json'}
|
|
)
|
|
if rsp.status == http.client.OK:
|
|
feature_enabled_dict = json.loads(content)
|
|
view_to_feature_dict = UIViews.view_to_feature()
|
|
if len(feature_enabled_dict) == 0:
|
|
e = ApiCommunicationException('Received response length of 0')
|
|
logger.exception(e)
|
|
raise e
|
|
else:
|
|
page_name = path.split('/')[-1]
|
|
page_required_feature = view_to_feature_dict.get(page_name)
|
|
if page_required_feature:
|
|
return not feature_enabled_dict[page_required_feature]
|
|
else:
|
|
return False
|
|
else:
|
|
e = ServerInfoException('Got bad status code %s - Aborting.' % rsp.status)
|
|
logger.exception(e)
|
|
raise e
|