Skip to content

Commit

Permalink
Merge pull request #4 from EchoSkorJjj/frontend-design
Browse files Browse the repository at this point in the history
Frontend design, user storage service, and notes service merge to main
  • Loading branch information
EchoSkorJjj authored Feb 25, 2024
2 parents b915ed5 + 50004fb commit c106982
Show file tree
Hide file tree
Showing 98 changed files with 4,971 additions and 651 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
**/*_password.txt
.DS_Store
node_modules
.env
.env
**/log.txt
**/user-storage.log
8 changes: 7 additions & 1 deletion backend/kong-gateway/authn-kong/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ local claim_spec = {
-- Access phase handler
function MyAuthHandler:access(conf)
local path = kong.request.get_path()
local publicPaths = conf.public_paths;

kong.log.notice("The path is ", path)


for i, pub_path in ipairs(publicPaths) do
if pub_path == path then
return
end
end
end

-- Return the handler
Expand Down
10 changes: 8 additions & 2 deletions backend/kong-gateway/authn-kong/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ return {
{ config = {
type = "record",
fields = {
-- Dummy field
{ enabled = { type = "boolean", default = true, required = false } },
{
public_paths = {
type = "array",
default = {},
required = false,
elements = { type = "string" },
}
},
},
},
},
Expand Down
28 changes: 25 additions & 3 deletions backend/kong-gateway/kong.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,21 @@ services:
- http
paths:
- /api/v1/user
- /api/v1/auth
plugins:
- name: grpc-gateway
config:
proto: /usr/local/share/lua/5.1/kong/protos/user_storage.proto

plugins:
- name: file-log
service: user-storage-service
config:
path: /usr/local/share/lua/5.1/kong/plugins/authn-kong/user-storage.log
- name: cors
config:
origins:
- "http://localhost:5173"
- "http://localhost:3001"
methods:
- HEAD
- GET
Expand All @@ -42,11 +47,28 @@ plugins:
- Authorization
exposed_headers:
- Authorization
- X-Myinfo-Unique-Id
- X-Access-Token
- X-Sgid-Unique-Id
credentials: true
max_age: 3600
preflight_continue: false

- name: correlation-id
config:
header_name: Kong-Request-ID
generator: uuid
echo_downstream: false

- name: rate-limiting
config:
minute: 100
policy: local
policy: local

- name: authn-kong
config:
public_paths:
- /api/v1/auth/google/callback
- /api/v1/auth/apple/callback
- /api/v1/auth/myInfo/generateCodeChallenge
- /api/v1/auth/myInfo/callback
78 changes: 47 additions & 31 deletions backend/kong-gateway/protos/user_storage.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,12 @@ import "google/protobuf/any.proto";
message ResponseMetadata {
string request_id = 1;
google.protobuf.Timestamp timestamp = 2;
bool success = 3;
string error_message = 4; // Simplified error handling
}

// Custom error response
message ErrorResponse {
int32 code = 1;
string message = 2;
}

// General response wrapper for all service responses
message ServiceResponseWrapper {
ResponseMetadata metadata = 1;
oneof result {
google.protobuf.Any payload = 2; // Flexible payload using Any
ErrorResponse error = 3; // Error details
}
}
message TestRequest {
string message = 1;
}

message TestResponse {
string message = 1;
google.protobuf.Any payload = 2; // Flexible payload using Any
}

// Simplified User definition for demonstration
Expand All @@ -44,26 +26,38 @@ message User {
string last_name = 4;
string email = 5;
}

// Singpass MyInfo generate challenge code request
message MyInfoCodeRequest {
}

message MyInfoCodeResponse {
string code_challenge = 1;
}

// Singpass SgId generate auth url request
message SgIdAuthUrlRequest {
}

message SgIdAuthUrlResponse {
string auth_url = 1;
}

// Request and response messages
message AuthRequest {
string request_id = 1;
string google_oauth_code = 2;
string code = 1;
}

message GetUserRequest {
string request_id = 1;
string user_id = 2;
string user_id = 1;
}

message UpdateUserRequest {
string request_id = 1;
User user = 2; // Using User message for updates
User user = 1; // Using User message for updates
}

message DeleteUserRequest {
string request_id = 1;
string user_id = 2;
string user_id = 1;
}

message HealthCheckRequest {
Expand All @@ -75,15 +69,37 @@ message HealthCheckResponse {
}

service UserStorage {
rpc Test(TestRequest) returns (TestResponse) {
rpc GoogleAuth(AuthRequest) returns (ServiceResponseWrapper) {
option (google.api.http) = {
post: "/api/v1/auth/google/callback"
body: "*"
};
}

rpc MyInfoCode(MyInfoCodeRequest) returns (MyInfoCodeResponse) {
option (google.api.http) = {
post: "/api/v1/auth/myInfo/generateCodeChallenge"
body: "*"
};
}

rpc MyInfoAuth(AuthRequest) returns (ServiceResponseWrapper) {
option (google.api.http) = {
get: "/api/v1/user/test"
post: "/api/v1/auth/myInfo/callback"
body: "*"
};
}

rpc SgIdAuthUrl(SgIdAuthUrlRequest) returns (SgIdAuthUrlResponse) {
option (google.api.http) = {
post: "/api/v1/auth/sgId/generateAuthUrl"
body: "*"
};
}

rpc Authenticate(AuthRequest) returns (ServiceResponseWrapper) {
rpc SgIdAuth(AuthRequest) returns (ServiceResponseWrapper) {
option (google.api.http) = {
post: "/api/v1/user/auth"
post: "/api/v1/auth/sgId/callback"
body: "*"
};
}
Expand Down
9 changes: 9 additions & 0 deletions backend/simple/notes/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.vscode
.DS_Store

.env
.env.local
.env.development.local

venv
__pycache__
20 changes: 20 additions & 0 deletions backend/simple/notes/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use an official Python runtime as a parent image
FROM python:3.9-slim
ENV PYTHONUNBUFFERED=1
# Set the working directory in the container
WORKDIR /app

# Install any needed packages specified in requirements.txt
# Copy only the requirements.txt first to leverage Docker cache
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy the rest of the application
COPY . .

# It's a good practice to expose the port your app runs on.
# This does not actually publish the port but serves as documentation.
EXPOSE 50052

# Run note_upload_service.py when the container launches
CMD ["python3", "note_upload_service.py"]
Binary file added backend/simple/notes/example_note.pdf
Binary file not shown.
18 changes: 18 additions & 0 deletions backend/simple/notes/instructions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

1. Build Image
docker build -t notes-service .

2. Run container
docker run -p 50051:50051 \
-e AWS_ACCESS_KEY_ID=your_access_key_id \
-e AWS_SECRET_ACCESS_KEY=your_secret_access_key \
notes-service

-
Build instructions from Neil Sharma:
1. 2x GRPC server (to talk to upload notes, to talk to retrieve notes)
(Server is just responding to requests)
2. We can choose between Unitary or bidirectional streaming
3. For client we should create simple client to upload notes
4. DB/Schema is up to us to create
5. Implement good logging, as a .log file
38 changes: 38 additions & 0 deletions backend/simple/notes/note_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import grpc
import notes_pb2
import notes_pb2_grpc

def upload_note(stub, user_id, filename, file_content):
# Create a request message
request = notes_pb2.UploadNoteRequest(userId=user_id, filename=filename, fileContent=file_content)
# Make the call to the server
response = stub.UploadNote(request)
return response

def retrieve_note(stub, note_id):
# Create a request message
request = notes_pb2.RetrieveNoteRequest(noteId=note_id)
# Make the call to the server
response = stub.RetrieveNote(request)
return response

def run():
with grpc.insecure_channel('localhost:50052') as channel:
stub = notes_pb2_grpc.NoteServiceStub(channel)

# Example usage: upload a PDF note
user_id = '123'
filename = 'example_note.pdf' # Change to your PDF file name
with open(filename, 'rb') as pdf_file: # Open the PDF file in binary mode
file_content = pdf_file.read() # Read the entire PDF file content
upload_response = upload_note(stub, user_id, filename, file_content)
print(f"Uploaded Note ID: {upload_response.noteId}")

# Example usage: retrieve a note
# Note: You need to implement this part on the server side for it to work
note_id = upload_response.noteId
retrieve_response = retrieve_note(stub, note_id)
# print(f"Retrieved Note Content: {retrieve_response.fileContent}")

if __name__ == '__main__':
run()
Loading

0 comments on commit c106982

Please sign in to comment.