GetAclResponseDeserializer.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. * Copyright (C) Alibaba Cloud Computing
  3. * All rights reserved.
  4. *
  5. * 版权所有 (C)阿里云计算有限公司
  6. */
  7. using System.IO;
  8. using Aliyun.OSS.Common.Communication;
  9. using Aliyun.OSS.Util;
  10. using Aliyun.OSS.Model;
  11. namespace Aliyun.OSS.Transform
  12. {
  13. internal class GetAclResponseDeserializer : ResponseDeserializer<AccessControlList, AccessControlPolicy>
  14. {
  15. public GetAclResponseDeserializer(IDeserializer<Stream, AccessControlPolicy> contentDeserializer)
  16. : base(contentDeserializer)
  17. { }
  18. public override AccessControlList Deserialize(ServiceResponse xmlStream)
  19. {
  20. var model = ContentDeserializer.Deserialize(xmlStream.Content);
  21. var acl = new AccessControlList {Owner = new Owner(model.Owner.Id, model.Owner.DisplayName)};
  22. foreach(var grant in model.Grants)
  23. {
  24. if (grant == EnumUtils.GetStringValue(CannedAccessControlList.PublicRead))
  25. acl.GrantPermission(GroupGrantee.AllUsers, Permission.Read);
  26. else if (grant == EnumUtils.GetStringValue(CannedAccessControlList.PublicReadWrite))
  27. acl.GrantPermission(GroupGrantee.AllUsers, Permission.FullControl);
  28. }
  29. return acl;
  30. }
  31. }
  32. }