bito-code-review[bot] commented on code in PR #37070:
URL: https://github.com/apache/superset/pull/37070#discussion_r2684867866


##########
superset/multitenancy/commands/seed_tenants.py:
##########
@@ -0,0 +1,190 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Command to seed tenants table with development data"""
+
+import json
+import logging
+from pathlib import Path
+from typing import Any
+
+import click
+from flask.cli import with_appcontext
+
+from superset import db
+from superset.multitenancy.factories.tenant_factory import TenantFactory
+from superset.multitenancy.models.tenant import Tenant
+from superset.multitenancy.repositories.tenant_repository import 
TenantRepository
+
+logger = logging.getLogger(__name__)
+
+
[email protected]()
[email protected](
+    "--config",
+    "-c",
+    type=click.Path(exists=True, path_type=Path),
+    help="Path to JSON file with tenant configurations",
+)
[email protected](
+    "--slug",
+    "-s",
+    help="Slug of a single tenant to create (requires other options)",
+)
[email protected](
+    "--name",
+    "-n",
+    help="Name of tenant (required with --slug)",
+)
[email protected](
+    "--oauth-issuer",
+    help="OAuth issuer URL (required with --slug)",
+)
[email protected](
+    "--oauth-provider-type",
+    default="generic",
+    help="OAuth provider type (e.g., 'generic', 'google', 'github', 'okta'). 
Default: 'generic'",
+)
[email protected](
+    "--client-id",
+    help="OAuth client ID (required with --slug)",
+)
[email protected](
+    "--client-secret",
+    help="OAuth client secret (required with --slug)",
+)
[email protected](
+    "--db-uri",
+    help="Database SQLAlchemy URI (required with --slug)",
+)
[email protected](
+    "--default-schema",
+    help="Default schema name (optional)",
+)
[email protected](
+    "--admin",
+    is_flag=True,
+    help="Mark tenant as admin tenant",
+)
[email protected](
+    "--overwrite",
+    is_flag=True,
+    help="Overwrite existing tenants with same slug",
+)
+@with_appcontext
+def seed_tenants(
+    config: Path | None,
+    slug: str | None,
+    name: str | None,
+    oauth_issuer: str | None,
+    oauth_provider_type: str,
+    client_id: str | None,
+    client_secret: str | None,
+    db_uri: str | None,
+    default_schema: str | None,
+    admin: bool,
+    overwrite: bool,
+) -> None:
+    """
+    Seed the tenants table with development data.
+
+    You can either:
+    1. Provide a JSON config file with multiple tenants
+    2. Provide individual tenant options via command line
+
+    Example JSON config file:
+    {
+        "tenants": [
+            {
+                "slug": "acme",
+                "name": "Acme Corp",
+                "oauth_issuer": "https://acme.okta.com/oauth2/default";,
+                "oauth_provider_type": "generic",
+                "client_id": "acme-client-id",
+                "client_secret": "acme-secret",
+                "db_sqlalchemy_uri": 
"postgresql://user:pass@localhost:5432/acmedb",
+                "default_schema": "acme_schema",
+                "is_admin_tenant": false
+            }
+        ]
+    }
+    """
+    if config:
+        # Load from JSON file
+        with open(config, encoding="utf-8") as f:
+            data = json.load(f)
+            tenants_config = data.get("tenants", [])

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Unhandled JSON parsing error</b></div>
   <div id="fix">
   
   If the config file contains invalid JSON, json.load will raise an unhandled 
exception, crashing the command.
   </div>
   
   
   <details>
   <summary>
   <b>Code suggestion</b>
   </summary>
   <blockquote>Check the AI-generated fix before applying</blockquote>
   <div id="code">
   
   
   ````suggestion
            with open(config, encoding="utf-8") as f:
                try:
                    data = json.load(f)
                except json.JSONDecodeError as e:
                    raise ValueError(f"Invalid JSON in config file {config}: 
{e}")
                tenants_config = data.get("tenants", [])
   ````
   
   </div>
   </details>
   
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #2aae92</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a 
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to