-
Notifications
You must be signed in to change notification settings - Fork 231
Invoke-GraphRequest cmdlet to allow direct requests using underlying HttpClient #245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
f551950
Add GertGraphClient and InvokeGraph request Cmdlests
608dc7c
Validate passed in URL.
d6fac21
Merge branch 'dev' into invokeGraphRequest
georgend f8e2eb2
Adding help messages and extra validation.
e615967
Merge branch 'invokeGraphRequest' of https://github.com/microsoftgrap…
bfaecd0
Merge branch 'dev' into invokeGraphRequest
d8f0cc7
- Enable users to specify their own Token (UserProvidedToken)
54c1bf3
Merge
e1647c8
Fixup suggested changes.
e87963a
Add license headers to all files.
425d234
Formatting
276f48c
Validate that Uri is not an empty string.
eb37982
Remove header exclusion list.
8c3a30a
Use SecureString to handle Tokens.
d9d9a7d
Operator precedence.
2f9908c
Avoid converting to dict and then discarding without using.
0688068
Try to infer encoding from charset, otherwise default to system default.
0a16c43
Simplify to trim op.
05507f8
Extra handlign of Body and Inputfile.
55211c7
Merge
208a7ea
incorrectly formatted file.
georgend File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
965 changes: 965 additions & 0 deletions
965
src/Authentication/Authentication/Cmdlets/InvokeGraphRequest.cs
Large diffs are not rendered by default.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
src/Authentication/Authentication/Helpers/AttachDebugger.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| using System; | ||
| using System.Management.Automation; | ||
|
|
||
| using Microsoft.Graph.PowerShell.Authentication.Cmdlets; | ||
|
|
||
| namespace Microsoft.Graph.PowerShell.Authentication.Helpers | ||
| { | ||
| internal static class AttachDebugger | ||
| { | ||
| internal static void Break(PSCmdlet invokedCmdLet) | ||
| { | ||
| while (!System.Diagnostics.Debugger.IsAttached) | ||
| { | ||
| Console.Error.WriteLine($"Waiting for debugger to attach to process {System.Diagnostics.Process.GetCurrentProcess().Id}"); | ||
| //invokedCmdLet.WriteDebug($"Waiting for debugger to attach to process {System.Diagnostics.Process.GetCurrentProcess().Id}"); | ||
| for (var i = 0; i < 50; i++) | ||
| { | ||
| if (System.Diagnostics.Debugger.IsAttached) | ||
| { | ||
| break; | ||
| } | ||
| System.Threading.Thread.Sleep(100); | ||
| //invokedCmdLet.WriteDebug("."); | ||
| Console.Error.Write("."); | ||
| } | ||
| //invokedCmdLet.WriteDebug(Environment.NewLine); | ||
| Console.Error.WriteLine(); | ||
| } | ||
| System.Diagnostics.Debugger.Break(); | ||
| } | ||
| } | ||
| } | ||
101 changes: 101 additions & 0 deletions
101
src/Authentication/Authentication/Helpers/BufferingStreamReader.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| using System; | ||
| using System.IO; | ||
|
|
||
| namespace Microsoft.Graph.PowerShell.Authentication.Helpers | ||
| { | ||
| internal class BufferingStreamReader : Stream | ||
| { | ||
| internal BufferingStreamReader(Stream baseStream) | ||
| { | ||
| _baseStream = baseStream; | ||
| _streamBuffer = new MemoryStream(); | ||
| _length = long.MaxValue; | ||
| _copyBuffer = new byte[4096]; | ||
| } | ||
|
|
||
| private readonly Stream _baseStream; | ||
| private readonly MemoryStream _streamBuffer; | ||
| private readonly byte[] _copyBuffer; | ||
|
|
||
| public override bool CanRead => true; | ||
|
|
||
| public override bool CanSeek => true; | ||
|
|
||
| public override bool CanWrite => false; | ||
|
|
||
| public override void Flush() | ||
| { | ||
| _streamBuffer.SetLength(0); | ||
| } | ||
|
|
||
| public override long Length => _length; | ||
|
|
||
| private long _length; | ||
|
|
||
| public override long Position | ||
| { | ||
| get => _streamBuffer.Position; | ||
|
|
||
| set => _streamBuffer.Position = value; | ||
| } | ||
|
|
||
| public override int Read(byte[] buffer, int offset, int count) | ||
| { | ||
| long previousPosition = Position; | ||
| bool consumedStream = false; | ||
| int totalCount = count; | ||
| while ((!consumedStream) && | ||
| ((Position + totalCount) > _streamBuffer.Length)) | ||
| { | ||
| // If we don't have enough data to fill this from memory, cache more. | ||
| // We try to read 4096 bytes from base stream every time, so at most we | ||
| // may cache 4095 bytes more than what is required by the Read operation. | ||
| int bytesRead = _baseStream.Read(_copyBuffer, 0, _copyBuffer.Length); | ||
|
|
||
| if (_streamBuffer.Position < _streamBuffer.Length) | ||
| { | ||
| // Win8: 651902 no need to -1 here as Position refers to the place | ||
| // where we can start writing from. | ||
| _streamBuffer.Position = _streamBuffer.Length; | ||
| } | ||
|
|
||
| _streamBuffer.Write(_copyBuffer, 0, bytesRead); | ||
|
|
||
| totalCount -= bytesRead; | ||
| if (bytesRead < _copyBuffer.Length) | ||
| { | ||
| consumedStream = true; | ||
| } | ||
| } | ||
|
|
||
| // Reset our backing store to its official position, as reading | ||
| // for the CopyTo updates the position. | ||
| _streamBuffer.Seek(previousPosition, SeekOrigin.Begin); | ||
|
|
||
| // Read from the backing store into the requested buffer. | ||
| int read = _streamBuffer.Read(buffer, offset, count); | ||
|
|
||
| if (read < count) | ||
| { | ||
| SetLength(Position); | ||
| } | ||
|
|
||
| return read; | ||
| } | ||
|
|
||
| public override long Seek(long offset, SeekOrigin origin) | ||
| { | ||
| return _streamBuffer.Seek(offset, origin); | ||
| } | ||
|
|
||
| public override void SetLength(long value) | ||
| { | ||
| _length = value; | ||
| } | ||
|
|
||
| public override void Write(byte[] buffer, int offset, int count) | ||
| { | ||
| throw new NotSupportedException(); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.