Disable Subscription if Stripe environment not setup

Deduplicate DJANGO_SECRET_KEY and KHOJ_DJANGO_SECRET_KEY to latter
name as prefixed with KHOJ as KHOJ app specific
This commit is contained in:
Debanjum Singh Solanky 2023-11-08 19:01:01 -08:00
parent 09e1235832
commit a2609973b8
7 changed files with 18 additions and 7 deletions

View file

@ -21,7 +21,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent.parent
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ # See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret! # SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.getenv("DJANGO_SECRET_KEY") SECRET_KEY = os.getenv("KHOJ_DJANGO_SECRET_KEY")
# SECURITY WARNING: don't run with debug turned on in production! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.getenv("DJANGO_DEBUG", "False") == "True" DEBUG = os.getenv("DJANGO_DEBUG", "False") == "True"

View file

@ -150,7 +150,9 @@ def configure_routes(app):
app.include_router(api, prefix="/api") app.include_router(api, prefix="/api")
app.include_router(api_beta, prefix="/api/beta") app.include_router(api_beta, prefix="/api/beta")
app.include_router(indexer, prefix="/api/v1/index") app.include_router(indexer, prefix="/api/v1/index")
app.include_router(subscription_router, prefix="/api/subscription") if state.billing_enabled:
logger.info("💳 Enabled Billing")
app.include_router(subscription_router, prefix="/api/subscription")
app.include_router(web_client) app.include_router(web_client)
app.include_router(auth_router, prefix="/auth") app.include_router(auth_router, prefix="/auth")

View file

@ -158,7 +158,8 @@
</div> </div>
</div> </div>
</div> </div>
<div class="section"> {% if billing_enabled %}
<div class="section">
<h2 class="section-title">Billing</h2> <h2 class="section-title">Billing</h2>
<div class="section-cards"> <div class="section-cards">
<div class="card"> <div class="card">
@ -219,6 +220,7 @@
</div> </div>
</div> </div>
</div> </div>
{% endif %}
<div class="section general-settings"> <div class="section general-settings">
<div id="results-count" title="Number of items to show in search and use for chat response"> <div id="results-count" title="Number of items to show in search and use for chat response">
<label for="results-count-slider">Results Count: <span id="results-count-value">5</span></label> <label for="results-count-slider">Results Count: <span id="results-count-value">5</span></label>

View file

@ -24,7 +24,9 @@ logger = logging.getLogger(__name__)
auth_router = APIRouter() auth_router = APIRouter()
if not state.anonymous_mode and not (os.environ.get("GOOGLE_CLIENT_ID") and os.environ.get("GOOGLE_CLIENT_SECRET")): if not state.anonymous_mode and not (os.environ.get("GOOGLE_CLIENT_ID") and os.environ.get("GOOGLE_CLIENT_SECRET")):
logger.info("Please set GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET environment variables to use Google OAuth") logger.warn(
"🚨 Use --anonymous-mode flag to disable Google OAuth or set GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET environment variables to enable it"
)
else: else:
config = Config(environ=os.environ) config = Config(environ=os.environ)

View file

@ -12,13 +12,11 @@ import stripe
# Internal Packages # Internal Packages
from database import adapters from database import adapters
# Stripe integration for Khoj Cloud Subscription # Stripe integration for Khoj Cloud Subscription
stripe.api_key = os.getenv("STRIPE_API_KEY") stripe.api_key = os.getenv("STRIPE_API_KEY")
endpoint_secret = os.getenv("STRIPE_SIGNING_SECRET") endpoint_secret = os.getenv("STRIPE_SIGNING_SECRET")
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
subscription_router = APIRouter() subscription_router = APIRouter()

View file

@ -150,6 +150,7 @@ def config_page(request: Request):
"conversation_options": all_conversation_options, "conversation_options": all_conversation_options,
"selected_conversation_config": selected_conversation_config.id if selected_conversation_config else None, "selected_conversation_config": selected_conversation_config.id if selected_conversation_config else None,
"user_photo": user_picture, "user_photo": user_picture,
"billing_enabled": state.billing_enabled,
"subscription_state": user_subscription_state, "subscription_state": user_subscription_state,
"subscription_renewal_date": subscription_renewal_date, "subscription_renewal_date": subscription_renewal_date,
"khoj_cloud_subscription_url": os.getenv("KHOJ_CLOUD_SUBSCRIPTION_URL"), "khoj_cloud_subscription_url": os.getenv("KHOJ_CLOUD_SUBSCRIPTION_URL"),

View file

@ -1,4 +1,5 @@
# Standard Packages # Standard Packages
import os
import threading import threading
from typing import List, Dict from typing import List, Dict
from collections import defaultdict from collections import defaultdict
@ -35,3 +36,8 @@ khoj_version: str = None
device = get_device() device = get_device()
chat_on_gpu: bool = True chat_on_gpu: bool = True
anonymous_mode: bool = False anonymous_mode: bool = False
billing_enabled: bool = (
os.getenv("STRIPE_API_KEY") is not None
and os.getenv("STRIPE_SIGNING_SECRET") is not None
and os.getenv("KHOJ_CLOUD_SUBSCRIPTION_URL") is not None
)