Skip to content

Commit adb5aa8

Browse files
authored
Merge pull request #61 from Cosmo-Tech/LAL/Configuration_usage_normalization
Normalize usage of configuration class
2 parents 8924ec1 + 1262134 commit adb5aa8

87 files changed

Lines changed: 706 additions & 731 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/track_dependencies.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
push:
55
branches:
66
- main
7-
7+
88
jobs:
99
generate-sbom:
1010
runs-on: ubuntu-latest
@@ -28,4 +28,3 @@ jobs:
2828
apikey: ${{ secrets.DEPENDENCY_TRACK_API_KEY }}
2929
project: '8d39a492-bf9e-49fa-a58c-b391ed4a1243'
3030
bomfilename: 'sbom.json'
31-

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
include README.md
22
include LICENSE
33
graft cosmotech/orchestrator_plugins
4-
graft cosmotech/translation
4+
graft cosmotech/translation

cosmotech/coal/azure/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
This module provides functions for interacting with Azure services like Storage and ADX.
1212
"""
1313

14+
# Re-export blob functions for easier importing
15+
from cosmotech.coal.azure.blob import (
16+
dump_store_to_azure,
17+
)
18+
1419
# Re-export storage functions for easier importing
1520
from cosmotech.coal.azure.storage import (
1621
upload_file,
1722
upload_folder,
1823
)
19-
20-
# Re-export blob functions for easier importing
21-
from cosmotech.coal.azure.blob import (
22-
dump_store_to_azure,
23-
)

cosmotech/coal/azure/adx/__init__.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,36 @@
55
# etc., to any person is prohibited unless it has been previously and
66
# specifically authorized by written means by Cosmo Tech.
77

8-
from cosmotech.coal.azure.adx.auth import create_kusto_client, create_ingest_client, initialize_clients
9-
from cosmotech.coal.azure.adx.query import run_query, run_command_query
8+
from cosmotech.coal.azure.adx.auth import (
9+
create_ingest_client,
10+
create_kusto_client,
11+
initialize_clients,
12+
)
1013
from cosmotech.coal.azure.adx.ingestion import (
11-
ingest_dataframe,
12-
send_to_adx,
14+
IngestionStatus,
1315
check_ingestion_status,
14-
monitor_ingestion,
1516
handle_failures,
16-
IngestionStatus,
17+
ingest_dataframe,
18+
monitor_ingestion,
19+
send_to_adx,
1720
)
18-
from cosmotech.coal.azure.adx.tables import table_exists, create_table, check_and_create_table, _drop_by_tag
19-
from cosmotech.coal.azure.adx.utils import type_mapping, create_column_mapping
20-
from cosmotech.coal.azure.adx.store import send_pyarrow_table_to_adx, send_table_data, process_tables, send_store_to_adx
21+
from cosmotech.coal.azure.adx.query import run_command_query, run_query
2122
from cosmotech.coal.azure.adx.runner import (
22-
prepare_csv_content,
2323
construct_create_query,
2424
insert_csv_files,
25+
prepare_csv_content,
2526
send_runner_data,
2627
)
28+
from cosmotech.coal.azure.adx.store import (
29+
process_tables,
30+
send_pyarrow_table_to_adx,
31+
send_store_to_adx,
32+
send_table_data,
33+
)
34+
from cosmotech.coal.azure.adx.tables import (
35+
_drop_by_tag,
36+
check_and_create_table,
37+
create_table,
38+
table_exists,
39+
)
40+
from cosmotech.coal.azure.adx.utils import create_column_mapping, type_mapping

cosmotech/coal/azure/adx/ingestion.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,24 @@
55
# etc., to any person is prohibited unless it has been previously and
66
# specifically authorized by written means by Cosmo Tech.
77

8+
import os
9+
import time
810
from enum import Enum
9-
from typing import Dict
10-
from typing import Iterator
11-
from typing import List
12-
from typing import Optional
13-
from typing import Tuple
11+
from typing import Dict, Iterator, List, Optional, Tuple
1412

15-
import os
1613
import pandas as pd
17-
import time
1814
import tqdm
1915
from azure.kusto.data import KustoClient
2016
from azure.kusto.data.data_format import DataFormat
21-
from azure.kusto.ingest import IngestionProperties
22-
from azure.kusto.ingest import QueuedIngestClient
23-
from azure.kusto.ingest import ReportLevel
24-
from azure.kusto.ingest.status import FailureMessage
25-
from azure.kusto.ingest.status import KustoIngestStatusQueues
26-
from azure.kusto.ingest.status import SuccessMessage
17+
from azure.kusto.ingest import IngestionProperties, QueuedIngestClient, ReportLevel
18+
from azure.kusto.ingest.status import (
19+
FailureMessage,
20+
KustoIngestStatusQueues,
21+
SuccessMessage,
22+
)
2723
from cosmotech.orchestrator.utils.translate import T
2824

29-
from cosmotech.coal.azure.adx.tables import create_table, _drop_by_tag
25+
from cosmotech.coal.azure.adx.tables import _drop_by_tag, create_table
3026
from cosmotech.coal.azure.adx.utils import type_mapping
3127
from cosmotech.coal.utils.logger import LOGGER
3228

cosmotech/coal/azure/adx/query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
from azure.kusto.data import KustoClient
99
from azure.kusto.data.response import KustoResponseDataSet
10+
from cosmotech.orchestrator.utils.translate import T
1011

1112
from cosmotech.coal.utils.logger import LOGGER
12-
from cosmotech.orchestrator.utils.translate import T
1313

1414

1515
def run_query(client: KustoClient, database: str, query: str) -> KustoResponseDataSet:

cosmotech/coal/azure/adx/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
# etc., to any person is prohibited unless it has been previously and
66
# specifically authorized by written means by Cosmo Tech.
77

8-
import dateutil.parser
98
from typing import Any, Dict
109

10+
import dateutil.parser
1111
import pyarrow
12+
from cosmotech.orchestrator.utils.translate import T
1213

1314
from cosmotech.coal.utils.logger import LOGGER
14-
from cosmotech.orchestrator.utils.translate import T
1515

1616

1717
def create_column_mapping(data: pyarrow.Table) -> Dict[str, str]:

cosmotech/coal/azure/blob.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from cosmotech.orchestrator.utils.translate import T
2222

2323
from cosmotech.coal.store.store import Store
24+
from cosmotech.coal.utils.configuration import Configuration
2425
from cosmotech.coal.utils.logger import LOGGER
2526

2627
VALID_TYPES = (
@@ -31,42 +32,35 @@
3132

3233

3334
def dump_store_to_azure(
34-
store_folder: str,
35-
account_name: str,
36-
container_name: str,
37-
tenant_id: str,
38-
client_id: str,
39-
client_secret: str,
40-
output_type: str = "sqlite",
41-
file_prefix: str = "",
35+
configuration: Configuration = Configuration(),
4236
selected_tables: list[str] = [],
4337
) -> None:
4438
"""
4539
Dump Store data to Azure Blob Storage.
4640
4741
Args:
48-
store_folder: Folder containing the Store
49-
account_name: Azure Storage account name
50-
container_name: Azure Storage container name
51-
tenant_id: Azure tenant ID
52-
client_id: Azure client ID
53-
client_secret: Azure client secret
54-
output_type: Output file type (sqlite, csv, or parquet)
55-
file_prefix: Prefix for uploaded files
42+
configuration: Configuration utils class
43+
selected_tables: List of tables name
5644
5745
Raises:
5846
ValueError: If the output type is invalid
5947
"""
60-
_s = Store(store_location=store_folder)
48+
_s = Store(configuration=configuration)
49+
output_type = configuration.safe_get("azure.output_type", default="sqlite")
50+
file_prefix = configuration.safe_get("azure.file_prefix", default="")
6151

6252
if output_type not in VALID_TYPES:
6353
LOGGER.error(T("coal.common.validation.invalid_output_type").format(output_type=output_type))
6454
raise ValueError(T("coal.common.validation.invalid_output_type").format(output_type=output_type))
6555

6656
container_client = BlobServiceClient(
67-
account_url=f"https://{account_name}.blob.core.windows.net/",
68-
credential=ClientSecretCredential(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret),
69-
).get_container_client(container_name)
57+
account_url=f"https://{configuration.azure.account_name}.blob.core.windows.net/",
58+
credential=ClientSecretCredential(
59+
tenant_id=configuration.azure.tenant_id,
60+
client_id=configuration.azure.client_id,
61+
client_secret=configuration.azure.client_secret,
62+
),
63+
).get_container_client(configuration.azure.container_name)
7064

7165
def data_upload(data_stream: BytesIO, file_name: str):
7266
uploaded_file_name = file_prefix + file_name

cosmotech/coal/postgresql/runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def send_runner_metadata_to_postgresql(
6161
LOGGER.info(T("coal.services.postgresql.metadata"))
6262
sql_upsert = f"""
6363
INSERT INTO {schema_table} (id, name, last_csm_run_id, run_template_id)
64-
VALUES(%s, %s, %s, %s)
64+
VALUES ($1, $2, $3, $4)
6565
ON CONFLICT (id)
6666
DO
6767
UPDATE SET name = EXCLUDED.name, last_csm_run_id = EXCLUDED.last_csm_run_id;

