22
33import com .fasterxml .jackson .databind .ObjectMapper ;
44import dev .tomr .hcloud .listener .ListenerManager ;
5+ import dev .tomr .hcloud .resources .server .Server ;
56import dev .tomr .hcloud .service .ServiceManager ;
67import org .apache .logging .log4j .LogManager ;
78import org .apache .logging .log4j .Logger ;
1415public class HetznerCloud {
1516 protected static final Logger logger = LogManager .getLogger ();
1617
17- private static final ListenerManager listenerManager = ListenerManager .getInstance ();
18- private static final ServiceManager serviceManager = ServiceManager .getInstance ();
18+ private static ListenerManager listenerManager = ListenerManager .getInstance ();
19+ private static ServiceManager serviceManager = ServiceManager .getInstance ();
1920 private static final ObjectMapper objectMapper = new ObjectMapper ();
20- private static String HETZNER_CLOUD_HOST = "https://api.hetzner.cloud/v1/" ;
21+ private static final String HETZNER_CLOUD_HOST = "https://api.hetzner.cloud/v1/" ;
2122
2223 private static HetznerCloud instance ;
2324
@@ -32,6 +33,7 @@ public HetznerCloud(String apiKey) {
3233 this .apiKey = apiKey ;
3334 this .host = HETZNER_CLOUD_HOST ;
3435 instance = this ;
36+ ServiceManager .getInstance ().getServerService ().forceRefreshServersCache ();
3537 }
3638
3739 /**
@@ -43,6 +45,7 @@ public HetznerCloud(String apiKey, String host) {
4345 this .apiKey = apiKey ;
4446 this .host = host ;
4547 instance = this ;
48+ ServiceManager .getInstance ().getServerService ().forceRefreshServersCache ();
4649 }
4750
4851 /**
@@ -96,4 +99,21 @@ public static ServiceManager getServiceManager() {
9699 public List <String > getHttpDetails () {
97100 return List .of (host , apiKey );
98101 }
102+
103+ /**
104+ * Whether we have an API Key supplied
105+ * @return true if one is present, false if not
106+ */
107+ public boolean hasApiKey () {
108+ return apiKey != null && !apiKey .isEmpty ();
109+ }
110+
111+ /**
112+ * Get a Hetzner Server Instance from the local cache
113+ * @param id ID of the server
114+ * @return A server object from the local cache
115+ */
116+ public Server getServer (Integer id ) {
117+ return serviceManager .getServerService ().getServer (id );
118+ }
99119}
0 commit comments