MCPcopy Create free account
hub / github.com/Keeper-Security/Commander / DockerSetupBase

Class DockerSetupBase

keepercommander/service/docker/setup_base.py:39–818  ·  view source on GitHub ↗

Base class for Docker setup with reusable core logic

Source from the content-addressed store, hash-verified

37
38
39class DockerSetupBase:
40 """Base class for Docker setup with reusable core logic"""
41
42 @staticmethod
43 def _is_owned_record(params, record_uid: str) -> bool:
44 """True when record_owner_cache marks the record as owned by this account."""
45 if not record_uid:
46 return False
47 owner_cache = getattr(params, 'record_owner_cache', None) or {}
48 owner = owner_cache.get(record_uid)
49 return bool(owner and owner.owner)
50
51 @staticmethod
52 def _is_owned_shared_folder(params, folder_uid: str) -> bool:
53 """True when the shared folder is owned by the current account."""
54 if not folder_uid:
55 return False
56 shared_folder = (getattr(params, 'shared_folder_cache', None) or {}).get(folder_uid)
57 if not shared_folder:
58 return False
59
60 owner_uid = shared_folder.get('owner_account_uid')
61 account_uid_bytes = getattr(params, 'account_uid_bytes', None)
62 if owner_uid and account_uid_bytes:
63 return owner_uid == utils.base64_url_encode(account_uid_bytes)
64
65 owner_username = shared_folder.get('owner_username')
66 if owner_username and getattr(params, 'user', None):
67 return owner_username.lower() == params.user.lower()
68 return False
69
70 @staticmethod
71 def _find_owned_ksm_app_by_title(params, app_name: str):
72 """Return an owned KSM app with this title, or None (ignores non-owned squats)."""
73 if not app_name:
74 return None
75 for rec_cache_val in (getattr(params, 'record_cache', None) or {}).values():
76 rec = KSMCommand._app_record_from_cache_entry(rec_cache_val)
77 if not rec:
78 continue
79 try:
80 title = json.loads(rec['data_unencrypted'].decode('utf-8')).get('title')
81 except Exception:
82 continue
83 if title == app_name and DockerSetupBase._is_owned_record(params, rec.get('record_uid')):
84 return rec
85 return None
86
87 @staticmethod
88 def resolve_commander_config_path(config_path: str = None, params=None) -> str:
89 """Resolve config.json using the same rules as login/shell startup."""
90 if config_path:
91 resolved = os.path.expanduser(config_path)
92 elif params and getattr(params, 'config_filename', None):
93 resolved = os.path.expanduser(params.config_filename)
94 else:
95 resolved = str(utils.get_default_path() / 'config.json')
96 return os.path.abspath(resolved)

Calls

no outgoing calls