Coverage Report - com.jcabi.s3.Region
 
Classes in this File Line Coverage Branch Coverage Complexity
Region
N/A
N/A
1
Region$Simple
0%
0/9
0%
0/20
1
Region$Simple$AjcClosure1
0%
0/1
N/A
1
Region$Simple$AjcClosure3
0%
0/1
N/A
1
 
 1  0
 /**
 2  
  * Copyright (c) 2012-2015, jcabi.com
 3  
  * All rights reserved.
 4  
  *
 5  
  * Redistribution and use in source and binary forms, with or without
 6  
  * modification, are permitted provided that the following conditions
 7  
  * are met: 1) Redistributions of source code must retain the above
 8  
  * copyright notice, this list of conditions and the following
 9  
  * disclaimer. 2) Redistributions in binary form must reproduce the above
 10  
  * copyright notice, this list of conditions and the following
 11  
  * disclaimer in the documentation and/or other materials provided
 12  
  * with the distribution. 3) Neither the name of the jcabi.com nor
 13  
  * the names of its contributors may be used to endorse or promote
 14  
  * products derived from this software without specific prior written
 15  
  * permission.
 16  
  *
 17  
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 18  
  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
 19  
  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 20  
  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 21  
  * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 22  
  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 23  
  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 24  
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 25  
  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 26  
  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 27  
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 28  
  * OF THE POSSIBILITY OF SUCH DAMAGE.
 29  
  */
 30  
 package com.jcabi.s3;
 31  
 
 32  
 import com.amazonaws.auth.BasicAWSCredentials;
 33  
 import com.amazonaws.services.s3.AmazonS3;
 34  
 import com.amazonaws.services.s3.AmazonS3Client;
 35  
 import com.jcabi.aspects.Immutable;
 36  
 import com.jcabi.aspects.Loggable;
 37  
 import lombok.EqualsAndHashCode;
 38  
 import lombok.ToString;
 39  
 
 40  
 /**
 41  
  * Amazon S3 abstraction.
 42  
  *
 43  
  * <p>To get an instance of this interface, instantiate {@code Region.Simple},
 44  
  * for example:
 45  
  *
 46  
  * <pre> Region region = new Region.Simple(key, secret);
 47  
  * Bucket bucket = region.bucket("my.example.com");
 48  
  * bucket.remove("README.txt");</pre>
 49  
  *
 50  
  * @author Yegor Bugayenko (yegor@tpc2.com)
 51  
  * @version $Id: bec62c35a10c64d1a66eddc34e36b2585671793f $
 52  
  * @since 0.1
 53  
  */
 54  
 @Immutable
 55  
 public interface Region {
 56  
 
 57  
     /**
 58  
      * Get bucket.
 59  
      * @param name Name of the bucket to get
 60  
      * @return Bucket
 61  
      */
 62  
     Bucket bucket(String name);
 63  
 
 64  
     /**
 65  
      * Get a client.
 66  
      * @return Amazon S3
 67  
      */
 68  
     AmazonS3 aws();
 69  
 
 70  
     /**
 71  
      * Simple implementation.
 72  
      */
 73  
     @Immutable
 74  0
     @ToString
 75  0
     @EqualsAndHashCode(of = { "key", "secret" })
 76  
     @Loggable(Loggable.DEBUG)
 77  
     final class Simple implements Region {
 78  
         /**
 79  
          * Key.
 80  
          */
 81  
         private final transient String key;
 82  
         /**
 83  
          * Secret.
 84  
          */
 85  
         private final transient String secret;
 86  
         /**
 87  
          * Public ctor.
 88  
          * @param akey Amazon key
 89  
          * @param scrt Amazon secret
 90  
          */
 91  0
         public Simple(final String akey, final String scrt) {
 92  0
             this.key = akey;
 93  0
             this.secret = scrt;
 94  0
         }
 95  
         @Override
 96  
         public Bucket bucket(final String name) {
 97  0
             return new AwsBucket(this, name);
 98  
         }
 99  
         @Override
 100  
         public AmazonS3 aws() {
 101  0
             return new AmazonS3Client(
 102  
                 new BasicAWSCredentials(this.key, this.secret)
 103  
             );
 104  
         }
 105  
     }
 106  
 }