Skip to content

Commit 2e05618

Browse files
author
seolmin
committed
refactor: apply black formatter
1 parent 77ffd16 commit 2e05618

29 files changed

Lines changed: 231 additions & 226 deletions

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ RUN python3 setup.py install && \
2424
EXPOSE ${SPACEONE_PORT}
2525

2626
ENTRYPOINT ["spaceone"]
27-
CMD ["grpc", "cloudforet.cost_analysis"]
27+
CMD ["run", "grpc-server", "cloudforet.cost_analysis"]

pkg/pip_requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ schematics
22
requests
33
pandas
44
numpy
5-
chardet
5+
chardet
6+
google-cloud-storage

src/cloudforet/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
1+
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
name = 'cost_analysis'
1+
name = "cost_analysis"

src/cloudforet/cost_analysis/conf/global_conf.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
1-
CONNECTORS = {
2-
'HTTPFileConnector': {}
3-
}
1+
CONNECTORS = {"HTTPFileConnector": {}}
42

53
LOG = {
6-
'filters': {
7-
'masking': {
8-
'rules': {
9-
'DataSource.verify': [
10-
'secret_data'
11-
],
12-
'Job.get_tasks': [
13-
'secret_data'
14-
],
15-
'Cost.get_data': [
16-
'secret_data'
17-
]
4+
"filters": {
5+
"masking": {
6+
"rules": {
7+
"DataSource.verify": ["secret_data"],
8+
"Job.get_tasks": ["secret_data"],
9+
"Cost.get_data": ["secret_data"],
1810
}
1911
}
2012
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PROTO = {
2-
'cloudforet.cost_analysis.interface.grpc.plugin.data_source': ['DataSource'],
3-
'cloudforet.cost_analysis.interface.grpc.plugin.job': ['Job'],
4-
'cloudforet.cost_analysis.interface.grpc.plugin.cost': ['Cost'],
2+
"cloudforet.cost_analysis.interface.grpc.plugin.data_source": ["DataSource"],
3+
"cloudforet.cost_analysis.interface.grpc.plugin.job": ["Job"],
4+
"cloudforet.cost_analysis.interface.grpc.plugin.cost": ["Cost"],
55
}

src/cloudforet/cost_analysis/connector/http_file_connector.py

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,78 +3,87 @@
33
import numpy as np
44
import chardet
55
import requests
6+
import google.oauth2.service_account
67

78
from spaceone.core.transaction import Transaction
89
from spaceone.core.connector import BaseConnector
910
from typing import List
1011

1112
from cloudforet.cost_analysis.error import *
1213

13-
__all__ = ['HTTPFileConnector']
14+
__all__ = ["HTTPFileConnector"]
1415

1516
_LOGGER = logging.getLogger(__name__)
1617

1718
_PAGE_SIZE = 1000
1819

1920

2021
class HTTPFileConnector(BaseConnector):
21-
2222
def __init__(self, *args, **kwargs):
2323
super().__init__(*args, **kwargs)
2424
self.base_url = None
2525
self.field_mapper = None
2626
self.default_vars = None
2727

28-
def create_session(self, options: dict, secret_data: dict, schema: str = None) -> None:
28+
def create_session(
29+
self, options: dict, secret_data: dict, schema: str = None
30+
) -> None:
2931
self._check_options(options)
30-
self.base_url = options['base_url']
32+
self.base_url = options["base_url"]
3133

32-
if 'field_mapper' in options:
33-
self.field_mapper = options['field_mapper']
34+
if "field_mapper" in options:
35+
self.field_mapper = options["field_mapper"]
3436

35-
if 'default_vars' in options:
36-
self.default_vars = options['default_vars']
37+
if "default_vars" in options:
38+
self.default_vars = options["default_vars"]
3739

3840
def get_cost_data(self, base_url):
39-
_LOGGER.debug(f'[get_cost_data] base url: {base_url}')
41+
_LOGGER.debug(f"[get_cost_data] base url: {base_url}")
4042

4143
costs_data = self._get_csv(base_url)
4244

43-
_LOGGER.debug(f'[get_cost_data] costs count: {len(costs_data)}')
45+
_LOGGER.debug(f"[get_cost_data] costs count: {len(costs_data)}")
4446

4547
# Paginate
4648
page_count = int(len(costs_data) / _PAGE_SIZE) + 1
4749

4850
for page_num in range(page_count):
4951
offset = _PAGE_SIZE * page_num
50-
yield costs_data[offset:offset + _PAGE_SIZE]
52+
yield costs_data[offset : offset + _PAGE_SIZE]
5153

5254
@staticmethod
5355
def _check_options(options: dict) -> None:
54-
if 'base_url' not in options:
55-
raise ERROR_REQUIRED_PARAMETER(key='options.base_url')
56+
if "base_url" not in options:
57+
raise ERROR_REQUIRED_PARAMETER(key="options.base_url")
5658

5759
def _get_csv(self, base_url: str) -> List[dict]:
5860
try:
5961
csv_format = self._search_csv_format(base_url)
60-
df = pd.read_csv(base_url, header=0, sep=',', engine='python', encoding=csv_format, dtype=str)
62+
df = pd.read_csv(
63+
base_url,
64+
header=0,
65+
sep=",",
66+
engine="python",
67+
encoding=csv_format,
68+
dtype=str,
69+
)
6170
df = df.replace({np.nan: None})
6271

63-
costs_data = df.to_dict('records')
72+
costs_data = df.to_dict("records")
6473
return costs_data
6574

6675
except Exception as e:
67-
_LOGGER.error(f'[_get_csv] download error: {e}', exc_info=True)
76+
_LOGGER.error(f"[_get_csv] download error: {e}", exc_info=True)
6877
raise e
6978

7079
@staticmethod
7180
def _search_csv_format(base_url: str) -> str:
7281
try:
7382
response = requests.get(base_url)
74-
response.encoding = chardet.detect(response.content)['encoding']
75-
_LOGGER.debug(f'[_search_csv_format] encoding: {response.encoding}')
83+
response.encoding = chardet.detect(response.content)["encoding"]
84+
_LOGGER.debug(f"[_search_csv_format] encoding: {response.encoding}")
7685
return response.encoding
7786

7887
except Exception as e:
79-
_LOGGER.error(f'[_search_csv_format] download error: {e}', exc_info=True)
88+
_LOGGER.error(f"[_search_csv_format] download error: {e}", exc_info=True)
8089
raise e
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from cloudforet.cost_analysis.error.cost import *
1+
from cloudforet.cost_analysis.error.cost import *

src/cloudforet/cost_analysis/error/cost.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33

44
class ERROR_EMPTY_BILLED_DATE(ERROR_UNKNOWN):
5-
_message = 'Must have billed_date field or year, month fields.: {result}'
5+
_message = "Must have billed_date field or year, month fields.: {result}"

src/cloudforet/cost_analysis/info/common_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from google.protobuf.empty_pb2 import Empty
22

3-
__all__ = ['EmptyInfo']
3+
__all__ = ["EmptyInfo"]
44

55

66
def EmptyInfo():

0 commit comments

Comments
 (0)