def version(cloud_model, version): v = Version.normalize(version) if v in cloud_model: return cloud_model[v] cloud_model[v] = dict() return cloud_model[v]
def load_versioned_model(self, version, config_key, optional=False, alias=None): LOG.info('%s()' % KenLog.fcn()) v = Version.normalize(version) config_value = self._get_config_value(v, config_key) if not config_value and alias: LOG.warn("Use of %s is deprecated, use %s instead" % (alias, config_key)) config_value = self._get_config_value(v, alias) if config_value: cloud_model = CloudModel.version(self._models['CloudModel'], v) cloud_model[config_key] = config_value elif not optional: raise Exception('Could not load model key "%s"' % config_key)
def generate_value(instructions, models, controllers, name, value, payload=None): if not isinstance(value, str): return value if value.count('%') != 2: return value sp = StatePersistor(models, controllers, 'private_data.yml') if not instructions['refresh_passwords']: ri = sp.recall_info([name]) ri_e = HlmVariable.was_persisted_value_encrypted(sp, name) if ri and not ri_e: if 'encryption_key' in instructions: key = instructions['encryption_key'] secure_value = CPSecurity.encrypt(key, ri) HlmVariable.persist_value(sp, name, secure_value, True) return ri elif ri and ri_e: return HlmVariable.decrypt_value(ri, instructions) p1 = value.find('%') + 1 p2 = value.rfind('%') variable_type = value[p1:p2] version = instructions['model_version'] version = Version.normalize(version) if float(version) > 1.0: variable_type += '-%s' % version try: namespace = 'helion.configurationprocessor.variable' mgr = driver.DriverManager( namespace=namespace, name=variable_type, invoke_on_load=True, invoke_args=(instructions, models, controllers)) except RuntimeError as e: return value value = mgr.driver.calculate(payload) if not mgr.driver.ok: msg = '@@@@ Variable %s Failed to complete for name %s:\n' % ( variable_type, name) for e in mgr.driver.errors: msg += '@@@@ \t%s\n' % e print(msg) return None if 'encryption_key' in instructions: key = instructions['encryption_key'] secure_value = CPSecurity.encrypt(key, value) is_secure_val = True else: secure_value = value is_secure_val = False HlmVariable.persist_value(sp, name, secure_value, is_secure_val) return value
def version(self): return Version.normalize(Version.get( self._instructions['cloud_input_path']))
def generate_value(instructions, models, controllers, name, value, payload=None): if not isinstance(value, str): return value if value.count('%') != 2: return value sp = StatePersistor(models, controllers, 'private_data.yml') if not instructions['refresh_passwords']: ri = sp.recall_info([name]) ri_e = HlmVariable.was_persisted_value_encrypted(sp, name) if ri and not ri_e: if 'encryption_key' in instructions: key = instructions['encryption_key'] secure_value = CPSecurity.encrypt(key, ri) HlmVariable.persist_value(sp, name, secure_value, True) return ri elif ri and ri_e: return HlmVariable.decrypt_value(ri, instructions) p1 = value.find('%') + 1 p2 = value.rfind('%') variable_type = value[p1:p2] version = instructions['model_version'] version = Version.normalize(version) if float(version) > 1.0: variable_type += '-%s' % version try: namespace = 'helion.configurationprocessor.variable' mgr = driver.DriverManager(namespace=namespace, name=variable_type, invoke_on_load=True, invoke_args=(instructions, models, controllers)) except RuntimeError as e: return value value = mgr.driver.calculate(payload) if not mgr.driver.ok: msg = '@@@@ Variable %s Failed to complete for name %s:\n' % ( variable_type, name) for e in mgr.driver.errors: msg += '@@@@ \t%s\n' % e print(msg) return None if 'encryption_key' in instructions: key = instructions['encryption_key'] secure_value = CPSecurity.encrypt(key, value) is_secure_val = True else: secure_value = value is_secure_val = False HlmVariable.persist_value(sp, name, secure_value, is_secure_val) return value
def version(self): return Version.normalize( Version.get(self._instructions['cloud_input_path']))