Skip to content

Commit f2c86b0

Browse files
refactoring error
1 parent 7b7f5bb commit f2c86b0

File tree

3 files changed

+32
-22
lines changed

3 files changed

+32
-22
lines changed

unstract/connectors/src/unstract/connectors/filesystems/azure_cloud_storage/static/json_schema.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@
1616
"account_name": {
1717
"type": "string",
1818
"title": "Account Name",
19-
"description": "Account name of azure cloud storage",
20-
"default":""
19+
"description": "Account name of azure cloud storage"
2120
},
2221
"access_key": {
2322
"type": "string",
2423
"title": "Access Key",
2524
"format": "password",
26-
"description": "Access key of the corresponding account",
27-
"default":""
25+
"description": "Access key of the corresponding account"
2826
},
2927
"bucket": {
3028
"type": "string",

unstract/connectors/src/unstract/connectors/filesystems/google_cloud_storage/google_cloud_storage.py

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,29 @@ def __init__(self, settings: dict[str, Any]):
1818
1919
Args:
2020
settings (dict[str, Any]): A json dict containing json connection string
21-
and bucket-name
22-
2321
Raises:
2422
ConnectorError: Error raised when connection initialization fails
2523
"""
2624
super().__init__("GoogleCloudStorage")
27-
self.bucket = settings.get("bucket", "")
25+
project_id = settings.get("project_id", "")
2826
json_credentials_str = settings.get("json_credentials", "{}")
29-
# project-id is not mandatory, since we already initilizing with json-creds
3027
try:
3128
json_credentials = json.loads(json_credentials_str)
32-
self.gcs_fs = GCSFileSystem(token=json_credentials, timeout=10)
29+
self.gcs_fs = GCSFileSystem(token=json_credentials, project=project_id)
3330
except json.JSONDecodeError as e:
3431
logger.error(f"Failed to parse JSON credentials: {str(e)}", exc_info=True)
35-
error_msg = f"GCS credentials are not in proper JSON format: {str(e)}"
32+
error_msg = (
33+
"Failed to connect to Google Cloud Storage. \n"
34+
"GCS credentials are not in proper JSON format. \n"
35+
f"Error: \n```\n{str(e)}\n```"
36+
)
3637
raise ConnectorError(error_msg) from e
3738
except Exception as e:
3839
logger.error(f"Failed to initialize GCSFileSystem: {str(e)}")
39-
error_msg = f"Failed to connect to Google Cloud Storage: {str(e)}"
40+
error_msg = (
41+
"Failed to connect to Google Cloud Storage. \n"
42+
f"Error: \n```\n{str(e)}\n```"
43+
)
4044
raise ConnectorError(error_msg) from e
4145

4246
@staticmethod
@@ -98,13 +102,20 @@ def extract_metadata_file_hash(self, metadata: dict[str, Any]) -> str | None:
98102
return None
99103

100104
def test_credentials(self) -> bool:
101-
"""To test credentials for Google Cloud Storage."""
105+
"""Test Google Cloud Storage credentials by accessing the root path info.
106+
107+
Raises:
108+
ConnectorError: connector-error
109+
110+
Returns:
111+
boolean: true if test-connection is successful
112+
"""
102113
try:
103-
is_dir = bool(self.get_fsspec_fs().isdir(self.bucket))
104-
if not is_dir:
105-
raise RuntimeError("Could not access bucket.")
114+
self.get_fsspec_fs().info("/")
106115
except Exception as e:
107-
raise ConnectorError(
108-
f"Error from Google Cloud Storage while testing connection: {str(e)}"
109-
) from e
116+
error_msg = (
117+
"Error from Google Cloud Storage while testing connection. \n"
118+
f"Error: \n```\n{str(e)}\n```"
119+
)
120+
raise ConnectorError(error_msg) from e
110121
return True

unstract/connectors/src/unstract/connectors/filesystems/google_cloud_storage/static/json_schema.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"type": "object",
44
"required": [
55
"connectorName",
6-
"json_credentials"
6+
"json_credentials",
7+
"project_id"
78
],
89
"properties": {
910
"connectorName": {
@@ -18,10 +19,10 @@
1819
"default": "",
1920
"description": "Refer [GCloud docs](https://developers.google.com/workspace/guides/create-credentials#create_credentials_for_a_service_account) on adding keys for service account"
2021
},
21-
"bucket": {
22+
"project_id": {
2223
"type": "string",
23-
"title": "Bucket Name",
24-
"description": "Name of the bucket to be restricted to."
24+
"title": "Project ID",
25+
"description": "Name of the project ID."
2526
}
2627
}
2728
}

0 commit comments

Comments
 (0)