// *** Public Methods ***********************************************
        public FileSystem(string svc, string accessKeyId, string secretAccessKey, string bucket, string acl)
        {
            if(svc == "REST") {
                _svc = new RestStorageService();
            } else if(svc == "SOAP") {
                _svc = new SoapStorageService();
            } else {
                throw new ArgumentException();
            }

            if(acl == "PrivateOnly") {
                _acl = AWSGrant.PrivateOnly;
            } else if(acl == "PublicRead") {
                _acl = AWSGrant.PublicRead;
            } else if(acl == "PublicWrite") {
                _acl = AWSGrant.PublicWrite;
            } else {
                throw new ArgumentException();
            }

            _svc.AccessKeyId     = accessKeyId;
            _svc.SecretAccessKey = secretAccessKey;

            _bucket = bucket;
            _root   = new DirectoryImpl(this, null, "", _bucket);
        }
        void IStorageService.CreateBucket(string bucket, AWSGrant acl)
        {
            Grant[]  acl2 = ConvertGrant(acl);
            DateTime time = GetCurrentTimeResolvedToMillis();
            string   sig  = MakeSignature("CreateBucket", time);

            _service.CreateBucket(bucket, acl2, _accessKeyId, time, true, sig);
        }
        Stream IStorageService.CreateObjectStream(string bucket, string key, long? size, AWSMetadataEntry[] meta, AWSGrant acl)
        {
            Grant[]         acl2  = ConvertGrant(acl);
            MetadataEntry[] meta2 = ConvertMetadata(meta);
            DateTime        time  = GetCurrentTimeResolvedToMillis();
            string          sig   = MakeSignature("PutObjectInline", time);
            string          cred  = null;

            return new SoapRequestStream(_service, bucket, key, meta2, acl2, _accessKeyId, time, sig, cred);
        }
        void IStorageService.CreateObject(string bucket, string key, AWSMetadataEntry[] meta, byte[] data, AWSGrant acl)
        {
            Grant[]         acl2  = ConvertGrant(acl);
            MetadataEntry[] meta2 = ConvertMetadata(meta);
            DateTime        time  = GetCurrentTimeResolvedToMillis();
            string          sig   = MakeSignature("PutObjectInline", time);
            string          cred  = null;

            _service.PutObjectInline(bucket, key, meta2, data, data.Length, acl2, StorageClass.STANDARD, false, _accessKeyId, time, true, sig, cred);
        }
        void IStorageService.CreateObject(string bucket, string key, AWSMetadataEntry[] meta, byte[] data, AWSGrant acl)
        {
            HttpWebRequest req = DoCreateObject(bucket, key, meta, acl);
            Stream         stm = req.GetRequestStream();

            try {
                stm.Write(data, 0, data.Length);
            } finally {
                stm.Close();
                req.GetResponse().Close();
            }
        }
