Repository: equinor/fmu-dataio

Issue:
`load_global_config()` used for simple exports should return `GlobalConfiguration`
The simple exporters all use the utility method `load_global_config` to load the config from a path into a dictionary. This should return a `GlobalConfiguration` model instead. 

All simple exports require the config to be valid, this moves the validation up earlier - currently the config is validated just before the export.

This will ease the implementation of #1109 where we need to dig into this config.

Hints from issue comments:

Solution patch:
diff --git a/src/fmu/dataio/dataio.py b/src/fmu/dataio/dataio.py
index 1aae82cb5..1add38d86 100644
--- a/src/fmu/dataio/dataio.py
+++ b/src/fmu/dataio/dataio.py
@@ -28,7 +28,6 @@ from ._utils import (
     detect_inside_rms,  # dataio_examples,
     export_metadata_file,
     export_object_to_file,
-    prettyprint_dict,
     read_metadata_from_file,
     some_config_from_env,
 )
@@ -404,10 +403,7 @@ class ExportData:
     _rootpath: Path = field(default_factory=Path, init=False)
 
     def __post_init__(self) -> None:
-        assert isinstance(self.config, dict)
         logger.info("Running __post_init__ ExportData")
-        logger.debug("Global config is %s", prettyprint_dict(self.config))
-
         self._show_deprecations_or_notimplemented()
 
         self._fmurun = get_fmu_context_from_environment() is not None
diff --git a/src/fmu/dataio/export/rms/_utils.py b/src/fmu/dataio/export/rms/_utils.py
index 49fb8e8c3..211c75745 100644
--- a/src/fmu/dataio/export/rms/_utils.py
+++ b/src/fmu/dataio/export/rms/_utils.py
@@ -3,11 +3,14 @@ from __future__ import annotations
 from pathlib import Path
 from typing import TYPE_CHECKING, Any, Final
 
+import pydantic
 import xtgeo
 from packaging.version import parse as versionparse
 
 from fmu.dataio._logging import null_logger
+from fmu.dataio._models.fmu_results.global_configuration import GlobalConfiguration
 from fmu.dataio._utils import load_config_from_path
+from fmu.dataio.exceptions import ValidationError
 
 from ._conditional_rms_imports import import_rms_package
 
@@ -59,13 +62,34 @@ def get_rms_project_units(project: Any) -> str:
     return str(units)
 
 
-def load_global_config() -> dict[str, Any]:
+def load_global_config() -> GlobalConfiguration:
+    """Load the global config from standard path and return validated config."""
     if not CONFIG_PATH.exists():
         raise FileNotFoundError(
             "Could not detect the global config file at standard "
             f"location: {CONFIG_PATH}."
         )
-    return load_config_from_path(CONFIG_PATH)
+    config = load_config_from_path(CONFIG_PATH)
+    return validate_global_config(config)
+
+
+def validate_global_config(config: dict[str, Any]) -> GlobalConfiguration:
+    """Validate the input config using pydantic, raise error if invalid."""
+    try:
+        return GlobalConfiguration.model_validate(config)
+    except pydantic.ValidationError as err:
+        error_message = (
+            "When exporting standard_results it is required to have a valid config.\n"
+        )
+        if "masterdata" not in config:
+            error_message += (
+                "Follow the 'Getting started' steps to do necessary preparations: "
+                "https://fmu-dataio.readthedocs.io/en/latest/preparations.html "
+            )
+
+        raise ValidationError(
+            f"{error_message}\nDetailed information: \n{err}"
+        ) from err
 
 
 def validate_horizon_folder(project: Any, horizon_folder: str) -> None:


Test patch:
diff --git a/tests/test_export_rms/test_utils.py b/tests/test_export_rms/test_utils.py
index dce326e2d..d4e81b55d 100644
--- a/tests/test_export_rms/test_utils.py
+++ b/tests/test_export_rms/test_utils.py
@@ -2,6 +2,8 @@ from unittest import mock
 
 import pytest
 
+from fmu.dataio._models.fmu_results.global_configuration import GlobalConfiguration
+
 
 def test_get_horizons_in_folder(mock_project_variable):
     from fmu.dataio.export.rms._utils import get_horizons_in_folder
@@ -132,3 +134,20 @@ def test_get_polygons_in_folder_all_empty(mock_project_variable):
 
     with pytest.raises(RuntimeError, match="only empty items"):
         get_polygons_in_folder(mock_project_variable, horizon_folder)
+
+
+def test_validate_global_config(mock_project_variable, globalconfig1):
+    from fmu.dataio.export.rms._utils import validate_global_config
+
+    config = validate_global_config(globalconfig1)
+    assert isinstance(config, GlobalConfiguration)
+
+
+def test_validate_global_config_invalid(mock_project_variable, globalconfig1):
+    from fmu.dataio.export.rms._utils import validate_global_config
+
+    invalid_config = globalconfig1.copy()
+    invalid_config.pop("masterdata")
+
+    with pytest.raises(ValueError, match="valid config"):
+        validate_global_config(invalid_config)