Esempio n. 1
0
        public S3AwsClient(string awsID, string awsKey, string locationConstraint, string servername,
                           string storageClass, bool useSSL, Dictionary <string, string> options)
        {
            var cfg = new AmazonS3Config
            {
                UseHttp    = !useSSL,
                ServiceURL = (useSSL ? "https://" : "http://") + servername,
                BufferSize = (int)Utility.Utility.DEFAULT_BUFFER_SIZE,
            };

            foreach (var opt in options.Keys.Where(x => x.StartsWith("s3-ext-", StringComparison.OrdinalIgnoreCase)))
            {
                var prop = cfg.GetType().GetProperties().FirstOrDefault(x =>
                                                                        string.Equals(x.Name, opt.Substring("s3-ext-".Length), StringComparison.OrdinalIgnoreCase));
                if (prop != null && prop.CanWrite)
                {
                    if (prop.PropertyType == typeof(bool))
                    {
                        prop.SetValue(cfg, Utility.Utility.ParseBoolOption(options, opt));
                    }
                    else if (prop.PropertyType.IsEnum)
                    {
                        prop.SetValue(cfg, Enum.Parse(prop.PropertyType, options[opt], true));
                    }
                    else if (prop.PropertyType == typeof(int))
                    {
                        prop.SetValue(cfg, int.Parse(options[opt]));
                    }
                    else if (prop.PropertyType == typeof(long))
                    {
                        prop.SetValue(cfg, long.Parse(options[opt]));
                    }
                    else if (prop.PropertyType == typeof(string))
                    {
                        prop.SetValue(cfg, options[opt]);
                    }
                }

                if (prop == null)
                {
                    Logging.Log.WriteWarningMessage(LOGTAG, "UnsupportedOption", null, "Unsupported option: {0}", opt);
                }
            }

            m_client = new AmazonS3Client(awsID, awsKey, cfg);

            m_locationConstraint = locationConstraint;
            m_storageClass       = storageClass;
            m_dnsHost            = string.IsNullOrWhiteSpace(cfg.ServiceURL) ? null : new Uri(cfg.ServiceURL).Host;
        }
