コード例 #1
0
        public override GetBucketLoggingResponse ParseGetBucketLoggingResponse(HttpResponse httpResponse)
        {
            GetBucketLoggingResponse response = new GetBucketLoggingResponse();

            using (XmlReader xmlReader = XmlReader.Create(httpResponse.Content))
            {
                Grant currentGrant = null;
                while (xmlReader.Read())
                {
                    if ("BucketLoggingStatus".Equals(xmlReader.Name))
                    {
                        if (xmlReader.IsStartElement())
                        {
                            response.Configuration = new LoggingConfiguration();
                        }
                    }
                    else if ("Agency".Equals(xmlReader.Name))
                    {
                        response.Configuration.Agency = xmlReader.ReadString();
                    }
                    else if ("TargetBucket".Equals(xmlReader.Name))
                    {
                        response.Configuration.TargetBucketName = xmlReader.ReadString();
                    }
                    else if ("TargetPrefix".Equals(xmlReader.Name))
                    {
                        response.Configuration.TargetPrefix = xmlReader.ReadString();
                    }
                    else if ("Grant".Equals(xmlReader.Name))
                    {
                        if (xmlReader.IsStartElement())
                        {
                            currentGrant = new Grant();
                            response.Configuration.Grants.Add(currentGrant);
                        }
                    }
                    else if ("ID".Equals(xmlReader.Name))
                    {
                        CanonicalGrantee grantee = new CanonicalGrantee();
                        grantee.Id           = xmlReader.ReadString();
                        currentGrant.Grantee = grantee;
                    }
                    else if ("Canned".Equals(xmlReader.Name))
                    {
                        GroupGrantee grantee = new GroupGrantee();
                        grantee.GroupGranteeType = this.ParseGroupGrantee(xmlReader.ReadString());
                        currentGrant.Grantee     = grantee;
                    }
                    else if ("Permission".Equals(xmlReader.Name))
                    {
                        currentGrant.Permission = this.ParsePermission(xmlReader.ReadString());
                    }
                }
            }
            return(response);
        }
コード例 #2
0
        private static string ConvertGroupGrantee(GroupGrantee grantee)
        {
            StringBuilder builder = new StringBuilder();

            builder.Append("<Grantee xmlns:xsi=\"" + xmlns + "\" xsi:type=\"Group\">");
            builder.Append("<URI>" + grantee.GetIdentifier() + "</URI>");
            builder.Append("</Grantee>");

            return(builder.ToString());
        }
コード例 #3
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            if (obj.GetType() != this.GetType())
            {
                return(false);
            }

            GroupGrantee _obj = obj as GroupGrantee;

            return(this.GroupGranteeType == _obj.GroupGranteeType);
        }
コード例 #4
0
        static void SetBucketLogging()
        {
            try
            {
                AccessControlList acl = new AccessControlList();
                acl.Owner    = new Owner();
                acl.Owner.Id = "domainId";
                Grant item = new Grant();
                item.Permission = PermissionEnum.FullControl;
                GroupGrantee group = new GroupGrantee();
                group.GroupGranteeType = GroupGranteeEnum.LogDelivery;
                item.Grantee           = group;
                acl.Grants.Add(item);

                SetBucketAclRequest setAclRequest = new SetBucketAclRequest
                {
                    BucketName        = "targetbucketname",
                    AccessControlList = acl,
                };


                SetBucketAclResponse setAclResponse = client.SetBucketAcl(setAclRequest);
                Console.WriteLine("Set bucket target acl response: {0}", setAclResponse.StatusCode);

                LoggingConfiguration loggingConfig = new LoggingConfiguration();
                loggingConfig.TargetBucketName = "targetbucketname";
                loggingConfig.TargetPrefix     = "targetPrefix";

                SetBucketLoggingRequest request = new SetBucketLoggingRequest()
                {
                    BucketName    = bucketName,
                    Configuration = loggingConfig
                };

                SetBucketLoggingResponse response = client.SetBucketLogging(request);

                Console.WriteLine("Set bucket logging status: {0}", response.StatusCode);
            }
            catch (ObsException ex)
            {
                Console.WriteLine("Exception errorcode: {0}, when set bucket logging.", ex.ErrorCode);
                Console.WriteLine("Exception errormessage: {0}", ex.ErrorMessage);
            }
        }
コード例 #5
0
        private void TransGrants(XmlWriter xmlWriter, IList <Grant> grants, bool isBucket, string startElementName)
        {
            xmlWriter.WriteStartElement(startElementName);
            foreach (Grant grant in grants)
            {
                if (grant.Grantee != null && grant.Permission.HasValue)
                {
                    xmlWriter.WriteStartElement("Grant");

                    if (grant.Grantee is GroupGrantee)
                    {
                        GroupGrantee groupGrantee = grant.Grantee as GroupGrantee;
                        if (groupGrantee.GroupGranteeType == GroupGranteeEnum.AllUsers)
                        {
                            xmlWriter.WriteStartElement("Grantee");
                            xmlWriter.WriteElementString("Canned", "Everyone");
                            xmlWriter.WriteEndElement();
                        }
                    }
                    else if (grant.Grantee is CanonicalGrantee)
                    {
                        xmlWriter.WriteStartElement("Grantee");
                        CanonicalGrantee canonicalGrantee = grant.Grantee as CanonicalGrantee;
                        xmlWriter.WriteElementString("ID", canonicalGrantee.Id);
                        xmlWriter.WriteEndElement();
                    }
                    xmlWriter.WriteElementString("Permission", EnumAdaptor.GetStringValue(grant.Permission));
                    if (isBucket)
                    {
                        xmlWriter.WriteElementString("Delivered", grant.Delivered.ToString().ToLower());
                    }
                    xmlWriter.WriteEndElement();
                }
            }
            xmlWriter.WriteEndElement();
        }
