Class which loads and resolves all the config values and returns a dictionary of resolved values which can be passed to the resource. It loads and resolves values in the following order: 1. Static values from /config.yaml file 2. Dynamic and or static values from /o
| 37 | |
| 38 | |
| 39 | class ContentPackConfigLoader(object): |
| 40 | """ |
| 41 | Class which loads and resolves all the config values and returns a dictionary of resolved values |
| 42 | which can be passed to the resource. |
| 43 | |
| 44 | It loads and resolves values in the following order: |
| 45 | |
| 46 | 1. Static values from <pack path>/config.yaml file |
| 47 | 2. Dynamic and or static values from /opt/stackstorm/configs/<pack name>.yaml file. |
| 48 | |
| 49 | Values are merged from left to right which means values from "<pack name>.yaml" file have |
| 50 | precedence and override values from pack local config file. |
| 51 | """ |
| 52 | |
| 53 | def __init__(self, pack_name, user=None): |
| 54 | self.pack_name = pack_name |
| 55 | self.user = user or cfg.CONF.system_user.user |
| 56 | |
| 57 | self.pack_path = content_utils.get_pack_base_path(pack_name=pack_name) |
| 58 | self._config_parser = ContentPackConfigParser(pack_name=pack_name) |
| 59 | |
| 60 | def get_config(self): |
| 61 | result = {} |
| 62 | |
| 63 | # Retrieve corresponding ConfigDB and ConfigSchemaDB object |
| 64 | # Note: ConfigSchemaDB is optional right now. If it doesn't exist, we assume every value |
| 65 | # is of a type string |
| 66 | try: |
| 67 | config_db = Config.get_by_pack(value=self.pack_name) |
| 68 | except StackStormDBObjectNotFoundError: |
| 69 | # Corresponding pack config doesn't exist. We set config_db to an empty config so |
| 70 | # that the default values from config schema are still correctly applied even if |
| 71 | # pack doesn't contain a config. |
| 72 | config_db = ConfigDB(pack=self.pack_name, values={}) |
| 73 | |
| 74 | try: |
| 75 | config_schema_db = ConfigSchema.get_by_pack(value=self.pack_name) |
| 76 | except StackStormDBObjectNotFoundError: |
| 77 | config_schema_db = None |
| 78 | |
| 79 | # 2. Retrieve values from "global" pack config file (if available) and resolve them if |
| 80 | # necessary |
| 81 | config = self._get_values_for_config( |
| 82 | config_schema_db=config_schema_db, config_db=config_db |
| 83 | ) |
| 84 | result.update(config) |
| 85 | |
| 86 | return result |
| 87 | |
| 88 | def _get_values_for_config(self, config_schema_db, config_db): |
| 89 | schema_values = getattr(config_schema_db, "attributes", {}) |
| 90 | config_values = getattr(config_db, "values", {}) |
| 91 | |
| 92 | config = copy.deepcopy(config_values or {}) |
| 93 | |
| 94 | # Assign dynamic config values based on the values in the datastore |
| 95 | config = self._assign_dynamic_config_values(schema=schema_values, config=config) |
| 96 |
no outgoing calls