commons-metrics 0.0.3__py3-none-any.whl → 0.0.5__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,4 +1,5 @@
1
1
  from .util import Util
2
+ from .database import DatabaseConnection
2
3
 
3
- __all__ = ['Util']
4
- __version__ = '0.1.0'
4
+ __all__ = ['Util', 'DatabaseConnection']
5
+ __version__ = '0.0.5'
@@ -0,0 +1,45 @@
1
+ import psycopg2
2
+
3
+ class DataBase:
4
+ def __init__(self, db_name):
5
+ self.connection = None
6
+
7
+ def connect(self, host, port, dbname, user, password):
8
+ try:
9
+ self.connection = psycopg2.connect(
10
+ host=host,
11
+ port=port,
12
+ database=dbname,
13
+ user=user,
14
+ password=password,
15
+ connect_timeout=30
16
+ )
17
+
18
+ except Exception as e:
19
+ if self.connection:
20
+ self.connection.rollback()
21
+ msg = f"Database connection error: {str(e)}"
22
+ raise Exception(msg)
23
+
24
+ def disconnect(self):
25
+ if self.connectWWWion:
26
+ self.connection.close()
27
+
28
+ def save_component(technical_name, id_type):
29
+ try:
30
+ cursor = connection.cursor()
31
+ params_insert = (
32
+ technical_name,
33
+ id_type
34
+ )
35
+
36
+ #cursor.execute("select id_component into v_id_component from schmesys.component where technical_name = v_component_name;", params)
37
+ cursor.execute("INSERT INTO schmesys.component(technical_name,id_type) values (%s, %d);", params_insert)
38
+ except Exception as e:
39
+ if self.connection:
40
+ self.connection.rollback()
41
+ msg = f"Database connection error: {str(e)}"
42
+ raise Exception(msg)
43
+ finally:
44
+ if cursor:
45
+ cursor.close()
@@ -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()
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(env: str, logger):
6
- secret_name = f"nu0051005-measurement-systems-{env}-mesysqcd-secretrds-cnx1"
7
- region_name = "us-east-1"
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,7 +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")
37
+
38
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: commons_metrics
3
- Version: 0.0.3
3
+ Version: 0.0.5
4
4
  Summary: A simple library for basic statistical calculations
5
5
  Author: Bancolombia
6
6
  Author-email: omar.david.pino@email.com
@@ -0,0 +1,9 @@
1
+ commons_metrics/__init__.py,sha256=vbEyX-oQv35rlSa0zSi-4CacNpyoCqxsedHAzDKQtwU,127
2
+ commons_metrics/data_base.py,sha256=7I9ywLqQMtTlK1uuubM8WrffwDsL9uyP3sygqanUQvQ,1439
3
+ commons_metrics/database.py,sha256=570TtLZ9psNzvIp75UFLYph34cKVEz6eGJgxXyRyjW4,1285
4
+ commons_metrics/util.py,sha256=98zuynalXumQRh-BB0Bcjyoh6vS2BTOUM8tVgr7iS9Q,1225
5
+ commons_metrics-0.0.5.dist-info/licenses/LICENSE,sha256=jsHZ2Sh1wCL74HC25pDDGXCyQ0xgsTAy62FvEnehKIg,1067
6
+ commons_metrics-0.0.5.dist-info/METADATA,sha256=6xfET92d3JXR9fRdIE5gGJZ2D2tRKxzYVo4CHcC-XvU,401
7
+ commons_metrics-0.0.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
+ commons_metrics-0.0.5.dist-info/top_level.txt,sha256=lheUN-3OKdU3A8Tg8Y-1IEB_9i_vVRA0g_FOiUsTQz8,16
9
+ commons_metrics-0.0.5.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- commons_metrics/__init__.py,sha256=EqBumKI85i-qgaT_d7Vw_IWiKg7ARdY642aw3gLnMBI,64
2
- commons_metrics/util.py,sha256=qxpXQOPBSh2jD8try1nD8fRRdyZwMAZWQQKFT6XajSU,1249
3
- commons_metrics-0.0.3.dist-info/licenses/LICENSE,sha256=jsHZ2Sh1wCL74HC25pDDGXCyQ0xgsTAy62FvEnehKIg,1067
4
- commons_metrics-0.0.3.dist-info/METADATA,sha256=L7lny4AYLCNf_gIa4_F9DUy-WqlfXzfMvFiqZCoHxgs,401
5
- commons_metrics-0.0.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
6
- commons_metrics-0.0.3.dist-info/top_level.txt,sha256=lheUN-3OKdU3A8Tg8Y-1IEB_9i_vVRA0g_FOiUsTQz8,16
7
- commons_metrics-0.0.3.dist-info/RECORD,,