@@ -172,10 +172,17 @@ def format_line(key: str, value: str, color: str = "cyan") -> str:
172172)
173173@click .option (
174174 "--api-key" ,
175- help = "API key for authentication" ,
175+ help = "API key for authentication (deprecated, use --auth-key or DISPATCH_API_AUTH_KEY) " ,
176176 envvar = "DISPATCH_API_KEY" ,
177177 show_envvar = True ,
178- required = True ,
178+ required = False ,
179+ )
180+ @click .option (
181+ "--auth-key" ,
182+ help = "API auth key for authentication" ,
183+ envvar = "DISPATCH_API_AUTH_KEY" ,
184+ show_envvar = True ,
185+ required = False ,
179186)
180187@click .option (
181188 "--sign-secret" ,
@@ -193,15 +200,28 @@ def format_line(key: str, value: str, color: str = "cyan") -> str:
193200 default = False ,
194201)
195202@click .pass_context
196- async def cli (
197- ctx : click .Context , url : str , api_key : str , sign_secret : str | None , raw : bool
203+ async def cli ( # pylint: disable=too-many-arguments, too-many-positional-arguments
204+ ctx : click .Context ,
205+ url : str ,
206+ api_key : str | None ,
207+ auth_key : str | None ,
208+ sign_secret : str | None ,
209+ raw : bool ,
198210) -> None :
199211 """Dispatch Service CLI."""
200212 if ctx .obj is None :
201213 ctx .obj = {}
202214
215+ key = auth_key or api_key
216+
217+ if not key :
218+ raise click .BadParameter (
219+ "You must provide an API auth key using --auth-key or "
220+ "the DISPATCH_API_AUTH_KEY environment variable."
221+ )
222+
203223 click .echo (f"Using API URL: { url } " , err = True )
204- click .echo (f"Using API Auth Key: { api_key [:4 ]} { '*' * 8 } " , err = True )
224+ click .echo (f"Using API Auth Key: { key [:4 ]} { '*' * 8 } " , err = True )
205225
206226 if sign_secret :
207227 if len (sign_secret ) > 8 :
@@ -211,24 +231,36 @@ async def cli(
211231 else :
212232 click .echo ("Using API Signing Secret (not shown)." , err = True )
213233
234+ if api_key and auth_key is None :
235+ click .echo (
236+ click .style (
237+ "Deprecation Notice: The --api-key option and the DISPATCH_API_KEY environment "
238+ "variable are deprecated. "
239+ "Please use --auth-key or set the DISPATCH_API_AUTH_KEY environment variable." ,
240+ fg = "red" ,
241+ bold = True ,
242+ ),
243+ err = True ,
244+ )
245+
214246 ctx .obj ["client" ] = DispatchApiClient (
215247 server_url = url ,
216- auth_key = api_key ,
248+ auth_key = key ,
217249 sign_secret = sign_secret ,
218250 connect = True ,
219251 )
220252
221253 ctx .obj ["params" ] = {
222254 "url" : url ,
223- "api_key " : api_key ,
255+ "auth_key " : key ,
224256 "sign_secret" : sign_secret ,
225257 }
226258
227259 ctx .obj ["raw" ] = raw
228260
229261 # Check if a subcommand was given
230262 if ctx .invoked_subcommand is None :
231- await interactive_mode (url , api_key , sign_secret )
263+ await interactive_mode (url , key , sign_secret )
232264
233265
234266@cli .command ("list" )
@@ -555,7 +587,7 @@ async def repl(
555587) -> None :
556588 """Start an interactive interface."""
557589 await interactive_mode (
558- obj ["params" ]["url" ], obj ["params" ]["api_key " ], obj ["params" ]["sign_secret" ]
590+ obj ["params" ]["url" ], obj ["params" ]["auth_key " ], obj ["params" ]["sign_secret" ]
559591 )
560592
561593
@@ -596,7 +628,7 @@ async def delete(
596628 raise click .ClickException ("Some deletions failed." )
597629
598630
599- async def interactive_mode (url : str , api_key : str , sign_secret : str | None ) -> None :
631+ async def interactive_mode (url : str , auth_key : str , sign_secret : str | None ) -> None :
600632 """Interactive mode for the CLI."""
601633 hist_file = os .path .expanduser ("~/.dispatch_cli_history.txt" )
602634 session : PromptSession [str ] = PromptSession (history = FileHistory (filename = hist_file ))
@@ -637,7 +669,7 @@ async def display_help() -> None:
637669 else :
638670 # Split, but keep quoted strings together
639671 params = (
640- ["--url" , url , "--api -key" , api_key ]
672+ ["--url" , url , "--auth -key" , auth_key ]
641673 + (["--sign-secret" , sign_secret ] if sign_secret else [])
642674 + click .parser .split_arg_string (user_input )
643675 )
0 commit comments