@@ -19,12 +19,45 @@ def run(host: str, client_id: Optional[str], client_secret: Optional[str], azure
1919 print (me )
2020
2121
22+ def register_custom_app () -> tuple [str , str ]:
23+ """Creates new Custom OAuth App in Databricks Account"""
24+ logging .info ("No OAuth custom app client/secret provided, creating new app" )
25+
26+ from databricks .sdk import AccountClient
27+
28+ account_client = AccountClient ()
29+
30+ custom_app = account_client .custom_app_integration .create (
31+ name = "external-browser-demo" ,
32+ redirect_urls = [
33+ f"http://localhost:8020" ,
34+ ],
35+ confidential = True ,
36+ scopes = ["all-apis" ],
37+ )
38+ logging .info (f"Created new custom app: "
39+ f"--client_id { custom_app .client_id } "
40+ f"--client_secret { custom_app .client_secret } " )
41+
42+ return custom_app .client_id , custom_app .client_secret
43+
44+
2245if __name__ == "__main__" :
2346 parser = argparse .ArgumentParser ()
2447 parser .add_argument ("--host" , help = "Databricks host" , required = True )
2548 parser .add_argument ("--client_id" , help = "Databricks client_id" , default = None )
2649 parser .add_argument ("--azure_client_id" , help = "Databricks azure_client_id" , default = None )
2750 parser .add_argument ("--client_secret" , help = "Databricks client_secret" , default = None )
2851 parser .add_argument ("--azure_client_secret" , help = "Databricks azure_client_secret" , default = None )
52+ parser .add_argument ("--register-custom-app" , action = "store_true" , help = "Register a new custom app" )
2953 namespace = parser .parse_args ()
30- run (namespace .host , namespace .client_id , namespace .client_secret , namespace .azure_client_id , namespace .azure_client_secret )
54+ if namespace .register_custom_app and (namespace .client_id is not None or namespace .azure_client_id is not None ):
55+ raise ValueError ("Cannot register custom app and provide --client_id/--azure_client_id at the same time" )
56+ if not namespace .register_custom_app and namespace .client_id is None and namespace .azure_client_secret is None :
57+ raise ValueError ("Must provide --client_id/--azure_client_id or register a custom app" )
58+ if namespace .register_custom_app :
59+ client_id , client_secret = register_custom_app ()
60+ else :
61+ client_id , client_secret = namespace .client_id , namespace .client_secret
62+
63+ run (namespace .host , client_id , client_secret , namespace .azure_client_id , namespace .azure_client_secret )
0 commit comments