Esempio n. 2
0
        public S3Wrapper(string awsID, string awsKey, string locationConstraint, string servername, string storageClass, bool useSSL, Dictionary <string, string> options)
        {
            var cfg = new AmazonS3Config();

            cfg.UseHttp    = !useSSL;
            cfg.ServiceURL = (useSSL ? "https://" : "http://") + servername;
            //cfg.UserAgent = "Duplicati v" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString() + " S3 client with AWS SDK v" + cfg.GetType().Assembly.GetName().Version.ToString();
            cfg.BufferSize = (int)Duplicati.Library.Utility.Utility.DEFAULT_BUFFER_SIZE;

            foreach (var opt in options.Keys.Where(x => x.StartsWith("s3-ext-", StringComparison.OrdinalIgnoreCase)))
            {
                var prop = cfg.GetType().GetProperties().Where(x => string.Equals(x.Name, opt.Substring("s3-ext-".Length), StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
                if (prop != null && prop.CanWrite)
                {
                    if (prop.PropertyType == typeof(bool))
                    {
                        prop.SetValue(cfg, Library.Utility.Utility.ParseBoolOption(options, opt));
                    }
                    else if (prop.PropertyType.IsEnum)
                    {
                        prop.SetValue(cfg, Enum.Parse(prop.PropertyType, options[opt], true));
                    }
                    else if (prop.PropertyType == typeof(int))
                    {
                        prop.SetValue(cfg, int.Parse(options[opt]));
                    }
                    else if (prop.PropertyType == typeof(long))
                    {
                        prop.SetValue(cfg, long.Parse(options[opt]));
                    }
                    else if (prop.PropertyType == typeof(string))
                    {
                        prop.SetValue(cfg, options[opt]);
                    }
                }

                if (prop == null)
                {
                    try { Console.Error.WriteLine("Unsupported option: {0}", opt); }
                    catch { }
                }
            }

            m_client = new Amazon.S3.AmazonS3Client(awsID, awsKey, cfg);

            m_locationConstraint = locationConstraint;
            m_storageClass       = storageClass;
            DNSHost = string.IsNullOrWhiteSpace(cfg.ServiceURL) ? null : new Uri(cfg.ServiceURL).Host;
        }
Esempio n. 3
0
        public S3Wrapper(string awsID, string awsKey, string locationConstraint, string servername, string storageClass, bool useSSL, Dictionary <string, string> options)
        {
            AmazonS3Config cfg = new AmazonS3Config();

            cfg.UseHttp    = !useSSL;
            cfg.ServiceURL = (useSSL ? "https://" : "http://") + servername;
            cfg.BufferSize = (int)Duplicati.Library.Utility.Utility.DEFAULT_BUFFER_SIZE;

            foreach (var opt in options.Keys.Where(x => x.StartsWith("s3-ext-")))
            {
                var prop = cfg.GetType().GetProperties().Where(x => string.Equals(x.Name, opt.Substring("s3-ext-".Length), StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
                if (prop != null && prop.CanWrite)
                {
                    if (prop.PropertyType == typeof(bool))
                    {
                        prop.SetValue(cfg, Library.Utility.Utility.ParseBoolOption(options, opt));
                    }
                    else if (prop.PropertyType.IsEnum)
                    {
                        prop.SetValue(cfg, Enum.Parse(prop.PropertyType, options[opt], true));
                    }
                    else if (prop.PropertyType == typeof(int))
                    {
                        prop.SetValue(cfg, int.Parse(options[opt]));
                    }
                    else if (prop.PropertyType == typeof(long))
                    {
                        prop.SetValue(cfg, long.Parse(options[opt]));
                    }
                    else if (prop.PropertyType == typeof(string))
                    {
                        prop.SetValue(cfg, options[opt]);
                    }
                }

                if (prop == null)
                {
                    try { Console.Error.WriteLine("Unsupported option: {0}", opt); }
                    catch { }
                }
            }

            m_client = new Amazon.S3.AmazonS3Client(awsID, awsKey, cfg);

            m_locationConstraint = locationConstraint;
            m_storageClass       = storageClass;
        }
Esempio n. 4
0
        public S3Wrapper(string awsID, string awsKey, string locationConstraint, string servername, string storageClass, bool useSSL)
        {
            AmazonS3Config cfg = new AmazonS3Config();

            cfg.UseHttp    = !useSSL;
            cfg.ServiceURL = (useSSL ? "https://" : "http://") + servername;
            cfg.UserAgent  = "Duplicati v" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString() + " S3 client with AWS SDK v" + cfg.GetType().Assembly.GetName().Version.ToString();
            cfg.BufferSize = (int)Duplicati.Library.Utility.Utility.DEFAULT_BUFFER_SIZE;

            m_client = new Amazon.S3.AmazonS3Client(awsID, awsKey, cfg);

            m_locationConstraint = locationConstraint;
            m_storageClass       = storageClass;
        }
Esempio n. 5
0
        public S3Wrapper(string awsID, string awsKey, string locationConstraint, string servername, bool useRRS, bool useSSL)
        {
            AmazonS3Config cfg = new AmazonS3Config();

            cfg.CommunicationProtocol          = useSSL ? Amazon.S3.Model.Protocol.HTTPS : Amazon.S3.Model.Protocol.HTTP;
            cfg.ServiceURL                     = servername;
            cfg.UserAgent                      = "Duplicati v" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString() + " S3 client with AWS SDK v" + cfg.GetType().Assembly.GetName().Version.ToString();
            cfg.UseSecureStringForAwsSecretKey = false;
            cfg.BufferSize                     = (int)Duplicati.Library.Utility.Utility.DEFAULT_BUFFER_SIZE;

            m_client = new Amazon.S3.AmazonS3Client(awsID, awsKey, cfg);

            m_locationConstraint = locationConstraint;
            m_useRRS             = useRRS;
        }