@@ -176,21 +176,40 @@ def main():
176176
177177@main .command ('config' )
178178def config_cmd ():
179- """Configure user-level SFTP credentials (username and key)."""
180- console .print ("[bold cyan]ChipFoundry CLI User Configuration[/bold cyan]" )
181- username = console .input ("Enter your ChipFoundry SFTP username: " ).strip ()
182- key_path = console .input ("Enter path to your SFTP private key (leave blank for ~/.ssh/chipfoundry-key): " ).strip ()
179+ """Configure a custom SSH private key path for SFTP access."""
180+ console .print ("[bold cyan]ChipFoundry CLI Configuration[/bold cyan]" )
181+ key_path = console .input ("Enter path to your SSH private key (leave blank for ~/.ssh/chipfoundry-key): " ).strip ()
183182 if not key_path :
184183 key_path = os .path .expanduser ('~/.ssh/chipfoundry-key' )
185184 else :
186185 key_path = os .path .abspath (os .path .expanduser (key_path ))
187- config = {
188- "sftp_username" : username ,
189- "sftp_key" : key_path ,
190- }
186+ config = load_user_config ()
187+ config ["sftp_key" ] = key_path
191188 save_user_config (config )
192189 console .print (f"[green]Configuration saved to { get_config_path ()} [/green]" )
193190
191+ def _try_register_ssh_key (public_key : str ) -> bool :
192+ """Attempt to register the SSH public key on the user's platform profile.
193+
194+ Returns True if the key was registered successfully, False otherwise.
195+ """
196+ config = load_user_config ()
197+ if not config .get ("api_key" ):
198+ return False
199+ try :
200+ _api_put ("/users/me" , {"ssh_public_key" : public_key })
201+ return True
202+ except SystemExit :
203+ return False
204+
205+
206+ def _print_manual_key_instructions ():
207+ """Print fallback instructions when auto-registration is not available."""
208+ console .print ("[bold cyan]To register this key:[/bold cyan]" )
209+ console .print (" Run [bold]cf login[/bold] first, then [bold]cf keygen --overwrite[/bold] to auto-register." )
210+ console .print (" Or paste the public key at [bold]https://platform.chipfoundry.io/ssh-key[/bold]" )
211+
212+
194213@main .command ('keygen' )
195214@click .option ('--overwrite' , is_flag = True , help = 'Overwrite existing key if it already exists.' )
196215def keygen (overwrite ):
@@ -211,11 +230,10 @@ def keygen(overwrite):
211230 public_key = f .read ().strip ()
212231 print (f"{ public_key } " , end = "" )
213232 print ("" )
214- console .print ("[bold cyan]Next steps:[/bold cyan]" )
215- console .print ("1. Copy the public key above" )
216- console .print ("2. Submit it to the registration form at: https://chipfoundry.io/sftp-registration" )
217- console .print ("3. Wait for account approval" )
218- console .print ("4. Use 'cf config' to configure your SFTP credentials" )
233+ if _try_register_ssh_key (public_key ):
234+ console .print ("[green]✓ Key registered on your ChipFoundry profile. SFTP access is ready.[/green]" )
235+ else :
236+ _print_manual_key_instructions ()
219237 return
220238 else :
221239 console .print (f"[yellow]Overwriting existing key at { private_key_path } [/yellow]" )
@@ -229,7 +247,6 @@ def keygen(overwrite):
229247 console .print ("[cyan]Generating new RSA SSH key for ChipFoundry...[/cyan]" )
230248
231249 try :
232- # Use ssh-keygen to generate the key
233250 cmd = [
234251 'ssh-keygen' ,
235252 '-t' , 'rsa' ,
@@ -256,12 +273,10 @@ def keygen(overwrite):
256273 print (f"{ public_key } " , end = "" )
257274 print ("" )
258275
259- # Display instructions
260- console .print ("[bold cyan]Next steps:[/bold cyan]" )
261- console .print ("1. Copy the public key above" )
262- console .print ("2. Submit it to the registration form at: https://chipfoundry.io/sftp-registration" )
263- console .print ("3. Wait for account approval" )
264- console .print ("4. Use 'cf config' to configure your SFTP credentials" )
276+ if _try_register_ssh_key (public_key ):
277+ console .print ("[green]✓ Key registered on your ChipFoundry profile. SFTP access is ready.[/green]" )
278+ else :
279+ _print_manual_key_instructions ()
265280
266281 except subprocess .CalledProcessError as e :
267282 console .print (f"[red]Failed to generate SSH key: { e } [/red]" )
@@ -289,11 +304,7 @@ def keyview():
289304 public_key = f .read ().strip ()
290305 print (f"{ public_key } " )
291306 print ("" )
292- console .print ("[bold cyan]Next steps:[/bold cyan]" )
293- console .print ("1. Copy the public key above" )
294- console .print ("2. Submit it to the registration form at: https://chipfoundry.io/sftp-registration" )
295- console .print ("3. Wait for account approval" )
296- console .print ("4. Use 'cf config' to configure your SFTP credentials" )
307+ _print_manual_key_instructions ()
297308
298309@main .command ('init' )
299310@click .option ('--project-root' , required = False , type = click .Path (file_okay = False ), help = 'Directory to create the project in (defaults to current directory).' )
0 commit comments