Skip to content

Commit

Permalink
Merge pull request #71 from epam/develop
Browse files Browse the repository at this point in the history
Remove accN index from usage (#70)
  • Loading branch information
bohdan-onsha authored Aug 19, 2024
2 parents c5eb295 + ced03ee commit c28a68b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [5.1.6] - 2024-08-19
- remove usage of `accN` index for Tenants model. Proxy old methods and attributes to `acc` index

## [5.1.5] - 2024-07-29
- fix `pynamodb` non compatible changes

Expand Down
31 changes: 12 additions & 19 deletions modular_sdk/models/tenant.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

DNTL_NAME_KEY = 'dntl'
GENERAL_PROJECT_ID = 'acc'
GOOGLE_ACCOUNT_NUMBER = 'accN'
PRIMARY_CONTACTS = 'pc'
SECONDARY_CONTACTS = 'sc'
TENANT_MANAGER = 'tmc'
Expand Down Expand Up @@ -79,21 +78,6 @@ class Meta(BaseMeta):
project = UnicodeAttribute(attr_name=GENERAL_PROJECT_ID, hash_key=True)


class AccountNumberIndex(BaseGSI):
"""
This class represents an Account Number global secondary index
"""

class Meta(BaseMeta):
index_name = F'{GOOGLE_ACCOUNT_NUMBER}-index'
read_capacity_units = 1
write_capacity_units = 1
projection = AllProjection()

account_number = UnicodeAttribute(attr_name=GOOGLE_ACCOUNT_NUMBER,
hash_key=True)


class CustomerNameIndex(BaseGSI):
class Meta(BaseMeta):
index_name = f"{CUSTOMER_NAME}-index"
Expand Down Expand Up @@ -124,16 +108,25 @@ class Meta(BaseMeta):
regions = ListAttribute(of=RegionAttr, attr_name=REGIONS, default=list)
contacts = Contacts(attr_name=TENANT_CONTACT, null=True)
parent_map = MapAttribute(attr_name=PARENT_MAP, default=dict)
account_number = UnicodeAttribute(attr_name=GOOGLE_ACCOUNT_NUMBER,
null=True)

customer_name_index = CustomerNameIndex()
project_index = ProjectIndex()
dntl_c_index = DisplayNameToLowerCloudIndex()
accN_index = AccountNumberIndex()

def get_parent_id(self, type_: str) -> Optional[str]:
assert type_ in ALLOWED_TENANT_PARENT_MAP_KEYS
if type_ in self.parent_map:
return self.parent_map[type_]
return

@property
def accN_index(self):
return self.project_index

@property
def account_number(self) -> str | None:
return self.project

@account_number.setter
def account_number(self, value: str | None):
self.project = value
7 changes: 4 additions & 3 deletions modular_sdk/services/tenant_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ def i_scan_tenants(only_active=False, limit: int = None,
filter_condition=condition)

@classmethod
@deprecated('represented logic is deprecated')
@deprecated('Logic is deprecated')
def get_tenants_by_parent_id(cls, parent_id, only_active=True):
return list(cls.i_get_tenant_by_parent_id(parent_id, only_active))

@staticmethod
@deprecated('represented logic is deprecated')
@deprecated('Logic is deprecated')
def i_get_tenant_by_parent_id(parent_id: str,
active: Optional[bool] = None,
limit: Optional[int] = None,
Expand Down Expand Up @@ -139,12 +139,13 @@ def i_get_by_dntl(
)

@staticmethod
@deprecated('Use i_get_by_acc instead')
def i_get_by_accN(accN: str, active: Optional[bool] = None,
limit: int = None,
last_evaluated_key: Union[dict, str] = None,
attributes_to_get: List[str] = None):
fc = None if active is None else (Tenant.is_active == active)
return Tenant.accN_index.query(
return Tenant.project_index.query(
hash_key=accN, filter_condition=fc,
limit=limit, last_evaluated_key=last_evaluated_key,
attributes_to_get=attributes_to_get
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "modular_sdk"
version = "5.1.5"
version = "5.1.6"
authors = [
{name = "EPAM Systems", email = "support@syndicate.team"}
]
Expand Down

0 comments on commit c28a68b

Please sign in to comment.