adb014 commented on code in PR #1116:
URL: https://github.com/apache/guacamole-client/pull/1116#discussion_r3093543437


##########
extensions/guacamole-vault/modules/guacamole-vault-hv/src/main/java/org/apache/guacamole/vault/hv/secret/HvClient.java:
##########
@@ -0,0 +1,270 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.vault.hv.secret;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.inject.Inject;
+import com.google.inject.assistedinject.Assisted;
+import com.google.inject.assistedinject.AssistedInject;
+import java.io.IOException;
+import java.net.URI;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionException;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.Future;
+import javax.annotation.Nullable;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.vault.hv.GuacamoleExceptionSupplier;
+import org.apache.guacamole.vault.hv.conf.HvConfigurationService;
+import org.apache.guacamole.vault.hv.secret.HvTimedSecretData;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Client which retrieves records from Hashicorp Vault.
+ */
+public class HvClient {
+
+    /**
+     * Name of the HTTP header for the token, as specified in documentation:
+     * https://developer.hashicorp.com/vault/docs/auth/token
+     */
+    static final String HASHICORP_VAULT_HTTP_HEADER_TOKEN = "X-Vault-Token";
+
+    /**
+     * API version.
+     */
+    static final String HASHICORP_VAULT_HTTP_VERSION = "/v1/";
+
+    /**
+     * Name of the Guacamole token to resolve on a Hashicorp Vault (secret path
+     * is set in the token modifier).
+     */
+    static final String HASHICORP_VAULT_TOKEN_PREFIX = "HASHIVAULT:";
+
+    /**
+     * Logger for this class.
+     */
+    private static final Logger logger = 
LoggerFactory.getLogger(HvClient.class);
+
+    /**
+     * HttpClient for this class.
+     */
+    private final HttpClient httpClient;
+
+    /**
+     * ObjectMapper for this class.
+     */
+    private final ObjectMapper objectMapper;
+
+    /**
+     * The HV configuration associated with this client instance.
+     */
+    private final Map<String, String> hvConfig;
+
+    /**
+     * The maximum amount of time that an entry will be stored in the cache
+     * before being refreshed, in milliseconds.
+     */
+    private long cacheLifetime;

Review Comment:
   One idea to avoid cache leaks is to use a weak cache like
   
   ```java
   private final Cache<String, Object> cachedSecrets = 
           Caffeine.newBuilder().weakKeys().build();
   ```
   
   The keys and values are garbage collected under memory pressure, meaning 
there will be more cache misses. But better that than a cache leak 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to