Example #1
0
 public void AddGrant(S3Grantee grantee, S3Permission permission)
 {
     S3Grant item = new S3Grant();
     item.WithGrantee(grantee);
     item.WithPermission(permission);
     this.grantList.Add(item);
 }
 /// <summary>
 /// Creates a S3Grant and adds it to the list of grants.
 /// </summary>
 /// <param name="grantee">The grantee for the grant.</param>
 /// <param name="permission">The permission for the grantee.</param>
 public void AddGrant(S3Grantee grantee, S3Permission permission)
 {
     S3Grant grant = new S3Grant();
     grant.WithGrantee(grantee);
     grant.WithPermission(permission);
     this.grantList.Add(grant);
 }
Example #3
0
        public static void loggingSerial()
        {
            System.Console.WriteLine("\nhello,Logging!!");
            NameValueCollection appConfig = ConfigurationManager.AppSettings;

            AmazonS3 s3Client = AWSClientFactory.CreateAmazonS3Client(appConfig["AWSAccessKey"], appConfig["AWSSecretKey"]);
            String bucketName = "chttest1";
            String logBucketName = "chttest2";

            //PutBucket
            System.Console.WriteLine("PutBucket: {0} + {1}\n", bucketName,logBucketName);
            s3Client.PutBucket(new PutBucketRequest().WithBucketName(bucketName));
            s3Client.PutBucket(new PutBucketRequest().WithBucketName(logBucketName));

            //PutBucketACL for logDelivery user
            SetACLRequest aclRequest = new SetACLRequest();
            aclRequest.WithBucketName(logBucketName);
            aclRequest.WithCannedACL(S3CannedACL.LogDeliveryWrite);
            SetACLResponse setACLResult = s3Client.SetACL(aclRequest);
            System.Console.WriteLine("SetBucketACL, requestID:{0}\n",setACLResult.RequestId);

            //PutBucketLogging
            S3BucketLoggingConfig config = new S3BucketLoggingConfig();
            config.WithTargetBucketName(logBucketName);
            config.WithTargetPrefix("log-prefix");
            EnableBucketLoggingResponse setLoggingResult = s3Client.EnableBucketLogging(new EnableBucketLoggingRequest().WithBucketName(bucketName).WithLoggingConfig(config));
            System.Console.WriteLine("SetBucketLogging, requestID:{0}\n", setLoggingResult.RequestId);

            //GetBucketLogging
            GetBucketLoggingResponse getLoggingResult = s3Client.GetBucketLogging(new GetBucketLoggingRequest().WithBucketName(bucketName));
            System.Console.WriteLine("GetBucketLogging:\n {0}\n", getLoggingResult.ResponseXml);

            //jerry add
            S3BucketLoggingConfig config2 = new S3BucketLoggingConfig();
            config2.WithTargetBucketName(logBucketName);
            config2.WithTargetPrefix("log-prefix");

            S3Grant grant = new  S3Grant();
            S3Grantee grantee = new S3Grantee();

            grantee.WithCanonicalUser("262ab9144f28c47d5f65ad45d5a4930a6547e12c175762cb14dbae95ec7c0680", "HNJERRY");
            grant.WithGrantee(grantee);
            //grant_list.Add(grant);
            config2.AddGrant(grantee, S3Permission.FULL_CONTROL);
            //config2.WithGrants(grant_list);
            EnableBucketLoggingResponse setLoggingResult2 = s3Client.EnableBucketLogging(new EnableBucketLoggingRequest().WithBucketName(bucketName).WithLoggingConfig(config2));
            System.Console.WriteLine("SetBucketLogging, requestID:{0}\n", setLoggingResult.RequestId);

            GetBucketLoggingResponse getLoggingResult2 = s3Client.GetBucketLogging(new GetBucketLoggingRequest().WithBucketName(bucketName));
            System.Console.WriteLine("GetBucketLogging:\n {0}\n", getLoggingResult2.ResponseXml);
            //jerry add end

            //DeleteBucket
            System.Console.WriteLine("Delete Bucket!");
            s3Client.DeleteBucket(new DeleteBucketRequest().WithBucketName(bucketName));
            s3Client.DeleteBucket(new DeleteBucketRequest().WithBucketName(logBucketName));
            System.Console.WriteLine("END!");
        }
 /// <summary>
 /// Removes a specific permission for the given grantee.
 /// </summary>
 /// <param name="grantee">The grantee</param>
 /// <param name="permission">The permission for the grantee to remove</param>
 public void RemoveGrant(S3Grantee grantee, S3Permission permission)
 {
     foreach (S3Grant grant in this.Grants)
     {
         if (grant.Grantee.Equals(grantee) && grant.Permission == permission)
         {
             this.Grants.Remove(grant);
             break;
         }
     }
 }
 /// <summary>
 /// Removes a specific permission for the given grantee.
 /// </summary>
 /// <param name="grantee">The grantee</param>
 /// <param name="permission">The permission for the grantee to remove</param>
 public void RemoveGrant(S3Grantee grantee, S3Permission permission)
 {
     foreach (S3Grant grant in this.Grants)
     {
         if (grant.Grantee.Equals(grantee) && grant.Permission == permission)
         {
             this.Grants.Remove(grant);
             break;
         }
     }
 }
