public override ReadVetoResult AllowRead(string name, RavenJObject metadata, ReadOperation operation) { if (name.EndsWith(RavenFileNameHelper.DownloadingFileSuffix)) return ReadVetoResult.Ignore; return ReadVetoResult.Allowed; }
public JsonDocument ProcessReadVetoes(JsonDocument document, TransactionInformation transactionInformation, ReadOperation operation) { if (document == null) return document; foreach (var readTrigger in triggers) { var readVetoResult = readTrigger.AllowRead(document.Key, document.DataAsJson ?? document.Projection, document.Metadata, operation, transactionInformation); switch (readVetoResult.Veto) { case ReadVetoResult.ReadAllow.Allow: break; case ReadVetoResult.ReadAllow.Deny: return new JsonDocument { DataAsJson = new JObject(), Metadata = new JObject( new JProperty("Raven-Read-Veto", new JObject(new JProperty("Reason", readVetoResult.Reason), new JProperty("Trigger", readTrigger.ToString()) )) ) }; case ReadVetoResult.ReadAllow.Ignore: return null; default: throw new ArgumentOutOfRangeException(readVetoResult.Veto.ToString()); } } return document; }
public override ReadVetoResult AllowRead(string name, RavenJObject metadata, ReadOperation operation) { if (metadata.Value<bool>(SynchronizationConstants.RavenDeleteMarker)) return ReadVetoResult.Ignore; return ReadVetoResult.Allowed; }
public override ReadVetoResult AllowRead(string key, RavenJObject metadata, ReadOperation operation, TransactionInformation transactionInformation) { // This trigger is only for simple query operations if (key == null || operation != ReadOperation.Query) return ReadVetoResult.Allowed; // Don't do anything if temporal versioning is inactive for this document type if (!Database.IsTemporalVersioningEnabled(key, metadata)) return ReadVetoResult.Allowed; // If an effective date was passed in, then use it. DateTimeOffset effective; var headerValue = CurrentOperationContext.Headers.Value[TemporalMetadata.RavenTemporalEffective]; if (headerValue == null || !DateTimeOffset.TryParse(headerValue, null, DateTimeStyles.RoundtripKind, out effective)) { // If no effective data passed, return as stored. return ReadVetoResult.Allowed; } // Return the requested effective date in the metadata. var temporal = metadata.GetTemporalMetadata(); temporal.Effective = effective; // Return the result if it's the active revision, or skip it otherwise. return temporal.Status == TemporalStatus.Revision && temporal.EffectiveStart <= effective && effective < temporal.EffectiveUntil && !temporal.Deleted ? ReadVetoResult.Allowed : ReadVetoResult.Ignore; }
public override ReadVetoResult AllowRead(string key, Stream data, RavenJObject metadata, ReadOperation operation) { RavenJToken value; if (metadata.TryGetValue("Raven-Delete-Marker", out value)) return ReadVetoResult.Ignore; return ReadVetoResult.Allowed; }
public JsonDocument ExecuteReadTriggers(JsonDocument document, TransactionInformation transactionInformation, ReadOperation operation) { if(disableReadTriggers.Value) return document; return ExecuteReadTriggersOnRead(ProcessReadVetoes(document, transactionInformation, operation), transactionInformation, operation); }
public override ReadVetoResult AllowRead(string key, Stream data, RavenJObject metadata, ReadOperation operation) { if (key.All(char.IsUpper)) return ReadVetoResult.Ignore; if (key.Any(char.IsUpper)) return ReadVetoResult.Deny("You don't get to read this attachment"); return ReadVetoResult.Allowed; }
public override ReadVetoResult AllowRead(string key, Json.Linq.RavenJObject metadata, ReadOperation operation, Abstractions.Data.TransactionInformation transactionInformation) { if (operation == ReadOperation.Index && metadata.ContainsKey(Constants.RavenReplicationConflictDocument)) { return ReadVetoResult.Ignore; } return ReadVetoResult.Allowed; }
public override ReadVetoResult AllowRead(string key, RavenJObject metadata, ReadOperation operation, TransactionInformation transactionInformation) { if (operation != ReadOperation.Index) return ReadVetoResult.Allowed; if (metadata.ContainsKey("Deleted") == false) return ReadVetoResult.Allowed; return ReadVetoResult.Ignore; }
public override void OnRead(string key, RavenJObject document, RavenJObject metadata, ReadOperation operation, TransactionInformation transactionInformation) { var name = document["name"]; if (name != null) { document["name"] = new RavenJValue(name.Value<string>().ToUpper()); } }
public override ReadVetoResult AllowRead(string key, byte[] data, Newtonsoft.Json.Linq.JObject metadata, ReadOperation operation) { if (key.All(char.IsUpper)) return ReadVetoResult.Ignore; if (key.Any(char.IsUpper)) return ReadVetoResult.Deny("You don't get to read this attachment"); return ReadVetoResult.Allowed; }
public override ReadVetoResult AllowRead(string key, JObject document, JObject metadata, ReadOperation operation, TransactionInformation transactionInformation) { if(key == null) return ReadVetoResult.Allowed; if (key.StartsWith("Raven/") && operation == ReadOperation.Query) return ReadVetoResult.Ignore; // hide Raven's documentation from queries return ReadVetoResult.Allowed; }
public override ReadVetoResult AllowRead(string key, RavenJObject metadata, ReadOperation operation, TransactionInformation transactionInformation) { // always reset these _temporalVersioningEnabled.Value = false; _effectiveVersionKey.Value = null; _now.Value = SystemTime.UtcNow; if (key == null) return ReadVetoResult.Allowed; // This trigger is only for load operations if (operation != ReadOperation.Load) return ReadVetoResult.Allowed; // Don't do anything if temporal versioning is inactive for this document type _temporalVersioningEnabled.Value = Database.IsTemporalVersioningEnabled(key, metadata); if (!_temporalVersioningEnabled.Value) return ReadVetoResult.Allowed; // Only operate on current temporal documents var temporal = metadata.GetTemporalMetadata(); if (temporal.Status != TemporalStatus.Current) return ReadVetoResult.Allowed; // If an effective date was passed in, then use it. DateTimeOffset effective; var headerValue = CurrentOperationContext.Headers.Value[TemporalMetadata.RavenTemporalEffective]; if (headerValue == null || !DateTimeOffset.TryParse(headerValue, null, DateTimeStyles.RoundtripKind, out effective)) { // If no effective data passed, return current data, as stored, effective now. temporal.Effective = _now.Value; return ReadVetoResult.Allowed; } // Return the requested effective date in the metadata. temporal.Effective = effective; // If the current document is already in range, just return it if (temporal.EffectiveStart <= effective && effective < temporal.EffectiveUntil) return ReadVetoResult.Allowed; // Load the history doc Etag historyEtag; var history = Database.GetTemporalHistoryFor(key, transactionInformation, out historyEtag); // Find the revision that is effective at the date requested var effectiveRevisionInfo = history.Revisions.FirstOrDefault(x => x.Status == TemporalStatus.Revision && x.EffectiveStart <= effective && x.EffectiveUntil > effective); // Return nothing if there is no revision at the effective date if (effectiveRevisionInfo == null) return ReadVetoResult.Ignore; // Hold on to the key so we can use it later in OnRead _effectiveVersionKey.Value = effectiveRevisionInfo.Key; return ReadVetoResult.Allowed; }
public override ReadVetoResult AllowRead(string key, byte[] data, JObject metadata, ReadOperation operation) { if (ReplicationContext.IsInReplicationContext) return ReadVetoResult.Allowed; JToken value; if (metadata.TryGetValue("Raven-Delete-Marker", out value)) return ReadVetoResult.Ignore; return ReadVetoResult.Allowed; }
public override ReadVetoResult AllowRead(string key, RavenJObject metadata, ReadOperation operation, TransactionInformation transactionInformation) { if (operation != ReadOperation.Index) return ReadVetoResult.Allowed; if (metadata.Value<string>(VersioningUtil.RavenDocumentRevisionStatus) == "Historical" && Database.IsVersioningActive(metadata)) return ReadVetoResult.Ignore; return ReadVetoResult.Allowed; }
public override ReadVetoResult AllowRead(string key, Raven.Json.Linq.RavenJObject metadata, ReadOperation operation, Raven.Abstractions.Data.TransactionInformation transactionInformation) { if (operation != ReadOperation.Index) return ReadVetoResult.Allowed; if (metadata.Value<string>(PublishedVersioningConstants.AtisDocumentRevisionStatus) == "Historical") return ReadVetoResult.Ignore; return ReadVetoResult.Allowed; }
public override ReadVetoResult AllowRead(string name, RavenJObject metadata, ReadOperation operation) { if (operation != ReadOperation.Index) return ReadVetoResult.Allowed; if (metadata.Value<string>(VersioningUtil.RavenFileRevisionStatus) == "Historical" && FileSystem.IsVersioningActive(name)) return ReadVetoResult.Ignore; return ReadVetoResult.Allowed; }
public override ReadVetoResult AllowRead(string key, RavenJObject metadata, ReadOperation operation, TransactionInformation transactionInformation) { if (metadata.Value<string>("Document-Owner") == Thread.CurrentPrincipal.Identity.Name) return ReadVetoResult.Allowed; if (operation == ReadOperation.Load) return ReadVetoResult.Deny("You don't have permission to read this document"); else return ReadVetoResult.Ignore; }
public override ReadVetoResult AllowRead(string key, RavenJObject metadata, ReadOperation operation, TransactionInformation transactionInformation) { if(metadata == null) return ReadVetoResult.Allowed; // this is a projection, it is allowed RavenJToken value; if (metadata.TryGetValue("Raven-Delete-Marker", out value)) return ReadVetoResult.Ignore; return ReadVetoResult.Allowed; }
public override ReadVetoResult AllowRead(string name, RavenJObject metadata, ReadOperation operation) { if (metadata.Value<bool>(SynchronizationConstants.RavenDeleteMarker)) return ReadVetoResult.Ignore; if (name.EndsWith(RavenFileNameHelper.DeletingFileSuffix)) // such file should already have RavenDeleteMarker, but just in case return ReadVetoResult.Ignore; return ReadVetoResult.Allowed; }
public override void OnRead(string key, RavenJObject document, RavenJObject metadata, ReadOperation operation, TransactionInformation transactionInformation) { var linkName = metadata.Value<string>("Raven-Link-Name"); var link = metadata.Value<string>("Raven-Link"); if (link == null) return; var linkedDocument = Database.Get(link, transactionInformation); document.Add(linkName, linkedDocument.ToJson()); }
public override ReadVetoResult AllowRead(string key, RavenJObject metadata, ReadOperation operation, TransactionInformation transactionInformation) { if (operation == ReadOperation.Index) return ReadVetoResult.Allowed; var name = metadata["name"]; if (name != null && name.Value<string>().Any(char.IsUpper)) { return ReadVetoResult.Deny("Upper case characters in the 'name' property means the document is a secret!"); } return ReadVetoResult.Allowed; }
private JsonDocument ExecuteReadTriggersOnRead(JsonDocument resultingDocument, TransactionInformation transactionInformation, ReadOperation operation) { if (resultingDocument == null) return null; foreach (var readTrigger in triggers) { readTrigger.OnRead(resultingDocument.Key, resultingDocument.DataAsJson, resultingDocument.Metadata, operation, transactionInformation); } return resultingDocument; }
public override ReadVetoResult AllowRead(string key, RavenJObject metadata, ReadOperation operation, TransactionInformation transactionInformation) { if (operation == ReadOperation.Index) return ReadVetoResult.Allowed; var name = metadata["hidden"]; if (name != null && name.Value<bool>()) { return ReadVetoResult.Ignore; } return ReadVetoResult.Allowed; }
public override ReadVetoResult AllowRead( string key, RavenJObject metadata, ReadOperation operation, TransactionInformation transactionInformation) { return operation != ReadOperation.Index ? ReadVetoResult.Allowed : (key.Contains(RevisionDocumentPutTrigger.RevisionSegment) ? ReadVetoResult.Ignore : ReadVetoResult.Allowed); }
public override ReadVetoResult AllowRead(string key, JObject document, JObject metadata, ReadOperation operation, TransactionInformation transactionInformation) { if(metadata == null) return ReadVetoResult.Allowed; var property = metadata.Property(RavenExpirationDate); if (property == null) return ReadVetoResult.Allowed; var dateTime = property.Value.Value<DateTime>(); if(dateTime > GetCurrentUtcDate()) return ReadVetoResult.Allowed; return ReadVetoResult.Ignore; }
public static bool CanReadFile(this OrderedPartCollection<AbstractFileReadTrigger> triggers, string name, RavenJObject metadata, ReadOperation operation) { foreach (var trigger in triggers) { var result = trigger.Value.AllowRead(name, metadata, operation); if (result.Veto == ReadVetoResult.ReadAllow.Allow) continue; Log.Debug("Trigger {0} asked us to ignore {1}", trigger.Value, name); return false; } return true; }
public override ReadVetoResult AllowRead(string key, RavenJObject metadata, ReadOperation operation, TransactionInformation transactionInformation) { if (operation == ReadOperation.Index) return ReadVetoResult.Allowed; // we have to allow indexing, because we are deleting using the index if(metadata == null) return ReadVetoResult.Allowed; var property = metadata[RavenExpirationDate]; if (property == null) return ReadVetoResult.Allowed; var dateTime = property.Value<DateTime>(); if(dateTime > GetCurrentUtcDate()) return ReadVetoResult.Allowed; return ReadVetoResult.Ignore; }
public override ReadVetoResult AllowRead(string key, JObject metadata, ReadOperation operation, TransactionInformation transactionInformation) { if(key == null) return ReadVetoResult.Allowed; if (key.StartsWith("Raven/")) { switch (operation) { case ReadOperation.Load: return ReadVetoResult.Allowed; case ReadOperation.Query: case ReadOperation.Index: return ReadVetoResult.Ignore; default: throw new ArgumentOutOfRangeException("operation"); } } return ReadVetoResult.Allowed; }
public override ReadVetoResult AllowRead(string key, RavenJObject metadata, ReadOperation readOperation, TransactionInformation transactionInformation) { using (Database.DisableAllTriggersForCurrentThread()) { var user = CurrentOperationContext.Headers.Value[Constants.RavenAuthorizationUser]; var operation = CurrentOperationContext.Headers.Value[Constants.RavenAuthorizationOperation]; if (string.IsNullOrEmpty(operation) || string.IsNullOrEmpty(user)) return ReadVetoResult.Allowed; var sw = new StringWriter(); var isAllowed = AuthorizationDecisions.IsAllowed(user, operation, key, metadata, sw.WriteLine); if (isAllowed) return ReadVetoResult.Allowed; return readOperation == ReadOperation.Query ? ReadVetoResult.Ignore : ReadVetoResult.Deny(sw.GetStringBuilder().ToString()); } }
// Win32 file impl // TODO: Other platforms public unsafe void OpenReadFile(string path) { var fileHandle = CreateFile(path, FileAccess.Read, FileShare.Read, IntPtr.Zero, FileMode.Open, EFileAttributes.Overlapped, IntPtr.Zero); var handle = ThreadPoolBoundHandle.BindHandle(fileHandle); var readOperation = new ReadOperation { Writer = _input, FileHandle = fileHandle, ThreadPoolBoundHandle = handle, IOCallback = IOCallback }; var overlapped = new PreAllocatedOverlapped(IOCallback, readOperation, null); readOperation.PreAllocatedOverlapped = overlapped; _input.ReadingStarted.ContinueWith((t, state) => { ((ReadOperation)state).Read(); }, readOperation); }
/// <summary> /// Returns true if the dictionary contains the specified key. /// </summary> public bool ContainsKey(K key) { return(ReadOperation.ContainsKey(key)); }
// Read callback from libuv thread void INativeUnsafe.FinishRead(ReadOperation operation) { var ch = _channel; IChannelConfiguration config = ch.Configuration; IChannelPipeline pipeline = ch.Pipeline; OperationException error = operation.Error; bool close = error is object || operation.EndOfStream; IRecvByteBufAllocatorHandle allocHandle = RecvBufAllocHandle; allocHandle.Reset(config); IByteBuffer buffer = operation.Buffer; Debug.Assert(buffer is object); allocHandle.LastBytesRead = operation.Status; if (allocHandle.LastBytesRead <= 0) { // nothing was read -> release the buffer. _ = buffer.Release(); close = allocHandle.LastBytesRead < 0; if (close) { // There is nothing left to read as we received an EOF. ch.ReadPending = false; } } else { _ = buffer.SetWriterIndex(buffer.WriterIndex + operation.Status); allocHandle.IncMessagesRead(1); ch.ReadPending = false; _ = pipeline.FireChannelRead(buffer); } allocHandle.ReadComplete(); _ = pipeline.FireChannelReadComplete(); if (close) { if (error is object) { _ = pipeline.FireExceptionCaught(ThrowHelper.GetChannelException(error)); } if (ch.Open) { Close(VoidPromise()); } // ## 苦竹 修改 this.CloseSafe(); ## } else { // If read is called from channel read or read complete // do not stop reading if (!ch.ReadPending && !config.AutoRead) { ch.DoStopRead(); } } }
public override ReadVetoResult AllowRead(string key, RavenJObject metadata, ReadOperation readOperation, TransactionInformation transactionInformation) { if (readOperation == ReadOperation.Query) { RavenJObject rawValue = metadata[Metadata.Key] as RavenJObject; if (rawValue != null) { Metadata value = rawValue.JsonDeserialization <Metadata>(); if (value != null) { this.Id = value.Id; } } } return(ReadVetoResult.Allowed); }
public override void OnRead(string key, RavenJObject document, RavenJObject metadata, ReadOperation operation, TransactionInformation transactionInformation) { var name = document["name"]; if (name != null) { document["name"] = new RavenJValue(name.Value <string>().ToUpper()); } }
public void BufferingReadStreamTest() { IEnumerable <ReadOperation[]> bufferingReads = new ReadOperation[][] { new ReadOperation[] { // No buffering reads }, new ReadOperation[] { new ReadOperation { Count = 10, ExpectedBytesRead = 10, ExpectedResult = 9 } }, new ReadOperation[] { new ReadOperation { Count = 5, ExpectedBytesRead = 5, ExpectedResult = 4 }, new ReadOperation { Count = 5, ExpectedBytesRead = 5, ExpectedResult = 9 }, new ReadOperation { Count = 5, ExpectedBytesRead = 5, ExpectedResult = 14 }, new ReadOperation { Count = 5, ExpectedBytesRead = 5, ExpectedResult = 19 }, }, new ReadOperation[] { new ReadOperation { Count = 5, ExpectedBytesRead = 5, ExpectedResult = 4 }, new ReadOperation { Count = 8, ExpectedBytesRead = 8, ExpectedResult = 12 }, }, new ReadOperation[] { new ReadOperation { Count = byte.MaxValue, ExpectedBytesRead = byte.MaxValue, ExpectedResult = byte.MaxValue - 1 }, }, }; IEnumerable <ReadOperation[]> replayReads = new ReadOperation[][] { new ReadOperation[] { }, new ReadOperation[] { new ReadOperation { Count = 5, ExpectedBytesRead = 5, ExpectedResult = 4 }, }, new ReadOperation[] { new ReadOperation { Count = 10, ExpectedBytesRead = 10, ExpectedResult = 9 } }, new ReadOperation[] { new ReadOperation { Count = 20, ExpectedBytesRead = 20, ExpectedResult = 19 } }, new ReadOperation[] { new ReadOperation { Count = 2, ExpectedBytesRead = 2, ExpectedResult = 1 }, new ReadOperation { Count = 5, ExpectedBytesRead = 5, ExpectedResult = 6 }, }, new ReadOperation[] { new ReadOperation { Count = 2, ExpectedBytesRead = 2, ExpectedResult = 1 }, new ReadOperation { Count = 5, ExpectedBytesRead = 5, ExpectedResult = 6 }, new ReadOperation { Count = 3, ExpectedBytesRead = 3, ExpectedResult = 9 }, }, new ReadOperation[] { new ReadOperation { Count = 1, ExpectedBytesRead = 1, ExpectedResult = 0 }, new ReadOperation { Count = 1, ExpectedBytesRead = 1, ExpectedResult = 1 }, new ReadOperation { Count = 1, ExpectedBytesRead = 1, ExpectedResult = 2 }, new ReadOperation { Count = 1, ExpectedBytesRead = 1, ExpectedResult = 3 }, }, new ReadOperation[] { new ReadOperation { Count = 5, ExpectedBytesRead = 5, ExpectedResult = 4 }, new ReadOperation { Count = 5, ExpectedBytesRead = 5, ExpectedResult = 9 }, new ReadOperation { Count = 5, ExpectedBytesRead = 5, ExpectedResult = 14 }, new ReadOperation { Count = 5, ExpectedBytesRead = 5, ExpectedResult = 19 }, }, new ReadOperation[] { new ReadOperation { Count = 10, ExpectedBytesRead = 10, ExpectedResult = 9 }, new ReadOperation { Count = 5, ExpectedBytesRead = 5, ExpectedResult = 14 }, }, new ReadOperation[] { new ReadOperation { Count = 10, ExpectedBytesRead = 10, ExpectedResult = 9 }, new ReadOperation { Count = 5, ExpectedBytesRead = 5, ExpectedResult = 14 }, new ReadOperation { Count = 10, ExpectedBytesRead = 10, ExpectedResult = 24 }, }, new ReadOperation[] { new ReadOperation { Count = 10, ExpectedBytesRead = 10, ExpectedResult = 9 }, new ReadOperation { Count = 5, ExpectedBytesRead = 5, ExpectedResult = 14 }, new ReadOperation { Count = 5, ExpectedBytesRead = 5, ExpectedResult = 19 }, }, new ReadOperation[] { new ReadOperation { Count = 5, ExpectedBytesRead = 5, ExpectedResult = 4 }, new ReadOperation { Count = 5, ExpectedBytesRead = 5, ExpectedResult = 9 }, new ReadOperation { Count = 10, ExpectedBytesRead = 10, ExpectedResult = 19 }, }, new ReadOperation[] { new ReadOperation { Count = 10, ExpectedBytesRead = 10, ExpectedResult = 9 }, new ReadOperation { Count = 10, ExpectedBytesRead = 10, ExpectedResult = 19 }, }, new ReadOperation[] { new ReadOperation { Count = 20, ExpectedBytesRead = 20, ExpectedResult = 19 }, new ReadOperation { Count = 20, ExpectedBytesRead = 20, ExpectedResult = 39 }, }, new ReadOperation[] { new ReadOperation { Count = byte.MaxValue, ExpectedBytesRead = byte.MaxValue, ExpectedResult = byte.MaxValue - 1 }, }, new ReadOperation[] { new ReadOperation { Count = byte.MaxValue, ExpectedBytesRead = byte.MaxValue, ExpectedResult = byte.MaxValue - 1 }, new ReadOperation { Count = 5, ExpectedBytesRead = 0, ExpectedResult = byte.MaxValue - 1 }, new ReadOperation { Count = 5, ExpectedBytesRead = 0, ExpectedResult = byte.MaxValue - 1 }, new ReadOperation { Count = 5, ExpectedBytesRead = 0, ExpectedResult = byte.MaxValue - 1 }, }, new ReadOperation[] { new ReadOperation { Count = 5, ExpectedBytesRead = 5, ExpectedResult = 4 }, new ReadOperation { Count = 10, ExpectedBytesRead = 10, ExpectedResult = 14 }, }, new ReadOperation[] { new ReadOperation { Count = 5, ExpectedBytesRead = 5, ExpectedResult = 4 }, new ReadOperation { Count = 5, ExpectedBytesRead = 5, ExpectedResult = 9 }, new ReadOperation { Count = 10, ExpectedBytesRead = 10, ExpectedResult = 19 }, }, new ReadOperation[] { new ReadOperation { Count = 5, ExpectedBytesRead = 5, ExpectedResult = 4 }, new ReadOperation { Count = byte.MaxValue - 5, ExpectedBytesRead = byte.MaxValue - 5, ExpectedResult = byte.MaxValue - 1 }, }, new ReadOperation[] { new ReadOperation { Count = 20, ExpectedBytesRead = 20, ExpectedResult = 19 }, new ReadOperation { Count = byte.MaxValue - 20, ExpectedBytesRead = byte.MaxValue - 20, ExpectedResult = byte.MaxValue - 1 }, }, }; this.CombinatorialEngineProvider.RunCombinations( bufferingReads, // Adding the null case to completely skip the buffering replay reads replayReads.ConcatSingle(null), replayReads, (bufferingRead, bufferingReplayRead, replayRead) => { MemoryStream testStream = new MemoryStream(testBytes); BufferingReadStreamTestWrapper bufferingReadStream = new BufferingReadStreamTestWrapper(testStream); byte[] targetBuffer = new byte[1000]; int currentOffset = 0; foreach (ReadOperation readOp in bufferingRead) { int bytesRead = bufferingReadStream.Read(targetBuffer, currentOffset, readOp.Count); this.Assert.AreEqual(readOp.ExpectedBytesRead, bytesRead, "Bytes read differs."); currentOffset += bytesRead; this.Assert.AreEqual(readOp.ExpectedResult, targetBuffer[currentOffset - 1], "Last byte read differs."); } if (bufferingReplayRead != null) { bufferingReadStream.ResetStream(); targetBuffer = new byte[1000]; currentOffset = 0; foreach (ReadOperation readOp in bufferingReplayRead) { int bytesRead = bufferingReadStream.Read(targetBuffer, currentOffset, readOp.Count); this.Assert.AreEqual(readOp.ExpectedBytesRead, bytesRead, "Bytes read differs."); currentOffset += bytesRead; this.Assert.AreEqual(readOp.ExpectedResult, targetBuffer[currentOffset - 1], "Last byte read differs."); } } bufferingReadStream.StopBuffering(); targetBuffer = new byte[1000]; currentOffset = 0; foreach (ReadOperation readOp in replayRead) { int bytesRead = bufferingReadStream.Read(targetBuffer, currentOffset, readOp.Count); this.Assert.AreEqual(readOp.ExpectedBytesRead, bytesRead, "Bytes read differs."); currentOffset += bytesRead; this.Assert.AreEqual(readOp.ExpectedResult, targetBuffer[currentOffset - 1], "Last byte read differs."); } }); }
/// <summary> /// Attempts to find the value for the specified key in the dictionary. /// </summary> public bool TryGetValue(K key, out V value) { return(ReadOperation.TryGetValue(key, out value)); }
public virtual void OnRead(string key, RavenJObject document, RavenJObject metadata, ReadOperation operation, TransactionInformation transactionInformation) { }
public override ReadVetoResult AllowRead(string key, RavenJObject metadata, ReadOperation operation, TransactionInformation transactionInformation) { if (metadata.Value <string>("Document-Owner") == Thread.CurrentPrincipal.Identity.Name) { return(ReadVetoResult.Allowed); } if (operation == ReadOperation.Load) { return(ReadVetoResult.Deny("You don't have permission to read this document")); } return(ReadVetoResult.Ignore); }
public override ReadVetoResult AllowRead(string key, JObject document, JObject metadata, ReadOperation operation, TransactionInformation transactionInformation) { if (ReplicationContext.IsInReplicationContext) { return(ReadVetoResult.Allowed); } JToken value; if (metadata.TryGetValue("Raven-Delete-Marker", out value)) { return(ReadVetoResult.Ignore); } return(ReadVetoResult.Allowed); }
public override ReadVetoResult AllowRead(string key, RavenJObject metadata, ReadOperation operation, TransactionInformation transactionInformation) { if (operation != ReadOperation.Index) { return(ReadVetoResult.Allowed); } if (metadata.ContainsKey("Deleted") == false) { return(ReadVetoResult.Allowed); } return(ReadVetoResult.Ignore); }
protected override void EncodeRead(ReadOperation operation) { //We don't need this as ExposedModbusTCPSlaveSession is used to test response processing functionality return; }
public override ReadVetoResult AllowRead(string key, Stream data, RavenJObject metadata, ReadOperation operation) { RavenJToken value; if (metadata.TryGetValue("Raven-Delete-Marker", out value)) { return(ReadVetoResult.Ignore); } return(ReadVetoResult.Allowed); }
public override ReadVetoResult AllowRead(string key, Stream data, RavenJObject metadata, ReadOperation operation) { if (key.All(char.IsUpper)) { return(ReadVetoResult.Ignore); } if (key.Any(char.IsUpper)) { return(ReadVetoResult.Deny("You don't get to read this attachment")); } return(ReadVetoResult.Allowed); }
public override async Task Read( ReadReq request, IServerStreamWriter <ReadResp> responseStream, ServerCallContext context) { var options = request.Options; var countOptionsCase = options.CountOptionCase; var streamOptionsCase = options.StreamOptionCase; var readDirection = options.ReadDirection; var filterOptionsCase = options.FilterOptionCase; var uuidOptionsCase = options.UuidOption.ContentCase; var user = context.GetHttpContext().User; var requiresLeader = GetRequiresLeader(context.RequestHeaders); var op = streamOptionsCase switch { StreamOptionOneofCase.Stream => ReadOperation.WithParameter( Plugins.Authorization.Operations.Streams.Parameters.StreamId(request.Options.Stream.StreamIdentifier)), StreamOptionOneofCase.All => ReadOperation.WithParameter( Plugins.Authorization.Operations.Streams.Parameters.StreamId(SystemStreams.AllStream)), _ => throw new InvalidOperationException() }; if (!await _provider.CheckAccessAsync(user, op, context.CancellationToken).ConfigureAwait(false)) { throw AccessDenied(); } await using var enumerator = (streamOptionsCase, countOptionsCase, readDirection, filterOptionsCase) switch { (StreamOptionOneofCase.Stream, CountOptionOneofCase.Count, ReadDirection.Forwards, FilterOptionOneofCase.NoFilter) => (IAsyncEnumerator <ResolvedEvent>) new Enumerators.ReadStreamForwards( _publisher, request.Options.Stream.StreamIdentifier, request.Options.Stream.ToStreamRevision(), request.Options.Count, request.Options.ResolveLinks, user, requiresLeader, context.Deadline, StreamNotFound, context.CancellationToken), (StreamOptionOneofCase.Stream, CountOptionOneofCase.Count, ReadDirection.Backwards, FilterOptionOneofCase.NoFilter) => new Enumerators.ReadStreamBackwards( _publisher, request.Options.Stream.StreamIdentifier, request.Options.Stream.ToStreamRevision(), request.Options.Count, request.Options.ResolveLinks, user, requiresLeader, context.Deadline, StreamNotFound, context.CancellationToken), (StreamOptionOneofCase.All, CountOptionOneofCase.Count, ReadDirection.Forwards, FilterOptionOneofCase.NoFilter) => new Enumerators.ReadAllForwards( _publisher, request.Options.All.ToPosition(), request.Options.Count, request.Options.ResolveLinks, user, requiresLeader, context.Deadline, context.CancellationToken), (StreamOptionOneofCase.All, CountOptionOneofCase.Count, ReadDirection.Backwards, FilterOptionOneofCase.NoFilter) => new Enumerators.ReadAllBackwards( _publisher, request.Options.All.ToPosition(), request.Options.Count, request.Options.ResolveLinks, user, requiresLeader, context.Deadline, context.CancellationToken), (StreamOptionOneofCase.Stream, CountOptionOneofCase.Subscription, ReadDirection.Forwards, FilterOptionOneofCase.NoFilter) => new Enumerators.StreamSubscription <TStreamId>( _publisher, request.Options.Stream.StreamIdentifier, request.Options.Stream.ToSubscriptionStreamRevision(), request.Options.ResolveLinks, user, requiresLeader, _readIndex, context.CancellationToken), (StreamOptionOneofCase.All, CountOptionOneofCase.Subscription, ReadDirection.Forwards, FilterOptionOneofCase.NoFilter) => new Enumerators.AllSubscription( _publisher, request.Options.All.ToSubscriptionPosition(), request.Options.ResolveLinks, user, requiresLeader, _readIndex, context.CancellationToken), (StreamOptionOneofCase.All, CountOptionOneofCase.Subscription, ReadDirection.Forwards, FilterOptionOneofCase.Filter) => new Enumerators.AllSubscriptionFiltered( _publisher, request.Options.All.ToSubscriptionPosition(), request.Options.ResolveLinks, ConvertToEventFilter(true, request.Options.Filter), user, requiresLeader, _readIndex, request.Options.Filter.WindowCase switch { ReadReq.Types.Options.Types.FilterOptions.WindowOneofCase.Count => null, ReadReq.Types.Options.Types.FilterOptions.WindowOneofCase.Max => request.Options.Filter.Max, _ => throw new InvalidOperationException() },
public JsonDocument ExecuteReadTriggers(JsonDocument document, TransactionInformation transactionInformation, ReadOperation operation) { return(ExecuteReadTriggersOnRead(ProcessReadVetoes(document, transactionInformation, operation), transactionInformation, operation)); }
public override ReadVetoResult AllowRead(string key, JObject document, JObject metadata, ReadOperation operation, TransactionInformation transactionInformation) { if (key == null) { return(ReadVetoResult.Allowed); } if (key.StartsWith("Raven/") && operation == ReadOperation.Query) { return(ReadVetoResult.Ignore); // hide Raven's documentation from queries } return(ReadVetoResult.Allowed); }
public override void OnRead(string key, RavenJObject document, RavenJObject metadata, ReadOperation operation, TransactionInformation transactionInformation) { // This trigger is only for simple query operations if (key == null || operation != ReadOperation.Query) { return; } // Don't do anything when temporal versioning is not enabled if (!Database.IsTemporalVersioningEnabled(key, metadata)) { return; } // Only operate on temporal revisions var temporal = metadata.GetTemporalMetadata(); if (temporal.Status != TemporalStatus.Revision) { return; } // Send back the revision number temporal.RevisionNumber = int.Parse(key.Split('/').Last()); // When we filtered by effective date, return the document id instead of the revision id if (temporal.Effective.HasValue) { metadata["@id"] = key.Substring(0, key.IndexOf(TemporalConstants.TemporalKeySeparator, StringComparison.Ordinal)); } }
public virtual ReadVetoResult AllowRead(string key, RavenJObject metadata, ReadOperation operation, TransactionInformation transactionInformation) { return(ReadVetoResult.Allowed); }
public override ReadVetoResult AllowRead(string key, RavenJObject metadata, ReadOperation operation, TransactionInformation transactionInformation) { if (operation == ReadOperation.Index) { return(ReadVetoResult.Allowed); } var name = metadata["name"]; if (name != null && name.Value <string>().Any(char.IsUpper)) { return(ReadVetoResult.Deny("Upper case characters in the 'name' property means the document is a secret!")); } return(ReadVetoResult.Allowed); }
public virtual ReadVetoResult AllowRead(string key, Stream data, RavenJObject metadata, ReadOperation operation) { return(ReadVetoResult.Allowed); }
public override ReadVetoResult AllowRead(string key, Raven.Json.Linq.RavenJObject metadata, ReadOperation operation, Raven.Abstractions.Data.TransactionInformation transactionInformation) { if (operation == ReadOperation.Query) { return(ReadVetoResult.Ignore); } return(ReadVetoResult.Allowed); }
public override void OnRead(string key, RavenJObject document, RavenJObject metadata, ReadOperation operation, TransactionInformation transactionInformation) { var linkName = metadata.Value <string>("Raven-Link-Name"); var link = metadata.Value <string>("Raven-Link"); if (link == null) { return; } var linkedDocument = Database.Get(link, transactionInformation); document.Add(linkName, linkedDocument.ToJson()); }
public override ReadVetoResult AllowRead(string key, RavenJObject metadata, ReadOperation operation, TransactionInformation transactionInformation) { if (operation == ReadOperation.Index) { return(ReadVetoResult.Allowed); } var name = metadata["hidden"]; if (name != null && name.Value <bool>()) { return(ReadVetoResult.Ignore); } return(ReadVetoResult.Allowed); }
private JsonDocument ExecuteReadTriggersOnRead(JsonDocument resultingDocument, TransactionInformation transactionInformation, ReadOperation operation) { if (resultingDocument == null) { return(null); } triggers.Apply( trigger => trigger.OnRead(resultingDocument.Key, resultingDocument.DataAsJson, resultingDocument.Metadata, operation, transactionInformation)); return(resultingDocument); }
/// <summary> /// Implementation of generic IEnumerable.GetEnumerator() /// </summary> public IEnumerator <KeyValuePair <K, V> > GetEnumerator() { return(ReadOperation.GetEnumerator()); }
public T ProcessReadVetoes <T>(T document, TransactionInformation transactionInformation, ReadOperation operation) where T : class, IJsonDocumentMetadata, new() { if (document == null) { return(null); } foreach (var readTrigger in triggers) { var readVetoResult = readTrigger.Value.AllowRead(document.Key, document.Metadata, operation, transactionInformation); switch (readVetoResult.Veto) { case ReadVetoResult.ReadAllow.Allow: break; case ReadVetoResult.ReadAllow.Deny: return(new T { Etag = Etag.Empty, LastModified = DateTime.MinValue, NonAuthoritativeInformation = false, Key = document.Key, Metadata = new RavenJObject { { "Raven-Read-Veto", new RavenJObject { { "Reason", readVetoResult.Reason }, { "Trigger", readTrigger.ToString() } } } } }); case ReadVetoResult.ReadAllow.Ignore: log.Debug("Trigger {0} asked us to ignore {1}", readTrigger.Value, document.Key); return(null); default: throw new ArgumentOutOfRangeException(readVetoResult.Veto.ToString()); } } return(document); }
/// <summary> /// Allow the trigger the option of modifying the document and metadata instances /// before the user can see them. /// </summary><remarks> /// The modified values are transient, and are NOT saved to the database. /// </remarks> /// <param name="key">The key of the read document - can be null if reading a projection</param> /// <param name="document">The document being read</param> /// <param name="metadata">The document metadata</param> /// <param name="operation">Whatever the operation is a load or a query</param> public virtual void OnRead(string key, RavenJObject document, RavenJObject metadata, ReadOperation operation) { }
private JsonDocument ExecuteReadTriggersOnRead(JsonDocument resultingDocument, TransactionInformation transactionInformation, ReadOperation operation) { if (resultingDocument == null) { return(null); } var doc = new JsonDocument { Key = resultingDocument.Key, Etag = resultingDocument.Etag, LastModified = resultingDocument.LastModified, SerializedSizeOnDisk = resultingDocument.SerializedSizeOnDisk, SkipDeleteFromIndex = resultingDocument.SkipDeleteFromIndex, NonAuthoritativeInformation = resultingDocument.NonAuthoritativeInformation, TempIndexScore = resultingDocument.TempIndexScore, DataAsJson = resultingDocument.DataAsJson.IsSnapshot ? (RavenJObject)resultingDocument.DataAsJson.CreateSnapshot() : resultingDocument.DataAsJson, Metadata = resultingDocument.Metadata.IsSnapshot ? (RavenJObject)resultingDocument.Metadata.CreateSnapshot() : resultingDocument.Metadata, }; triggers.Apply( trigger => trigger.OnRead(doc.Key, doc.DataAsJson, doc.Metadata, operation, transactionInformation)); return(doc); }
public List <ModbusOutValue> ProcessResponse(ModbusSlaveConfig config, ReadOperation x) { return(base.ProcessResponse(config, x)); }