Пример #1
0
		/// <summary>Create a new S3 client for the supplied user information.</summary>
		/// <remarks>
		/// Create a new S3 client for the supplied user information.
		/// <p>
		/// The connection properties are a subset of those supported by the popular
		/// <a href="http://jets3t.s3.amazonaws.com/index.html">jets3t</a> library.
		/// For example:
		/// <pre>
		/// # AWS Access and Secret Keys (required)
		/// accesskey: &lt;YourAWSAccessKey&gt;
		/// secretkey: &lt;YourAWSSecretKey&gt;
		/// # Access Control List setting to apply to uploads, must be one of:
		/// # PRIVATE, PUBLIC_READ (defaults to PRIVATE).
		/// acl: PRIVATE
		/// # Number of times to retry after internal error from S3.
		/// httpclient.retry-max: 3
		/// # End-to-end encryption (hides content from S3 owners)
		/// password: &lt;encryption pass-phrase&gt;
		/// crypto.algorithm: PBEWithMD5AndDES
		/// </pre>
		/// </remarks>
		/// <param name="props">connection properties.</param>
		public AmazonS3(Sharpen.Properties props)
		{
			publicKey = props.GetProperty("accesskey");
			if (publicKey == null)
			{
				throw new ArgumentException(JGitText.Get().missingAccesskey);
			}
			string secret = props.GetProperty("secretkey");
			if (secret == null)
			{
				throw new ArgumentException(JGitText.Get().missingSecretkey);
			}
			privateKey = new SecretKeySpec(Constants.EncodeASCII(secret), HMAC);
			string pacl = props.GetProperty("acl", "PRIVATE");
			if (StringUtils.EqualsIgnoreCase("PRIVATE", pacl))
			{
				acl = "private";
			}
			else
			{
				if (StringUtils.EqualsIgnoreCase("PUBLIC", pacl))
				{
					acl = "public-read";
				}
				else
				{
					if (StringUtils.EqualsIgnoreCase("PUBLIC-READ", pacl))
					{
						acl = "public-read";
					}
					else
					{
						if (StringUtils.EqualsIgnoreCase("PUBLIC_READ", pacl))
						{
							acl = "public-read";
						}
						else
						{
							throw new ArgumentException("Invalid acl: " + pacl);
						}
					}
				}
			}
			try
			{
				string cPas = props.GetProperty("password");
				if (cPas != null)
				{
					string cAlg = props.GetProperty("crypto.algorithm");
					if (cAlg == null)
					{
						cAlg = "PBEWithMD5AndDES";
					}
					encryption = new WalkEncryption.ObjectEncryptionV2(cAlg, cPas);
				}
				else
				{
					encryption = WalkEncryption.NONE;
				}
			}
			catch (InvalidKeySpecException e)
			{
				throw new ArgumentException(JGitText.Get().invalidEncryption, e);
			}
			catch (NoSuchAlgorithmException e)
			{
				throw new ArgumentException(JGitText.Get().invalidEncryption, e);
			}
			maxAttempts = System.Convert.ToInt32(props.GetProperty("httpclient.retry-max", "3"
				));
			proxySelector = ProxySelector.GetDefault();
		}
Пример #2
0
		/// <summary>Determine the proxy server (if any) needed to obtain a URL.</summary>
		/// <remarks>Determine the proxy server (if any) needed to obtain a URL.</remarks>
		/// <param name="proxySelector">proxy support for the caller.</param>
		/// <param name="u">location of the server caller wants to talk to.</param>
		/// <returns>proxy to communicate with the supplied URL.</returns>
		/// <exception cref="Sharpen.ConnectException">
		/// the proxy could not be computed as the supplied URL could not
		/// be read. This failure should never occur.
		/// </exception>
		public static Proxy ProxyFor(ProxySelector proxySelector, Uri u)
		{
			try
			{
				return proxySelector.Select(u.ToURI())[0];
			}
			catch (URISyntaxException e)
			{
				ConnectException err;
				err = new ConnectException(MessageFormat.Format(JGitText.Get().cannotDetermineProxyFor
					, u));
				Sharpen.Extensions.InitCause(err, e);
				throw err;
			}
		}