@@ -28,10 +28,16 @@ def __init__(self):
2828 self .client : SparkHistoryClient | None = None
2929 self .session : Session = Session ()
3030 self .json_mode : bool = False
31+ self .basic_auth_username : str | None = None
32+ self .basic_auth_password : str | None = None
3133
3234 def ensure_client (self ) -> SparkHistoryClient :
3335 if self .client is None :
34- self .client = SparkHistoryClient (self .session .server_url )
36+ self .client = SparkHistoryClient (
37+ self .session .server_url ,
38+ basic_auth_username = self .basic_auth_username ,
39+ basic_auth_password = self .basic_auth_password ,
40+ )
3541 return self .client
3642
3743 def resolve_app_id (self , app_id : str | None ) -> str :
@@ -86,17 +92,39 @@ def _fetch_sql_jobs(client, app_id: str, sql_exec: dict) -> list[dict]:
8692@click .option ("--server" , "-s" , default = "http://localhost:18080" ,
8793 envvar = "SPARK_HISTORY_SERVER" ,
8894 help = "Spark History Server URL (default: http://localhost:18080)" )
95+ @click .option ("--basic-auth-user" , default = None ,
96+ envvar = "SPARK_HISTORY_BASIC_AUTH_USER" ,
97+ help = "Basic Auth username for Spark History Server" )
98+ @click .option ("--basic-auth-password" , default = None ,
99+ envvar = "SPARK_HISTORY_BASIC_AUTH_PASSWORD" ,
100+ help = "Basic Auth password for Spark History Server (omit to prompt securely)" )
89101@click .option ("--json" , "json_mode" , is_flag = True , default = False ,
90102 help = "Output in JSON format for machine consumption" )
91103@click .option ("--app-id" , "-a" , default = None ,
92104 help = "Application ID to use (sets context for subcommands)" )
93105@click .version_option (__version__ , prog_name = "spark-history-cli" )
94106@click .pass_context
95- def cli (ctx , server : str , json_mode : bool , app_id : str | None ):
107+ def cli (
108+ ctx ,
109+ server : str ,
110+ basic_auth_user : str | None ,
111+ basic_auth_password : str | None ,
112+ json_mode : bool ,
113+ app_id : str | None ,
114+ ):
96115 """CLI for querying the Apache Spark History Server REST API."""
116+ if basic_auth_password is not None and basic_auth_user is None :
117+ raise click .UsageError (
118+ "--basic-auth-password requires --basic-auth-user."
119+ )
120+ if basic_auth_user is not None and basic_auth_password is None :
121+ basic_auth_password = click .prompt ("Basic Auth password" , hide_input = True )
122+
97123 state = CliState ()
98124 state .session .server_url = server
99125 state .json_mode = json_mode
126+ state .basic_auth_username = basic_auth_user
127+ state .basic_auth_password = basic_auth_password
100128 if app_id :
101129 state .session .set_app (app_id )
102130 state .ensure_client ()
@@ -192,7 +220,11 @@ def repl(state: CliState):
192220 elif cmd == "server" :
193221 if args :
194222 state .session .server_url = args [0 ]
195- state .client = SparkHistoryClient (args [0 ])
223+ state .client = SparkHistoryClient (
224+ args [0 ],
225+ basic_auth_username = state .basic_auth_username ,
226+ basic_auth_password = state .basic_auth_password ,
227+ )
196228 client = state .client
197229 try :
198230 ver = client .get_version ()
@@ -205,6 +237,7 @@ def repl(state: CliState):
205237 elif cmd == "status" :
206238 skin .status_block ({
207239 "Server" : state .session .server_url ,
240+ "Basic Auth" : "enabled" if state .basic_auth_username else "disabled" ,
208241 "Current App" : state .session .current_app_id or "(none)" ,
209242 "Attempt" : state .session .current_attempt_id or "(none)" ,
210243 }, title = "Session" )
0 commit comments