/Amazon.S3/AmazonS3Config.cs

https://bitbucket.org/mdavid/awssdkfornet-extended · C# · 355 lines · 143 code · 30 blank · 182 comment · 1 complexity · 02b8d7d937fc292e5320e47c71a2e893 MD5 · raw file

  1. /*******************************************************************************
  2. * Copyright 2008-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3. * Licensed under the Apache License, Version 2.0 (the "License"). You may not use
  4. * this file except in compliance with the License. A copy of the License is located at
  5. *
  6. * http://aws.amazon.com/apache2.0
  7. *
  8. * or in the "license" file accompanying this file.
  9. * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  10. * CONDITIONS OF ANY KIND, either express or implied. See the License for the
  11. * specific language governing permissions and limitations under the License.
  12. * *****************************************************************************
  13. * __ _ _ ___
  14. * ( )( \/\/ )/ __)
  15. * /__\ \ / \__ \
  16. * (_)(_) \/\/ (___/
  17. *
  18. * AWS SDK for .NET
  19. * API Version: 2006-03-01
  20. *
  21. */
  22. using Amazon.S3.Model;
  23. using Amazon.S3.Util;
  24. namespace Amazon.S3
  25. {
  26. /// <summary>
  27. /// Configuration for Amazon S3 Client.
  28. /// </summary>
  29. public class AmazonS3Config
  30. {
  31. #region Private Members
  32. private string serviceURL = S3Constants.S3DefaultEndpoint;
  33. private string userAgent = Amazon.Util.AWSSDKUtils.SDKUserAgent;
  34. private string proxyHost;
  35. private int proxyPort = -1;
  36. private string proxyUsername;
  37. private string proxyPassword;
  38. private int maxErrorRetry = 3;
  39. private Protocol protocol = Protocol.HTTPS;
  40. private bool fUseSecureString = true;
  41. private int bufferSize = S3Constants.DefaultBufferSize;
  42. #endregion
  43. /// <summary>
  44. /// Gets and sets the ServiceURL property.
  45. /// </summary>
  46. public string ServiceURL
  47. {
  48. get { return this.serviceURL; }
  49. set { this.serviceURL = value; }
  50. }
  51. /// <summary>
  52. /// Sets the ServiceURL property
  53. /// </summary>
  54. /// <param name="serviceURL">ServiceURL property</param>
  55. /// <returns>this instance</returns>
  56. public AmazonS3Config WithServiceURL(string serviceURL)
  57. {
  58. this.serviceURL = serviceURL;
  59. return this;
  60. }
  61. /// <summary>
  62. /// Checks if ServiceURL property is set
  63. /// </summary>
  64. /// <returns>true if ServiceURL property is set</returns>
  65. internal bool IsSetServiceURL()
  66. {
  67. return !System.String.IsNullOrEmpty(this.serviceURL);
  68. }
  69. /// <summary>
  70. /// Gets and sets the UserAgent property.
  71. /// </summary>
  72. public string UserAgent
  73. {
  74. get { return this.userAgent; }
  75. set { this.userAgent = value; }
  76. }
  77. /// <summary>
  78. /// Sets the UserAgent property
  79. /// </summary>
  80. /// <param name="userAgent">UserAgent property</param>
  81. /// <returns>this instance</returns>
  82. public AmazonS3Config WithUserAgent(string userAgent)
  83. {
  84. this.userAgent = userAgent;
  85. return this;
  86. }
  87. /// <summary>
  88. /// Checks if UserAgent property is set
  89. /// </summary>
  90. /// <returns>true if UserAgent property is set</returns>
  91. internal bool IsSetUserAgent()
  92. {
  93. return !System.String.IsNullOrEmpty(this.userAgent);
  94. }
  95. /// <summary>
  96. /// Gets and sets the ProxyHost property.
  97. /// </summary>
  98. public string ProxyHost
  99. {
  100. get { return this.proxyHost; }
  101. set { this.proxyHost = value; }
  102. }
  103. /// <summary>
  104. /// Sets the ProxyHost property
  105. /// </summary>
  106. /// <param name="proxyHost">ProxyHost property</param>
  107. /// <returns>this instance</returns>
  108. public AmazonS3Config WithProxyHost(string proxyHost)
  109. {
  110. this.proxyHost = proxyHost;
  111. return this;
  112. }
  113. /// <summary>
  114. /// Checks if ProxyHost property is set
  115. /// </summary>
  116. /// <returns>true if ProxyHost property is set</returns>
  117. internal bool IsSetProxyHost()
  118. {
  119. return !System.String.IsNullOrEmpty(this.proxyHost);
  120. }
  121. /// <summary>
  122. /// Gets and sets the ProxyPort property.
  123. /// </summary>
  124. public int ProxyPort
  125. {
  126. get { return this.proxyPort; }
  127. set { this.proxyPort = value; }
  128. }
  129. /// <summary>
  130. /// Sets the ProxyPort property
  131. /// </summary>
  132. /// <param name="proxyPort">ProxyPort property</param>
  133. /// <returns>this instance</returns>
  134. public AmazonS3Config WithProxyPort(int proxyPort)
  135. {
  136. this.proxyPort = proxyPort;
  137. return this;
  138. }
  139. /// <summary>
  140. /// Checks if ProxyPort property is set
  141. /// </summary>
  142. /// <returns>true if ProxyPort property is set</returns>
  143. internal bool IsSetProxyPort()
  144. {
  145. return (ProxyPort > -1 && ProxyPort <= 65535);
  146. }
  147. /// <summary>
  148. /// Gets and sets the ProxyUsername property.
  149. /// Used in conjunction with the ProxyPassword
  150. /// property to authenticate requests with the
  151. /// specified Proxy server.
  152. /// </summary>
  153. public string ProxyUsername
  154. {
  155. get { return this.proxyUsername; }
  156. set { this.proxyUsername = value; }
  157. }
  158. /// <summary>
  159. /// Sets the ProxyUsername property
  160. /// </summary>
  161. /// <param name="userName">Value for the ProxyUsername property</param>
  162. /// <returns>this instance</returns>
  163. public AmazonS3Config WithProxyUsername(string userName)
  164. {
  165. this.proxyUsername = userName;
  166. return this;
  167. }
  168. /// <summary>
  169. /// Checks if ProxyUsername property is set
  170. /// </summary>
  171. /// <returns>true if ProxyUsername property is set</returns>
  172. internal bool IsSetProxyUsername()
  173. {
  174. return !System.String.IsNullOrEmpty(this.proxyUsername);
  175. }
  176. /// <summary>
  177. /// Gets and sets the ProxyPassword property.
  178. /// Used in conjunction with the ProxyUsername
  179. /// property to authenticate requests with the
  180. /// specified Proxy server.
  181. /// </summary>
  182. /// <remarks>
  183. /// If this property isn't set, String.Empty is used as
  184. /// the proxy password. This property isn't
  185. /// used if ProxyUsername is null or empty.
  186. /// </remarks>
  187. public string ProxyPassword
  188. {
  189. get { return this.proxyPassword; }
  190. set { this.proxyPassword = value; }
  191. }
  192. /// <summary>
  193. /// Sets the ProxyPassword property.
  194. /// Used in conjunction with the ProxyUsername
  195. /// property to authenticate requests with the
  196. /// specified Proxy server.
  197. /// </summary>
  198. /// <remarks>
  199. /// If this property isn't set, String.Empty is used as
  200. /// the proxy password. This property isn't
  201. /// used if ProxyUsername is null or empty.
  202. /// </remarks>
  203. /// <param name="password">ProxyPassword property</param>
  204. /// <returns>this instance</returns>
  205. public AmazonS3Config WithProxyPassword(string password)
  206. {
  207. this.proxyPassword = password;
  208. return this;
  209. }
  210. /// <summary>
  211. /// Checks if ProxyPassword property is set
  212. /// </summary>
  213. /// <returns>true if ProxyPassword property is set</returns>
  214. internal bool IsSetProxyPassword()
  215. {
  216. return !System.String.IsNullOrEmpty(this.proxyPassword);
  217. }
  218. /// <summary>
  219. /// Gets and sets the MaxErrorRetry property.
  220. /// </summary>
  221. public int MaxErrorRetry
  222. {
  223. get { return this.maxErrorRetry; }
  224. set { this.maxErrorRetry = value; }
  225. }
  226. /// <summary>
  227. /// Sets the MaxErrorRetry property
  228. /// </summary>
  229. /// <param name="maxErrorRetry">MaxErrorRetry property</param>
  230. /// <returns>this instance</returns>
  231. public AmazonS3Config WithMaxErrorRetry(int maxErrorRetry)
  232. {
  233. this.maxErrorRetry = maxErrorRetry;
  234. return this;
  235. }
  236. /// <summary>
  237. /// Checks if MaxErrorRetry property is set
  238. /// </summary>
  239. /// <returns>true if MaxErrorRetry property is set</returns>
  240. internal bool IsSetMaxErrorRetry()
  241. {
  242. return MaxErrorRetry > -1;
  243. }
  244. /// <summary>
  245. /// Gets and Sets the property that determines whether
  246. /// the HTTP or HTTPS protocol is used to make requests to the
  247. /// S3 service. By default Protocol.HTTPS is used to
  248. /// communicate with S3.
  249. /// </summary>
  250. public Protocol CommunicationProtocol
  251. {
  252. get { return this.protocol; }
  253. set { this.protocol = value; }
  254. }
  255. /// <summary>
  256. /// Sets the Protocol property. Valid values are Protocol.HTTP
  257. /// and Protocol.HTTPS. Default is Protocol.HTTPS.
  258. /// </summary>
  259. /// <param name="protocol">The protocol to use</param>
  260. /// <returns>this instance</returns>
  261. public AmazonS3Config WithCommunicationProtocol(Protocol protocol)
  262. {
  263. this.protocol = protocol;
  264. return this;
  265. }
  266. /// <summary>
  267. /// Gets and Sets the UseSecureString property.
  268. /// By default, the AWS Secret Access Key is stored
  269. /// in a SecureString (true) - this is one of the secure
  270. /// ways to store a secret provided by the .NET Framework.
  271. /// But, the use of SecureStrings is not supported in Medium
  272. /// Trust Windows Hosting environments. If you are building an
  273. /// ASP.NET application that needs to run with Medium Trust,
  274. /// set this property to false, and the client will
  275. /// not save your AWS Secret Key in a secure string. Changing
  276. /// the default to false can result in the Secret Key being
  277. /// vulnerable; please use this property judiciously.
  278. /// </summary>
  279. /// <remarks>Storing the AWS Secret Access Key is not
  280. /// recommended unless absolutely necessary.
  281. /// </remarks>
  282. /// <seealso cref="T:System.Security.SecureString"/>
  283. public bool UseSecureStringForAwsSecretKey
  284. {
  285. get { return this.fUseSecureString; }
  286. set { this.fUseSecureString = value; }
  287. }
  288. /// <summary>
  289. /// Sets the UseSecureString property.
  290. /// By default, the AWS Secret Access Key is stored
  291. /// in a SecureString (true) - this is one of the secure
  292. /// ways to store a secret provided by the .NET Framework.
  293. /// But, the use of SecureStrings is not supported in Medium
  294. /// Trust Windows Hosting environments. If you are building an
  295. /// ASP.NET application that needs to run with Medium Trust,
  296. /// set this property to false, and the client will
  297. /// not save your AWS Secret Key in a secure string. Changing
  298. /// the default to false can result in the Secret Key being
  299. /// vulnerable; please use this property judiciously.
  300. /// </summary>
  301. /// <param name="fSecure">
  302. /// Whether a secure string should be used or not.
  303. /// </param>
  304. /// <returns>The Config object with the property set</returns>
  305. /// <remarks>Storing the AWS Secret Access Key is not
  306. /// recommended unless absolutely necessary.
  307. /// </remarks>
  308. /// <seealso cref="T:System.Security.SecureString"/>
  309. public AmazonS3Config WithUseSecureStringForAwsSecretKey(bool fSecure)
  310. {
  311. fUseSecureString = fSecure;
  312. return this;
  313. }
  314. /// <summary>
  315. /// Gets and Sets the BufferSize property.
  316. /// The BufferSize controls the buffer used to read in from input streams and write
  317. /// out to the request.
  318. /// </summary>
  319. public int BufferSize
  320. {
  321. get { return this.bufferSize; }
  322. set { this.bufferSize = value; }
  323. }
  324. }
  325. }