Example #6
0
 private bool Equals(S3Grantee grantee)
 {
     if (grantee.IsSetCanonicalUser() && this.IsSetCanonicalUser())
     {
         return grantee.canonicalUser.Equals(this.canonicalUser);
     }
     if (grantee.IsSetEmailAddress() && this.IsSetEmailAddress())
     {
         return grantee.EmailAddress.Equals(this.EmailAddress);
     }
     return ((grantee.IsSetURI() && this.IsSetURI()) && grantee.URI.Equals(this.URI));
 }
 private bool Equals(S3Grantee grantee)
 {
     if (grantee.IsSetCanonicalUser() && this.IsSetCanonicalUser())
     {
         return(grantee.canonicalUser.Equals(this.canonicalUser));
     }
     if (grantee.IsSetEmailAddress() && this.IsSetEmailAddress())
     {
         return(grantee.EmailAddress.Equals(this.EmailAddress));
     }
     return((grantee.IsSetURI() && this.IsSetURI()) && grantee.URI.Equals(this.URI));
 }
 /// <summary>
 /// Removes all permissions for the given grantee.
 /// </summary>
 /// <param name="grantee"></param>
 public void RemoveGrant(S3Grantee grantee)
 {
     List<S3Grant> removeList = new List<S3Grant>();
     foreach (S3Grant grant in this.Grants)
     {
         if (grant.Grantee.Equals(grantee))
         {
             removeList.Add(grant);
         }
     }
     foreach (S3Grant grant in removeList)
     {
         this.Grants.Remove(grant);
     }
 }
Example #9
0
 public void RemoveGrant(S3Grantee grantee)
 {
     List<S3Grant> list = new List<S3Grant>();
     foreach (S3Grant grant in this.grantList)
     {
         if (grant.Grantee.Equals(grantee))
         {
             list.Add(grant);
         }
     }
     foreach (S3Grant grant2 in list)
     {
         this.grantList.Remove(grant2);
     }
 }
        /// <summary>
        /// Removes all permissions for the given grantee.
        /// </summary>
        /// <param name="grantee"></param>
        public void RemoveGrant(S3Grantee grantee)
        {
            List <S3Grant> removeList = new List <S3Grant>();

            foreach (S3Grant grant in Grants)
            {
                if (grant.Grantee.Equals(grantee))
                {
                    removeList.Add(grant);
                }
            }
            foreach (S3Grant grant in removeList)
            {
                this.Grants.Remove(grant);
            }
        }
Example #11
0
        public void RemoveGrant(S3Grantee grantee)
        {
            List <S3Grant> list = new List <S3Grant>();

            foreach (S3Grant grant in Grants)
            {
                if (grant.Grantee.Equals(grantee))
                {
                    list.Add(grant);
                }
            }
            foreach (S3Grant item in list)
            {
                Grants.Remove(item);
            }
        }
Example #12
0
        public void RemoveGrant(S3Grantee grantee)
        {
            List <S3Grant> list = new List <S3Grant>();

            foreach (S3Grant grant in this.grantList)
            {
                if (grant.Grantee.Equals(grantee))
                {
                    list.Add(grant);
                }
            }
            foreach (S3Grant grant2 in list)
            {
                this.grantList.Remove(grant2);
            }
        }