cosmotech/coal/postgresql/store.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,27 @@ def dump_store_to_postgresql(
5353
selected_tables: list of tables to send
5454
fk_id: foreign key id to add to all table on all rows
5555
"""
56-
_c = Configuration()
57-
_c.postgres.host = postgres_host
58-
_c.postgres.port = postgres_port
59-
_c.postgres.db_name = postgres_db
60-
_c.postgres.db_schema = postgres_schema
61-
_c.postgres.user_name = postgres_user
62-
_c.postgres.user_password = postgres_password
63-
_c.postgres.password_encoding = force_encode
64-
_c.postgres.table_prefix = table_prefix
65-
66-
dump_store_to_postgresql_from_conf(
67-
configuration=_c, store_folder=store_folder, replace=replace, selected_tables=selected_tables, fk_id=fk_id
56+
_c = Configuration(
57+
{
58+
"coal": {"store": store_folder},
59+
"postgres": {
60+
"host": postgres_host,
61+
"port": postgres_port,
62+
"db_name": postgres_db,
63+
"db_schema": postgres_schema,
64+
"user_name": postgres_user,
65+
"user_password": postgres_password,
66+
"password_encoding": force_encode,
67+
"table_prefix": table_prefix,
68+
},
69+
}
6870
)
6971

72+
dump_store_to_postgresql_from_conf(configuration=_c, replace=replace, selected_tables=selected_tables, fk_id=fk_id)
73+
7074

7175
def dump_store_to_postgresql_from_conf(
7276
configuration: Configuration,
73-
store_folder: str,
7477
replace: bool = True,
7578
selected_tables: list[str] = [],
7679
fk_id: str = None,
@@ -80,13 +83,12 @@ def dump_store_to_postgresql_from_conf(
8083
8184
Args:
8285
configuration: coal Configuration
83-
store_folder: Folder containing the Store
8486
replace: Whether to replace existing tables
8587
selected_tables: list of tables to send
8688
fk_id: foreign key id to add to all table on all rows
8789
"""
8890
_psql = PostgresUtils(configuration)
89-
_s = Store(store_location=store_folder)
91+
_s = Store(configuration=configuration)
9092

9193
tables = list(_s.list_tables())
9294
if selected_tables:
@@ -104,7 +106,7 @@ def dump_store_to_postgresql_from_conf(
104106
f"""
105107
ALTER TABLE {table_name}
106108
ADD csm_run_id TEXT NOT NULL
107-
DEFAULT ('{fk_id})
109+
DEFAULT ('{fk_id}')
108110
"""
109111
)
110112
data = _s.get_table(table_name)

0 commit comments

Comments
 (0)