Skip to content
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

Refactor users service from go to python #596

Open
wants to merge 101 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
67633d5
initial python users
Adibuer-lab May 24, 2024
8c4025c
initial python users
Adibuer-lab May 24, 2024
d385501
dockerise
Adibuer-lab May 28, 2024
d8e042c
dockerise
Adibuer-lab May 28, 2024
5b0a7b1
restructure users-py
Adibuer-lab May 29, 2024
edb9813
test functionality:claim pending
Adibuer-lab May 29, 2024
0ecf15b
test functionality
Adibuer-lab May 29, 2024
8ba9fc7
start editing cfn stack
Adibuer-lab May 30, 2024
9694c3f
start editing cfn stack
Adibuer-lab May 30, 2024
56eeadc
cfn-stack
Adibuer-lab May 30, 2024
7dfe946
rm init_done
Adibuer-lab May 30, 2024
b4794ad
rm init_done
Adibuer-lab May 30, 2024
5597464
add users-service url to deployment-support
Adibuer-lab May 31, 2024
b0f6f8d
switch to python users
Adibuer-lab May 31, 2024
dc52f84
switch to python users buildspec
Adibuer-lab May 31, 2024
c3c76ac
make cloudfront policy names unique across stacks
Adibuer-lab May 31, 2024
67bbf5a
change folder structure
Adibuer-lab May 31, 2024
d9dddac
change folder structure
Adibuer-lab May 31, 2024
8734359
change folder structure
Adibuer-lab May 31, 2024
446c1a7
fix cloudfront names
Adibuer-lab May 31, 2024
f18d1cb
fix identity index name
Adibuer-lab May 31, 2024
40fe809
fix cloudfront names
Adibuer-lab May 31, 2024
887301d
fix table perms
Adibuer-lab May 31, 2024
b8cae11
set empty user
Adibuer-lab Jun 1, 2024
348b76e
set empty user
Adibuer-lab Jun 1, 2024
c2319fd
debug statement
Adibuer-lab Jun 1, 2024
fe877c1
debug statement
Adibuer-lab Jun 1, 2024
fa01276
set default user age to 0
Adibuer-lab Jun 5, 2024
3f5e703
set default persona to ''
Adibuer-lab Jun 5, 2024
90ac2f6
set string defaults to ''
Adibuer-lab Jun 5, 2024
a105d4f
debug statement for update_user_with_data
Adibuer-lab Jun 5, 2024
cbec108
set selectable defaults to false and phone number defaults to ''
Adibuer-lab Jun 5, 2024
97cae3f
parse string timestamps
Adibuer-lab Jun 5, 2024
2e4b3e1
set default persona to ''
Adibuer-lab Jun 5, 2024
198db80
set default strings to '' and not null
Adibuer-lab Jun 5, 2024
f089792
set default strings to '' and not null
Adibuer-lab Jun 5, 2024
34943df
try map for claimed users see if faster
Adibuer-lab Jun 5, 2024
ae8212b
ruff fixes
Adibuer-lab Jun 5, 2024
eb59295
Merge branch 'aws-samples:master' into refactor-users-service-from-go…
Adibuer-lab Jun 7, 2024
5162d49
change to using flask, x-ray, remove init
Adibuer-lab Jun 19, 2024
5124170
change to using flask, x-ray, remove init
Adibuer-lab Jun 19, 2024
bbbae8a
Merge branch 'refactor-users-service-from-go-to-python' of github.com…
Adibuer-lab Jun 19, 2024
a4443e3
change to using flask, x-ray, remove init
Adibuer-lab Jun 19, 2024
885c88c
use app logger
Adibuer-lab Jun 19, 2024
ffe14e8
remove redundant stopiteration exception
Adibuer-lab Jun 19, 2024
9383170
next(User.identity_id_index.query(identity_id), User())
Adibuer-lab Jun 19, 2024
0bb6459
change create and update to upsert
Adibuer-lab Jun 19, 2024
4069b10
change user persona file path to follow standard
Adibuer-lab Jun 19, 2024
515d7b4
fix copy-paste error in user load data lambda
Adibuer-lab Jun 19, 2024
829f3e7
add license comment
Adibuer-lab Jun 19, 2024
c48a7d2
configure x-ray to users service
Adibuer-lab Jun 19, 2024
20ecd37
retry CustomLoadDataUsers
Adibuer-lab Jun 24, 2024
0f1b731
use claimed-index and not local dict
Adibuer-lab Jun 24, 2024
fa1c70b
add health route
Adibuer-lab Jun 24, 2024
736b200
test users init
Adibuer-lab Jun 24, 2024
a67b878
add claimed_user attribute
Adibuer-lab Jun 24, 2024
c2e6c22
increase timeouts
Adibuer-lab Jun 24, 2024
c03fdd5
add retries to product load as well
Adibuer-lab Jun 24, 2024
6e8fbc4
fix datetime values
Adibuer-lab Jun 24, 2024
ab04432
get claimed index gsi working
Adibuer-lab Jun 26, 2024
56d6b64
fix date time handling
Adibuer-lab Jun 26, 2024
cad670e
use upsert for claim user
Adibuer-lab Jun 26, 2024
98da900
debug statement for date
Adibuer-lab Jun 26, 2024
1c704cd
remove duplicate date code
Adibuer-lab Jun 26, 2024
1b8f187
debug statements
Adibuer-lab Jun 26, 2024
c256258
debug statements
Adibuer-lab Jun 26, 2024
27f3ccb
handle none
Adibuer-lab Jun 26, 2024
0685608
parse_Date
Adibuer-lab Jun 26, 2024
a278459
test old prepro
Adibuer-lab Jun 26, 2024
294e46a
check new parse_date
Adibuer-lab Jun 26, 2024
2fbd28d
move date parse to repository
Adibuer-lab Jun 26, 2024
7271243
handle query strings
Adibuer-lab Jun 26, 2024
8cef4a5
use base boto api's
Adibuer-lab Jun 27, 2024
f01326e
use client create table
Adibuer-lab Jun 27, 2024
9362ab0
kl
Adibuer-lab Jun 27, 2024
0092bbd
hj
Adibuer-lab Jun 27, 2024
7e192e7
add new indices for efficient querying
Adibuer-lab Jun 27, 2024
c3a3c13
claim_user type error
Adibuer-lab Jun 27, 2024
6f0ff0e
change index name to persona-index
Adibuer-lab Jun 27, 2024
78c85c9
add new indices to templates
Adibuer-lab Jun 27, 2024
2b8d0ea
change primary_persona index
Adibuer-lab Jun 27, 2024
e92ca86
fix claimed user
Adibuer-lab Jun 27, 2024
a3f1a1a
cleanup
Adibuer-lab Jun 27, 2024
36dd141
use batch write for loading, parallelise later
Adibuer-lab Jun 27, 2024
f4993ed
return empty User for gets
Adibuer-lab Jun 27, 2024
e222c51
remove none if in secondary index gets
Adibuer-lab Jun 27, 2024
7aa9962
return empty user
Adibuer-lab Jun 27, 2024
0584692
make user class flexible
Adibuer-lab Jun 27, 2024
8fe043e
defaults for class
Adibuer-lab Jun 27, 2024
bb3f681
create user function
Adibuer-lab Jun 27, 2024
3fce468
change empty strings
Adibuer-lab Jun 27, 2024
590ca8d
debug statements
Adibuer-lab Jun 27, 2024
492329c
validate posts
Adibuer-lab Jun 27, 2024
231d158
remove empty strings
Adibuer-lab Jun 27, 2024
96d641f
handle personas
Adibuer-lab Jun 27, 2024
1e864a7
for updateUserAttributes except gen
Adibuer-lab Jun 27, 2024
20e44d7
gender must not be null
Adibuer-lab Jun 27, 2024
b0e455f
add random filter to get_random to speed up
Adibuer-lab Jun 27, 2024
896b9f7
reset random retry
Adibuer-lab Jun 27, 2024
3a2d8ff
make random retry count local to function
Adibuer-lab Jun 27, 2024
59599f8
remove useless else
Adibuer-lab Jun 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix datetime values
Adibuer-lab committed Jun 24, 2024
commit 6e8fbc40b55b3c5e06fffa53c2c72b968eb164f3
27 changes: 23 additions & 4 deletions src/users/src/users_service/models.py
Original file line number Diff line number Diff line change
@@ -101,8 +101,8 @@ def init_tables(cls):
gender = UnicodeAttribute(default="")
persona = UnicodeAttribute(default="")
discount_persona = UnicodeAttribute(default="")
sign_up_date = UTCDateTimeAttribute(null=True)
selectable_user = BooleanAttribute(null=True)
sign_up_date = UTCDateTimeAttribute(null=True)
last_sign_in_date = UTCDateTimeAttribute(null=True)
identity_id = UnicodeAttribute(null=True)
phone_number = UnicodeAttribute(default="")
@@ -144,7 +144,26 @@ def parse_iso_datetime(date_str):
current_app.logger.info(f"Error parsing date: {e}")
return None

def save(self,**expected_values):
"""Override save to preprocess datetime fields."""
def save(self, **kwargs):
self.preprocess_datetime_fields()
super(User, self).save(**expected_values)
super(User, self).save(**kwargs)

def update(self, **kwargs):
self.preprocess_datetime_fields()
super(User, self).update(**kwargs)

def preprocess_datetime_fields(self):
datetime_fields = ['sign_up_date', 'last_sign_in_date']
for field in datetime_fields:
value = getattr(self, field, None)
if isinstance(value, str):
try:
parsed_date = datetime.fromisoformat(value.rstrip('Z'))
if parsed_date.tzinfo is None:
parsed_date = parsed_date.replace(tzinfo=pytz.UTC)
setattr(self, field, parsed_date)
except ValueError:
current_app.logger.warning(f"Invalid date format for {field}: {value}")
setattr(self, field, None)
elif isinstance(value, datetime) and value.tzinfo is None:
setattr(self, field, value.replace(tzinfo=pytz.UTC))