nacx commented on code in PR #186:
URL: https://github.com/apache/jclouds/pull/186#discussion_r1365677001


##########
providers/azureblob/src/main/java/org/jclouds/azure/storage/filters/SharedKeyLiteAuthentication.java:
##########
@@ -203,6 +240,24 @@ public String createStringToSign(HttpRequest request) {
       return buffer.toString();
    }
 
+   private void appendPayloadMetadataForSharedKey(HttpRequest request, 
StringBuilder buffer) {

Review Comment:
   Probably we can just early return if the request payload is null, and don't 
check it every time?



##########
providers/azureblob/src/main/java/org/jclouds/azure/storage/filters/SharedKeyLiteAuthentication.java:
##########
@@ -187,7 +209,22 @@ public String[] cutUri(URI uri) throws 
IllegalArgumentException {
          throw new IllegalArgumentException("there is neither ContainerName 
nor BlobName in the URI path");
       }
       return result;
-   } 
+   }
+
+   public String createStringToSignForSharedKey(HttpRequest request) {
+      utils.logRequest(signatureLog, request, ">>");
+      StringBuilder buffer = new StringBuilder();
+      // re-sign the request
+      appendMethod(request, buffer);
+      appendPayloadMetadataForSharedKey(request, buffer);
+      appendHttpHeadersForSharedKey(request, buffer);
+      appendCanonicalizedHeaders(request, buffer);
+      appendCanonicalizedResourceForSharedKey(request, buffer);
+      if (signatureWire.enabled())
+         signatureWire.output(buffer.toString());
+      System.out.println(buffer);

Review Comment:
   ```suggestion
   ```



##########
providers/azureblob/src/main/java/org/jclouds/azure/storage/filters/SharedKeyLiteAuthentication.java:
##########
@@ -216,6 +271,7 @@ public String calculateSignature(String toSign) throws 
HttpException {
       String signature = signString(toSign);
       if (signatureWire.enabled())
          signatureWire.input(Strings2.toInputStream(signature));
+      System.out.println(signature);

Review Comment:
   Change this for logs if you really need this output, otherwise let's just 
remove this.



##########
providers/azureblob/src/main/java/org/jclouds/azure/storage/filters/SharedKeyLiteAuthentication.java:
##########
@@ -268,6 +329,51 @@ void appendCanonicalizedResource(HttpRequest request, 
StringBuilder toSign) {
       appendUriPath(request, toSign);
    }
 
+   void appendCanonicalizedResourceForSharedKey(HttpRequest request, 
StringBuilder toSign) {
+      // 1. Beginning with an empty string (""), append a forward slash (/), 
followed by the name of
+      // the identity that owns the resource being accessed.
+      toSign.append("/").append(creds.get().identity);
+      // 2. Append the resource's encoded URI path
+      toSign.append(request.getEndpoint().getRawPath());
+      appendQueryParametersForSharedKey(request, toSign);
+   }
+
+   void appendQueryParametersForSharedKey(HttpRequest request, StringBuilder 
toSign) {
+      // 3. Append each query parameter as a new line
+      Map<String, Multiset<String>> sortedParams = Maps.newTreeMap();
+      if (request.getEndpoint().getQuery() != null) {
+         String[] params = request.getEndpoint().getQuery().split("&");
+         for (String param : params) {

Review Comment:
   Can you use something like?
   ```java
   Map<String, String> params = Splitter.on('&')
      .trimResults()
      .omitEmptyStrings()
      .withKeyValueSeparator('=')
      .split(request.getEndpoint().getQuery());
   ```



-- 
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...@jclouds.apache.org

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

Reply via email to