@@ -67,8 +67,8 @@ public static void main(String[] args) {
6767 return ;
6868 }
6969
70- if (opts .retrievableAccounts ) {
71- handleRetrievableAccounts (opts );
70+ if (opts .retrievableAccounts || opts . retrievePassword || opts . setPassword ) {
71+ handleA2aOperation (opts );
7272 System .exit (0 );
7373 return ;
7474 }
@@ -178,35 +178,55 @@ private static String handleStreamingRequest(ToolOptions opts, ISafeguardConnect
178178 }
179179 }
180180
181- private static void handleRetrievableAccounts (ToolOptions opts ) throws Exception {
182- char [] password = null ;
181+ private static void handleA2aOperation (ToolOptions opts ) throws Exception {
182+ Scanner stdinScanner = new Scanner (System .in );
183+
184+ char [] certPassword = null ;
183185 if (opts .readPassword ) {
184186 System .err .print ("Password: " );
185- password = new Scanner ( System . in ) .nextLine ().toCharArray ();
187+ certPassword = stdinScanner .nextLine ().toCharArray ();
186188 }
187189
188190 ISafeguardA2AContext a2aContext ;
189191 if (opts .certificateFile != null ) {
190192 System .err .println ("Creating A2A context for " + opts .appliance + " with certificate file " + opts .certificateFile );
191- a2aContext = Safeguard .A2A .getContext (opts .appliance , opts .certificateFile , password , null , opts .insecure );
193+ a2aContext = Safeguard .A2A .getContext (opts .appliance , opts .certificateFile , certPassword , null , opts .insecure );
192194 } else if (opts .thumbprint != null ) {
193195 System .err .println ("Creating A2A context for " + opts .appliance + " with thumbprint " + opts .thumbprint );
194196 a2aContext = Safeguard .A2A .getContext (opts .appliance , opts .thumbprint , null , opts .insecure );
195197 } else {
196198 throw new IllegalArgumentException (
197- "--retrievable-accounts requires a certificate (-c or -t)." );
199+ "A2A operations require a certificate (-c or -t)." );
198200 }
199201
200202 try {
201- List <IA2ARetrievableAccount > accounts ;
202- if (opts .filter != null && opts .filter .length () > 0 ) {
203- System .err .println ("Retrieving accounts with filter: " + opts .filter );
204- accounts = a2aContext .getRetrievableAccounts (opts .filter );
205- } else {
206- System .err .println ("Retrieving all accounts" );
207- accounts = a2aContext .getRetrievableAccounts ();
203+ if (opts .retrievableAccounts ) {
204+ List <IA2ARetrievableAccount > accounts ;
205+ if (opts .filter != null && opts .filter .length () > 0 ) {
206+ System .err .println ("Retrieving accounts with filter: " + opts .filter );
207+ accounts = a2aContext .getRetrievableAccounts (opts .filter );
208+ } else {
209+ System .err .println ("Retrieving all accounts" );
210+ accounts = a2aContext .getRetrievableAccounts ();
211+ }
212+ System .out .println (mapper .writeValueAsString (accounts ));
213+ } else if (opts .retrievePassword ) {
214+ if (opts .apiKey == null || opts .apiKey .length () == 0 ) {
215+ throw new IllegalArgumentException ("--retrieve-password requires --api-key" );
216+ }
217+ System .err .println ("Retrieving password via A2A" );
218+ char [] password = a2aContext .retrievePassword (opts .apiKey .toCharArray ());
219+ System .out .println (new String (password ));
220+ } else if (opts .setPassword ) {
221+ if (opts .apiKey == null || opts .apiKey .length () == 0 ) {
222+ throw new IllegalArgumentException ("--set-password requires --api-key" );
223+ }
224+ System .err .print ("New password: " );
225+ char [] newPassword = stdinScanner .nextLine ().toCharArray ();
226+ System .err .println ("Setting password via A2A" );
227+ a2aContext .SetPassword (opts .apiKey .toCharArray (), newPassword );
228+ System .out .println ("OK" );
208229 }
209- System .out .println (mapper .writeValueAsString (accounts ));
210230 } finally {
211231 a2aContext .dispose ();
212232 }
0 commit comments