bb-integrations-library 3.0.11__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.
- bb_integrations_lib/__init__.py +0 -0
- bb_integrations_lib/converters/__init__.py +0 -0
- bb_integrations_lib/gravitate/__init__.py +0 -0
- bb_integrations_lib/gravitate/base_api.py +20 -0
- bb_integrations_lib/gravitate/model.py +29 -0
- bb_integrations_lib/gravitate/pe_api.py +122 -0
- bb_integrations_lib/gravitate/rita_api.py +552 -0
- bb_integrations_lib/gravitate/sd_api.py +572 -0
- bb_integrations_lib/gravitate/testing/TTE/sd/models.py +1398 -0
- bb_integrations_lib/gravitate/testing/TTE/sd/tests/test_models.py +2987 -0
- bb_integrations_lib/gravitate/testing/__init__.py +0 -0
- bb_integrations_lib/gravitate/testing/builder.py +55 -0
- bb_integrations_lib/gravitate/testing/openapi.py +70 -0
- bb_integrations_lib/gravitate/testing/util.py +274 -0
- bb_integrations_lib/mappers/__init__.py +0 -0
- bb_integrations_lib/mappers/prices/__init__.py +0 -0
- bb_integrations_lib/mappers/prices/model.py +106 -0
- bb_integrations_lib/mappers/prices/price_mapper.py +127 -0
- bb_integrations_lib/mappers/prices/protocol.py +20 -0
- bb_integrations_lib/mappers/prices/util.py +61 -0
- bb_integrations_lib/mappers/rita_mapper.py +523 -0
- bb_integrations_lib/models/__init__.py +0 -0
- bb_integrations_lib/models/dtn_supplier_invoice.py +487 -0
- bb_integrations_lib/models/enums.py +28 -0
- bb_integrations_lib/models/pipeline_structs.py +76 -0
- bb_integrations_lib/models/probe/probe_event.py +20 -0
- bb_integrations_lib/models/probe/request_data.py +431 -0
- bb_integrations_lib/models/probe/resume_token.py +7 -0
- bb_integrations_lib/models/rita/audit.py +113 -0
- bb_integrations_lib/models/rita/auth.py +30 -0
- bb_integrations_lib/models/rita/bucket.py +17 -0
- bb_integrations_lib/models/rita/config.py +188 -0
- bb_integrations_lib/models/rita/constants.py +19 -0
- bb_integrations_lib/models/rita/crossroads_entities.py +293 -0
- bb_integrations_lib/models/rita/crossroads_mapping.py +428 -0
- bb_integrations_lib/models/rita/crossroads_monitoring.py +78 -0
- bb_integrations_lib/models/rita/crossroads_network.py +41 -0
- bb_integrations_lib/models/rita/crossroads_rules.py +80 -0
- bb_integrations_lib/models/rita/email.py +39 -0
- bb_integrations_lib/models/rita/issue.py +63 -0
- bb_integrations_lib/models/rita/mapping.py +227 -0
- bb_integrations_lib/models/rita/probe.py +58 -0
- bb_integrations_lib/models/rita/reference_data.py +110 -0
- bb_integrations_lib/models/rita/source_system.py +9 -0
- bb_integrations_lib/models/rita/workers.py +76 -0
- bb_integrations_lib/models/sd/bols_and_drops.py +241 -0
- bb_integrations_lib/models/sd/get_order.py +301 -0
- bb_integrations_lib/models/sd/orders.py +18 -0
- bb_integrations_lib/models/sd_api.py +115 -0
- bb_integrations_lib/pipelines/__init__.py +0 -0
- bb_integrations_lib/pipelines/parsers/__init__.py +0 -0
- bb_integrations_lib/pipelines/parsers/distribution_report/__init__.py +0 -0
- bb_integrations_lib/pipelines/parsers/distribution_report/order_by_site_product_parser.py +50 -0
- bb_integrations_lib/pipelines/parsers/distribution_report/tank_configs_parser.py +47 -0
- bb_integrations_lib/pipelines/parsers/dtn/__init__.py +0 -0
- bb_integrations_lib/pipelines/parsers/dtn/dtn_price_parser.py +102 -0
- bb_integrations_lib/pipelines/parsers/dtn/model.py +79 -0
- bb_integrations_lib/pipelines/parsers/price_engine/__init__.py +0 -0
- bb_integrations_lib/pipelines/parsers/price_engine/parse_accessorials_prices_parser.py +67 -0
- bb_integrations_lib/pipelines/parsers/price_engine/price_file_upload/__init__.py +0 -0
- bb_integrations_lib/pipelines/parsers/price_engine/price_file_upload/price_merge_parser.py +111 -0
- bb_integrations_lib/pipelines/parsers/price_engine/price_file_upload/price_sync_parser.py +107 -0
- bb_integrations_lib/pipelines/parsers/price_engine/price_file_upload/shared.py +81 -0
- bb_integrations_lib/pipelines/parsers/tank_reading_parser.py +155 -0
- bb_integrations_lib/pipelines/parsers/tank_sales_parser.py +144 -0
- bb_integrations_lib/pipelines/shared/__init__.py +0 -0
- bb_integrations_lib/pipelines/shared/allocation_matching.py +227 -0
- bb_integrations_lib/pipelines/shared/bol_allocation.py +2793 -0
- bb_integrations_lib/pipelines/steps/__init__.py +0 -0
- bb_integrations_lib/pipelines/steps/create_accessorials_step.py +80 -0
- bb_integrations_lib/pipelines/steps/distribution_report/__init__.py +0 -0
- bb_integrations_lib/pipelines/steps/distribution_report/distribution_report_datafram_to_raw_data.py +33 -0
- bb_integrations_lib/pipelines/steps/distribution_report/get_model_history_step.py +50 -0
- bb_integrations_lib/pipelines/steps/distribution_report/get_order_by_site_product_step.py +62 -0
- bb_integrations_lib/pipelines/steps/distribution_report/get_tank_configs_step.py +40 -0
- bb_integrations_lib/pipelines/steps/distribution_report/join_distribution_order_dos_step.py +85 -0
- bb_integrations_lib/pipelines/steps/distribution_report/upload_distribution_report_datafram_to_big_query.py +47 -0
- bb_integrations_lib/pipelines/steps/echo_step.py +14 -0
- bb_integrations_lib/pipelines/steps/export_dataframe_to_rawdata_step.py +28 -0
- bb_integrations_lib/pipelines/steps/exporting/__init__.py +0 -0
- bb_integrations_lib/pipelines/steps/exporting/bbd_export_payroll_file_step.py +107 -0
- bb_integrations_lib/pipelines/steps/exporting/bbd_export_readings_step.py +236 -0
- bb_integrations_lib/pipelines/steps/exporting/cargas_wholesale_bundle_upload_step.py +33 -0
- bb_integrations_lib/pipelines/steps/exporting/dataframe_flat_file_export.py +29 -0
- bb_integrations_lib/pipelines/steps/exporting/gcs_bucket_export_file_step.py +34 -0
- bb_integrations_lib/pipelines/steps/exporting/keyvu_export_step.py +356 -0
- bb_integrations_lib/pipelines/steps/exporting/pe_price_export_step.py +238 -0
- bb_integrations_lib/pipelines/steps/exporting/platform_science_order_sync_step.py +500 -0
- bb_integrations_lib/pipelines/steps/exporting/save_rawdata_to_disk.py +15 -0
- bb_integrations_lib/pipelines/steps/exporting/sftp_export_file_step.py +60 -0
- bb_integrations_lib/pipelines/steps/exporting/sftp_export_many_files_step.py +23 -0
- bb_integrations_lib/pipelines/steps/exporting/update_exported_orders_table_step.py +64 -0
- bb_integrations_lib/pipelines/steps/filter_step.py +22 -0
- bb_integrations_lib/pipelines/steps/get_latest_sync_date.py +34 -0
- bb_integrations_lib/pipelines/steps/importing/bbd_import_payroll_step.py +30 -0
- bb_integrations_lib/pipelines/steps/importing/get_order_numbers_to_export_step.py +138 -0
- bb_integrations_lib/pipelines/steps/importing/load_file_to_dataframe_step.py +46 -0
- bb_integrations_lib/pipelines/steps/importing/load_imap_attachment_step.py +172 -0
- bb_integrations_lib/pipelines/steps/importing/pe_bulk_sync_price_structure_step.py +68 -0
- bb_integrations_lib/pipelines/steps/importing/pe_price_merge_step.py +86 -0
- bb_integrations_lib/pipelines/steps/importing/sftp_file_config_step.py +124 -0
- bb_integrations_lib/pipelines/steps/importing/test_exact_file_match.py +57 -0
- bb_integrations_lib/pipelines/steps/null_step.py +15 -0
- bb_integrations_lib/pipelines/steps/pe_integration_job_step.py +32 -0
- bb_integrations_lib/pipelines/steps/processing/__init__.py +0 -0
- bb_integrations_lib/pipelines/steps/processing/archive_gcs_step.py +76 -0
- bb_integrations_lib/pipelines/steps/processing/archive_sftp_step.py +48 -0
- bb_integrations_lib/pipelines/steps/processing/bbd_format_tank_readings_step.py +492 -0
- bb_integrations_lib/pipelines/steps/processing/bbd_upload_prices_step.py +54 -0
- bb_integrations_lib/pipelines/steps/processing/bbd_upload_tank_sales_step.py +124 -0
- bb_integrations_lib/pipelines/steps/processing/bbd_upload_tankreading_step.py +80 -0
- bb_integrations_lib/pipelines/steps/processing/convert_bbd_order_to_cargas_step.py +226 -0
- bb_integrations_lib/pipelines/steps/processing/delete_sftp_step.py +33 -0
- bb_integrations_lib/pipelines/steps/processing/dtn/__init__.py +2 -0
- bb_integrations_lib/pipelines/steps/processing/dtn/convert_dtn_invoice_to_sd_model.py +145 -0
- bb_integrations_lib/pipelines/steps/processing/dtn/parse_dtn_invoice_step.py +38 -0
- bb_integrations_lib/pipelines/steps/processing/file_config_parser_step.py +720 -0
- bb_integrations_lib/pipelines/steps/processing/file_config_parser_step_v2.py +418 -0
- bb_integrations_lib/pipelines/steps/processing/get_sd_price_price_request.py +105 -0
- bb_integrations_lib/pipelines/steps/processing/keyvu_upload_deliveryplan_step.py +39 -0
- bb_integrations_lib/pipelines/steps/processing/mark_orders_exported_in_bbd_step.py +185 -0
- bb_integrations_lib/pipelines/steps/processing/pe_price_rows_processing_step.py +174 -0
- bb_integrations_lib/pipelines/steps/processing/send_process_report_step.py +47 -0
- bb_integrations_lib/pipelines/steps/processing/sftp_renamer_step.py +61 -0
- bb_integrations_lib/pipelines/steps/processing/tank_reading_touchup_steps.py +75 -0
- bb_integrations_lib/pipelines/steps/processing/upload_supplier_invoice_step.py +16 -0
- bb_integrations_lib/pipelines/steps/send_attached_in_rita_email_step.py +44 -0
- bb_integrations_lib/pipelines/steps/send_rita_email_step.py +34 -0
- bb_integrations_lib/pipelines/steps/sleep_step.py +24 -0
- bb_integrations_lib/pipelines/wrappers/__init__.py +0 -0
- bb_integrations_lib/pipelines/wrappers/accessorials_transformation.py +104 -0
- bb_integrations_lib/pipelines/wrappers/distribution_report.py +191 -0
- bb_integrations_lib/pipelines/wrappers/export_tank_readings.py +237 -0
- bb_integrations_lib/pipelines/wrappers/import_tank_readings.py +192 -0
- bb_integrations_lib/pipelines/wrappers/wrapper.py +81 -0
- bb_integrations_lib/protocols/__init__.py +0 -0
- bb_integrations_lib/protocols/flat_file.py +210 -0
- bb_integrations_lib/protocols/gravitate_client.py +104 -0
- bb_integrations_lib/protocols/pipelines.py +697 -0
- bb_integrations_lib/provider/__init__.py +0 -0
- bb_integrations_lib/provider/api/__init__.py +0 -0
- bb_integrations_lib/provider/api/cargas/__init__.py +0 -0
- bb_integrations_lib/provider/api/cargas/client.py +43 -0
- bb_integrations_lib/provider/api/cargas/model.py +49 -0
- bb_integrations_lib/provider/api/cargas/protocol.py +23 -0
- bb_integrations_lib/provider/api/dtn/__init__.py +0 -0
- bb_integrations_lib/provider/api/dtn/client.py +128 -0
- bb_integrations_lib/provider/api/dtn/protocol.py +9 -0
- bb_integrations_lib/provider/api/keyvu/__init__.py +0 -0
- bb_integrations_lib/provider/api/keyvu/client.py +30 -0
- bb_integrations_lib/provider/api/keyvu/model.py +149 -0
- bb_integrations_lib/provider/api/macropoint/__init__.py +0 -0
- bb_integrations_lib/provider/api/macropoint/client.py +28 -0
- bb_integrations_lib/provider/api/macropoint/model.py +40 -0
- bb_integrations_lib/provider/api/pc_miler/__init__.py +0 -0
- bb_integrations_lib/provider/api/pc_miler/client.py +130 -0
- bb_integrations_lib/provider/api/pc_miler/model.py +6 -0
- bb_integrations_lib/provider/api/pc_miler/web_services_apis.py +131 -0
- bb_integrations_lib/provider/api/platform_science/__init__.py +0 -0
- bb_integrations_lib/provider/api/platform_science/client.py +147 -0
- bb_integrations_lib/provider/api/platform_science/model.py +82 -0
- bb_integrations_lib/provider/api/quicktrip/__init__.py +0 -0
- bb_integrations_lib/provider/api/quicktrip/client.py +52 -0
- bb_integrations_lib/provider/api/telapoint/__init__.py +0 -0
- bb_integrations_lib/provider/api/telapoint/client.py +68 -0
- bb_integrations_lib/provider/api/telapoint/model.py +178 -0
- bb_integrations_lib/provider/api/warren_rogers/__init__.py +0 -0
- bb_integrations_lib/provider/api/warren_rogers/client.py +207 -0
- bb_integrations_lib/provider/aws/__init__.py +0 -0
- bb_integrations_lib/provider/aws/s3/__init__.py +0 -0
- bb_integrations_lib/provider/aws/s3/client.py +126 -0
- bb_integrations_lib/provider/ftp/__init__.py +0 -0
- bb_integrations_lib/provider/ftp/client.py +140 -0
- bb_integrations_lib/provider/ftp/interface.py +273 -0
- bb_integrations_lib/provider/ftp/model.py +76 -0
- bb_integrations_lib/provider/imap/__init__.py +0 -0
- bb_integrations_lib/provider/imap/client.py +228 -0
- bb_integrations_lib/provider/imap/model.py +3 -0
- bb_integrations_lib/provider/sqlserver/__init__.py +0 -0
- bb_integrations_lib/provider/sqlserver/client.py +106 -0
- bb_integrations_lib/secrets/__init__.py +4 -0
- bb_integrations_lib/secrets/adapters.py +98 -0
- bb_integrations_lib/secrets/credential_models.py +222 -0
- bb_integrations_lib/secrets/factory.py +85 -0
- bb_integrations_lib/secrets/providers.py +160 -0
- bb_integrations_lib/shared/__init__.py +0 -0
- bb_integrations_lib/shared/exceptions.py +25 -0
- bb_integrations_lib/shared/model.py +1039 -0
- bb_integrations_lib/shared/shared_enums.py +510 -0
- bb_integrations_lib/storage/README.md +236 -0
- bb_integrations_lib/storage/__init__.py +0 -0
- bb_integrations_lib/storage/aws/__init__.py +0 -0
- bb_integrations_lib/storage/aws/s3.py +8 -0
- bb_integrations_lib/storage/defaults.py +72 -0
- bb_integrations_lib/storage/gcs/__init__.py +0 -0
- bb_integrations_lib/storage/gcs/client.py +8 -0
- bb_integrations_lib/storage/gcsmanager/__init__.py +0 -0
- bb_integrations_lib/storage/gcsmanager/client.py +8 -0
- bb_integrations_lib/storage/setup.py +29 -0
- bb_integrations_lib/util/__init__.py +0 -0
- bb_integrations_lib/util/cache/__init__.py +0 -0
- bb_integrations_lib/util/cache/custom_ttl_cache.py +75 -0
- bb_integrations_lib/util/cache/protocol.py +9 -0
- bb_integrations_lib/util/config/__init__.py +0 -0
- bb_integrations_lib/util/config/manager.py +391 -0
- bb_integrations_lib/util/config/model.py +41 -0
- bb_integrations_lib/util/exception_logger/__init__.py +0 -0
- bb_integrations_lib/util/exception_logger/exception_logger.py +146 -0
- bb_integrations_lib/util/exception_logger/test.py +114 -0
- bb_integrations_lib/util/utils.py +364 -0
- bb_integrations_lib/workers/__init__.py +0 -0
- bb_integrations_lib/workers/groups.py +13 -0
- bb_integrations_lib/workers/rpc_worker.py +50 -0
- bb_integrations_lib/workers/topics.py +20 -0
- bb_integrations_library-3.0.11.dist-info/METADATA +59 -0
- bb_integrations_library-3.0.11.dist-info/RECORD +217 -0
- bb_integrations_library-3.0.11.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
# File Storage
|
|
2
|
+
|
|
3
|
+
A standard internal library to interact with file storage systems across integration processes.
|
|
4
|
+
|
|
5
|
+
# Installation
|
|
6
|
+
|
|
7
|
+
To install run:
|
|
8
|
+
|
|
9
|
+
- `pip install git+https://github.com/gravitate-energy/bb_file_storage.git`
|
|
10
|
+
|
|
11
|
+
# Requirements
|
|
12
|
+
|
|
13
|
+
- run `setup.py` to create default service_accounts files:
|
|
14
|
+
- `ftp.credentials.json` for FTP, which must include:
|
|
15
|
+
- `host`: `str`
|
|
16
|
+
- `username`: `str`
|
|
17
|
+
- `password`: `str`
|
|
18
|
+
- `port`: `int` = 22
|
|
19
|
+
- `ftp_type`: `str`
|
|
20
|
+
- `aws.credentials.json` for AWS, must include:
|
|
21
|
+
- `bucket_name`: `str`
|
|
22
|
+
- `access_key_id`: `str`
|
|
23
|
+
- `secret_access_key`: `str`
|
|
24
|
+
- `google.credentials.json` for Google, must include:
|
|
25
|
+
- `type`: `str`
|
|
26
|
+
- `project_id`: `str`
|
|
27
|
+
- `private_key_id`: `str`
|
|
28
|
+
- `private_key`: `str`
|
|
29
|
+
- `client_email`: `str`
|
|
30
|
+
- `client_id`: `str`
|
|
31
|
+
- `auth_uri`: `str`
|
|
32
|
+
- `token_uri`: `str`
|
|
33
|
+
- `auth_provider_x509_cert_url`: `str`
|
|
34
|
+
- `client_x509_cert_url`: `str`
|
|
35
|
+
- `universe_domain`: `str`
|
|
36
|
+
|
|
37
|
+
# Methods
|
|
38
|
+
|
|
39
|
+
Integrations within the library will follow the same protocol:
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
class Integration(Protocol):
|
|
43
|
+
def list_files(self, directory: str, credential_file_name: str = None) -> list[str]:
|
|
44
|
+
"""Integration method to list files in a remote directory"""
|
|
45
|
+
pass
|
|
46
|
+
|
|
47
|
+
def get_raw_data(self, min_date: datetime, credential_file_name: str = None, check_date: bool = True) -> \
|
|
48
|
+
Iterable[RawData]:
|
|
49
|
+
"""Integration method to download a file from a remote directory"""
|
|
50
|
+
pass
|
|
51
|
+
|
|
52
|
+
def rename_file(self, old_name: str, new_name: str, credential_file_name: str = None) -> None:
|
|
53
|
+
"""Integration method to rename a remote file"""
|
|
54
|
+
pass
|
|
55
|
+
|
|
56
|
+
def delete_file(self, path: str, credential_file_name: str = None) -> None:
|
|
57
|
+
"""Integration method to delete a remote file"""
|
|
58
|
+
pass
|
|
59
|
+
|
|
60
|
+
def upload_file(self, file: File, path: str, credential_file_name: str = None) -> None:
|
|
61
|
+
"""Integration method to upload a file to a remote directory"""
|
|
62
|
+
pass
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### *Raw Data:
|
|
69
|
+
|
|
70
|
+
RawData is defined as follows:
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
class RawData(BaseModel):
|
|
74
|
+
file_name: str
|
|
75
|
+
data: Any
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
File is defined as follows:
|
|
79
|
+
```python
|
|
80
|
+
class File(BaseModel):
|
|
81
|
+
file_name: str | None = None
|
|
82
|
+
file_data: str
|
|
83
|
+
content_type: str = 'text/csv'
|
|
84
|
+
is_public: bool = False
|
|
85
|
+
file_extension: str = 'csv'
|
|
86
|
+
check_if_exists: bool = True
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
# Services
|
|
90
|
+
|
|
91
|
+
### FTP - SFTP
|
|
92
|
+
|
|
93
|
+
Support for both `FTP` and `SFTP` protocols.
|
|
94
|
+
|
|
95
|
+
- `ftp_type` will determine which protocol to use
|
|
96
|
+
|
|
97
|
+
*Examples:*
|
|
98
|
+
|
|
99
|
+
- Import FTP Client:
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
from storage.ftp.client import FTPClient
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
- List files:
|
|
106
|
+
|
|
107
|
+
``` python
|
|
108
|
+
ls = FTPClient.list_files(directory="/")
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
- Rename file:
|
|
112
|
+
|
|
113
|
+
``` python
|
|
114
|
+
FTPClient.rename_file(old_name="old_folder/old_name.csv", new_name="new_folder/new_name.csv")
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
- Upload file:
|
|
118
|
+
|
|
119
|
+
``` python
|
|
120
|
+
df = pd.DataFrame({
|
|
121
|
+
'column1': [1, 2, 3],
|
|
122
|
+
'column2': ['a', 'b', 'c']
|
|
123
|
+
})
|
|
124
|
+
f = File(
|
|
125
|
+
file_name="TestFile",
|
|
126
|
+
file_data=df,
|
|
127
|
+
)
|
|
128
|
+
FTPClient.upload_file(file=f, path='Inbound')
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
- Get file:
|
|
132
|
+
|
|
133
|
+
``` python
|
|
134
|
+
FTPClient.get_file( path='folder/sub_folder', file_name='file_name.txt')
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
- Delete file:
|
|
138
|
+
|
|
139
|
+
``` python
|
|
140
|
+
FTPClient.delete_file( path='folder/file_name.txt')
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### GCP - Cloud Storage
|
|
144
|
+
|
|
145
|
+
Support for Google Cloud Storage.
|
|
146
|
+
|
|
147
|
+
*Examples:*
|
|
148
|
+
|
|
149
|
+
- Import Google Client:
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
from storage.gcs.client import GCSClient
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
- List files:
|
|
156
|
+
|
|
157
|
+
``` python
|
|
158
|
+
ls = GCSClient.list_files(directory="erp-export-bkp/japan")
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
- Rename file:
|
|
162
|
+
|
|
163
|
+
``` python
|
|
164
|
+
GCSClient().rename_file(old_name='bboil-integration-bkp/test/testfile.csv', new_name='bboil-integration-bkp/archive/testfile.csv')
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
- Upload file:
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
df = pd.DataFrame({
|
|
171
|
+
'column1': [1, 2, 3],
|
|
172
|
+
'column2': ['a', 'b', 'c']
|
|
173
|
+
})
|
|
174
|
+
f = File(
|
|
175
|
+
file_name="TestFile",
|
|
176
|
+
file_data=df.to_csv(index=False),
|
|
177
|
+
)
|
|
178
|
+
GCSClient.upload_file(file=f, path="bboil-integration-bkp/test")
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
- Get file:
|
|
182
|
+
|
|
183
|
+
``` python
|
|
184
|
+
ff = GCSClient().get_file(path='bboil-integration-bkp/test/TestingSomeStuff', file_name="Test")
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
- Delete file:
|
|
188
|
+
|
|
189
|
+
``` python
|
|
190
|
+
GCSClient().delete_file(path='bboil-integration-bkp/archive/testfile.csv')
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### GCP - Secret Manager
|
|
194
|
+
Support for Google Cloud Secret Manager.
|
|
195
|
+
|
|
196
|
+
*Examples:*
|
|
197
|
+
|
|
198
|
+
- Import Google Client:
|
|
199
|
+
|
|
200
|
+
```python
|
|
201
|
+
from storage.gcsmanager.client import GCSMClient
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
- List files:
|
|
205
|
+
|
|
206
|
+
``` python
|
|
207
|
+
ls = GCSMClient.list_files(directory="projects")
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
- Rename file:
|
|
211
|
+
Not Implemented
|
|
212
|
+
|
|
213
|
+
- Upload file:
|
|
214
|
+
|
|
215
|
+
```python
|
|
216
|
+
file_data = {'name': 'your-name'}
|
|
217
|
+
file = File(file_name="test", file_data=file_data)
|
|
218
|
+
GCSMClient.upload_file(file=file, path="/")
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
- Get file:
|
|
222
|
+
|
|
223
|
+
``` python
|
|
224
|
+
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
- Delete file:
|
|
228
|
+
|
|
229
|
+
``` python
|
|
230
|
+
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### AWS - S3
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import warnings
|
|
2
|
+
|
|
3
|
+
from bb_integrations_lib.provider.aws.s3.client import S3Client
|
|
4
|
+
|
|
5
|
+
class AWSIntegration(S3Client):
|
|
6
|
+
def __init__(self, *args, **kwargs):
|
|
7
|
+
warnings.warn("Use provider.aws.s3.client.S3Client", DeprecationWarning, stacklevel=2)
|
|
8
|
+
super().__init__(*args, **kwargs)
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
from pydantic import BaseModel
|
|
2
|
+
from typing import Dict
|
|
3
|
+
from bb_integrations_lib.shared.model import CredentialType
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Default(BaseModel):
|
|
7
|
+
name: str
|
|
8
|
+
type: CredentialType
|
|
9
|
+
credential: dict
|
|
10
|
+
|
|
11
|
+
@property
|
|
12
|
+
def file_name(self):
|
|
13
|
+
return f'{self.type.value}.json'
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class DefaultCredentials(BaseModel):
|
|
17
|
+
credentials: Dict[str, Default]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# Example default objects
|
|
21
|
+
google_default = Default(
|
|
22
|
+
name="Google",
|
|
23
|
+
type=CredentialType.google,
|
|
24
|
+
credential={
|
|
25
|
+
"type": "",
|
|
26
|
+
"project_id": "",
|
|
27
|
+
"private_key_id": "",
|
|
28
|
+
"private_key": "",
|
|
29
|
+
"client_email": "",
|
|
30
|
+
"client_id": "",
|
|
31
|
+
"auth_uri": "",
|
|
32
|
+
"token_uri": "",
|
|
33
|
+
"auth_provider_x509_cert_url": "",
|
|
34
|
+
"client_x509_cert_url": "",
|
|
35
|
+
"universe_domain": "googleapis.com"
|
|
36
|
+
}
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
ftp_default = Default(
|
|
40
|
+
name="FTP",
|
|
41
|
+
type=CredentialType.ftp,
|
|
42
|
+
credential={
|
|
43
|
+
"username": "",
|
|
44
|
+
"password": "",
|
|
45
|
+
"host": "",
|
|
46
|
+
"port": 0,
|
|
47
|
+
"ftp_type": "sftp",
|
|
48
|
+
"file_base_name": "",
|
|
49
|
+
"base_dir": "",
|
|
50
|
+
"date_format": "%Y-%m-%d-%H-%M"
|
|
51
|
+
}
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
aws_default = Default(
|
|
55
|
+
name="AWS",
|
|
56
|
+
type=CredentialType.aws,
|
|
57
|
+
credential={
|
|
58
|
+
"bucket_name": "",
|
|
59
|
+
"access_key_id": "",
|
|
60
|
+
"secret_access_key": ""
|
|
61
|
+
}
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
default_credentials = DefaultCredentials(credentials={
|
|
65
|
+
"google": google_default,
|
|
66
|
+
"ftp": ftp_default,
|
|
67
|
+
"aws": aws_default
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
if __name__ == '__main__':
|
|
71
|
+
for key, default in default_credentials.credentials.items():
|
|
72
|
+
print(f"Key: {key}, File Name: {default.file_name}")
|
|
File without changes
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import warnings
|
|
2
|
+
|
|
3
|
+
from bb_integrations_lib.provider.gcp.cloud_storage.client import CloudStorageClient
|
|
4
|
+
|
|
5
|
+
class GCSClient(CloudStorageClient):
|
|
6
|
+
def __init__(self):
|
|
7
|
+
warnings.warn("Use provider.gcp.cloud_storage.client.CloudStorageClient", DeprecationWarning, stacklevel=2)
|
|
8
|
+
super().__init__()
|
|
File without changes
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import warnings
|
|
2
|
+
|
|
3
|
+
from bb_integrations_lib.provider.gcp.cloud_secrets.client import CloudSecretsClient
|
|
4
|
+
|
|
5
|
+
class GCSMClient(CloudSecretsClient):
|
|
6
|
+
def __init__(self):
|
|
7
|
+
warnings.warn("Use provider.gcp.cloud_secrets.client.CloudSecretsClient", DeprecationWarning, stacklevel=2)
|
|
8
|
+
super().__init__()
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Script for initiating the package.
|
|
3
|
+
- Creates [service].credentials.json if not in project
|
|
4
|
+
- Tries to create secrets for storage services if not created
|
|
5
|
+
"""
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
|
|
9
|
+
from loguru import logger
|
|
10
|
+
|
|
11
|
+
from bb_integrations_lib.storage.defaults import default_credentials
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def check_credentials() -> None:
|
|
15
|
+
for key, default in default_credentials.credentials.items():
|
|
16
|
+
if not os.path.exists(default.file_name):
|
|
17
|
+
logger.debug(f'Could not find {default.file_name},creating {key} default credentials')
|
|
18
|
+
with open(default.file_name, "w") as f:
|
|
19
|
+
credentials_data = default_credentials.credentials[key].credential
|
|
20
|
+
json.dump(credentials_data, f, indent=4)
|
|
21
|
+
return None
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def setup():
|
|
25
|
+
check_credentials()
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
if __name__ == '__main__':
|
|
29
|
+
setup()
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import time
|
|
2
|
+
from loguru import logger
|
|
3
|
+
from typing import TypeVar, Callable, Dict, Tuple, Any
|
|
4
|
+
import asyncio
|
|
5
|
+
|
|
6
|
+
T = TypeVar('T')
|
|
7
|
+
|
|
8
|
+
class CustomTTLCache:
|
|
9
|
+
def __init__(self, verbose: bool = False):
|
|
10
|
+
self.caches: dict = {}
|
|
11
|
+
self.verbose = verbose
|
|
12
|
+
|
|
13
|
+
def _is_expired(self, timestamp: float) -> bool:
|
|
14
|
+
return time.time() > timestamp
|
|
15
|
+
|
|
16
|
+
def ttl_cache(self, seconds: int, cache_key: str):
|
|
17
|
+
def decorator(func: Callable[..., T]) -> Callable[..., T]:
|
|
18
|
+
def wrapper(*args, **kwargs):
|
|
19
|
+
if cache_key in self.caches:
|
|
20
|
+
value, expires_at = self.caches[cache_key]
|
|
21
|
+
if time.time() < expires_at:
|
|
22
|
+
if self.verbose:
|
|
23
|
+
logger.info(f"Cache HIT for {cache_key}")
|
|
24
|
+
return value
|
|
25
|
+
else:
|
|
26
|
+
if self.verbose:
|
|
27
|
+
logger.info(f"Cache EXPIRED for {cache_key}")
|
|
28
|
+
del self.caches[cache_key]
|
|
29
|
+
else:
|
|
30
|
+
if self.verbose:
|
|
31
|
+
logger.info(f"Cache MISS for {cache_key}")
|
|
32
|
+
result = func(*args, **kwargs)
|
|
33
|
+
expires_at = time.time() + seconds
|
|
34
|
+
self.caches[cache_key] = (result, expires_at)
|
|
35
|
+
if self.verbose:
|
|
36
|
+
logger.info(
|
|
37
|
+
f"Cached result for {cache_key} (expires at {time.strftime('%H:%M:%S', time.localtime(expires_at))})")
|
|
38
|
+
return result
|
|
39
|
+
return wrapper
|
|
40
|
+
return decorator
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class CustomAsyncTTLCache:
|
|
44
|
+
def __init__(self, verbose: bool = False):
|
|
45
|
+
self.caches: Dict[str, Tuple[Any, float]] = {}
|
|
46
|
+
self.verbose = verbose
|
|
47
|
+
self.locks: Dict[str, asyncio.Lock] = {}
|
|
48
|
+
|
|
49
|
+
def _is_expired(self, timestamp: float) -> bool:
|
|
50
|
+
return time.time() > timestamp
|
|
51
|
+
|
|
52
|
+
async def get_or_set(self, cache_key: str, seconds: int, fetch_func, *args, **kwargs):
|
|
53
|
+
if cache_key not in self.locks:
|
|
54
|
+
self.locks[cache_key] = asyncio.Lock()
|
|
55
|
+
async with self.locks[cache_key]:
|
|
56
|
+
if cache_key in self.caches:
|
|
57
|
+
value, expires_at = self.caches[cache_key]
|
|
58
|
+
if time.time() < expires_at:
|
|
59
|
+
if self.verbose:
|
|
60
|
+
logger.info(f"Cache HIT for {cache_key}")
|
|
61
|
+
return value
|
|
62
|
+
else:
|
|
63
|
+
if self.verbose:
|
|
64
|
+
logger.info(f"Cache EXPIRED for {cache_key}")
|
|
65
|
+
del self.caches[cache_key]
|
|
66
|
+
else:
|
|
67
|
+
if self.verbose:
|
|
68
|
+
logger.info(f"Cache MISS for {cache_key}")
|
|
69
|
+
result = await fetch_func(*args, **kwargs)
|
|
70
|
+
expires_at = time.time() + seconds
|
|
71
|
+
self.caches[cache_key] = (result, expires_at)
|
|
72
|
+
if self.verbose:
|
|
73
|
+
logger.info(
|
|
74
|
+
f"Cached result for {cache_key} (expires at {time.strftime('%H:%M:%S', time.localtime(expires_at))})")
|
|
75
|
+
return result
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
from typing import Protocol
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class CustomTTLCacheProtocol(Protocol):
|
|
5
|
+
def _is_expired(self, timestamp: float) -> bool:
|
|
6
|
+
"""Checks if cache is expired"""
|
|
7
|
+
|
|
8
|
+
def ttl_cache(self, seconds: int, cache_key: str):
|
|
9
|
+
"""Wrapper function to manage a custom ttl object"""
|
|
File without changes
|