Skip to content

Commit

Permalink
add addpikey and removeapikey management commands
Browse files Browse the repository at this point in the history
  • Loading branch information
DrCBeatz committed Mar 16, 2024
1 parent a5464ee commit 56e6336
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 30 deletions.
60 changes: 30 additions & 30 deletions frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
{
"name": "frontend",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"@fortawesome/fontawesome-free": "^6.5.1",
"chart.js": "^4.4.2",
"mdb-react-ui-kit": "git+https://oauth2:[api-key-redacted]@git.mdbootstrap.com/mdb/react/mdb5/prd/mdb5-react-ui-kit-pro-essential",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.2.56",
"@types/react-dom": "^18.2.19",
"@typescript-eslint/eslint-plugin": "^7.0.2",
"@typescript-eslint/parser": "^7.0.2",
"@vitejs/plugin-react": "^4.2.1",
"eslint": "^8.56.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.5",
"typescript": "^5.2.2",
"vite": "^5.1.4"
}
}
"name": "frontend",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"@fortawesome/fontawesome-free": "^6.5.1",
"chart.js": "^4.4.2",
"mdb-react-ui-kit": "git+https://oauth2:[api-key-redacted]@git.mdbootstrap.com/mdb/react/mdb5/prd/mdb5-react-ui-kit-pro-essential",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.2.56",
"@types/react-dom": "^18.2.19",
"@typescript-eslint/eslint-plugin": "^7.0.2",
"@typescript-eslint/parser": "^7.0.2",
"@vitejs/plugin-react": "^4.2.1",
"eslint": "^8.56.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.5",
"typescript": "^5.2.2",
"vite": "^5.1.4"
}
}
23 changes: 23 additions & 0 deletions mastertheorem/management/commands/addapikey.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# mastertheorem/management/commands/addapikey.py

from django.core.management.base import BaseCommand
import os

class Command(BaseCommand):
help = 'Adds the MDB Pro API key to package.json and package-lock.json'

def handle(self, *args, **kwargs):
api_key = os.getenv('MDB_PRO_KEY')
for filename in ['package.json', 'package-lock.json']:
file_path = f'frontend/{filename}'
with open(file_path, 'r') as file:
content = file.read()

updated_content = content.replace('[api-key-redacted]', api_key)

if content != updated_content:
with open(file_path, 'w') as file:
file.write(updated_content)
self.stdout.write(self.style.SUCCESS(f'Successfully added the API key to {filename}.'))
else:
self.stdout.write(self.style.SUCCESS(f'No changes made to {filename}.'))
23 changes: 23 additions & 0 deletions mastertheorem/management/commands/removeapikey.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# mastertheorem/management/commands/removeapikey.py

from django.core.management.base import BaseCommand
import os

class Command(BaseCommand):
help = 'Removes the MDB Pro API key from package.json and package-lock.json'

def handle(self, *args, **kwargs):
api_key = os.getenv('MDB_PRO_KEY')
for filename in ['package.json', 'package-lock.json']:
file_path = f'frontend/{filename}'
with open(file_path, 'r') as file:
content = file.read()

updated_content = content.replace(api_key, '[api-key-redacted]')

if content != updated_content:
with open(file_path, 'w') as file:
file.write(updated_content)
self.stdout.write(self.style.SUCCESS(f'Successfully removed the API key from {filename}.'))
else:
self.stdout.write(self.style.SUCCESS(f'No changes made to {filename}.'))

0 comments on commit 56e6336

Please sign in to comment.