gcp-platforms-auto 0.2.0__tar.gz
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.
- gcp_platforms_auto-0.2.0/PKG-INFO +17 -0
- gcp_platforms_auto-0.2.0/README.md +1 -0
- gcp_platforms_auto-0.2.0/gcp_platforms_auto.egg-info/PKG-INFO +17 -0
- gcp_platforms_auto-0.2.0/gcp_platforms_auto.egg-info/SOURCES.txt +9 -0
- gcp_platforms_auto-0.2.0/gcp_platforms_auto.egg-info/dependency_links.txt +1 -0
- gcp_platforms_auto-0.2.0/gcp_platforms_auto.egg-info/requires.txt +4 -0
- gcp_platforms_auto-0.2.0/gcp_platforms_auto.egg-info/top_level.txt +1 -0
- gcp_platforms_auto-0.2.0/gcpro_auto/__init__.py +1 -0
- gcp_platforms_auto-0.2.0/gcpro_auto/git.py +84 -0
- gcp_platforms_auto-0.2.0/pyproject.toml +25 -0
- gcp_platforms_auto-0.2.0/setup.cfg +4 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: gcp_platforms_auto
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: A brief description of your package
|
|
5
|
+
Author-email: ofir4858 <ofirshasha10@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.6
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
Requires-Dist: requests
|
|
13
|
+
Requires-Dist: pyjwt
|
|
14
|
+
Requires-Dist: google-cloud-logging
|
|
15
|
+
Requires-Dist: gitpython
|
|
16
|
+
|
|
17
|
+
test
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
test
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: gcp_platforms_auto
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: A brief description of your package
|
|
5
|
+
Author-email: ofir4858 <ofirshasha10@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.6
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
Requires-Dist: requests
|
|
13
|
+
Requires-Dist: pyjwt
|
|
14
|
+
Requires-Dist: google-cloud-logging
|
|
15
|
+
Requires-Dist: gitpython
|
|
16
|
+
|
|
17
|
+
test
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
gcp_platforms_auto.egg-info/PKG-INFO
|
|
4
|
+
gcp_platforms_auto.egg-info/SOURCES.txt
|
|
5
|
+
gcp_platforms_auto.egg-info/dependency_links.txt
|
|
6
|
+
gcp_platforms_auto.egg-info/requires.txt
|
|
7
|
+
gcp_platforms_auto.egg-info/top_level.txt
|
|
8
|
+
gcpro_auto/__init__.py
|
|
9
|
+
gcpro_auto/git.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
gcpro_auto
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .git import get_github_app_token, generate_github_path, get_repo, git_push
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import time
|
|
3
|
+
import jwt
|
|
4
|
+
import google.cloud.logging
|
|
5
|
+
from git import Repo, NoSuchPathError
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
# Initialize Google Cloud Logging
|
|
9
|
+
client = google.cloud.logging.Client()
|
|
10
|
+
client.setup_logging()
|
|
11
|
+
|
|
12
|
+
# Configure the logger
|
|
13
|
+
logger = logging.getLogger("uvicorn")
|
|
14
|
+
logger.setLevel(logging.INFO)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def auth_payload():
|
|
18
|
+
return {
|
|
19
|
+
"iat": int(time.time()),
|
|
20
|
+
"exp": int(time.time()) + 600,
|
|
21
|
+
"iss": CLIENT_ID,
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def get_github_app_token(installation_id, secret):
|
|
26
|
+
encoded_jwt = jwt.encode(auth_payload(), secret, algorithm="RS256")
|
|
27
|
+
logger.info("Getting github token...")
|
|
28
|
+
auth_token = requests.post(
|
|
29
|
+
url=f"https://api.github.com/app/installations/{installation_id}/access_tokens",
|
|
30
|
+
headers={
|
|
31
|
+
"Accept": "application/vnd.github+json",
|
|
32
|
+
"Authorization": f"Bearer {encoded_jwt}",
|
|
33
|
+
},
|
|
34
|
+
).json()["token"]
|
|
35
|
+
logger.info("Successfully got github token.")
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def generate_github_path(username, password, org, repo):
|
|
39
|
+
return f"https://{username}:{password}@github.com/{org}/{repo}.git"
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def get_repo(path_of_git_repo, branch="main", path_to_local_repo="/tmp/repo"):
|
|
43
|
+
try:
|
|
44
|
+
if path_to_local_repo.exists():
|
|
45
|
+
logger.info("Pulling latest changes from the repository.")
|
|
46
|
+
repo = Repo(path_to_local_repo)
|
|
47
|
+
repo.remotes.origin.pull()
|
|
48
|
+
else:
|
|
49
|
+
logger.info("Cloning repository...")
|
|
50
|
+
repo = Repo.clone_from(
|
|
51
|
+
path_of_git_repo, str(path_to_local_repo), branch=branch
|
|
52
|
+
)
|
|
53
|
+
return repo
|
|
54
|
+
except NoSuchPathError:
|
|
55
|
+
logger.error("Repository path does not exist. Cloning fresh repository.")
|
|
56
|
+
return Repo.clone_from(path_of_git_repo, str(path_to_local_repo), branch=branch)
|
|
57
|
+
except Exception as e:
|
|
58
|
+
logger.exception(f"Error accessing repo: {str(e)}")
|
|
59
|
+
raise e
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def git_push(repo, commit_message, files_to_push=None):
|
|
63
|
+
try:
|
|
64
|
+
logger.info(f"Attempting to push changes to Git with commit message: '{commit_message}'")
|
|
65
|
+
if files_to_push:
|
|
66
|
+
logger.info(f"Adding specific files to commit: {files_to_push}")
|
|
67
|
+
repo.index.add(files_to_push)
|
|
68
|
+
else:
|
|
69
|
+
logger.info("Adding all changes to commit.")
|
|
70
|
+
repo.git.add(all=True)
|
|
71
|
+
logger.info(f"Committing changes with message: '{commit_message}'")
|
|
72
|
+
repo.index.commit(commit_message)
|
|
73
|
+
logger.info("Pushing changes to remote 'origin'")
|
|
74
|
+
push_info = repo.remote(name="origin").push()
|
|
75
|
+
for info in push_info:
|
|
76
|
+
if info.flags >0:
|
|
77
|
+
logger.info(f"Git push info: {info.summary}")
|
|
78
|
+
if info.flags == 0:
|
|
79
|
+
logger.info(f"Git push info: No update {info.summary}")
|
|
80
|
+
|
|
81
|
+
logger.info("Successfully pushed changes to Git.")
|
|
82
|
+
except Exception as e:
|
|
83
|
+
logger.exception(f"Error pushing to Git: {str(e)}")
|
|
84
|
+
raise e
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=42", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "gcp_platforms_auto"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "A brief description of your package"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
authors = [
|
|
11
|
+
{ name = "ofir4858", email = "ofirshasha10@gmail.com" }
|
|
12
|
+
]
|
|
13
|
+
license = { text = "MIT" }
|
|
14
|
+
dependencies = [
|
|
15
|
+
"requests",
|
|
16
|
+
"pyjwt",
|
|
17
|
+
"google-cloud-logging",
|
|
18
|
+
"gitpython"
|
|
19
|
+
]
|
|
20
|
+
classifiers = [
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"License :: OSI Approved :: MIT License",
|
|
23
|
+
"Operating System :: OS Independent"
|
|
24
|
+
]
|
|
25
|
+
requires-python = ">=3.6"
|