kubernetes-watch 0.1.8__py3-none-any.whl → 0.1.10__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,15 @@
1
-
1
+ from prefect import get_run_logger
2
+ logger = get_run_logger()
2
3
 
3
4
  def dicts_has_diff(dict_a, dict_b):
4
5
  return dict_a != dict_b
5
6
 
6
7
 
7
8
  def remove_keys(d, keys):
8
- return {k: v for k, v in d.items() if k not in keys}
9
+ return {k: v for k, v in d.items() if k not in keys}
10
+
11
+
12
+ def print_data(data, indicator = None):
13
+ if indicator:
14
+ logger.info(indicator)
15
+ logger.info(data)
@@ -1,6 +1,6 @@
1
1
  from typing import Any, List, Dict
2
2
  from kube_watch.enums.logic import Operations
3
-
3
+ from copy import deepcopy
4
4
 
5
5
  def merge_logical_outputs(inp_dict: Dict):
6
6
  if 'operation' not in inp_dict.keys():
@@ -25,7 +25,8 @@ def partial_dict_update(orig_data, new_data):
25
25
  This function is used when some key value pairs in orig_data should
26
26
  be updated from new_data.
27
27
  """
28
+ orig_data_copy = deepcopy(orig_data)
28
29
  for k, v in new_data.items():
29
- orig_data[k] = v
30
+ orig_data_copy[k] = v
30
31
 
31
- return orig_data
32
+ return orig_data_copy
@@ -1,11 +1,16 @@
1
1
  import os
2
- from git import Repo
2
+ import shutil
3
+ import subprocess
4
+ import tempfile
5
+ from pathlib import Path
3
6
 
4
7
  from prefect import get_run_logger
5
8
 
6
9
  logger = get_run_logger()
7
10
 
8
- def clone_repo(git_pat, git_url, clone_base_path):
11
+
12
+ def clone_pat_repo(git_pat, git_url, clone_base_path):
13
+ """ Clone a Git repository using a Personal Access Token (PAT) for authentication."""
9
14
  # Retrieve environment variables
10
15
  access_token = git_pat # os.environ.get('GIT_PAT')
11
16
  repo_url = git_url # os.environ.get('GIT_URL')
@@ -30,4 +35,75 @@ def clone_repo(git_pat, git_url, clone_base_path):
30
35
  repo = Repo.clone_from(repo_url, repo_path)
31
36
  logger.info("Repository cloned successfully.")
32
37
  else:
33
- logger.info(f"Repository already exists at {repo_path}")
38
+ logger.info(f"Repository already exists at {repo_path}")
39
+
40
+
41
+ def clone_ssh_repo(
42
+ git_url: str,
43
+ clone_base_path: str,
44
+ repo_dir_name: str = "manifest-repo",
45
+ depth: int = 1,
46
+ ssh_key_env: str = "GIT_SSH_PRIVATE_KEY",
47
+ known_hosts_env: str = "GIT_SSH_KNOWN_HOSTS",
48
+ ) -> Path:
49
+ """
50
+ Clone/update a repo via SSH using key + known_hosts from env vars.
51
+ - GIT_SSH_PRIVATE_KEY: full private key (BEGIN/END ...)
52
+ - GIT_SSH_KNOWN_HOSTS: lines from `ssh-keyscan github.com`
53
+ """
54
+ if not git_url.startswith("git@"):
55
+ raise ValueError("git_url must be an SSH URL like 'git@github.com:org/repo.git'")
56
+
57
+ priv_key = os.environ.get(ssh_key_env)
58
+ kh_data = os.environ.get(known_hosts_env)
59
+ if not priv_key:
60
+ raise ValueError(f"Missing env var {ssh_key_env}")
61
+ if not kh_data:
62
+ raise ValueError(f"Missing env var {known_hosts_env}")
63
+
64
+ base = Path(clone_base_path).expanduser().resolve()
65
+ base.mkdir(parents=True, exist_ok=True)
66
+ repo_path = base / repo_dir_name
67
+
68
+ tmpdir = Path(tempfile.mkdtemp(prefix="git_ssh_"))
69
+ key_path = tmpdir / "id_rsa"
70
+ kh_path = tmpdir / "known_hosts"
71
+
72
+ try:
73
+ key_path.write_text(priv_key, encoding="utf-8")
74
+ kh_path.write_text(kh_data, encoding="utf-8")
75
+ try:
76
+ os.chmod(key_path, 0o600)
77
+ except PermissionError:
78
+ pass # ignore on platforms where chmod doesn't apply
79
+
80
+ # Note: no StrictModes here
81
+ ssh_cmd = (
82
+ f"ssh -i {key_path} -o IdentitiesOnly=yes "
83
+ f"-o UserKnownHostsFile={kh_path} "
84
+ f"-o StrictHostKeyChecking=yes"
85
+ )
86
+
87
+ env = os.environ.copy()
88
+ env["GIT_SSH_COMMAND"] = ssh_cmd
89
+
90
+ if not repo_path.exists():
91
+ cmd = ["git", "clone"]
92
+ if depth and depth > 0:
93
+ cmd += ["--depth", str(depth)]
94
+ cmd += [git_url, str(repo_path)]
95
+ subprocess.check_call(cmd, env=env)
96
+ else:
97
+ if not (repo_path / ".git").exists():
98
+ raise RuntimeError(f"Path exists but is not a git repo: {repo_path}")
99
+ subprocess.check_call(["git", "remote", "set-url", "origin", git_url], cwd=repo_path, env=env)
100
+ subprocess.check_call(["git", "fetch", "--all", "--prune"], cwd=repo_path, env=env)
101
+ subprocess.check_call(["git", "pull", "--ff-only", "origin"], cwd=repo_path, env=env)
102
+
103
+ return repo_path
104
+
105
+ finally:
106
+ try:
107
+ shutil.rmtree(tmpdir)
108
+ except Exception:
109
+ pass
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kubernetes-watch
3
- Version: 0.1.8
3
+ Version: 0.1.10
4
4
  Summary:
5
5
  Author: bmotevalli
6
6
  Author-email: b.motevalli@gmail.com
@@ -81,6 +81,14 @@ workflow:
81
81
  inputsArgType: arg
82
82
  conditional:
83
83
  tasks: ["Task_B"]
84
+
85
+ - name: Task_external
86
+ module: <module_external_path>
87
+ plugin_path: <path_to_module>
88
+ task: <func_name>
89
+ inputsArgType: arg
90
+ conditional:
91
+ tasks: ["Task_B"]
84
92
  ```
85
93
 
86
94
 
@@ -88,6 +96,10 @@ workflow:
88
96
 
89
97
  **module**: all modules are located in 'modules' directory in kube_watch. This is where you can extend the library and add new tasks / modules. Below modules, there are submodules such as providers, clusters, and logic. Within each of this submodules, specific modules are defined. For example: providers.aws contains a series of tasks related to AWS. In this case, <module_path> = providers.aws. To add new tasks, add a new module with a similar pattern and refer the path in your task block.
90
98
 
99
+ **plugin_path**: you can add new funtions outside the library without needing to modify this library. If plugin_path is defined, the
100
+ library assumes you are referring to a module outside the library (e.g. in your app or workflow). The plugin_path is path to your
101
+ py script (the folder). Then, provide your script name as module and function name as task.
102
+
91
103
  **task**: task is simply the name function that you put in the <module_path>. i.e. as you define a function in a module, you can simply start to use it in your manifests.
92
104
 
93
105
  **inputArgType**: arg | dict | list: if the task functions accept known-fixed number of parameters, then use arg.
@@ -14,23 +14,23 @@ kube_watch/modules/database/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMp
14
14
  kube_watch/modules/database/model.py,sha256=MWG9UW6g0KuBzW6MjzPBtknAk7GmuncQrdAq6HHarTo,207
15
15
  kube_watch/modules/database/postgre.py,sha256=1Sq2YFwgCJM_FWKabV2S1bFAIl2GBwytTtPCuLfVhu8,8182
16
16
  kube_watch/modules/logic/actions.py,sha256=hMvqqzR2EzcZ68_O8GdyLaPSLftA-tWAPaJnKdUMj-k,2416
17
- kube_watch/modules/logic/checks.py,sha256=2q4iNi3nOtGU_CMPIX_j3XY0krzE12fCZ_lAYifcJcA,150
17
+ kube_watch/modules/logic/checks.py,sha256=7tIR5ipZgnYsAI3ref0qfeFmzXpSyWJNclnO45OUizs,327
18
18
  kube_watch/modules/logic/load.py,sha256=XC-SsWIChhW-QXJeCGMsLuLsn9v5nRni5Y6utwYLt48,781
19
- kube_watch/modules/logic/merge.py,sha256=sRKm4aTYfNFZnrXceGRWdGPDyoaMcTp6XhAkazckpPU,895
19
+ kube_watch/modules/logic/merge.py,sha256=J3zOswXE0v3iy2rguDJrdPYKkEujZfA2s9QwjV_rjzU,971
20
20
  kube_watch/modules/logic/scheduler.py,sha256=fwUfj4hnYX3yCj6fdZyLvlJE8RTBWHnHOwJPrpNJ8hw,3443
21
21
  kube_watch/modules/logic/trasnform.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
22
  kube_watch/modules/mock/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
23
  kube_watch/modules/mock/mock_generator.py,sha256=BKKQFCxxQgFW_GFgeIbkyIbuNU4328xTTaFfTwFLsS8,1262
24
24
  kube_watch/modules/providers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
25
  kube_watch/modules/providers/aws.py,sha256=oly88Bihn-vR0NdOoCT-P1MNgPw8FLNfS1Ha4hc_4bc,8375
26
- kube_watch/modules/providers/git.py,sha256=Cb0iulruhd0vlmWiIqkowc1e5HVjoSFwE0jR1Ea9Cxo,1151
26
+ kube_watch/modules/providers/git.py,sha256=5d7vkeTbVD_XN-mpCoPTRmM6lwgrwkDwcCIsjqYwmaQ,3778
27
27
  kube_watch/modules/providers/github.py,sha256=eQY8sLy2U6bOWMpFxA73DFCPVuswhTXSG25KmYSuo5s,5212
28
28
  kube_watch/modules/providers/vault.py,sha256=etzzHbTrUDsTUpeUN-xg0Xh8ulqC0-1FA3tHRZinIOo,7193
29
29
  kube_watch/standalone/metarecogen/ckan_to_gn.py,sha256=LWd7ikyxRIC1IGt6CtALnDOEoyuG07a8NoDHhgMkX4o,4635
30
30
  kube_watch/watch/__init__.py,sha256=9KE0Sf1nLUTNaFvXbiQCgf11vpG8Xgmb5ddeMAmak3Q,88
31
31
  kube_watch/watch/helpers.py,sha256=8BQnQ6AeLHs0JEq54iKYDvWURb1F-kROJxwIcl_nv_Y,6276
32
32
  kube_watch/watch/workflow.py,sha256=CaXHFuEWVsFjBv5dU4IfVMeTlGJWyKaE1But9-YzVWk,9769
33
- kubernetes_watch-0.1.8.dist-info/LICENSE,sha256=_H2QdL-2dXbivDmOpJ11DnqJewSFhSJwGpHx_WAE-CA,1075
34
- kubernetes_watch-0.1.8.dist-info/METADATA,sha256=mloy8yyoPpvpKY1icFj0Mf_hC0kEjlybthnILlDJICc,5056
35
- kubernetes_watch-0.1.8.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
36
- kubernetes_watch-0.1.8.dist-info/RECORD,,
33
+ kubernetes_watch-0.1.10.dist-info/LICENSE,sha256=_H2QdL-2dXbivDmOpJ11DnqJewSFhSJwGpHx_WAE-CA,1075
34
+ kubernetes_watch-0.1.10.dist-info/METADATA,sha256=Fof5Cg1A--c2oCQ8VCrNb_GAeqw1rKjHMltZzjXurLY,5607
35
+ kubernetes_watch-0.1.10.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
36
+ kubernetes_watch-0.1.10.dist-info/RECORD,,