Example #13
0
 public S3Grant WithGrantee(S3Grantee grantee)
 {
     this.grantee = grantee;
     return(this);
 }
 /// <summary>
 /// Creates a S3Grant and adds it to the list of grants.
 /// </summary>
 /// <param name="grantee">The grantee for the grant.</param>
 /// <param name="permission">The permission for the grantee.</param>
 public void AddGrant(S3Grantee grantee, S3Permission permission)
 {
     S3Grant grant = new S3Grant
     {
         Grantee = grantee,
         Permission = permission
     };
     Grants.Add(grant);
 }
 private void SetAcltoObject(string key)
 {
     try
     {
         var versionsRequest = new ListVersionsRequest
                                   {
                                       BucketName = Utilities.MyConfig.BucketKey,
                                       Prefix = key
                                   };
         var result = _amazons3.ListVersions(versionsRequest);
         foreach (S3ObjectVersion s3ObjectVersion in result.Versions)
         {
             if (!s3ObjectVersion.IsDeleteMarker)
             {
                 try
                 {
                     // Get ACL.
                     var getRequest = new GetACLRequest { BucketName = Utilities.MyConfig.BucketKey, Key = key, VersionId = s3ObjectVersion.VersionId };
                     GetACLResponse getResponse = _amazons3.GetACL(getRequest);
                     if (getResponse.AccessControlList.Grants.Count < 2)
                     {
                         S3AccessControlList acl = getResponse.AccessControlList;
                         getResponse.Dispose();
                         //acl.Grants.Clear();
                         //var grantee0 = new S3Grantee();
                         //grantee0.WithCanonicalUser(acl.Owner.Id, acl.Owner.DisplayName);
                         //acl.AddGrant(grantee0, S3Permission.FULL_CONTROL);
                         var grantee1 = new S3Grantee();
                         grantee1.WithURI("http://acs.amazonaws.com/groups/global/AllUsers");
                         acl.AddGrant(grantee1, S3Permission.READ);
                         var request = new SetACLRequest
                                           {
                                               BucketName = Utilities.MyConfig.BucketKey,
                                               ACL = acl,
                                               Key = key,
                                               VersionId = s3ObjectVersion.VersionId
                                           };
                         SetACLResponse response = _amazons3.SetACL(request);
                         response.Dispose();
                     }
                 }
                 catch (Exception)
                 {
                     // Todo
                     return;
                 }
             }
         }
     }
     catch (Exception)
     {
         return;
     }
 }
        private void setS3Permission(String bucketName, String key)
        {
            // Get the ACL for the file and retrieve the owner ID (not sure how to get it otherwise).
            GetACLRequest getAclRequest = new GetACLRequest().WithBucketName(bucketName).WithKey(key);
            GetACLResponse aclResponse = s3.GetACL(getAclRequest);
            Owner owner = aclResponse.AccessControlList.Owner;

            // Create a grantee as the MessageGears account
            S3Grantee grantee = new S3Grantee().WithCanonicalUser(properties.MessageGearsAWSCanonicalId, "MessageGears");

            // Grant MessageGears Read-only access
            S3Permission messageGearsPermission = S3Permission.READ;
            S3AccessControlList acl = new S3AccessControlList().WithOwner(owner);
            acl.AddGrant(grantee, messageGearsPermission);

            // Create a new ACL granting the owner full control.
            grantee = new S3Grantee().WithCanonicalUser(owner.Id, "MyAWSId");
            acl.AddGrant(grantee, S3Permission.FULL_CONTROL);
            SetACLRequest aclRequest = new SetACLRequest().WithACL(acl).WithBucketName(bucketName).WithKey(key);
            s3.SetACL(aclRequest);
        }
 /// <summary>
 /// Creates a S3Grant and adds it to the list of grants.
 /// </summary>
 /// <param name="grantee">The grantee for the grant.</param>
 /// <param name="permission">The permission for the grantee.</param>
 public void AddGrant(S3Grantee grantee, S3Permission permission)
 {
     S3Grant grant = new S3Grant();
     grant.Grantee = grantee;
     grant.Permission = permission;
     this.Grants.Add(grant);
 }
Example #18
0
 public S3Grant WithGrantee(S3Grantee grantee)
 {
     this.grantee = grantee;
     return this;
 }