feat: Phase 1 Week 1 - User Service Foundation #167
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Date: 16 Jan 2025
Developer Name: @lakshayman
Description
This PR implements Phase 1, Week 1: User Service Foundation for the Feature Flag Backend. It establishes a standalone user authentication system, enabling the service to manage users independently without relying on external RDS authentication.
Key Features Implemented:
User Data Model
Usermodel with fields: id, email, passwordHash, role, createdAt, updatedAt, isActiveADMIN,DEVELOPER,VIEWERPassword Security
HashPassword()andCheckPasswordHash()functions for secure password managementUser Registration Endpoint
POST /users/register- Register new usersUser Login Endpoint
POST /users/login- Authenticate users and generate JWT tokensUser Profile Management
GET /users/{userId}- Retrieve user profile (excludes password hash)PUT /users/{userId}- Update user profile (email, role, isActive status)JWT Token Generation
JWTUtilsto support private key loading from SSM Parameter StoreGenerateToken()method for creating JWT tokensInfrastructure Updates
setup-dynamodb-tables.shwith email-index GSIRegisterUserFunction,LoginUserFunction,GetUserByIdFunction, andUpdateUserFunctionto SAM templateDocumentation Updated?
Under Feature Flag
Database Changes
Database Changes:
usertable with partition keyidand GSI onemailfieldBreaking Changes
Development Tested?
Testing:
Screenshots
Screenshot 1
Test Coverage
Test Coverage Details
Additional Notes
Setup Requirements
DynamoDB Table Creation:
./setup-dynamodb-tables.sh
This will create the
usertable with email-index GSI.SSM Parameter Setup:
Private keys need to be stored in SSM Parameter Store:
PROD_RDS_BACKEND_PRIVATE_KEY(for production)STAGING_RDS_BACKEND_PRIVATE_KEY(for staging)The public key should already exist from previous setup.
API Endpoints:
POST /users/register- No authentication requiredPOST /users/login- No authentication requiredGET /users/{userId}- JWT authentication requiredPUT /users/{userId}- JWT authentication requiredNext Steps (Week 2)
Security Considerations
Files Changed
layer/models/user.go(new)layer/utils/password.go(new)layer/utils/RequestResponse.go(updated)layer/utils/Constants.go(updated)layer/utils/ErrorOutput.go(updated)layer/jwt/jwt.go(updated)registerUser/main.go(new)loginUser/main.go(new)getUserById/main.go(new)updateUser/main.go(new)setup-dynamodb-tables.sh(updated)template.yaml(updated)go.mod(updated)