ierandra commented on code in PR #1861:
URL: https://github.com/apache/jackrabbit-oak/pull/1861#discussion_r1865616020


##########
oak-blob-cloud-azure/src/main/java/org/apache/jackrabbit/oak/blob/cloud/azure/blobstorage/Utils.java:
##########
@@ -1,130 +1,92 @@
-/*
- * 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.jackrabbit.oak.blob.cloud.azure.blobstorage;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.InetSocketAddress;
-import java.net.Proxy;
-import java.net.SocketAddress;
-import java.net.URISyntaxException;
-import java.security.InvalidKeyException;
-import java.util.Properties;
-
-import org.apache.jackrabbit.guava.common.base.Strings;
-import com.microsoft.azure.storage.CloudStorageAccount;
-import com.microsoft.azure.storage.OperationContext;
-import com.microsoft.azure.storage.RetryExponentialRetry;
-import com.microsoft.azure.storage.RetryNoRetry;
-import com.microsoft.azure.storage.RetryPolicy;
-import com.microsoft.azure.storage.StorageException;
-import com.microsoft.azure.storage.blob.BlobRequestOptions;
-import com.microsoft.azure.storage.blob.CloudBlobClient;
-import com.microsoft.azure.storage.blob.CloudBlobContainer;
+import com.azure.core.http.HttpClient;
+import com.azure.core.http.ProxyOptions;
+import com.azure.core.http.netty.NettyAsyncHttpClientBuilder;
+import com.azure.storage.blob.BlobContainerClient;
+import com.azure.storage.blob.BlobServiceClient;
+import com.azure.storage.blob.BlobServiceClientBuilder;
+import com.azure.storage.common.policy.RequestRetryOptions;
+import com.azure.storage.common.policy.RetryPolicyType;
+import com.google.common.base.Strings;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.jackrabbit.core.data.DataStoreException;
 import org.apache.jackrabbit.oak.commons.PropertiesUtil;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
-public final class Utils {
-
-    public static final String DEFAULT_CONFIG_FILE = "azure.properties";
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.InetSocketAddress;
+import java.time.Duration;
+import java.util.Properties;
 
+public class Utils {
     public static final String DASH = "-";
+    public static final String DEFAULT_CONFIG_FILE = "azure.properties";
 
-    /**
-     * private constructor so that class cannot initialized from outside.
-     */
-    private Utils() {
-    }
-
-    /**
-     * Create CloudBlobClient from properties.
-     *
-     * @param connectionString connectionString to configure @link {@link 
CloudBlobClient}
-     * @return {@link CloudBlobClient}
-     */
-    public static CloudBlobClient getBlobClient(@NotNull final String 
connectionString) throws URISyntaxException, InvalidKeyException {
-        return getBlobClient(connectionString, null);
-    }
+    public Utils() {}
 
-    public static CloudBlobClient getBlobClient(@NotNull final String 
connectionString,
-                                                @Nullable final 
BlobRequestOptions requestOptions) throws URISyntaxException, 
InvalidKeyException {
-        CloudStorageAccount account = 
CloudStorageAccount.parse(connectionString);
-        CloudBlobClient client = account.createCloudBlobClient();
-        if (null != requestOptions) {
-            client.setDefaultRequestOptions(requestOptions);
-        }
-        return client;
-    }
+    public static BlobContainerClient getBlobContainer(String accountName, 
String accountKey, @NotNull final String connectionString,
+                                                       @NotNull final String 
containerName,
+                                                       @Nullable final 
RequestRetryOptions retryOptions,
+                                                       boolean isProxyNeeded, 
final Properties properties) throws DataStoreException {
+        BlobContainerClient blobContainerClient;
+        try {
+            if(isProxyNeeded) {
+                String proxyHost = 
properties.getProperty(AzureConstants.PROXY_HOST);
+                String proxyPort = 
properties.getProperty(AzureConstants.PROXY_PORT);
+
+                ProxyOptions proxyOptions = new 
ProxyOptions(ProxyOptions.Type.HTTP,
+                        new InetSocketAddress(proxyHost, 
Integer.parseInt(proxyPort)));
+
+                HttpClient httpClient = new NettyAsyncHttpClientBuilder()
+                        .proxy(proxyOptions)
+                        .build();
+
+                BlobServiceClient blobServiceClient = new 
BlobServiceClientBuilder()

Review Comment:
   lines 49-55 are duplicates with 58-63. the method should be refactored and 
do apply some abstractisation.



-- 
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: oak-dev-unsubscr...@jackrabbit.apache.org

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

Reply via email to