Пример #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>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();
        }