11package io .sentrius .agent .analysis .agents .agents ;
22
3- import io .sentrius .agent .services .ZeroTrustClientService ;
3+ import java .io .IOException ;
4+ import java .util .List ;
5+ import com .fasterxml .jackson .core .JsonProcessingException ;
6+ import io .sentrius .agent .analysis .agents .verbs .AgentVerbs ;
7+ import io .sentrius .sso .core .exceptions .ZtatException ;
8+ import io .sentrius .sso .core .services .agents .LLMService ;
9+ import io .sentrius .sso .core .services .agents .ZeroTrustClientService ;
410import io .sentrius .sso .core .dto .UserDTO ;
511import lombok .RequiredArgsConstructor ;
612import lombok .extern .slf4j .Slf4j ;
7- import org .springframework .beans .factory .annotation .Value ;
813import org .springframework .boot .autoconfigure .condition .ConditionalOnProperty ;
914import org .springframework .boot .context .event .ApplicationReadyEvent ;
1015import org .springframework .context .ApplicationListener ;
@@ -19,23 +24,68 @@ public class RegisteredAgent implements ApplicationListener<ApplicationReadyEven
1924
2025 final ZeroTrustClientService zeroTrustClientService ;
2126
27+ final VerbRegistry verbRegistry ;
28+ final AgentVerbs agentVerbs ;
29+
30+
31+
32+
33+
2234 @ Override
2335 public void onApplicationEvent (final ApplicationReadyEvent event ) {
2436
25- // get username from token
26- UserDTO user = UserDTO .builder ()
27- .username (zeroTrustClientService .getUsername ())
28- .build ();
37+ verbRegistry .scanClasspath ();
38+
39+ // Load agent config
40+
41+
42+
43+ try {
44+
45+
46+
47+ // get username from token
48+ UserDTO user = UserDTO .builder ()
49+ .username (zeroTrustClientService .getUsername ())
50+ .build ();
51+
52+ log .info (zeroTrustClientService .getUsername ());
53+
54+ log .info ("Registering v1.0.2 agent..." );
55+
56+ // register
57+ var register = zeroTrustClientService .registerAgent (user );
58+ log .info ("Registered agent is running {} " , register );
59+
60+
61+ //while(true){
62+
63+ try {
64+ // this phase is called "prompting"
65+ var response = agentVerbs .promptAgent (null );
66+ log .info ("got " + response );
67+ } catch (ZtatException e ) {
68+ e .printStackTrace ();
69+ //zeroTrustClientService.requestZtatToken()
70+ // we have been requested to get a ztat
71+ } catch (JsonProcessingException e ) {
72+ throw new RuntimeException (e );
73+ } catch (IOException e ) {
74+ throw new RuntimeException (e );
75+ }
76+ // execute command
77+ // var result = verbRegistry.execute(command, null);
78+ //log.info("Command executed: {}", result);
79+
2980
30- log .info (zeroTrustClientService .getUsername ());
31- String command = "ssh connect host123" ;
3281
33- log .info ("Registering v1.0.2 agent..." );
82+ // sleep for 5 seconds
83+ Thread .sleep (5000 );
84+ // }
3485
35- // register
36- var register = zeroTrustClientService .registerAgent (user );
37- log .info ("Registered agent is running {} " , register );
38- return ;
86+ } catch (InterruptedException e ) {
87+ throw new RuntimeException (e );
88+ }
3989 }
4090
4191}
0 commit comments