/// <summary> /// Set the ACL for the node of the given path if such a node exists and the /// given version matches the version of the node. Return the stat of the /// node. /// /// A KeeperException with error code KeeperException.NoNode will be thrown /// if no node with the given path exists. /// /// A KeeperException with error code KeeperException.BadVersion will be /// thrown if the given version does not match the node's version. /// @param path /// @param acl /// @param version /// @return the stat of the node. /// @throws InterruptedException If the server transaction is interrupted. /// @throws KeeperException If the server signals an error with a non-zero error code. /// @throws org.apache.zookeeper.KeeperException.InvalidACLException If the acl is invalide. /// @throws IllegalArgumentException if an invalid path is specified /// </summary> public Stat SetACL(string path, IEnumerable <ACL> acl, int version) { string clientPath = path; PathUtils.ValidatePath(clientPath); if (acl != null && acl.Count() == 0) { throw new KeeperException.InvalidACLException(); } string serverPath = PrependChroot(clientPath); RequestHeader h = new RequestHeader(); h.Type = (int)OpCode.SetACL; SetACLRequest request = new SetACLRequest(serverPath, acl, version); SetACLResponse response = new SetACLResponse(); ReplyHeader r = cnxn.SubmitRequest(h, request, response, null); if (r.Err != 0) { throw KeeperException.Create((KeeperException.Code)Enum.ToObject(typeof(KeeperException.Code), r.Err), clientPath); } return(response.Stat); }
private async Task <Stat> SetACLAsyncInternal(string path, IEnumerable <ACL> acl, int version, bool sync) { string clientPath = path; PathUtils.ValidatePath(clientPath); if (acl != null && acl.Count() == 0) { throw new KeeperException.InvalidACLException(); } string serverPath = PrependChroot(clientPath); RequestHeader h = new RequestHeader(); h.Type = (int)OpCode.SetACL; SetACLRequest request = new SetACLRequest(serverPath, acl, version); SetACLResponse response = new SetACLResponse(); ReplyHeader r = sync ? cnxn.SubmitRequest(h, request, response, null) : await cnxn.SubmitRequestAsync(h, request, response, null).ConfigureAwait(false); if (r.Err != 0) { throw KeeperException.Create((KeeperException.Code)Enum.ToObject(typeof(KeeperException.Code), r.Err), clientPath); } return(response.Stat); }
public void SetACL(string fileKey, bool anonymouseReadAccess) { SetACLRequest aclRequest = new SetACLRequest(); aclRequest.Key = fileKey; aclRequest.BucketName = BucketName; S3AccessControlList aclList = new S3AccessControlList(); Owner owner = new Owner(); owner.Id = "oyesil"; owner.DisplayName = ""; aclList.Owner = owner; if (anonymouseReadAccess) { S3Grantee grantPublicRead = new S3Grantee(); grantPublicRead.URI = " http://acs.amazonaws.com/groups/global/AllUsers"; aclList.AddGrant(grantPublicRead, S3Permission.READ); } //Authenticated user read access S3Grantee grantAuthenticatedRead = new S3Grantee(); grantAuthenticatedRead.URI = " http://acs.amazonaws.com/groups/global/AuthenticatedUsers"; aclList.AddGrant(grantAuthenticatedRead, S3Permission.READ); aclRequest.ACL = aclList; Amazon.S3.AmazonS3Client client = new Amazon.S3.AmazonS3Client(ConfigurationLibrary.Config.fileAmazonS3AccessKey, ConfigurationLibrary.Config.fileAmazonS3SecreyKey); SetACLResponse aclResponse = client.SetACL(aclRequest); client.Dispose(); }