Fix 1539: Add --skip-repo option for Helm
[osm/N2VC.git] / n2vc / config.py
index 59a74be..374ec73 100644 (file)
 #     See the License for the specific language governing permissions and
 #     limitations under the License.
 
 #     See the License for the specific language governing permissions and
 #     limitations under the License.
 
+import os
+import typing
+
+
+class EnvironConfig(dict):
+    prefixes = ["OSMLCM_VCA_", "OSMMON_VCA_"]
+
+    def __init__(self, prefixes: typing.List[str] = None):
+        if prefixes:
+            self.prefixes = prefixes
+        for key, value in os.environ.items():
+            if any(key.startswith(prefix) for prefix in self.prefixes):
+                self.__setitem__(self._get_renamed_key(key), value)
+
+    def _get_renamed_key(self, key: str) -> str:
+        for prefix in self.prefixes:
+            key = key.replace(prefix, "")
+        return key.lower()
+
+
 MODEL_CONFIG_KEYS = [
     "agent-metadata-url",
     "agent-stream",
 MODEL_CONFIG_KEYS = [
     "agent-metadata-url",
     "agent-stream",