sdedic commented on code in PR #7754:
URL: https://github.com/apache/netbeans/pull/7754#discussion_r1761273599


##########
enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/developer/BearerTokenCommand.java:
##########
@@ -0,0 +1,140 @@
+/*
+ * 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.netbeans.modules.cloud.oracle.developer;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import com.google.gson.JsonPrimitive;
+import com.oracle.bmc.http.Priorities;
+import com.oracle.bmc.http.client.HttpClient;
+import com.oracle.bmc.http.client.HttpRequest;
+import com.oracle.bmc.http.client.HttpResponse;
+import com.oracle.bmc.http.client.Method;
+import com.oracle.bmc.http.client.jersey.JerseyHttpProvider;
+import com.oracle.bmc.http.signing.RequestSigningFilter;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Path;
+import java.time.Duration;
+import java.time.Instant;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import javax.ws.rs.core.MediaType;
+import org.netbeans.modules.cloud.oracle.OCIManager;
+import org.netbeans.modules.cloud.oracle.OCIProfile;
+import org.netbeans.modules.cloud.oracle.assets.TempFileGenerator;
+import org.netbeans.spi.lsp.CommandProvider;
+import org.openide.util.RequestProcessor;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ *
+ * @author Jan Horvath
+ */
+@ServiceProvider(service = CommandProvider.class)
+public class BearerTokenCommand implements CommandProvider {
+
+    private static final String COMMAND_CREATE_BEARER_TOKEN = 
"nbls.cloud.assets.createBearerToken"; //NOI18N
+
+    private static final String API_VERSION = "20180419"; //NOI18N
+    private static String lastPath;
+    private static Instant lastTaken = Instant.MIN;
+
+    private static final RequestProcessor RP = new 
RequestProcessor(BearerTokenCommand.class);
+
+    private static final Set COMMANDS = new HashSet<>(Arrays.asList(
+            COMMAND_CREATE_BEARER_TOKEN
+    ));
+
+    @Override
+    public Set<String> getCommands() {
+        return Collections.unmodifiableSet(COMMANDS);
+    }
+
+    @Override
+    public CompletableFuture<Object> runCommand(String command, List<Object> 
arguments) {
+        final String ocirServer;
+        if (arguments != null && !arguments.isEmpty()) {
+            JsonPrimitive s = (JsonPrimitive) arguments.get(0);
+            ocirServer = s.getAsString();
+        } else {
+            return null;
+        }
+        CompletableFuture<Object> result = new CompletableFuture<>();
+        RP.post(() -> {
+            OCIProfile session = OCIManager.getDefault().getActiveProfile();
+            try {
+                result.complete(generateBearerToken(session, ocirServer));
+            } catch (URISyntaxException | InterruptedException | 
ExecutionException | IOException e) {
+                result.completeExceptionally(e);
+            }
+        });
+        return result;
+    }
+
+    public static synchronized String generateBearerToken(OCIProfile provider, 
String ocirServer) throws URISyntaxException, IOException, ExecutionException, 
InterruptedException  {
+        if (Duration.between(lastTaken, Instant.now()).toMinutes() > 55) {

Review Comment:
   Q: since the cache file's timestamp is +- the same as `lastTaken`, could it 
be taken after NBLS start as a valid token - or is it preferred to generate a 
new token after each NBLS restart ?



##########
enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/ImageBuilderCommand.java:
##########
@@ -64,6 +71,7 @@
 public class ImageBuilderCommand implements CommandProvider {
 
     private static final Logger LOG = 
Logger.getLogger(ImageBuilderCommand.class.getName());
+    private static final boolean IS_WINDOWS = System.getProperty("os.name", 
"").toLowerCase().startsWith("win");

Review Comment:
   Use `BaseUtilities.isWindows()`



-- 
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: notifications-unsubscr...@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@netbeans.apache.org
For additional commands, e-mail: notifications-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to