Skip to content

Commit

Permalink
Merge pull request #118 from ImMin5/master
Browse files Browse the repository at this point in the history
Refactor all apis based on identity v2
  • Loading branch information
ImMin5 authored Dec 17, 2023
2 parents 3b19433 + dfaab4f commit e01bb82
Show file tree
Hide file tree
Showing 38 changed files with 2,713 additions and 1,843 deletions.
2 changes: 1 addition & 1 deletion deploy/helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ description: SpaceONE Cost Analysis Helm chart for Kubernetes

type: application

version: 1.3.15
version: 1.3.164
appVersion: 1.x.y

9 changes: 0 additions & 9 deletions deploy/helm/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,6 @@ GLOBAL:
file:
type: file
filename: /var/log/spaceone/cost_analysis.log
HANDLERS:
authentication:
- backend: spaceone.core.handler.authentication_handler.AuthenticationGRPCHandler
uri: grpc://identity:50051/v1/Domain/get_public_key
authorization:
- backend: spaceone.core.handler.authorization_handler.AuthorizationGRPCHandler
uri: grpc://identity:50051/v1/Authorization/verify
mutation:
- backend: spaceone.core.handler.mutation_handler.SpaceONEMutationHandler
QUEUES:
cost_analysis_q:
backend: spaceone.core.queue.redis_queue.RedisQueue
Expand Down
1 change: 0 additions & 1 deletion pkg/pip_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
spaceone-core
spaceone-api
boto3
pandas
Expand Down
1 change: 0 additions & 1 deletion src/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
license='Apache License 2.0',
packages=find_packages(),
install_requires=[
'spaceone-core',
'spaceone-api',
'boto3',
'pandas',
Expand Down
58 changes: 33 additions & 25 deletions src/spaceone/cost_analysis/conf/global_conf.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,48 @@
DATABASE_AUTO_CREATE_INDEX = True
DATABASES = {
'default': {
'db': 'cost-analysis',
'host': 'localhost',
'port': 27017,
'username': '',
'password': ''
"default": {
"db": "cost-analysis",
"host": "localhost",
"port": 27017,
"username": "",
"password": "",
}
}

CACHES = {
'default': {},
'local': {
'backend': 'spaceone.core.cache.local_cache.LocalCache',
'max_size': 128,
'ttl': 300
}
"default": {},
"local": {
"backend": "spaceone.core.cache.local_cache.LocalCache",
"max_size": 128,
"ttl": 300,
},
}

HANDLERS = {
# "authentication": [{
# "backend": "spaceone.core.handler.authentication_handler:SpaceONEAuthenticationHandler"
# }],
# "authorization": [{
# "backend": "spaceone.core.handler.authorization_handler:SpaceONEAuthorizationHandler"
# }],
# "mutation": [{
# "backend": "spaceone.core.handler.mutation_handler:SpaceONEMutationHandler"
# }],
# "event": []
}

CONNECTORS = {
'SpaceConnector': {
'backend': 'spaceone.core.connector.space_connector.SpaceConnector',
'endpoints': {
'identity': 'grpc://identity:50051',
'plugin': 'grpc://plugin:50051',
'repository': 'grpc://repository:50051',
'secret': 'grpc://secret:50051',
'notification': 'grpc://notification:50051'

}
},
'DataSourcePluginConnector': {
"SpaceConnector": {
"backend": "spaceone.core.connector.space_connector.SpaceConnector",
"endpoints": {
"identity": "grpc://identity:50051",
"plugin": "grpc://plugin:50051",
"repository": "grpc://repository:50051",
"secret": "grpc://secret:50051",
"notification": "grpc://notification:50051",
},
},
"DataSourcePluginConnector": {},
}

# Scheduler Settings
Expand All @@ -47,7 +55,7 @@
# Job Settings
JOB_TIMEOUT = 600
DATA_SOURCE_SYNC_HOUR = 16 # Hour (UTC)
COST_QUERY_CACHE_TIME = 4 # Day
COST_QUERY_CACHE_TIME = 4 # Day

DEFAULT_EXCHANGE_RATE = {
# 'KRW': 1178.7,
Expand Down
39 changes: 25 additions & 14 deletions src/spaceone/cost_analysis/error/budget.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,62 @@


class ERROR_ONLY_ONF_OF_PROJECT_OR_PROJECT_GROUP(ERROR_INVALID_ARGUMENT):
_message = 'Only one of project_id or project_group_id is allowed.'
_message = "Only one of project_id or project_group_id is allowed."


class ERROR_INVALID_TIME_RANGE(ERROR_INVALID_ARGUMENT):
_message = 'Budget end time must be greater than start time. (start = {start}, end = {end})'
_message = "Budget end time must be greater than start time. (start = {start}, end = {end})"


class ERROR_NO_DATE_IN_PLANNED_LIMITS(ERROR_INVALID_ARGUMENT):
_message = 'No date in the planned limits. (date = {date})'
_message = "No date in the planned limits. (date = {date})"


class ERROR_DATE_IS_REQUIRED(ERROR_INVALID_ARGUMENT):
_message = 'Date is required for planned limits. (key = planned_limits, value = {value})'
_message = (
"Date is required for planned limits. (key = planned_limits, value = {value})"
)


class ERROR_LIMIT_IS_WRONG(ERROR_INVALID_ARGUMENT):
_message = 'Limit must be greater than zero. (key = planned_limits, value = {value})'
_message = (
"Limit must be greater than zero. (key = planned_limits, value = {value})"
)


class ERROR_DATE_IS_WRONG(ERROR_INVALID_ARGUMENT):
_message = 'Date is wrong in the planned limits. (wrong date = {date})'
_message = "Date is wrong in the planned limits. (wrong date = {date})"


class ERROR_UNIT_IS_REQUIRED(ERROR_INVALID_ARGUMENT):
_message = 'Unit is required for notifications (key = notifications, value = {value})'
_message = (
"Unit is required for notifications (key = notifications, value = {value})"
)


class ERROR_NOTIFICATION_TYPE_IS_REQUIRED(ERROR_INVALID_ARGUMENT):
_message = 'Notification type is required for notifications (key = notifications, value = {value})'
_message = "Notification type is required for notifications (key = notifications, value = {value})"


class ERROR_THRESHOLD_IS_WRONG(ERROR_INVALID_ARGUMENT):
_message = 'Threshold must be greater than zero. (key = notifications, value = {value})'
_message = (
"Threshold must be greater than zero. (key = notifications, value = {value})"
)


class ERROR_THRESHOLD_IS_WRONG_IN_PERCENT_TYPE(ERROR_INVALID_ARGUMENT):
_message = 'In percentage type, the threshold must be less than 100. (key = notifications, value = {value})'
_message = "In percentage type, the threshold must be less than 100. (key = notifications, value = {value})"


class ERROR_PROVIDER_FILTER_IS_EMPTY(ERROR_INVALID_ARGUMENT):
_message = 'Provider filter is empty. (key = provider_filter.providers, value = [])'
_message = "Provider filter is empty. (key = provider_filter.providers, value = [])"


class ERROR_BUDGET_ALREADY_EXIST(ERROR_INVALID_ARGUMENT):
_message = 'Budget already exist. (data_source_id = {data_source_id}, target = {target})'
_message = (
"Budget already exist. (data_source_id = {data_source_id}, target = {target})"
)


class ERROR_NOTIFICATION_IS_NOT_SUPPORTED_IN_PROJECT_GROUP(ERROR_INVALID_ARGUMENT):
_message = 'Notification is not supported in project group. (target = {target})'
class ERROR_NOTIFICATION_IS_NOT_SUPPORTED_IN_PROJECT(ERROR_INVALID_ARGUMENT):
_message = "Notification is not supported in project. (target = {target})"
71 changes: 39 additions & 32 deletions src/spaceone/cost_analysis/info/budget_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
from spaceone.api.cost_analysis.v1 import budget_pb2
from spaceone.core.pygrpc.message_type import *
from spaceone.core import utils
from spaceone.cost_analysis.model.budget_model import Budget, PlannedLimit, Notification, ProviderFilter
from spaceone.cost_analysis.model.budget_model import (
Budget,
PlannedLimit,
Notification,
ProviderFilter,
)

__all__ = ['BudgetInfo', 'BudgetsInfo']
__all__ = ["BudgetInfo", "BudgetsInfo"]


def PlannedLimitsInfo(planned_limit_vos: List[PlannedLimit]):
Expand All @@ -15,10 +20,7 @@ def PlannedLimitsInfo(planned_limit_vos: List[PlannedLimit]):
planned_limits_info = []

for vo in planned_limit_vos:
info = {
'date': vo.date,
'limit': vo.limit
}
info = {"date": vo.date, "limit": vo.limit}

planned_limits_info.append(budget_pb2.PlannedLimit(**info))

Expand All @@ -33,9 +35,9 @@ def BudgetNotificationsInfo(notification_vos: List[Notification]):

for vo in notification_vos:
info = {
'threshold': vo.threshold,
'unit': vo.unit,
'notification_type': vo.notification_type
"threshold": vo.threshold,
"unit": vo.unit,
"notification_type": vo.notification_type,
}

notifications_info.append(budget_pb2.BudgetNotification(**info))
Expand All @@ -48,41 +50,46 @@ def ProviderFilterInfo(provider_filter_vo: ProviderFilter):
return None

info = {
'state': provider_filter_vo.state,
'providers': list(provider_filter_vo.providers)
"state": provider_filter_vo.state,
"providers": list(provider_filter_vo.providers),
}

return budget_pb2.ProviderFilter(**info)


def BudgetInfo(budget_vo: Budget, minimal=False):
info = {
'budget_id': budget_vo.budget_id,
'name': budget_vo.name,
'limit': budget_vo.limit,
'currency': budget_vo.currency,
'provider_filter': ProviderFilterInfo(budget_vo.provider_filter),
'project_id': budget_vo.project_id,
'project_group_id': budget_vo.project_group_id,
'data_source_id': budget_vo.data_source_id,
"budget_id": budget_vo.budget_id,
"name": budget_vo.name,
"limit": budget_vo.limit,
"currency": budget_vo.currency,
"provider_filter": ProviderFilterInfo(budget_vo.provider_filter),
"resource_group": budget_vo.resource_group,
"project_id": budget_vo.project_id,
"project_group_id": budget_vo.project_group_id,
"data_source_id": budget_vo.data_source_id,
}

if not minimal:
info.update({
'planned_limits': PlannedLimitsInfo(budget_vo.planned_limits),
'time_unit': budget_vo.time_unit,
'start': budget_vo.start,
'end': budget_vo.end,
'notifications': BudgetNotificationsInfo(budget_vo.notifications),
'tags': change_struct_type(budget_vo.tags),
'domain_id': budget_vo.domain_id,
'created_at': utils.datetime_to_iso8601(budget_vo.created_at),
'updated_at': utils.datetime_to_iso8601(budget_vo.updated_at)
})
info.update(
{
"planned_limits": PlannedLimitsInfo(budget_vo.planned_limits),
"time_unit": budget_vo.time_unit,
"start": budget_vo.start,
"end": budget_vo.end,
"notifications": BudgetNotificationsInfo(budget_vo.notifications),
"tags": change_struct_type(budget_vo.tags),
"domain_id": budget_vo.domain_id,
"created_at": utils.datetime_to_iso8601(budget_vo.created_at),
"updated_at": utils.datetime_to_iso8601(budget_vo.updated_at),
}
)

return budget_pb2.BudgetInfo(**info)


def BudgetsInfo(budget_vos, total_count, **kwargs):
return budget_pb2.BudgetsInfo(results=list(
map(functools.partial(BudgetInfo, **kwargs), budget_vos)), total_count=total_count)
return budget_pb2.BudgetsInfo(
results=list(map(functools.partial(BudgetInfo, **kwargs), budget_vos)),
total_count=total_count,
)
45 changes: 26 additions & 19 deletions src/spaceone/cost_analysis/info/budget_usage_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,51 @@
from spaceone.core import utils
from spaceone.cost_analysis.model.budget_usage_model import BudgetUsage, ProviderFilter

__all__ = ['BudgetUsageInfo', 'BudgetUsagesInfo']
__all__ = ["BudgetUsageInfo", "BudgetUsagesInfo"]


def ProviderFilterInfo(provider_filter_vo: ProviderFilter):
if provider_filter_vo is None:
return None

info = {
'state': provider_filter_vo.state,
'providers': list(provider_filter_vo.providers)
"state": provider_filter_vo.state,
"providers": list(provider_filter_vo.providers),
}

return budget_usage_pb2.BudgetUsageProviderFilter(**info)


def BudgetUsageInfo(budget_usage_vo: BudgetUsage, minimal=False):
info = {
'budget_id': budget_usage_vo.budget_id,
'name': budget_usage_vo.name,
'date': budget_usage_vo.date,
'cost': budget_usage_vo.cost,
'limit': budget_usage_vo.limit,
'currency': budget_usage_vo.currency,
'provider_filter': ProviderFilterInfo(budget_usage_vo.provider_filter),
'project_id': budget_usage_vo.project_id,
'project_group_id': budget_usage_vo.project_group_id,
'data_source_id': budget_usage_vo.data_source_id,
"budget_id": budget_usage_vo.budget_id,
"name": budget_usage_vo.name,
"date": budget_usage_vo.date,
"cost": budget_usage_vo.cost,
"limit": budget_usage_vo.limit,
"currency": budget_usage_vo.currency,
"provider_filter": ProviderFilterInfo(budget_usage_vo.provider_filter),
"resource_group": budget_usage_vo.resource_group,
"project_id": budget_usage_vo.project_id,
"data_source_id": budget_usage_vo.data_source_id,
"workspace_id": budget_usage_vo.workspace_id,
}

if not minimal:
info.update({
'domain_id': budget_usage_vo.domain_id,
'updated_at': utils.datetime_to_iso8601(budget_usage_vo.updated_at)
})
info.update(
{
"domain_id": budget_usage_vo.domain_id,
"updated_at": utils.datetime_to_iso8601(budget_usage_vo.updated_at),
}
)

return budget_usage_pb2.BudgetUsageInfo(**info)


def BudgetUsagesInfo(budget_usage_vos, total_count, **kwargs):
return budget_usage_pb2.BudgetUsagesInfo(results=list(
map(functools.partial(BudgetUsageInfo, **kwargs), budget_usage_vos)), total_count=total_count)
return budget_usage_pb2.BudgetUsagesInfo(
results=list(
map(functools.partial(BudgetUsageInfo, **kwargs), budget_usage_vos)
),
total_count=total_count,
)
Loading

0 comments on commit e01bb82

Please sign in to comment.