Skip to content

Commit 7e92953

Browse files
authored
Fix get identity (#153)
* Fix GetIdentity for hosted service * Add support to traversing the type hierarchy * Fix compiler directive * Fix RestApiService for PS Desktop (5.1) * Update WinGet packaging script * Update release notes
1 parent ecc4125 commit 7e92953

File tree

19 files changed

+349
-274
lines changed

19 files changed

+349
-274
lines changed

.github/workflows/main.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,9 @@ jobs:
275275
run: |
276276
git clone --single-branch --branch "master" "https://igoravl:[email protected]/igoravl/winget-pkgs.git"
277277
cd winget-pkgs
278+
git remote add upstream https://github.com/microsoft/winget-pkgs.git
278279
git fetch upstream
279-
git checkout -b "TfsCmdlets_{{ env.BUILD_NAME }}"
280+
git checkout -b "TfsCmdlets_$BUILD_NAME"
280281
- name: Download artifact
281282
uses: actions/download-artifact@v2
282283
with:
@@ -289,8 +290,8 @@ jobs:
289290
git config --local user.email "[email protected]"
290291
git config --local user.name "Igor Abade"
291292
git add manifests/i/Igoravl/TfsCmdlets/*
292-
git commit -m "Release ${{ env.BUILD_NAME }}"
293-
git push -u origin TfsCmdlets_{{ env.BUILD_NAME }}
293+
git commit -m "Release $BUILD_NAME"
294+
git push -u origin "TfsCmdlets_$BUILD_NAME"
294295
- name: Create pull request to microsoft/winget-pkgs
295296
shell: pwsh
296297
run: |
@@ -301,8 +302,8 @@ jobs:
301302
Set-GitHubAuthentication -SessionOnly -Credential (New-Object System.Management.Automation.PSCredential @("pat",
302303
(ConvertTo-SecureString -String $env:GITHUB_TOKEN -AsPlainText -Force)))
303304
# Create pull request
304-
New-GitHubPullRequest -Draft -OwnerName Microsoft -RepositoryName winget-pkgs `
305-
-Title 'TfsCmdlets_{{ env.BUILD_NAME }}' -Head 'igoravl:TfsCmdlets_{{ env.BUILD_NAME }}' -base master -Body @'
305+
New-GitHubPullRequest -OwnerName Microsoft -RepositoryName winget-pkgs `
306+
-Title "TfsCmdlets_$env:BUILD_NAME" -Head "igoravl:TfsCmdlets_$env:BUILD_NAME" -base master -Body @'
306307
- [x] Have you signed the [Contributor License Agreement](https://cla.opensource.microsoft.com/microsoft/winget-pkgs)?
307308
- [x] Have you checked that there aren't other open [pull requests](https://github.com/microsoft/winget-pkgs/pulls) for the same manifest update/change?
308309
- [x] Have you validated your manifest locally with `winget validate --manifest <path>`?

CSharp/TfsCmdlets/AssemblyResolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public partial class AssemblyResolver
2525
public void Register()
2626
{
2727

28-
#if NET471
28+
#if NET471_OR_GREATER
2929
AppDomain.CurrentDomain.AssemblyResolve += (sender, e) =>
3030
{
3131
var assemblyName = e.Name.Split(',')[0];

CSharp/TfsCmdlets/Cmdlets/Identity/GetIdentity.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace TfsCmdlets.Cmdlets.Identity
1010
{
1111
/// <summary>
1212
/// Gets one or more identities that represents either users or groups in Azure DevOps.
13+
/// This cmdlet resolves legacy identity information for use with older APIs such as the Security APIs.
1314
/// </summary>
1415
[Cmdlet(VerbsCommon.Get, "TfsIdentity")]
1516
[OutputType(typeof(WebApiIdentity))]
@@ -39,10 +40,16 @@ public partial class GetIdentity : CmdletBase
3940
[Parameter(Mandatory = true, ParameterSetName = "Get current user")]
4041
public SwitchParameter Current { get; set; }
4142

43+
/// <summary>
44+
/// HELP_PARAM_Collection
45+
/// </summary>
46+
[Parameter()]
47+
public object Collection { get; set; }
48+
4249
/// <summary>
4350
/// HELP_PARAM_SERVER
4451
/// </summary>
45-
[Parameter(ValueFromPipeline = true)]
52+
[Parameter()]
4653
public object Server { get; set; }
4754

4855
/// <summary>
@@ -63,15 +70,20 @@ internal partial class IdentityDataService : BaseDataService<Models.Identity>
6370
var queryMembership = GetParameter<TfsQueryMembership>("QueryMembership");
6471
var identity = GetParameter<object>("Identity");
6572

73+
var tpc = GetCollection();
74+
6675
if (current)
6776
{
68-
var srv = GetServer();
69-
if (srv == null) yield break;
77+
if (tpc == null) yield break;
7078

71-
identity = srv.AuthorizedIdentity.UniqueName;
79+
identity = tpc.AuthorizedIdentity.UniqueName;
7280
}
7381

74-
var client = GetClient<Microsoft.VisualStudio.Services.Identity.Client.IdentityHttpClient>(ClientScope.Server);
82+
var client = GetClient<Microsoft.VisualStudio.Services.Identity.Client.IdentityHttpClient>(
83+
tpc.IsHosted?
84+
ClientScope.Collection:
85+
ClientScope.Server);
86+
7587
var qm = queryMembership;
7688

7789
while (true) switch(identity)

CSharp/TfsCmdlets/Extensions/ObjectExtensions.cs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
using System.Linq;
23
using System.Management.Automation;
4+
using System.Reflection;
35
using Microsoft.TeamFoundation.Framework.Common;
46
using Newtonsoft.Json;
57
using Newtonsoft.Json.Linq;
@@ -30,20 +32,42 @@ public static void CopyFrom(this object self, object parent)
3032

3133
public static T GetHiddenField<T>(this object self, string fieldName)
3234
{
33-
var field = self.GetType().GetField(fieldName, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
34-
return (T) field.GetValue(self);
35+
var field = FindMember<FieldInfo>(self, fieldName);
36+
return (T)field.GetValue(self);
3537
}
3638

3739
public static void SetHiddenField(this object self, string fieldName, object value)
3840
{
39-
var field = self.GetType().GetField(fieldName, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
41+
var field = FindMember<FieldInfo>(self, fieldName);
4042
field.SetValue(self, value);
4143
}
4244

4345
public static object CallHiddenMethod(this object self, string methodName, params object[] parameters)
4446
{
45-
var method = self.GetType().GetMethod(methodName, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
47+
var method = FindMember<MethodInfo>(self, methodName);
4648
return method.Invoke(self, parameters);
4749
}
50+
51+
private static T FindMember<T>(object self, string memberName)
52+
where T : MemberInfo
53+
{
54+
var rootType = self.GetType();
55+
56+
while (rootType != null)
57+
{
58+
var member = rootType
59+
.GetMember(memberName, MemberTypes.All, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
60+
.FirstOrDefault(mi => mi is T);
61+
62+
if (member != null)
63+
{
64+
return (T)member;
65+
}
66+
67+
rootType = rootType.BaseType;
68+
}
69+
70+
throw new ArgumentException($"Member {memberName} not found");
71+
}
4872
}
4973
}

CSharp/TfsCmdlets/Services/RestApiService.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,15 @@ private GenericHttpClient GetClient(Models.Connection connection, string service
133133

134134
if (client.BaseAddress.Host != uri.Host)
135135
{
136-
var pipeline = conn.GetHiddenField<HttpMessageHandler>("m_pipeline");
137-
client = new GenericHttpClient(uri, pipeline, false);
138-
139-
#if NETCOREAPP3_1_OR_GREATER
140-
conn.CallHiddenMethod("RegisterClientServiceInstance", typeof(GenericHttpClient), client);
136+
VssConnection vssConn;
137+
#if NET471_OR_GREATER
138+
vssConn = conn.GetHiddenField<VssConnection>("m_vssConnection");;
141139
#else
142-
throw new NotImplementedException("RegisterClientServiceInstance is not implemented in PS Desktop");
140+
vssConn = conn;
143141
#endif
142+
var pipeline = vssConn.GetHiddenField<HttpMessageHandler>("m_pipeline");
143+
client = new GenericHttpClient(uri, pipeline, false);
144+
vssConn.CallHiddenMethod("RegisterClientServiceInstance", typeof(GenericHttpClient), client);
144145
}
145146

146147
return _client = client;

Docs/ReleaseNotes/1.0.0-alpha3.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# TfsCmdlets Release Notes
2+
3+
## Version 1.0.0-alpha4 (_03/Sep/2015_)
4+
5+
### Improvements
6+
7+
* Add help comments to the Areas & Iterations functions
8+
9+
### Bug fixes
10+
11+
* Fix an issue in the AssemblyResolver implementation. Previously it was implemented as a scriptblock and was running into some race conditions that would crash PowerShell. Switched to a pure .NET implementation in order to avoid the race condition.
12+
13+
### Known Issues
14+
15+
* TfsCmdlets has currently a dependency on .NET 3.5 and won't load in computers with only .NET 4.x installed. Workaround is to install .NET 3.5. Next version will no longer depend on .NET 3.5.

Docs/ReleaseNotes/1.0.0-alpha4.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# TfsCmdlets Release Notes
2+
3+
## Version 1.0.0-alpha4 (_03/Sep/2015_)
4+
5+
### Improvements
6+
7+
* Remove dependency on .NET 3.5
8+
9+
### Bug fixes
10+
11+
* N/A
12+
13+
### Known Issues
14+
15+
* N/A

Docs/ReleaseNotes/1.0.0-alpha5.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# TfsCmdlets Release Notes
2+
3+
## Version 1.0.0-alpha5 (_10/Sep/2015_)
4+
5+
### Improvements
6+
7+
* Add cascade disconnection: When calling a "higher" Disconnect cmdlet (e.g. Disconnect-TfsConfigurationServer), the "lower" ones (e.g. TeamProjectCollection, TeamProject) are cascade-invoked, in other to prevent inconsistent connection information.
8+
9+
### Bug fixes
10+
11+
* Fix conditional use of -Title in New-TfsWorkItem ([96a8a60](https://github.com/igoravl/tfscmdlets/commit/818af6e9d6ba3f30e976f3ef20d6070ac50fa3e7))
12+
* Fix argument naming and pipelined return in Get-TfsWorkItem ([0a118125](https://github.com/igoravl/tfscmdlets/commit/0a11812554b447f4418e11454911ca5f53f34924))
13+
* Fix return when passing -Current in Get-TfsConfigurationServer ([58647d2f](https://github.com/igoravl/tfscmdlets/commit/58647d2f29d84d6f5db4e0022062c2dd30cfaba1))
14+
15+
### Known Issues
16+
17+
* N/A

Docs/ReleaseNotes/1.0.0-alpha6.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# TfsCmdlets Release Notes
2+
3+
## Version 1.0.0-alpha6 (_22/Oct/2015_)
4+
5+
### Improvements
6+
7+
* Enable build from cmdline with VS 2015 ([ab2325b](https://github.com/igoravl/tfscmdlets/commit/ab2325bae7cce788292d8532742a230756d1fd06))
8+
* Change PoShTools detection from error to warning ([09e62f3](https://github.com/igoravl/tfscmdlets/commit/09e62f3b034e1706fb5845b3f8588658f99a21f8))
9+
* Skip PoShTools detection in AppVeyor ([47cafa4](https://github.com/igoravl/tfscmdlets/commit/47cafa40f16c3e9c7d6f18594154f994d74cfb9c))
10+
* Add custom type detection logic ([b10f32c](https://github.com/igoravl/tfscmdlets/commit/b10f32c5538576ea3cec7bf9f8b8d4c96eddba56))
11+
12+
### Bug Fixes
13+
14+
* Fix commit message with apostrophe breaking build ([8066ab8](https://github.com/igoravl/tfscmdlets/commit/8066ab8310fa21111e09c5ecba306914edb6e4ab))
15+
* Add proper parameter initialization for credentials ([d0c4d6c](https://github.com/igoravl/tfscmdlets/commit/d0c4d6c7d28682f43ae730904d802ebf4a2d4584))
16+
* Fix handling of current config server ([d7b53f](https://github.com/igoravl/tfscmdlets/commit/d7b53fca74a66f22f793bed39f1ef3bdf642ae83))
17+
18+
### Known Issues
19+
20+
* N/A

Docs/ReleaseNotes/1.0.0-alpha7.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# TfsCmdlets Release Notes
2+
3+
## Version 1.0.0-alpha7 (_22/Oct/2015_)
4+
5+
### Improvements
6+
7+
- Added essential help comments to all cmdlets. Future versions will improve the documentation quality and depth.
8+
9+
### Bug Fixes
10+
11+
- Fix Nuget and Chocolatey package icons
12+
- Fix bug in Get-TfsWorkItemType that would not return any WITDs
13+
14+
### Known Issues
15+
16+
- N/A
17+

0 commit comments

Comments
 (0)