88
99If you have already Custom App:
1010
11- ./flask_app_with_oauth.py <databricks workspace url> \
11+ ./flask_app_with_oauth.py --host <databricks workspace url> \
1212 --client_id <app-client-id> \
1313 --client_secret <app-secret> \
1414 --port 5001
1515
1616If you want this script to register Custom App and redirect URL for you:
1717
18- ./flask_app_with_oauth.py <databricks workspace url >
18+ ./flask_app_with_oauth.py --port 5001 --profile <databricks account profile >
1919
2020You'll get prompted for Databricks Account username and password for
2121script to enroll your account into OAuth and create a custom app with
4444</ul>"""
4545
4646
47- def create_flask_app (oauth_client : OAuthClient , port : int ):
47+ def create_flask_app (oauth_client : OAuthClient ):
4848 """The create_flask_app function creates a Flask app that is enabled with OAuth.
4949
5050 It initializes the app and web session secret keys with a randomly generated token. It defines two routes for
@@ -91,23 +91,13 @@ def index():
9191 return app
9292
9393
94- def register_custom_app (oauth_client : OAuthClient , args : argparse .Namespace ) -> tuple [str , str ]:
94+ def register_custom_app (args : argparse .Namespace ) -> tuple [str , str ]:
9595 """Creates new Custom OAuth App in Databricks Account"""
96- if not oauth_client .is_aws :
97- logging .error ("Not supported for other clouds than AWS" )
98- sys .exit (2 )
99-
10096 logging .info ("No OAuth custom app client/secret provided, creating new app" )
10197
102- import getpass
103-
10498 from databricks .sdk import AccountClient
10599
106- account_client = AccountClient (host = "https://accounts.cloud.databricks.com" ,
107- account_id = input ("Databricks Account ID: " ),
108- username = input ("Username: " ),
109- password = getpass .getpass ("Password: " ),
110- )
100+ account_client = AccountClient (profile = args .profile )
111101
112102 custom_app = account_client .custom_app_integration .create (
113103 name = APP_NAME , redirect_urls = [f"http://localhost:{ args .port } /callback" ], confidential = True ,
@@ -129,7 +119,7 @@ def init_oauth_config(args) -> OAuthClient:
129119 scopes = ["all-apis" ],
130120 )
131121 if not oauth_client .client_id :
132- client_id , client_secret = register_custom_app (oauth_client , args )
122+ client_id , client_secret = register_custom_app (args )
133123 oauth_client .client_id = client_id
134124 oauth_client .client_secret = client_secret
135125
@@ -139,10 +129,11 @@ def init_oauth_config(args) -> OAuthClient:
139129def parse_arguments () -> argparse .Namespace :
140130 """Parses arguments for this demo"""
141131 parser = argparse .ArgumentParser (prog = APP_NAME , description = __doc__ .strip ())
142- parser .add_argument ("host" )
132+ parser .add_argument ("-- host" )
143133 for flag in ["client_id" , "client_secret" ]:
144134 parser .add_argument (f"--{ flag } " )
145135 parser .add_argument ("--port" , default = 5001 , type = int )
136+ parser .add_argument ("--profile" , default = "DEFAULT" , help = "Databricks account profile to use for authentication." )
146137 return parser .parse_args ()
147138
148139
@@ -155,7 +146,7 @@ def parse_arguments() -> argparse.Namespace:
155146
156147 args = parse_arguments ()
157148 oauth_cfg = init_oauth_config (args )
158- app = create_flask_app (oauth_cfg , args . port )
149+ app = create_flask_app (oauth_cfg )
159150
160151 app .run (
161152 host = "localhost" ,
0 commit comments