How to use the msticpy.common.pkg_config function in msticpy

To help you get started, we’ve selected a few msticpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / msticpy / tests / unit_test_lib.py View on Github external
----------
    mp_path : Union[str, Path]
        Path to msticpy config yaml

    Yields
    ------
    Dict[str, Any]
        Custom settings.

    Raises
    ------
    FileNotFoundError
        If mp_path does not exist.

    """
    current_path = os.environ.get(pkg_config._CONFIG_ENV_VAR, "")
    if not Path(mp_path).is_file():
        raise FileNotFoundError(f"Setting MSTICPYCONFIG to non-existent file {mp_path}")
    try:
        os.environ[pkg_config._CONFIG_ENV_VAR] = str(mp_path)
        pkg_config.refresh_config()
        yield pkg_config.settings
    finally:
        os.environ[pkg_config._CONFIG_ENV_VAR] = current_path
        pkg_config.refresh_config()
github microsoft / msticpy / tests / unit_test_lib.py View on Github external
Yields
    ------
    Dict[str, Any]
        Custom settings.

    Raises
    ------
    FileNotFoundError
        If mp_path does not exist.

    """
    current_path = os.environ.get(pkg_config._CONFIG_ENV_VAR, "")
    if not Path(mp_path).is_file():
        raise FileNotFoundError(f"Setting MSTICPYCONFIG to non-existent file {mp_path}")
    try:
        os.environ[pkg_config._CONFIG_ENV_VAR] = str(mp_path)
        pkg_config.refresh_config()
        yield pkg_config.settings
    finally:
        os.environ[pkg_config._CONFIG_ENV_VAR] = current_path
        pkg_config.refresh_config()
github microsoft / msticpy / msticpy / common / secret_settings.py View on Github external
def _get_kv_vault_and_name(
        self, setting_path: str
    ) -> Tuple[Optional[str], Optional[str]]:
        """Return the vault and secret name for a config path."""
        setting_item = config.get_config_path(setting_path)

        if not isinstance(setting_item, dict):
            return None, str(setting_item)
        if "KeyVault" in setting_item:
            kv_val = setting_item.get("KeyVault")
            def_vault_name = self._kv_settings.get("VaultName")
            if not kv_val or kv_val.casefold() == "default":
                # If no value, get the default VaultName from settings
                # and use the setting path as the secret name
                if not def_vault_name:
                    raise ValueError("No VaultName defined in KeyVault settings.")
                secret_name = self.format_kv_name(setting_path)
                return def_vault_name, secret_name
            if "/" in kv_val:
                # '/' delimited string means VaultName/Secret
                vault_name, secret_name = kv_val.split("/")
github microsoft / msticpy / msticpy / sectools / domain_utils.py View on Github external
----------
    url : str
        The url a screenshot is wanted for.
    api_key : str (optional)
        Browshot API key. If not set msticpyconfig checked for this.

    Returns
    -------
    image_data: requests.models.Response
        The final screenshot request response data.

    """
    # Get Broshot API key from kwargs or config
    if api_key is not None:
        bs_api_key = api_key
    elif config.settings.get("Browshot") is not None:
        bs_api_key = config.settings.get("Browshot")["Args"]["AuthKey"]  # type: ignore
    else:
        raise AttributeError("No configuration found for Browshot")
    # Request screenshot from Browshot and get request ID
    id_string = f"https://api.browshot.com/api/v1/screenshot/create?url={url}/&instance_id=26&size=screen&cache=0&key={bs_api_key}"  # pylint: disable=line-too-long
    id_data = requests.get(id_string)
    bs_id = json.loads(id_data.content)["id"]
    status_string = (
        f"https://api.browshot.com/api/v1/screenshot/info?id={bs_id}&key={bs_api_key}"
    )
    image_string = f"https://api.browshot.com/api/v1/screenshot/thumbnail?id={bs_id}&zoom=50&key={bs_api_key}"  # pylint: disable=line-too-long
    # Wait until the screenshot is ready and keep user updated with progress
    print("Getting screenshot")
    progress = IntProgress(min=0, max=40)
    display.display(progress)
    ready = False
github microsoft / msticpy / msticpy / common / keyvault_client.py View on Github external
def __init__(self):
        """Initialize new instance of KeyVault Settings."""
        try:
            kv_config = config.get_config_path("KeyVault")
        except KeyError:
            warnings.warn("No KeyVault section found in msticpyconfig.yaml")
            kv_config = {}
        norm_settings = {key.casefold(): val for key, val in kv_config.items()}
        self.__dict__.update(norm_settings)
        if "authority_uri" in self:
            rev_lookup = {uri.casefold(): code for code, uri in self.AAD_AUTHORITIES}
            self.__dict__["authority"] = rev_lookup.get(
                self["authorityuri"].casefold(), "global"
            ).casefold()
github microsoft / msticpy / msticpy / common / provider_settings.py View on Github external
def reload_settings():
    """
    Reload settings from config files.

    Parameters
    ----------
    clear_keyring : bool, optional
        Clears any secrets cached in keyring, by default False

    """
    config.refresh_config()
github microsoft / msticpy / msticpy / common / wsconfig.py View on Github external
if not config_file:
            self._read_pkg_config_values(workspace_name=workspace)
            if self.config_loaded:
                return
            if Path("./config.json").exists():
                config_file = "./config.json"
            else:
                config_file = self._search_for_file("**/config.json")
        self._config_file = config_file
        #
        config = self._read_config_values(config_file)
        if config:
            self._config.update(config)
        else:
            os.environ["MSTICPYCONFIG"] = config_file
            pkg_config.refresh_config()
            self._read_pkg_config_values(workspace_name=workspace)