Example #6
0
        public Form1()
        {
            InitializeComponent();
            this.FormClosing += new FormClosingEventHandler(Form1_FormClosing);

            _registry = Registry.CurrentUser.CreateSubKey("Software").CreateSubKey("ch.ph.AmazonUI");

            _service = new SoapStorageService();
            uiMenuSoap.Checked = true;
            uiMenuRest.Checked = false;

            _rights = AWSGrant.PrivateOnly;
            uiMenuRightPrivate.    Checked = true;
            uiMenuRightPublicRead. Checked = false;
            uiMenuRightPublicWrite.Checked = false;
        }
        void IStorageService.CreateBucket(string bucket, AWSGrant acl)
        {
            string acl2 = ConvertGrant(acl);
            string time = GetCurrentTime();
            string s2s  = "PUT\n" +
                          "\n" +
                          "\n" +
                          "\n" +
                          "x-amz-acl:" + acl2 + "\n" +
                          "x-amz-date:" + time + "\n" +
                          "/" + bucket + "/";

            string sig = MakeSignature(s2s);

            HttpWebRequest req = (HttpWebRequest) WebRequest.Create(SERVICE_URL + bucket + "/");
            req.Method = "PUT";
            req.Headers["x-amz-acl"]     = acl2;
            req.Headers["x-amz-date"]    = time;
            req.Headers["Authorization"] = "AWS " + _accessKeyId + ":" + sig;

            req.GetResponse().Close();
        }
        Stream IStorageService.CreateObjectStream(string bucket, string key, long? size, AWSMetadataEntry[] meta, AWSGrant acl)
        {
            HttpWebRequest req = DoCreateObject(bucket, key, meta, acl);

            if(size.HasValue) {
                req.ContentLength = size.Value;
            }

            return new HttpRequestStream(req);
        }
        private HttpWebRequest DoCreateObject(string bucket, string key, AWSMetadataEntry[] meta, AWSGrant acl)
        {
            string acl2  = ConvertGrant(acl);
            string meta2 = ConvertMetadata4Sig(meta);
            //          string cmd5  = MakeHash(data);
            string ctyp  = GetContentType(meta);
            string time  = GetCurrentTime();
            string s2s   = "PUT\n" +
                          /* cmd5 + */ "\n" +
                          ctyp + "\n" +
                          "\n" +
                          "x-amz-acl:" + acl2 + "\n" +
                          "x-amz-date:" + time + "\n" +
                          meta2 +
                          HttpUtility.UrlPathEncode("/" + bucket + "/" + key);

            string sig = MakeSignature(s2s);

            HttpWebRequest req = (HttpWebRequest) WebRequest.Create(SERVICE_URL + HttpUtility.UrlPathEncode(bucket + "/" + key));
            req.Method                   = "PUT";
            req.ContentType              = ctyp;
            req.ReadWriteTimeout         = -1; // Not setting to -1 doesnt help a shit
            req.Timeout                  = -1;
            //          req.ContentLength            = data.Length;
            //          req.AllowWriteStreamBuffering = false; // Setting to false doesnt help a shit
            req.Headers["x-amz-acl"]     = acl2;
            req.Headers["x-amz-date"]    = time;
            req.Headers["Authorization"] = "AWS " + _accessKeyId + ":" + sig;

            if(meta != null) {
                foreach(AWSMetadataEntry metaety in meta) {
                    if(metaety.MetaKey.ToLower() != "content-type")
                        req.Headers["x-amz-meta-" + metaety.MetaKey.ToLower()] = metaety.MetaValue;
                }
            }

            return req;
        }
 // ***
 private string ConvertGrant(AWSGrant acl)
 {
     switch(acl) {
         case AWSGrant.PrivateOnly:
             return "private";
         case AWSGrant.PublicRead:
             return "public-read";
         case AWSGrant.PublicWrite:
             return "public-read-write";
         default:
             throw new ArgumentException();
     }
 }
 // ***
 private Grant[] ConvertGrant(AWSGrant acl)
 {
     Grant[] ret;
     switch(acl) {
         case AWSGrant.PrivateOnly:
             ret = null;
             break;
         case AWSGrant.PublicRead: {
             Group gra = new Group();
             gra.URI = "http://acs.amazonaws.com/groups/global/AllUsers";
             ret = new Grant[1];
             ret[0] = new Grant();
             ret[0].Grantee    = gra;
             ret[0].Permission = Permission.READ;
         }   break;
         case AWSGrant.PublicWrite: {
             Group gra = new Group();
             gra.URI = "http://acs.amazonaws.com/groups/global/AllUsers";
             ret = new Grant[1];
             ret[0] = new Grant();
             ret[0].Grantee    = gra;
             ret[0].Permission = Permission.WRITE;
         }   break;
         default:
             throw new ArgumentException();
     }
     return ret;
 }
Example #12
0
 private void uiMenuRightPublicWrite_Click(object sender, EventArgs e)
 {
     _rights = AWSGrant.PublicWrite;
     uiMenuRightPrivate.    Checked = false;
     uiMenuRightPublicRead. Checked = false;
     uiMenuRightPublicWrite.Checked = true;
 }