nacx commented on a change in pull request #43: JCLOUDS-1511: allow 
configuration of S3 to use V4 signatures
URL: https://github.com/apache/jclouds/pull/43#discussion_r317844796
 
 

 ##########
 File path: apis/s3/src/main/java/org/jclouds/s3/config/S3HttpApiModule.java
 ##########
 @@ -183,8 +183,16 @@ protected void bindErrorHandlers() {
       
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ParseS3ErrorFromXmlContent.class);
    }
 
-   protected void bindRequestSigner() {
-      
bind(RequestAuthorizeSignature.class).to(RequestAuthorizeSignatureV2.class).in(Scopes.SINGLETON);
+   @Provides
+   @Singleton
+   protected void 
bindRequestSigner(@Named(Constants.PROPERTY_V4_REQUEST_SIGNATURES) boolean 
v4Signatures) {
+      Class<? extends RequestAuthorizeSignature> clazz;
+      if (v4Signatures) {
+         clazz = RequestAuthorizeSignatureV4.class;
+      } else {
+         clazz = RequestAuthorizeSignatureV2.class;
+      }
+      bind(RequestAuthorizeSignature.class).to(clazz).in(Scopes.SINGLETON);
 
 Review comment:
   Hmm, does this actually work? I don't know if `bind` statements can fo in a 
provider method, but it looks semantically weird. Provider methods are supposed 
to return objects that can be injected. Instead, I'd change this method to 
something like this (I haven't tried it, but you'll get the idea):
   
   ```java
   @Provides
   @Singleton
   protected RequestAuthorizeSignature bindRequestSigner(
         @Named(Constants.PROPERTY_V4_REQUEST_SIGNATURES) boolean v4Signatures,
         RequestAuthorizeSignatureV2 v2,
         RequestAuthorizeSignatureV4 v4) {
      return v4Signatures ? v4 : v2;
   }
   ```
   
   The idea is to have the provider method get injected the possible instances 
and return the right one when an injection is requested.
   
   Adding a test for this should be pretty straightforward. I'd just create a 
test class that creates a raw Guice injector with this module and the value of 
the property, then call `injector.getInstance` and verify that the returned 
object is of the expected type.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to