forked from aws/aws-sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBucketLoggingConfiguration.java
More file actions
138 lines (126 loc) · 5.02 KB
/
BucketLoggingConfiguration.java
File metadata and controls
138 lines (126 loc) · 5.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
* Copyright 2010-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Portions copyright 2006-2009 James Murty. Please see LICENSE.txt
* for applicable license terms and NOTICE.txt for applicable notices.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file 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 com.amazonaws.services.s3.model;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
/**
* <p>
* Represents bucket logging configuration used to control bucket-based server
* access logging in Amazon S3.
* </p>
* <p>
* For logging to be enabled for a bucket both the <code>destinationBucketName</code> and
* <code>logfilePrefix</code> must not be <code>null</code>, and the named bucket must exist. When both
* variables are not <code>null</code>, this object represents an <b>enabled</b> logging
* configuration (as indicated by {@link #isLoggingEnabled()}).
* <p>
* If either the <code>targetBucketName</code> or <code>logfilePrefix</code> are <code>null</code>,
* this object represents a <b>disabled</b> logging configuration (as indicated by
* {@link #isLoggingEnabled()}).
* <p>
* Server access logging can be enabled or disabled with
* {@link AmazonS3Client#setBucketLoggingConfiguration(SetBucketLoggingConfigurationRequest)}
* and the current status of server access logging for a bucket can be retrieved
* through {@link AmazonS3Client#getBucketLoggingConfiguration(String)}
*
* @see AmazonS3#getBucketLoggingConfiguration(String)
* @see AmazonS3#setBucketLoggingConfiguration(SetBucketLoggingConfigurationRequest)
*/
public class BucketLoggingConfiguration {
private String destinationBucketName = null;
private String logFilePrefix = null;
/**
* Creates a new bucket logging configuration, which by default is
* <b>disabled</b>.
* <p>
* Passing this new object directly to
* {@link AmazonS3#setBucketLoggingConfiguration(SetBucketLoggingConfigurationRequest)}
* will turn off bucket logging for the specified bucket.
* </p>
*/
public BucketLoggingConfiguration() {}
/**
* Creates a new bucket logging configuration which enables server access
* logs to be collected and stored in the specified destination bucket with
* the specified log file prefix.
*
* @param destinationBucketName
* The name of the bucket to which to delivery server access logs
* from the target bucket. This may be the same bucket for which
* logging is being configured.
* @param logFilePrefix
* The optional prefix to append to server access logs when they
* are written to the destination bucket.
*/
public BucketLoggingConfiguration(String destinationBucketName, String logFilePrefix) {
setLogFilePrefix(logFilePrefix);
setDestinationBucketName(destinationBucketName);
}
/**
* Returns true if logging is enabled.
*
* @return True if logging is enabled.
*/
public boolean isLoggingEnabled() {
return destinationBucketName != null
&& logFilePrefix != null;
}
/**
* Returns the optional log file prefix.
*
* @return The optional log file prefix.
*/
public String getLogFilePrefix() {
return logFilePrefix;
}
/**
* Sets the log file prefix for this bucket logging configuration.
*
* @param logFilePrefix The log file prefix for this logging configuration.
*/
public void setLogFilePrefix(String logFilePrefix) {
// Default log file prefix to the empty string if none is specified
if (logFilePrefix == null)
logFilePrefix = "";
this.logFilePrefix = logFilePrefix;
}
/**
* Returns the destination bucket name for this logging configuration.
*
* @return The destination bucket name for this logging configuration.
*/
public String getDestinationBucketName() {
return destinationBucketName;
}
/**
* Sets the destination bucket name for this logging configuration.
*
* @param destinationBucketName The destination bucket name for this logging configuration.
*/
public void setDestinationBucketName(String destinationBucketName) {
this.destinationBucketName = destinationBucketName;
}
public String toString() {
String result = "LoggingConfiguration enabled=" + isLoggingEnabled();
if (isLoggingEnabled()) {
result += ", destinationBucketName=" + getDestinationBucketName()
+ ", logFilePrefix=" + getLogFilePrefix();
}
return result;
}
}