Skip to content

Commit 7207be0

Browse files
author
seolmin
committed
fix: add metadata in init method
1 parent 657e871 commit 7207be0

4 files changed

Lines changed: 35 additions & 8 deletions

File tree

src/cloudforet/cost_analysis/connector/google_storage_collector.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ def get_cost_data(self, bucket_name: str):
5959

6060
@staticmethod
6161
def _check_options(options: dict) -> None:
62-
if "base_url" not in options or "bucket_name" not in options:
63-
raise ERROR_REQUIRED_PARAMETER(key="options.base_url")
62+
if "bucket_name" not in options:
63+
raise ERROR_REQUIRED_PARAMETER(key="options.bucket_name")
6464

6565
@staticmethod
6666
def _get_csv(csv_file: str) -> List[dict]:

src/cloudforet/cost_analysis/connector/http_file_connector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def get_cost_data(self, base_url):
5050

5151
@staticmethod
5252
def _check_options(options: dict) -> None:
53-
if "base_url" not in options or "bucket_name" not in options:
53+
if "base_url" not in options:
5454
raise ERROR_REQUIRED_PARAMETER(key="options.base_url")
5555

5656
def _get_csv(self, base_url: str) -> List[dict]:

src/cloudforet/cost_analysis/manager/cost_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def get_data(self, options, secret_data, schema, task_options):
2727
if "field_mapper" in options:
2828
self.field_mapper = options["field_mapper"]
2929

30-
if not secret_data:
30+
if "base_url" in task_options:
3131
base_url = task_options["base_url"]
3232
http_file_connector = self.locator.get_connector(HTTPFileConnector)
3333
http_file_connector.create_session(options, secret_data, schema)

src/cloudforet/cost_analysis/manager/data_source_manager.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import logging
22

33
from spaceone.core.manager import BaseManager
4+
5+
from cloudforet.cost_analysis.connector.google_storage_collector import (
6+
GoogleStorageConnector,
7+
)
48
from cloudforet.cost_analysis.model.data_source_model import PluginMetadata
59
from cloudforet.cost_analysis.connector.http_file_connector import HTTPFileConnector
610

@@ -13,10 +17,33 @@ def init_response(options):
1317
plugin_metadata = PluginMetadata()
1418
plugin_metadata.validate()
1519

20+
if "bucket_name" in options:
21+
return {
22+
"metadata": {
23+
"data_source_rules": [
24+
{
25+
"name": "match_service_account",
26+
"conditions_policy": "ALWAYS",
27+
"actions": {
28+
"match_service_account": {
29+
"source": "additional_info.Project ID",
30+
"target": "data.project_id",
31+
}
32+
},
33+
"options": {"stop_processing": True},
34+
}
35+
],
36+
"currency": "KRW",
37+
}
38+
}
39+
1640
return {"metadata": plugin_metadata.to_primitive()}
1741

1842
def verify_plugin(self, options, secret_data, schema):
19-
http_file_connector: HTTPFileConnector = self.locator.get_connector(
20-
HTTPFileConnector
21-
)
22-
http_file_connector.create_session(options, secret_data, schema)
43+
if "base_url" in options:
44+
http_file_connector: HTTPFileConnector = self.locator.get_connector(
45+
HTTPFileConnector
46+
)
47+
http_file_connector.create_session(options, secret_data, schema)
48+
elif "bucket_name" in options:
49+
self.locator.get_connector(GoogleStorageConnector, secret_data=secret_data)

0 commit comments

Comments
 (0)