File tree Expand file tree Collapse file tree 3 files changed +37
-0
lines changed
nisystemlink/clients/core/helpers Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ """Example to demonstrate reading the minion ID from the Salt configuration."""
2+
3+ from nisystemlink .clients .core .helpers import read_minion_id
4+
5+ # Read the minion ID from the Salt configuration file
6+ minion_id = read_minion_id ()
7+
8+ if minion_id :
9+ print (f"Minion ID: { minion_id } " )
10+ else :
11+ print ("Minion ID not found. Please ensure the SystemLink client is connected to the Server." )
Original file line number Diff line number Diff line change 11from ._iterator_file_like import IteratorFileLike
2+ from ._minion_id import read_minion_id
23
34# flake8: noqa
Original file line number Diff line number Diff line change 1+ # -*- coding: utf-8 -*-
2+
3+ """Helper function to get minion ID from Salt configuration."""
4+
5+ from typing import Optional
6+
7+ from nisystemlink .clients .core ._internal ._path_constants import PathConstants
8+
9+
10+ def read_minion_id () -> Optional [str ]:
11+ """Read the minion ID from the Salt configuration.
12+
13+ Returns:
14+ str | None: The minion ID content if the file exists, None otherwise.
15+ """
16+ minion_id_path = PathConstants .salt_data_directory / "conf" / "minion_id"
17+
18+ if not minion_id_path .exists ():
19+ return None
20+
21+ try :
22+ with open (minion_id_path , "r" , encoding = "utf-8" ) as fp :
23+ return fp .read ().strip ()
24+ except (OSError , PermissionError ):
25+ return None
You can’t perform that action at this time.
0 commit comments