Skip to content

Move off NuGet APIs and use HTTP client side APIs #1019

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

Closed
wants to merge 76 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
1805b2e
add interface classes (#796)
anamnavi Sep 14, 2022
cf5fbe9
Update api calls for Find and Install (#799)
anamnavi Sep 15, 2022
9c3e140
Add ServerAPICalls and IServerAPICalls
alerickson Sep 16, 2022
e5823e0
Update IServerAPICalls based on changes made in ServerAPICalls
alerickson Sep 16, 2022
0fed626
Rename ServerAPICalls to V2ServerAPICalls, update IServerAPICalls
alerickson Sep 16, 2022
955fb87
Fill out code for V2ServerAPICalls
alerickson Oct 4, 2022
337e43a
Add NuGet.Versioning directive back in
alerickson Oct 4, 2022
72deb4c
Add implementation for HttpFindPSResource
alerickson Oct 5, 2022
554d032
Beginning of impl for converting xml to PSResourceInfo obj (#823)
alerickson Oct 5, 2022
612a804
Parse PSResourceInfo (#824)
alyssa1303 Oct 7, 2022
0f9cf49
Interface impl (#825)
alerickson Oct 10, 2022
964898d
Remove XmlSerializer and implement parser (#828)
alyssa1303 Oct 11, 2022
6cc3408
Finish Parser Implementation (#829)
alyssa1303 Oct 12, 2022
04c06c7
Continue interface implementation (#844)
alerickson Nov 1, 2022
50edd20
complete FindName() and FindVersion() (#845)
anamnavi Nov 3, 2022
b17856f
add implementation for FindVersionGlobbing (#851)
anamnavi Nov 8, 2022
8cf25da
implement find-psresource with v2 api (#852)
alyssa1303 Nov 8, 2022
635a081
Integrate FindVersionGlobbing V2 into FindPSResource (#853)
alerickson Nov 9, 2022
98e2473
Bug fix for using version ranges when finding packages (#854)
alerickson Nov 9, 2022
4580ec7
Add FindTags implementation (#856)
alerickson Nov 9, 2022
aacc1be
get FindTag (multiple), FindType, FindCommandName, FindDSCResourceNam…
anamnavi Nov 11, 2022
1993ea0
Find Tags, find CommandName and find DSCResourceName impl (#858)
alerickson Nov 11, 2022
f69b98b
Fix up bugs with find tags (#859)
alerickson Nov 14, 2022
0491eab
Add some error handling (#861)
alerickson Nov 15, 2022
98015ad
Interface err for VersionGlobbing (#862)
anamnavi Nov 15, 2022
ee60002
start implement FindNameGlobbing (#863)
alyssa1303 Nov 16, 2022
cacb6f9
Clean up interface files (#865)
alerickson Nov 17, 2022
958e87d
Start adding pagination (#869)
alerickson Nov 22, 2022
2b390e0
Interface pagination (#872)
anamnavi Jan 10, 2023
0c45711
Add tests for find and install using REST calls (#897)
alerickson Jan 19, 2023
89cf66b
WIP: Add dependency resolution for REST calls (#913)
alerickson Jan 25, 2023
af1a69b
add preliminary implementation for v3 server api calls (#917)
alerickson Jan 31, 2023
151a5fa
Implement findVersion for v3 endpoint (using newtonsoft.json) (#923)
alerickson Feb 2, 2023
88fc73e
Move off Newtonsoft.Json and use System.Text.Json (#927)
alerickson Feb 6, 2023
4802297
Complete impl for v3 find name, find version, find version globbing (…
alerickson Feb 7, 2023
86ed56d
implement FindNameGlobbing (#930)
anamnavi Feb 7, 2023
16961aa
Add implementation for v3 implementation find tags (#931)
alerickson Feb 7, 2023
f629333
Add install implementation (not complete) (#932)
alerickson Feb 7, 2023
056149a
Code clean up for v3ServerAPICalls.cs (#933)
alerickson Feb 8, 2023
9cc3e5f
Add streaming to v2 and v3 find REST calls (#935)
alerickson Feb 8, 2023
ff4c3d8
return wrapper object when streaming (#936)
anamnavi Feb 9, 2023
fdc0a7c
Clean up HttpFindPSResource (#944)
alerickson Feb 13, 2023
e18e4ae
fix prerelease install name bug for v3 (#945)
anamnavi Feb 13, 2023
6ac782b
If 'APIVersion' is not in repository store, add it (#951)
alerickson Feb 14, 2023
35583cd
Bug fix for creating new PSResourceResult object (#952)
alerickson Feb 14, 2023
683c07e
Clean up code (#953)
alerickson Feb 14, 2023
159bf70
code clean up (#954)
anamnavi Feb 14, 2023
a6195c9
add base class for ServerApi (#965)
anamnavi Feb 16, 2023
f5f7a11
Find: integrate with factory pattern for server and response (#966)
anamnavi Feb 17, 2023
de55af0
Fix bugs for Install factory refactor (#967)
alerickson Feb 21, 2023
35850b7
Add reinstall functionality to 'httpInstallPackage' method (#968)
alerickson Feb 22, 2023
e114c02
refactor install and fix bug with prerelease reinstall (#970)
anamnavi Feb 22, 2023
8cacddc
write warning for deps for V3 (#971)
anamnavi Feb 22, 2023
9f831f4
Add credential and credential persistence to refactor (#972)
alerickson Feb 23, 2023
4f4bf4c
Add networkCredential to base constructor of ServerApiCall class (#973)
alerickson Feb 23, 2023
3a9529a
Add exception handling (#974)
alerickson Feb 24, 2023
b1a764b
Exception handling fixes (#986)
alerickson Feb 24, 2023
65f0b47
Exception continue (#987)
anamnavi Feb 24, 2023
f36ad8b
Add exception handling to V2ServerAPICalls and code cleanup (#990)
alerickson Feb 25, 2023
522ebf7
Fix two minor bugs w/reading V3 server responses (#991)
alerickson Feb 27, 2023
e1259fb
Tag name (#995)
anamnavi Mar 9, 2023
46d819a
Add install dependency logic (#996)
alerickson Mar 9, 2023
a20b74a
Quick fix for save and update calling install helper (#997)
alerickson Mar 9, 2023
fd17fb3
Bug fixes for retrieving all packages on machine (#999)
alerickson Mar 9, 2023
ac91b1e
Add UpdatePSResourceV2Tests (for REST api calls) (#1001)
alerickson Mar 10, 2023
db52804
Add V3 tests for update-psresource (#1002)
alerickson Mar 10, 2023
9279c7c
Add tests for Save-PSResource, update tests for Update-PSResource (#1…
alerickson Mar 13, 2023
0145628
Resolve bugs when using local repositories (#1005)
alerickson Mar 13, 2023
6bf05d2
dependencies bugfix for Find and partially install (#1006)
anamnavi Mar 13, 2023
6a6a6ee
Add local api version (#1007)
alerickson Mar 14, 2023
2140d31
Update local tests for save and update (#1008)
alerickson Mar 14, 2023
b8eb58d
Add not yet implemented warning to save-psresource -asNupkg (#1009)
alerickson Mar 14, 2023
c63ed99
Separate out tests for V2 and V3 server protocol for Find (#998)
anamnavi Mar 14, 2023
07158f3
Bug fix for installing dependencies (#1010)
alerickson Mar 14, 2023
50bdd3e
Add tests for Find (local), Install (V2,V3,local) (#1011)
anamnavi Mar 16, 2023
6c70084
remove old tests, and clean up code (#1017)
anamnavi Mar 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doBuild.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ function DoBuild
'NuGet.Repositories'
'NuGet.Versioning'
'Newtonsoft.Json'
'System.Text.Json'
)

$buildSuccess = $true
Expand Down
22 changes: 22 additions & 0 deletions src/PSGet.Format.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,28 @@
</TableRowEntries>
</TableControl>
</View>
<View>
<Name>PSCommandResourceInfo</Name>
<ViewSelectedBy>
<TypeName>Microsoft.PowerShell.PowerShellGet.UtilClasses.PSCommandResourceInfo</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader><Label>Name</Label></TableColumnHeader>
<TableColumnHeader><Label>Package Name</Label></TableColumnHeader>
<TableColumnHeader><Label>Version</Label></TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem><PropertyName>Names</PropertyName></TableColumnItem>
<TableColumnItem><ScriptBlock>$_.ParentResource.Name</ScriptBlock></TableColumnItem>
<TableColumnItem><ScriptBlock>$_.ParentResource.Version</ScriptBlock></TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>
<View>
<Name>PSIncludedResourceInfoTable</Name>
<ViewSelectedBy>
Expand Down
860 changes: 693 additions & 167 deletions src/code/FindHelper.cs

Large diffs are not rendered by default.

209 changes: 110 additions & 99 deletions src/code/FindPSResource.cs

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion src/code/GetHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,16 @@ public IEnumerable<PSResourceInfo> GetInstalledPackages(
foreach (var pkg in pkgs)
{
// Filter on specific version.
var nugetVersion = new NuGetVersion(pkg.Version);
pkg.AdditionalMetadata.TryGetValue("NormalizedVersion", out string normalizedVersion);

if (!NuGetVersion.TryParse(
value: normalizedVersion,
version: out NuGetVersion nugetVersion))
{
_cmdletPassedIn.WriteVerbose(String.Format("Package's normalized version '{0}' cannot be parsed into NuGetVersion.", normalizedVersion));
yield break;
}

var pkgVersionRange = new VersionRange(
minVersion: nugetVersion,
includeMinVersion: true,
Expand Down
2 changes: 1 addition & 1 deletion src/code/GetPSResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ protected override void ProcessRecord()
{
WriteVerbose("Entering GetPSResource");

var namesToSearch = Utils.ProcessNameWildcards(Name, out string[] errorMsgs, out bool _);
var namesToSearch = Utils.ProcessNameWildcards(Name, removeWildcardEntries:false, out string[] errorMsgs, out bool _);
foreach (string error in errorMsgs)
{
WriteError(new ErrorRecord(
Expand Down
95 changes: 95 additions & 0 deletions src/code/IServerAPICalls.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.PowerShell.PowerShellGet.UtilClasses;
using NuGet.Versioning;
using System.Net.Http;
using System.Runtime.ExceptionServices;

public interface IServerAPICalls
{
#region Methods
/// <summary>
/// Find method which allows for searching for all packages from a repository and returns latest version for each.
/// Examples: Search -Repository PSGallery
/// API call:
/// - Include prerelease: http://www.powershellgallery.com/api/v2/Search()?$filter=IsAbsoluteLatestVersion&includePrerelease=true
/// </summary>
string[] FindAll(bool includePrerelease, ResourceType type, out ExceptionDispatchInfo edi);

/// <summary>
/// Find method which allows for searching for packages with tag from a repository and returns latest version for each.
/// Examples: Search -Tag "JSON" -Repository PSGallery
/// API call:
/// - Include prerelease: http://www.powershellgallery.com/api/v2/Search()?$filter=IsAbsoluteLatestVersion&searchTerm='tag:JSON'&includePrerelease=true
/// </summary>
string[] FindTag(string tag, bool includePrerelease, ResourceType _type, out ExceptionDispatchInfo edi);

/// <summary>
/// Find method which allows for searching for single name and returns latest version.
/// Name: no wildcard support
/// Examples: Search "PowerShellGet"
/// API call:
/// - No prerelease: http://www.powershellgallery.com/api/v2/FindPackagesById()?id='PowerShellGet'
/// - Include prerelease: http://www.powershellgallery.com/api/v2/FindPackagesById()?id='PowerShellGet'
/// Implementation Note: Need to filter further for latest version (prerelease or non-prerelease dependening on user preference)
/// </summary>
string FindName(string packageName, bool includePrerelease, ResourceType type, out ExceptionDispatchInfo edi);

string FindNameWithTag(string packageName, string[] tags, bool includePrerelease, ResourceType type, out ExceptionDispatchInfo edi);

/// <summary>
/// Find method which allows for searching for single name with version range.
/// Name: no wildcard support
/// Version: supports wildcards
/// Examples: Search "PowerShellGet" "[3.0.0.0, 5.0.0.0]"
/// Search "PowerShellGet" "3.*"
/// API Call: http://www.powershellgallery.com/api/v2/FindPackagesById()?id='PowerShellGet'
/// Implementation note: Returns all versions, including prerelease ones. Later (in the API client side) we'll do filtering on the versions to satisfy what user provided.
/// </summary>
string[] FindNameGlobbing(string packageName, bool includePrerelease, ResourceType type, out ExceptionDispatchInfo edi);

string[] FindNameGlobbingWithTag(string packageName, string[] tags, bool includePrerelease, ResourceType type, out ExceptionDispatchInfo edi);

/// <summary>
/// Find method which allows for searching for single name with specific version.
/// Name: no wildcard support
/// Version: no wildcard support
/// Examples: Search "PowerShellGet" "2.2.5"
/// API call: http://www.powershellgallery.com/api/v2/Packages(Id='PowerShellGet', Version='2.2.5')
/// </summary>
string[] FindVersionGlobbing(string packageName, VersionRange versionRange, bool includePrerelease, ResourceType type, bool getOnlyLatest, out ExceptionDispatchInfo edi);

// <summary>
/// Find method which allows for searching for single name with specific version.
/// Name: no wildcard support
/// Version: no wildcard support
/// Examples: Search "PowerShellGet" "2.2.5"
/// API call: http://www.powershellgallery.com/api/v2/Packages(Id='PowerShellGet', Version='2.2.5')
/// </summary>
string FindVersion(string packageName, string version, ResourceType type, out ExceptionDispatchInfo edi);

string FindVersionWithTag(string packageName, string version, string[] tags, ResourceType type, out ExceptionDispatchInfo edi);


/// <summary>
/// Installs specific package.
/// Name: no wildcard support.
/// Examples: Install "PowerShellGet"
/// Implementation Note: if prerelease: call IFindPSResource.FindName()
/// if not prerelease: https://www.powershellgallery.com/api/v2/package/Id (Returns latest stable)
/// </summary>
HttpContent InstallName(string packageName, bool includePrerelease, out ExceptionDispatchInfo edi);

/// <summary>
/// Installs package with specific name and version.
/// Name: no wildcard support.
/// Version: no wildcard support.
/// Examples: Install "PowerShellGet" -Version "3.0.0.0"
/// Install "PowerShellGet" -Version "3.0.0-beta16"
/// API Call: https://www.powershellgallery.com/api/v2/package/Id/version (version can be prerelease)
/// </summary>
HttpContent InstallVersion(string packageName, string version, out ExceptionDispatchInfo edi);

#endregion
}
Loading