-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added the policy es_model helps to unique policy data #747
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from datetime import datetime, timezone | ||
from dataclasses import dataclass, asdict | ||
|
||
from cloud_governance.common.utils.utils import Utils | ||
|
||
|
||
@dataclass | ||
class PolicyEsMetaData(dict): | ||
|
||
""" | ||
This class is the data modal for policy elasticsearch data | ||
""" | ||
|
||
account: str | ||
resource_id: str | ||
user: str | ||
skip_policy: str | ||
dry_run: str | ||
name: str | ||
region_name: str | ||
public_cloud: str | ||
expire_days: int | ||
|
||
unit_price: float = '' | ||
total_yearly_savings: float = '' | ||
resource_type: str = '' | ||
resource_state: str = '' | ||
clean_up_days: int = '' | ||
days_count: int = '' | ||
resource_action: str = '' | ||
IndexId: str = '' | ||
SnapshotDate: str = datetime.now(timezone.utc).date().__str__() | ||
|
||
# Specific Policy Attributes | ||
volume_size: int = '' | ||
instance_type: str = '' | ||
launch_time: str = '' | ||
running_days: int = '' | ||
create_date: str = '' | ||
|
||
def __post_init__(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What the purpose of post init, why not to use init ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It helps to init the variables after initialization of variables in the init method. |
||
""" | ||
This method initializes the IndexId | ||
:return: | ||
:rtype: | ||
""" | ||
self.IndexId = (f'{self.SnapshotDate}-{self.public_cloud}-{self.account}-{self.region_name}-{self.resource_id}-' | ||
f'{self.resource_state}').lower() | ||
|
||
def get_as_dict_title_case(self): | ||
""" | ||
This method returns the dict object | ||
:return: | ||
:rtype: | ||
""" | ||
return {Utils.convert_to_title_case(k): v for k, v in asdict(self).items() if v != ''} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
import os | ||
from datetime import datetime, timedelta | ||
from typing import Union | ||
import re | ||
|
||
|
||
class Utils: | ||
|
@@ -130,3 +131,17 @@ def get_start_and_end_datetime(days: int) -> [datetime, datetime]: | |
end_date = datetime.utcnow() | ||
start_date = end_date - timedelta(days=days) | ||
return start_date, end_date | ||
|
||
@staticmethod | ||
def convert_to_title_case(snake_case: str): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if this method is only for testing purpose, I think it should be under test directory There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it helps to convert lower case to title case, that is being push to the ElasticSearch There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @athiruma, WDYT ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not a testing method. |
||
""" | ||
This method converts lower case to title case | ||
ex: test_name => TestName | ||
test-name => TestName | ||
:param snake_case: | ||
:type snake_case: | ||
:return: | ||
:rtype: | ||
""" | ||
title_case = re.sub(r'(?:^|[_-])([a-z])', lambda match: match.group(1).upper(), snake_case) | ||
return title_case |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can u add the class purpose ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok