Skip to content

Commit

Permalink
fix(userstorage & kong): temp fix
Browse files Browse the repository at this point in the history
  • Loading branch information
EchoSkorJjj committed Apr 22, 2024
1 parent 72a4719 commit 8aa32c4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
4 changes: 0 additions & 4 deletions backend/kong-gateway/kong.deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,6 @@ services:
proto: /usr/local/share/lua/5.1/kong/protos/handle_temporary_contents.proto

plugins:
- name: file-log
service: verify-user-service
config:
path: /usr/local/share/lua/5.1/kong/plugins/authn-kong/user-storage.log
- name: cors
config:
origins:
Expand Down
28 changes: 19 additions & 9 deletions backend/kong-gateway/rawstring-adapter/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,34 @@ local RawStringAdapterHandler = {
}

function RawStringAdapterHandler:access(config)
-- Retrieve the raw body directly without transformation
local raw_body, err = kong.request.get_raw_body()
if err then
kong.log.err("Error reading request body: ", err)
return
if err or not raw_body then
kong.log.err("Error reading request body or body is empty: ", err)
return kong.response.exit(400, { message = "Bad request" })
end

local body_json = cjson.encode(raw_body)
if not body_json then
kong.log.err("Failed to encode JSON")
return
-- Attempt to decode and re-encode to ensure it's valid JSON
local decoded_json, decode_err = cjson.decode(raw_body)
if decode_err then
kong.log.err("Failed to decode JSON: ", decode_err)
return kong.response.exit(400, { message = "Invalid JSON" })
end

local encoded_json, encode_err = cjson.encode(decoded_json)
if encode_err then
kong.log.err("Failed to re-encode JSON: ", encode_err)
return kong.response.exit(500, { message = "Internal Server Error" })
end

-- Forward the validated and re-encoded JSON
kong.service.request.set_raw_body(encoded_json)

-- Optionally, forward headers as is
local headers = kong.request.get_headers()
for k, v in pairs(headers) do
kong.service.request.set_header(k, v)
end

kong.service.request.set_raw_body(body_json)
end

return RawStringAdapterHandler
1 change: 1 addition & 0 deletions backend/simple/user-storage/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ RUN GRPC_HEALTH_PROBE_VERSION=v0.4.13 && \

FROM node:20.11.1-alpine3.19
ENV NODE_ENV production
ENV ENVIRONMENT development
WORKDIR /app

COPY --from=build /app/dist ./dist
Expand Down
1 change: 1 addition & 0 deletions backend/simple/user-storage/UserStorage.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ WORKDIR /app

# Set the environment to production to optimize for production
ENV NODE_ENV production
ENV ENVIRONMENT production

# Copy compiled protobuf definitions to the container
COPY protos /app/dist/protos
Expand Down
1 change: 1 addition & 0 deletions backend/simple/user-storage/src/services/redis.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class RedisService {
socket: {
host: REDIS_CONFIG.REDIS_HOST,
port: REDIS_CONFIG.REDIS_PORT,
tls: process.env.ENVIRONMENT === 'production',
},
});

Expand Down

0 comments on commit 8aa32c4

Please sign in to comment.