예제 #1
0
 public void Init()
 {
     _config = new AwsS3ClientConfig {
         Endpoint = AwsTestHelpers.AWS,
         Bucket = "bucket",
         RootPath = "root/path",
         PrivateKey = "private",
         PublicKey = "public",
     };
     _hostInfo = DreamTestHelper.CreateRandomPortHost();
 }
예제 #2
0
파일: AwsS3Client.cs 프로젝트: bjorg/DReAM
 //--- Constructors ---
 /// <summary>
 /// Create new client instance 
 /// </summary>
 /// <param name="config">Client configuration.</param>
 /// <param name="timerFactory">Timer factory.</param>
 public AwsS3Client(AwsS3ClientConfig config, TaskTimerFactory timerFactory)
 {
     _config = config;
     _bucketPlug = Plug.New(_config.Endpoint.S3Uri)
         .WithS3Authentication(_config.PrivateKey, _config.PublicKey)
         .WithTimeout(_config.Timeout)
         .At(_config.Bucket);
     _rootPlug = _bucketPlug;
     if(!string.IsNullOrEmpty(_config.RootPath)) {
         _keyRootParts = _config.RootPath.Split(new[] { config.Delimiter }, StringSplitOptions.RemoveEmptyEntries);
         if(_keyRootParts.Any()) {
             _rootPlug = _rootPlug.At(_keyRootParts);
         }
     }
     _expirationEntries = new ExpiringHashSet<string>(timerFactory);
     _expirationEntries.EntryExpired += OnDelete;
 }
예제 #3
0
        //--- Constructors ---

        /// <summary>
        /// Create new client instance
        /// </summary>
        /// <param name="config">Client configuration.</param>
        /// <param name="timerFactory">Timer factory.</param>
        public AwsS3Client(AwsS3ClientConfig config, TaskTimerFactory timerFactory)
        {
            _config     = config;
            _bucketPlug = Plug.New(_config.Endpoint.S3Uri)
                          .WithS3Authentication(_config.PrivateKey, _config.PublicKey)
                          .WithTimeout(_config.Timeout)
                          .At(_config.Bucket);
            _rootPlug = _bucketPlug;
            if (!string.IsNullOrEmpty(_config.RootPath))
            {
                _keyRootParts = _config.RootPath.Split(new[] { config.Delimiter }, StringSplitOptions.RemoveEmptyEntries);
                if (_keyRootParts.Any())
                {
                    _rootPlug = _rootPlug.At(_keyRootParts);
                }
            }
            _expirationEntries = new ExpiringHashSet <string>(timerFactory);
            _expirationEntries.EntryExpired += OnDelete;
        }
예제 #4
0
 public void Setup()
 {
     _config = new AwsS3ClientConfig {
         Endpoint = AwsTestHelpers.AWS,
         Bucket = "bucket",
         Delimiter = "/",
         RootPath = "root/path",
         PrivateKey = "private",
         PublicKey = "public",
         Timeout = TimeSpan.FromSeconds(30)
     };
     _client = new AwsS3Client(_config, TaskTimerFactory.Current);
     MockPlug.DeregisterAll();
 }
예제 #5
0
        //--- Methods ---
        protected override Yield Start(XDoc config, ILifetimeScope container, Result result)
        {
            yield return Coroutine.Invoke(base.Start, config, new Result());

            // are we a private storage service?
            _private = config["sid"].Contents == "sid://mindtouch.com/2010/10/dream/s3.storage.private";
            _log.DebugFormat("storage is {0}", _private ? "private" : "public");

            // is the root blocked from access?
            _privateRoot = config["private-root"].AsBool.GetValueOrDefault();
            _log.DebugFormat("storage root is {0}accessible", _privateRoot ? "not " : "");

            // set up S3 client
            var s3Config = new AwsS3ClientConfig() {
                Endpoint = AwsEndpoint.GetEndpoint(config["endpoint"].AsText) ?? AwsEndpoint.Default,
                Bucket = config["bucket"].AsText,
                Delimiter = "/",
                RootPath = config["folder"].AsText,
                PrivateKey = config["privatekey"].AsText,
                PublicKey = config["publickey"].AsText,
                Timeout = TimeSpan.FromSeconds(config["timeout"].AsDouble ?? DEFAULT_S3_TIMEOUT)
            };
            if(string.IsNullOrEmpty(s3Config.Bucket)) {
                throw new ArgumentException("missing configuration parameter 'bucket'");
            }
            if(string.IsNullOrEmpty(s3Config.PrivateKey)) {
                throw new ArgumentException("missing configuration parameter 'privatekey'");
            }
            if(string.IsNullOrEmpty(s3Config.PublicKey)) {
                throw new ArgumentException("missing configuration parameter 'publickey'");
            }
            _s3Client = container.Resolve<IAwsS3Client>(TypedParameter.From(s3Config));
            result.Return();
        }