001/* 002 * Copyright (c) 2007-2022 The Cascading Authors. All Rights Reserved. 003 * 004 * Project and contact information: https://cascading.wensel.net/ 005 * 006 * This file is part of the Cascading project. 007 * 008 * Licensed under the Apache License, Version 2.0 (the "License"); 009 * you may not use this file except in compliance with the License. 010 * You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, software 015 * distributed under the License is distributed on an "AS IS" BASIS, 016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 017 * See the License for the specific language governing permissions and 018 * limitations under the License. 019 */ 020 021package cascading.local.tap.aws.s3; 022 023import java.util.Properties; 024 025import cascading.property.Props; 026 027/** 028 * Class S3TapProps provides S3 specific properties for overriding the AWS client 029 * endpoint and region. 030 */ 031public class S3TapProps extends Props 032 { 033 /** Field S3_ENDPOINT */ 034 public static final String S3_ENDPOINT = "cascading.tap.aws.s3.endpoint"; 035 /** Field S3_REGION */ 036 public static final String S3_REGION = "cascading.tap.aws.s3.region"; 037 /** Field S3_PATH_STYLE_ACCESS */ 038 public static final String S3_PATH_STYLE_ACCESS = "cascading.tap.aws.s3.path_style_access"; 039 /** Field S3_PROXY_HOST */ 040 public static final String S3_PROXY_HOST = "cascading.tap.aws.s3.proxy.host"; 041 /** Field S3_PROXY_PORT */ 042 public static final String S3_PROXY_PORT = "cascading.tap.aws.s3.proxy.port"; 043 044 /** Field endpoint */ 045 String endpoint; 046 /** Field region */ 047 String region; 048 /** pathStyleAccess */ 049 boolean pathStyleAccess = false; 050 /** Field proxyHost */ 051 String proxyHost; 052 /** Field proxyPort */ 053 int proxyPort; 054 055 /** 056 * Constructor S3TapProps creates a new S3TapProps instance. 057 */ 058 public S3TapProps() 059 { 060 } 061 062 /** 063 * Method getEndpoint returns the endpoint of this S3TapProps object. 064 * 065 * @return the endpoint (type String) of this S3TapProps object. 066 */ 067 public String getEndpoint() 068 { 069 return endpoint; 070 } 071 072 /** 073 * Method setEndpoint sets the endpoint of this S3TapProps object. 074 * 075 * @param endpoint the endpoint of this S3TapProps object. 076 * @return S3TapProps 077 */ 078 public S3TapProps setEndpoint( String endpoint ) 079 { 080 this.endpoint = endpoint; 081 082 return this; 083 } 084 085 /** 086 * Method getRegion returns the region of this S3TapProps object. 087 * 088 * @return the region (type String) of this S3TapProps object. 089 */ 090 public String getRegion() 091 { 092 return region; 093 } 094 095 /** 096 * Method setRegion sets the region of this S3TapProps object. 097 * 098 * @param region the region of this S3TapProps object. 099 * @return S3TapProps 100 */ 101 public S3TapProps setRegion( String region ) 102 { 103 this.region = region; 104 105 return this; 106 } 107 108 /** 109 * Method isPathStyleAccess returns true if the underlying S3 client should use 110 * path style access to the S3 host. 111 * 112 * @return true if path style access should be used 113 */ 114 public boolean isPathStyleAccess() 115 { 116 return pathStyleAccess; 117 } 118 119 /** 120 * Method setPathStyleAccess should be called if the underlying S3 client should 121 * use path style access to reach the target S3 host. 122 * 123 * @param pathStyleAccess true if path style access should be used. 124 * @return S3TapProps 125 * @see <a href="https://docs.aws.amazon.com/AmazonS3/latest/dev/VirtualHosting.html">Virtual Hosting</a> 126 */ 127 public S3TapProps setPathStyleAccess( boolean pathStyleAccess ) 128 { 129 this.pathStyleAccess = pathStyleAccess; 130 131 return this; 132 } 133 134 /** 135 * Method getProxyHost returns the optional S3 proxy host of this S3TapProps object. 136 * 137 * @return the S3 proxy host (type String) of this S3TapProps object. 138 */ 139 public String getProxyHost() 140 { 141 return proxyHost; 142 } 143 144 /** 145 * Method setProxyHost sets the optional proxy host this S3TapProps object will connect through. 146 * 147 * @param proxyHost the proxy host this S3TapProps object will connect through . 148 * @return S3TapProps 149 */ 150 public S3TapProps setProxyHost( String proxyHost ) 151 { 152 this.proxyHost = proxyHost; 153 154 return this; 155 } 156 157 /** 158 * Method getProxyPort returns the optional S3 proxy port this S3TapProps object will connect through 159 * 160 * @return the S3 proxy port (type int) this S3TapProps object will connect through. 161 */ 162 public int getProxyPort() 163 { 164 return proxyPort; 165 } 166 167 /** 168 * Method setProxyPort sets the optional proxy port this S3TapProps object will connect through. 169 * 170 * @param proxyPort the proxy host this S3TapProps object will connect through . 171 * @return S3TapProps 172 */ 173 public S3TapProps setProxyPort( int proxyPort ) 174 { 175 this.proxyPort = proxyPort; 176 177 return this; 178 } 179 180 @Override 181 protected void addPropertiesTo( Properties properties ) 182 { 183 if( endpoint != null ) 184 properties.setProperty( S3_ENDPOINT, endpoint ); 185 186 if( region != null ) 187 properties.setProperty( S3_REGION, region ); 188 189 if( pathStyleAccess ) 190 properties.setProperty( S3_PATH_STYLE_ACCESS, "true" ); 191 192 if( proxyHost != null ) 193 properties.setProperty( S3_PROXY_HOST, proxyHost ); 194 195 if( proxyPort > 0 ) 196 properties.setProperty( S3_PROXY_PORT, String.valueOf( proxyPort ) ); 197 } 198 }