| 1 | /** |
| 2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
| 3 | * contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. jclouds licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.jclouds.s3.domain; |
| 20 | |
| 21 | import java.util.Set; |
| 22 | |
| 23 | import org.jclouds.s3.domain.AccessControlList.Grant; |
| 24 | |
| 25 | import com.google.common.collect.Iterables; |
| 26 | import com.google.common.collect.Sets; |
| 27 | |
| 28 | /** |
| 29 | * Each Amazon S3 bucket has an associated XML sub-resource that you can read and write in order to |
| 30 | * inspect or change the logging status for that bucket. |
| 31 | * |
| 32 | * @author Adrian Cole |
| 33 | * @see <a href="http://docs.amazonwebservices.com/AmazonS3/latest/index.html?ServerLogs.html"/> |
| 34 | */ |
| 35 | public class BucketLogging { |
| 36 | private final String targetBucket; |
| 37 | private final String targetPrefix; |
| 38 | private final Set<Grant> targetGrants = Sets.newHashSet(); |
| 39 | |
| 40 | /** |
| 41 | * |
| 42 | * @param targetBucket |
| 43 | * {@link #getTargetBucket} |
| 44 | * @param targetPrefix |
| 45 | * {@link #getTargetPrefix} |
| 46 | * @param targetGrants |
| 47 | * {@link #getTargetGrants} |
| 48 | */ |
| 49 | public BucketLogging(String targetBucket, String targetPrefix, Iterable<Grant> targetGrants) { |
| 50 | this.targetBucket = targetBucket; |
| 51 | this.targetPrefix = targetPrefix; |
| 52 | Iterables.addAll(this.targetGrants, targetGrants); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * |
| 57 | * @param targetBucket |
| 58 | * {@link #getTargetBucket} |
| 59 | * @param targetPrefix |
| 60 | * {@link #getTargetPrefix} |
| 61 | */ |
| 62 | public BucketLogging(String targetBucket, String targetPrefix) { |
| 63 | this.targetBucket = targetBucket; |
| 64 | this.targetPrefix = targetPrefix; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * The bucket owner is automatically granted FULL_CONTROL to all logs delivered to the bucket. |
| 69 | * This optional element enables you grant access to others. Any specified TargetGrants are added |
| 70 | * to the default ACL. For more information about ACLs, see Access Control Lists. |
| 71 | */ |
| 72 | public Set<Grant> getTargetGrants() { |
| 73 | return targetGrants; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Specifies the bucket where server access logs will be delivered. You can have your logs |
| 78 | * delivered to any bucket that you own, including the same bucket that is being logged. You can |
| 79 | * also configure multiple buckets to deliver their logs to the same target bucket. In this case |
| 80 | * you should choose a different TargetPrefix for each source bucket so that the delivered log |
| 81 | * files can be distinguished by key. |
| 82 | * <p/> |
| 83 | * <h3>Note</h3> |
| 84 | * |
| 85 | * The source and the target buckets must be in the same location. For more information about |
| 86 | * bucket location constraints, see Buckets and Regions |
| 87 | */ |
| 88 | public String getTargetBucket() { |
| 89 | return targetBucket; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * This element lets you specify a prefix for the keys that the delivered log files will be |
| 94 | * stored under. For information on how the key name for log files is constructed, see Delivery |
| 95 | * of Server Access Logs. |
| 96 | */ |
| 97 | public String getTargetPrefix() { |
| 98 | return targetPrefix; |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public int hashCode() { |
| 103 | final int prime = 31; |
| 104 | int result = 1; |
| 105 | result = prime * result + ((targetBucket == null) ? 0 : targetBucket.hashCode()); |
| 106 | result = prime * result + ((targetGrants == null) ? 0 : targetGrants.hashCode()); |
| 107 | result = prime * result + ((targetPrefix == null) ? 0 : targetPrefix.hashCode()); |
| 108 | return result; |
| 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public boolean equals(Object obj) { |
| 113 | if (this == obj) |
| 114 | return true; |
| 115 | if (obj == null) |
| 116 | return false; |
| 117 | if (getClass() != obj.getClass()) |
| 118 | return false; |
| 119 | BucketLogging other = (BucketLogging) obj; |
| 120 | if (targetBucket == null) { |
| 121 | if (other.targetBucket != null) |
| 122 | return false; |
| 123 | } else if (!targetBucket.equals(other.targetBucket)) |
| 124 | return false; |
| 125 | if (targetGrants == null) { |
| 126 | if (other.targetGrants != null) |
| 127 | return false; |
| 128 | } else if (!targetGrants.equals(other.targetGrants)) |
| 129 | return false; |
| 130 | if (targetPrefix == null) { |
| 131 | if (other.targetPrefix != null) |
| 132 | return false; |
| 133 | } else if (!targetPrefix.equals(other.targetPrefix)) |
| 134 | return false; |
| 135 | return true; |
| 136 | } |
| 137 | |
| 138 | @Override |
| 139 | public String toString() { |
| 140 | return "BucketLogging [targetBucket=" + targetBucket + ", targetGrants=" + targetGrants |
| 141 | + ", targetPrefix=" + targetPrefix + "]"; |
| 142 | } |
| 143 | |
| 144 | } |