commons-metrics 0.0.4__py3-none-any.whl → 0.0.6__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.
- commons_metrics/__init__.py +4 -2
- commons_metrics/database.py +39 -0
- commons_metrics/repositories.py +43 -0
- commons_metrics/util.py +8 -9
- {commons_metrics-0.0.4.dist-info → commons_metrics-0.0.6.dist-info}/METADATA +1 -1
- commons_metrics-0.0.6.dist-info/RECORD +10 -0
- commons_metrics-0.0.4.dist-info/RECORD +0 -8
- {commons_metrics-0.0.4.dist-info → commons_metrics-0.0.6.dist-info}/WHEEL +0 -0
- {commons_metrics-0.0.4.dist-info → commons_metrics-0.0.6.dist-info}/licenses/LICENSE +0 -0
- {commons_metrics-0.0.4.dist-info → commons_metrics-0.0.6.dist-info}/top_level.txt +0 -0
commons_metrics/__init__.py
CHANGED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import psycopg2
|
|
2
|
+
|
|
3
|
+
class DatabaseConnection:
|
|
4
|
+
"""
|
|
5
|
+
Class to handle PostgreSQL database connections
|
|
6
|
+
using AWS Secrets Manager credentials
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
def __init__(self):
|
|
10
|
+
self.connection = None
|
|
11
|
+
|
|
12
|
+
def connect(self, credentials):
|
|
13
|
+
"""Establishes database connection using credentials"""
|
|
14
|
+
try:
|
|
15
|
+
self.connection = psycopg2.connect(
|
|
16
|
+
host=credentials['host'],
|
|
17
|
+
port=credentials['port'],
|
|
18
|
+
database=credentials['dbname'],
|
|
19
|
+
user=credentials['username'],
|
|
20
|
+
password=credentials['password'],
|
|
21
|
+
connect_timeout=30
|
|
22
|
+
)
|
|
23
|
+
except Exception as e:
|
|
24
|
+
raise Exception(f"Database connection error: {str(e)}")
|
|
25
|
+
|
|
26
|
+
def close(self):
|
|
27
|
+
"""Closes the database connection"""
|
|
28
|
+
if self.connection and not self.connection.closed:
|
|
29
|
+
self.connection.close()
|
|
30
|
+
|
|
31
|
+
def commit_transaction(self):
|
|
32
|
+
"""Commits pending transactions"""
|
|
33
|
+
if self.connection and not self.connection.closed:
|
|
34
|
+
self.connection.commit()
|
|
35
|
+
|
|
36
|
+
def rollback_transaction(self):
|
|
37
|
+
"""Rolls back pending transactions in case of error"""
|
|
38
|
+
if self.connection and not self.connection.closed:
|
|
39
|
+
self.connection.rollback()
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
class ComponentRepository:
|
|
2
|
+
"""
|
|
3
|
+
Repository class for component-specific database operations
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
def __init__(self, db_connection):
|
|
7
|
+
"""
|
|
8
|
+
Initialize repository with database connection
|
|
9
|
+
"""
|
|
10
|
+
self.db = db_connection
|
|
11
|
+
|
|
12
|
+
def save_component(self, technical_name, id_type, status=1):
|
|
13
|
+
"""
|
|
14
|
+
Inserts a new component into schmesys.component table
|
|
15
|
+
|
|
16
|
+
Args:
|
|
17
|
+
technical_name (str): Technical name of the component
|
|
18
|
+
id_type (int): Component type ID
|
|
19
|
+
status (int): Component status (default: 1)
|
|
20
|
+
"""
|
|
21
|
+
cursor = None
|
|
22
|
+
try:
|
|
23
|
+
cursor = self.db.connection.cursor()
|
|
24
|
+
|
|
25
|
+
insert_query = """
|
|
26
|
+
INSERT INTO schmesys.component(technical_name, id_type, status)
|
|
27
|
+
VALUES (%s, %s, %s)
|
|
28
|
+
RETURNING id;
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
cursor.execute(insert_query, (technical_name, id_type, status))
|
|
32
|
+
component_id = cursor.fetchone()[0]
|
|
33
|
+
self.db.commit_transaction()
|
|
34
|
+
|
|
35
|
+
return component_id
|
|
36
|
+
|
|
37
|
+
except Exception as e:
|
|
38
|
+
self.db.rollback_transaction()
|
|
39
|
+
raise Exception(f"Error saving component '{technical_name}': {str(e)}")
|
|
40
|
+
finally:
|
|
41
|
+
if cursor:
|
|
42
|
+
cursor.close()
|
|
43
|
+
|
commons_metrics/util.py
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import boto3
|
|
2
2
|
import json
|
|
3
|
+
|
|
3
4
|
class Util:
|
|
5
|
+
"""Utility class for common operations"""
|
|
6
|
+
|
|
4
7
|
@staticmethod
|
|
5
|
-
def get_secret_aws(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
def get_secret_aws(secret_name: str, logger, region_name: str):
|
|
9
|
+
"""
|
|
10
|
+
Retrieves AWS Secrets Manager secret and returns database credentials
|
|
11
|
+
"""
|
|
9
12
|
try:
|
|
10
13
|
session = boto3.session.Session()
|
|
11
14
|
client = session.client(
|
|
@@ -31,9 +34,5 @@ class Util:
|
|
|
31
34
|
msg = f"Error getting the secret '{secret_name}': {str(e)}"
|
|
32
35
|
logger.error(msg)
|
|
33
36
|
raise Exception(msg)
|
|
34
|
-
|
|
35
|
-
@staticmethod
|
|
36
|
-
def show(env: str, logger):
|
|
37
|
-
print("Hola mundo")
|
|
38
|
-
print(f"Environment: {env}")
|
|
37
|
+
|
|
39
38
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
commons_metrics/__init__.py,sha256=W2Qz4cA0bOvTGIlf3R0eNMg6DJ8XhgK4eChf8gOyw8k,196
|
|
2
|
+
commons_metrics/data_base.py,sha256=7I9ywLqQMtTlK1uuubM8WrffwDsL9uyP3sygqanUQvQ,1439
|
|
3
|
+
commons_metrics/database.py,sha256=570TtLZ9psNzvIp75UFLYph34cKVEz6eGJgxXyRyjW4,1285
|
|
4
|
+
commons_metrics/repositories.py,sha256=JruFtcT3IOTOKn3euM67c0SZtJKmYVc07gN5dMAFSmw,1365
|
|
5
|
+
commons_metrics/util.py,sha256=98zuynalXumQRh-BB0Bcjyoh6vS2BTOUM8tVgr7iS9Q,1225
|
|
6
|
+
commons_metrics-0.0.6.dist-info/licenses/LICENSE,sha256=jsHZ2Sh1wCL74HC25pDDGXCyQ0xgsTAy62FvEnehKIg,1067
|
|
7
|
+
commons_metrics-0.0.6.dist-info/METADATA,sha256=-FNZi97I757Id2ukBPtK_PvJvq1SGtTvFdihDL75GSA,401
|
|
8
|
+
commons_metrics-0.0.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
9
|
+
commons_metrics-0.0.6.dist-info/top_level.txt,sha256=lheUN-3OKdU3A8Tg8Y-1IEB_9i_vVRA0g_FOiUsTQz8,16
|
|
10
|
+
commons_metrics-0.0.6.dist-info/RECORD,,
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
commons_metrics/__init__.py,sha256=RRtS7dpbGr6V0p2t_wGcqMOnyW1IxADMwo25i3BjKyU,64
|
|
2
|
-
commons_metrics/data_base.py,sha256=7I9ywLqQMtTlK1uuubM8WrffwDsL9uyP3sygqanUQvQ,1439
|
|
3
|
-
commons_metrics/util.py,sha256=H8lyVqfy73AvohCedBRoadpFnqRhGRiEnjI7b6tvg2w,1288
|
|
4
|
-
commons_metrics-0.0.4.dist-info/licenses/LICENSE,sha256=jsHZ2Sh1wCL74HC25pDDGXCyQ0xgsTAy62FvEnehKIg,1067
|
|
5
|
-
commons_metrics-0.0.4.dist-info/METADATA,sha256=bWcn6USQP6aqgq3Gferi-sv74yf5qlM805m2nVk2fpM,401
|
|
6
|
-
commons_metrics-0.0.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
7
|
-
commons_metrics-0.0.4.dist-info/top_level.txt,sha256=lheUN-3OKdU3A8Tg8Y-1IEB_9i_vVRA0g_FOiUsTQz8,16
|
|
8
|
-
commons_metrics-0.0.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|