コード例 #6
0
 private AccessControlList ParseAccessControlList(HttpResponse httpResponse, bool isBucket)
 {
     using (XmlReader xmlReader = XmlReader.Create(httpResponse.Content))
     {
         AccessControlList acl = new AccessControlList();
         bool  innerOwner      = false;
         Grant currentGrant    = null;
         while (xmlReader.Read())
         {
             if ("Owner".Equals(xmlReader.Name))
             {
                 if (xmlReader.IsStartElement())
                 {
                     acl.Owner = new Owner();
                 }
                 innerOwner = xmlReader.IsStartElement();
             }
             else if ("ID".Equals(xmlReader.Name))
             {
                 if (innerOwner)
                 {
                     acl.Owner.Id = xmlReader.ReadString();
                 }
                 else
                 {
                     CanonicalGrantee grantee = new CanonicalGrantee();
                     grantee.Id           = xmlReader.ReadString();
                     currentGrant.Grantee = grantee;
                 }
             }
             else if ("Grant".Equals(xmlReader.Name))
             {
                 if (xmlReader.IsStartElement())
                 {
                     currentGrant = new Grant();
                     acl.Grants.Add(currentGrant);
                 }
             }
             else if ("Canned".Equals(xmlReader.Name))
             {
                 GroupGrantee grantee = new GroupGrantee();
                 grantee.GroupGranteeType = this.ParseGroupGrantee(xmlReader.ReadString());
                 currentGrant.Grantee     = grantee;
             }
             else if ("Permission".Equals(xmlReader.Name))
             {
                 currentGrant.Permission = this.ParsePermission(xmlReader.ReadString());
             }
             else if ("Delivered".Equals(xmlReader.Name))
             {
                 if (isBucket)
                 {
                     currentGrant.Delivered = Convert.ToBoolean(xmlReader.ReadString());
                 }
                 else
                 {
                     acl.Delivered = Convert.ToBoolean(xmlReader.ReadString());
                 }
             }
         }
         return(acl);
     }
 }
コード例 #7
0
        public AccessControlList unmarshall(Stream inputStream)
        {
            AccessControlList acl              = new AccessControlList();
            Owner             owner            = null;
            String            ownerId          = null;
            String            ownerDisplayName = null;
            Grantee           grantee          = null;
            String            granteeType      = null;
            String            userId           = null;
            String            userDisplayName  = null;
            String            groupUri         = null;
            String            permission       = null;
            bool          insideGrant          = false;
            StringBuilder currText             = new StringBuilder();

            XmlReader xr = XmlReader.Create(new BufferedStream(inputStream));

            while (xr.Read())
            {
                if (xr.NodeType.Equals(XmlNodeType.Element))
                {
                    if (xr.Name.Equals("Grant"))
                    {
                        insideGrant = true;
                    }
                    else if (xr.Name.Equals("Grantee"))
                    {
                        granteeType = xr.GetAttribute("xsi:type");
                    }
                }
                else if (xr.NodeType.Equals(XmlNodeType.EndElement))
                {
                    if (xr.Name.Equals("DisplayName"))
                    {
                        if (!insideGrant)
                        {
                            ownerId = currText.ToString();
                        }
                        else
                        {
                            userId = currText.ToString();
                        }
                    }
                    else if (xr.Name.Equals("ID"))
                    {
                        if (!insideGrant)
                        {
                            ownerDisplayName = currText.ToString();
                        }
                        else
                        {
                            userDisplayName = currText.ToString();
                        }
                    }
                    else if (xr.Name.Equals("URI"))
                    {
                        groupUri = currText.ToString();
                    }
                    else if (xr.Name.Equals("Owner"))
                    {
                        owner = new Owner(ownerId, ownerDisplayName);
                        acl.setOwner(owner);
                    }
                    else if (xr.Name.Equals("Grantee"))
                    {
                        if (granteeType.Equals("CanonicalUser"))
                        {
                            grantee = new CanonicalGrantee(userId, userDisplayName);
                        }
                        else if (granteeType.Equals("Group"))
                        {
                            grantee = new GroupGrantee(groupUri);
                        }
                    }
                    else if (xr.Name.Equals("Permission"))
                    {
                        permission = currText.ToString();
                    }
                    else if (xr.Name.Equals("Grant"))
                    {
                        acl.grantPermission(grantee, permission);
                        insideGrant = false;
                    }

                    currText.Clear();
                }
                else if (xr.NodeType.Equals(XmlNodeType.Text))
                {
                    currText.Append(xr.Value);
                }
            } // end while

            return(acl);
        } // end of unmarshall