Skip to content

Commit

Permalink
update_04
Browse files Browse the repository at this point in the history
  • Loading branch information
Lungsangg committed Nov 29, 2024
1 parent 8878075 commit 27663b3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ RUN npm run build-prod
# Copy application source code
COPY . ./

ARG IS_BUILD_ENV=1
ENV IS_BUILD_ENV=$IS_BUILD_ENV

RUN python manage.py collectstatic --noinput


# Run Django migrations and start the server
CMD ["bash", "-c", "python manage.py migrate && python manage.py runserver 0.0.0.0:8000"]

Expand Down
43 changes: 23 additions & 20 deletions decoder.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
import base64
import os
import binascii

def add_base64_padding(base64_string):
"""Add padding to the Base64 string if necessary."""
missing_padding = len(base64_string) % 4
if missing_padding:
base64_string += '=' * (4 - missing_padding)
return base64_string
# Check if the script is running in a build environment
IS_BUILD_ENV = os.getenv('IS_BUILD_ENV') == '1'

# Retrieve the base64 encoded private key from the environment variable
encoded_key = os.getenv('private_key')
if not IS_BUILD_ENV:
import base64
import binascii

if encoded_key is None:
raise ValueError("Environment variable 'PRIVATE_KEY_BASE64' is not set.")
def add_base64_padding(base64_string):
missing_padding = len(base64_string) % 4
if missing_padding:
base64_string += '=' * (4 - missing_padding)
return base64_string

# Add padding to the encoded key
encoded_key = add_base64_padding(encoded_key)
encoded_key = os.getenv('PRIVATE_KEY_BASE64')
if not encoded_key:
raise ValueError("Environment variable 'PRIVATE_KEY_BASE64' is not set.")

# Decode the private key
try:
private_key = base64.b64decode(encoded_key)
except binascii.Error as e:
raise ValueError(f"Failed to decode Base64 string: {e}")
encoded_key = add_base64_padding(encoded_key)

private_key_1 = private_key.replace(b'\\n', b'\n')
try:
private_key = base64.b64decode(encoded_key)
except binascii.Error as e:
raise ValueError(f"Failed to decode Base64 string: {e}")

private_key_1 = private_key.replace(b'\\n', b'\n')
else:
print("Skipping private key decoding during build.")
private_key_1 = b""

0 comments on commit 27663b3

Please sign in to comment.