Skip to content

Clean interface up interface methods #865

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 1 commit into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
114 changes: 7 additions & 107 deletions src/code/HttpFindPSResource.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
using System;
using System.Collections;
using System.Linq;
using System.Xml;
using Microsoft.PowerShell.PowerShellGet.UtilClasses;
using NuGet.Versioning;
using System.Collections.Generic;
using System.Xml.Schema;

namespace Microsoft.PowerShell.PowerShellGet.Cmdlets
{
internal class HttpFindPSResource : IFindPSResource
{
V2ServerAPICalls v2ServerAPICall = new V2ServerAPICalls();
#region Members

readonly V2ServerAPICalls v2ServerAPICall = new V2ServerAPICalls();

#endregion

#region Constructor

Expand All @@ -28,26 +30,16 @@ public HttpFindPSResource() {}
/// - No prerelease: http://www.powershellgallery.com/api/v2/Search()?$filter=IsLatestVersion
/// - Include prerelease: http://www.powershellgallery.com/api/v2/Search()?$filter=IsAbsoluteLatestVersion&includePrerelease=true
/// </summary>
public PSResourceInfo FindAll(PSRepositoryInfo repository, bool includePrerelease, out string errRecord)
public PSResourceInfo FindAll(PSRepositoryInfo repository, bool includePrerelease, ResourceType type, out string errRecord)
{
var response = string.Empty;
if (includePrerelease)
{
response = v2ServerAPICall.FindAllWithPrerelease(repository, out errRecord);
}
else {
response = v2ServerAPICall.FindAllWithNoPrerelease(repository, out errRecord);
}
var response = v2ServerAPICall.FindAll(repository, includePrerelease, type, out errRecord);

PSResourceInfo currentPkg = null;
if (!string.IsNullOrEmpty(errRecord))
{
return currentPkg;
}

/*
// Convert to PSResourceInfo object
*/
return currentPkg;
}

Expand Down Expand Up @@ -177,68 +169,6 @@ public PSCommandResourceInfo[] FindCommandOrDscResource(string[] tags, PSReposit
return cmdInfoObjs.ToArray();
}


/// <summary>
/// Find method which allows for searching for packages with resource type specified from a repository and returns latest version for each.
/// Name: supports wildcards
/// Type: Module, Script, Command, DSCResource (can take multiple)
/// Examples: Search -Type Module -Repository PSGallery
/// Search -Type Module -Name "Az*" -Repository PSGallery
/// TODO: discuss consolidating Modules and Scripts endpoints (move scripts to modules endpoint)
/// TODO Note: searchTerm is tokenized by whitespace.
/// - No prerelease: http://www.powershellgallery.com/api/v2/Search()?$filter=IsLatestVersion&searchTerm='Az* tag:PSModule'
/// - Include prerelease: http://www.powershellgallery.com/api/v2/Search()?$filter=IsLatestVersion&searchTerm='az* tag:PSScript'&includePrerelease=true
/// </summary>
public PSResourceInfo FindTypes(ResourceType packageResourceType, string packageName, PSRepositoryInfo repository, bool includePrerelease, out string errRecord)
{
var response = string.Empty;
if (includePrerelease)
{
response = v2ServerAPICall.FindTypesWithPrerelease(packageResourceType, packageName, repository, out errRecord);
}
else {
response = v2ServerAPICall.FindTypesWithPrerelease(packageResourceType, packageName, repository, out errRecord);
}

PSResourceInfo currentPkg = null;
if (!string.IsNullOrEmpty(errRecord))
{
return currentPkg;
}

// Convert to PSResourceInfo object
return currentPkg;

}

/// <summary>
/// Find method which allows for searching for command names AND/OR DSC resource names and returns latest version of matching packages.
/// Name: supports wildcards.
/// Examples: Search -Name "Command1", "Command2" -Repository PSGallery
/// - No prerelease: http://www.powershellgallery.com/api/v2/Search()?$filter=IsLatestVersion&searchTerm='Az* tag:PSCommand_Command1 tag:PSCommand_Command2'
/// - Include prerelease: http://www.powershellgallery.com/api/v2/Search()?$filter=IsLatestVersion&searchTerm='Az* tag:PSCommand_Command1 tag:PSCommand_Command2'&includePrerelease=true
/// </summary>
public PSResourceInfo FindCommandName(string[] commandNames, PSRepositoryInfo repository, bool includePrerelease, out string errRecord)
{
var response = string.Empty;
if (includePrerelease)
{
response = v2ServerAPICall.FindCommandNameWithPrerelease(commandNames, repository, out errRecord);
}
else {
response = v2ServerAPICall.FindCommandNameWithNoPrerelease(commandNames, repository, out errRecord);
}

PSResourceInfo currentPkg = null;
if (!string.IsNullOrEmpty(errRecord))
{
return currentPkg;
}

// Convert to PSResourceInfo object
return currentPkg;
}

/// <summary>
/// Find method which allows for searching for single name and returns latest version.
/// Name: no wildcard support
Expand Down Expand Up @@ -421,40 +351,10 @@ public PSResourceInfo FindVersion(string packageName, string version, PSReposito
return null;
}

/// <summary>
/// *** we will not support this scenario ***
/// Find method which allows for searching for single name with wildcards with version range.
/// Name: supports wildcards
/// Version: support wildcards
/// Examples: Search "PowerShell*" "[3.0.0.0, 5.0.0.0]"
/// Search "PowerShell*" "3.*"
/// </summary>
//PSResourceInfo FindNameGlobbingAndVersionGlobbing(string packageName, VersionRange versionRange, PSRepositoryInfo repository, bool includePrerelease, out string errRecord);

/// <summary>
/// *** we will not support this scenario ***
/// Find method which allows for searching for single name with wildcards with specific version.
/// Name: supports wildcards
/// Version: no wildcard support
/// Examples: Search "PowerShell*" "3.0.0.0"
/// </summary>
//PSResourceInfo FindNameGlobbingAndVersion(string packageName, NuGetVersion version, PSRepositoryInfo repository, out string errRecord);


/// <summary>
/// *** we will not support this scenario ***
/// Find method which allows for searching for multiple names with specific version.
/// Name: supports wildcards
/// Version: no wildcard support
/// Examples: Search "PowerShellGet", "Package*", "PSReadLine" "3.0.0.0"
/// </summary>
//PSResourceInfo FindNamesGlobbingAndVersion(string[] packageNames, NuGetVersion version, PSRepositoryInfo repository)

#endregion

#region HelperMethods

// TODO: in progress
public XmlNode[] ConvertResponseToXML(string httpResponse) {

//Create the XmlDocument.
Expand Down
71 changes: 1 addition & 70 deletions src/code/IFindPSResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface IFindPSResource
/// - No prerelease: http://www.powershellgallery.com/api/v2/Search()?$filter=IsLatestVersion
/// - Include prerelease: http://www.powershellgallery.com/api/v2/Search()?$filter=IsAbsoluteLatestVersion&includePrerelease=true
/// </summary>
PSResourceInfo FindAll(PSRepositoryInfo repository, bool includePrerelease, out string errRecord);
PSResourceInfo FindAll(PSRepositoryInfo repository, bool includePrerelease, ResourceType type, out string errRecord);

/// <summary>
/// Find method which allows for searching for packages with tag(s) from a repository and returns latest version for each.
Expand All @@ -24,28 +24,6 @@ public interface IFindPSResource
/// </summary>
PSResourceInfo[] FindTags(string[] tags, PSRepositoryInfo repository, bool includePrerelease, ResourceType type, out HashSet<string> tagsFound, out string errRecord);

/// <summary>
/// Find method which allows for searching for packages with resource type specified from a repository and returns latest version for each.
/// Name: supports wildcards
/// Type: Module, Script, Command, DSCResource (can take multiple)
/// Examples: Search -Type Module -Repository PSGallery
/// Search -Type Module -Name "Az*" -Repository PSGallery
/// TODO: discuss consolidating Modules and Scripts endpoints (move scripts to modules endpoint)
/// TODO Note: searchTerm is tokenized by whitespace.
/// - No prerelease: http://www.powershellgallery.com/api/v2/Search()?$filter=IsLatestVersion&searchTerm='Az* tag:PSModule'
/// - Include prerelease: http://www.powershellgallery.com/api/v2/Search()?$filter=IsLatestVersion&searchTerm='az* tag:PSScript'&includePrerelease=true
/// </summary>
PSResourceInfo FindTypes(ResourceType packageResourceType, string packageName, PSRepositoryInfo repository, bool includePrerelease, out string errRecord);

/// <summary>
/// Find method which allows for searching for command names and returns latest version of matching packages.
/// Name: supports wildcards.
/// Examples: Search -Name "Command1", "Command2" -Repository PSGallery
/// - No prerelease: http://www.powershellgallery.com/api/v2/Search()?$filter=IsLatestVersion&searchTerm='Az* tag:PSCommand_Command1 tag:PSCommand_Command2'
/// - Include prerelease: http://www.powershellgallery.com/api/v2/Search()?$filter=IsLatestVersion&searchTerm='Az* tag:PSCommand_Command1 tag:PSCommand_Command2'&includePrerelease=true
/// </summary>
PSResourceInfo FindCommandName(string[] commandNames, PSRepositoryInfo repository, bool includePrerelease, out string errRecord);

/// <summary>
/// Find method which allows for searching for single name and returns latest version.
/// Name: no wildcard support
Expand Down Expand Up @@ -88,52 +66,5 @@ public interface IFindPSResource
/// </summary>
PSResourceInfo FindVersion(string packageName, string version, PSRepositoryInfo repository, ResourceType type, out string errRecord);

/// <summary>
/// *** we will not support this scenario ***
/// Find method which allows for searching for single name with wildcards with version range.
/// Name: supports wildcards
/// Version: support wildcards
/// Examples: Search "PowerShell*" "[3.0.0.0, 5.0.0.0]"
/// Search "PowerShell*" "3.*"
/// </summary>
//PSResourceInfo FindNameGlobbingAndVersionGlobbing(string packageName, VersionRange versionRange, PSRepositoryInfo repository, bool includePrerelease, out string errRecord);

/// <summary>
/// *** we will not support this scenario ***
/// Find method which allows for searching for single name with wildcards with specific version.
/// Name: supports wildcards
/// Version: no wildcard support
/// Examples: Search "PowerShell*" "3.0.0.0"
/// </summary>
//PSResourceInfo FindNameGlobbingAndVersion(string packageName, NuGetVersion version, PSRepositoryInfo repository, out string errRecord);

/// <summary>
/// *** Note: we would just iterate through the names client side and call FindName() or FindNameGlobbing() ***
/// Find method which allows for searching for multiple names and returns latest version for each.
/// Name: supports wildcards
/// Examples: Search "PowerShellGet", "Package*", "PSReadLine"
/// </summary>
// PSResourceInfo FindNamesGlobbing(string[] packageNames, PSRepositoryInfo repository, bool includePrerelease, out string[] errRecords);

/// <summary>
/// *** we will not support this scenario ***
/// Find method which allows for searching for multiple names with specific version.
/// Name: supports wildcards
/// Version: no wildcard support
/// Examples: Search "PowerShellGet", "Package*", "PSReadLine" "3.0.0.0"
/// </summary>
//PSResourceInfo FindNamesGlobbingAndVersion(string[] packageNames, NuGetVersion version, PSRepositoryInfo repository, out string errRecord);

/// <summary>
/// *** Note: would just iterate through names client side, and call FindVersionGlobbing() for each and discard (error) for name with globbing) ***
/// Find method which allows for searching for multiple names with version range.
/// Name: supports wildcards
/// Version: support wildcards
/// Examples: Search "PowerShellGet", "Package*", "PSReadLine" "[3.0.0.0, 5.0.0.0]" --> do it for first, write error for second, do it for third
/// Search "PowerShellGet", "Package*", "PSReadLine" "3.*" --> do it for first, write error for second, do it for third
/// Search "Package*", "PSReadLin*" "3.*" --> not supported
/// </summary>
// PSResourceInfo FindNamesAndVersionGlobbing(string[] packageNames, VersionRange versionRange, PSRepositoryInfo repository, bool includePrerelease, ResourceType type, out string[] errRecord);

#endregion
}
90 changes: 1 addition & 89 deletions src/code/IServerAPICalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,13 @@
public interface IServerAPICalls
{
#region Methods
// Find-PSResource >>> IFindPSResource (loops, version) >>> IServerAPICalls (http://www.powershellgallery.com/api/v2/Search()?$filter=IsLatestVersion)

/// <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 FindAllWithNoPrerelease(PSRepositoryInfo repository, out string errRecord);

/// <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 FindAllWithPrerelease(PSRepositoryInfo repository, out string errRecord);

string FindAll(PSRepositoryInfo repository, bool includePrerelease, ResourceType type, out string errRecord);

/// <summary>
/// Find method which allows for searching for packages with tag from a repository and returns latest version for each.
Expand All @@ -33,37 +22,7 @@ public interface IServerAPICalls
/// - Include prerelease: http://www.powershellgallery.com/api/v2/Search()?$filter=IsAbsoluteLatestVersion&searchTerm='tag:JSON'&includePrerelease=true
/// </summary>
string[] FindTag(string tag, PSRepositoryInfo repository, bool includePrerelease, ResourceType _type, out string errRecord);


/// <summary>
/// Find method which allows for searching for packages with resource type specified from a repository and returns latest version for each.
/// Name: supports wildcards
/// Type: Module, Script, Command, DSCResource (can take multiple)
/// Examples: Search -Type Module -Repository PSGallery
/// Search -Type Module -Name "Az*" -Repository PSGallery
/// TODO: discuss consolidating Modules and Scripts endpoints (move scripts to modules endpoint)
/// TODO Note: searchTerm is tokenized by whitespace.
/// - Include prerelease: http://www.powershellgallery.com/api/v2/Search()?$filter=IsLatestVersion&searchTerm='az* tag:PSScript'&includePrerelease=true
/// </summary>
string FindTypesWithPrerelease(ResourceType packageResourceType, string packageName, PSRepositoryInfo repository, out string errRecord);


/// <summary>
/// Find method which allows for searching for command names and returns latest version of matching packages.
/// Name: supports wildcards.
/// Examples: Search -Name "Command1", "Command2" -Repository PSGallery
/// - No prerelease: http://www.powershellgallery.com/api/v2/Search()?$filter=IsLatestVersion&searchTerm='Az* tag:PSCommand_Command1 tag:PSCommand_Command2'
/// </summary>
string FindCommandNameWithNoPrerelease(string[] commandNames, PSRepositoryInfo repository, out string errRecord);

/// <summary>
/// Find method which allows for searching for command names and returns latest version of matching packages.
/// Name: supports wildcards.
/// Examples: Search -Name "Command1", "Command2" -Repository PSGallery
/// - Include prerelease: http://www.powershellgallery.com/api/v2/Search()?$filter=IsLatestVersion&searchTerm='Az* tag:PSCommand_Command1 tag:PSCommand_Command2'&includePrerelease=true
/// </summary>
string FindCommandNameWithPrerelease(string[] commandNames, PSRepositoryInfo repository, out string errRecord);

/// <summary>
/// Find method which allows for searching for single name and returns latest version.
/// Name: no wildcard support
Expand Down Expand Up @@ -96,53 +55,6 @@ public interface IServerAPICalls
/// </summary>
string FindVersionGlobbing(string packageName, VersionRange versionRange, PSRepositoryInfo repository, bool includePrerelease, ResourceType type, out string errRecord);

/// <summary>
/// *** we will not support this scenario ***
/// Find method which allows for searching for single name with wildcards with version range.
/// Name: supports wildcards
/// Version: support wildcards
/// Examples: Search "PowerShell*" "[3.0.0.0, 5.0.0.0]"
/// Search "PowerShell*" "3.*"
/// </summary>
/// PSResourceInfo FindNameGlobbingAndVersionGlobbing(string packageName, VersionRange versionRange, PSRepositoryInfo repository, bool includePrerelease);

/// <summary>
/// *** we will not support this scenario ***
/// Find method which allows for searching for single name with wildcards with specific version.
/// Name: supports wildcards
/// Version: no wildcard support
/// Examples: Search "PowerShell*" "3.0.0.0"
/// </summary>
/// PSResourceInfo FindNameGlobbingAndVersion(string packageName, NuGetVersion version, PSRepositoryInfo repository);

/// <summary>
/// *** Note: we would just iterate through the names client side and call FindName() or FindNameGlobbing() ***
/// Find method which allows for searching for multiple names and returns latest version for each.
/// Name: supports wildcards
/// Examples: Search "PowerShellGet", "Package*", "PSReadLine"
/// </summary>
/// PSResourceInfo FindNamesGlobbing(string[] packageNames, PSRepositoryInfo repository, bool includePrerelease);

/// <summary>
/// *** we will not support this scenario ***
/// Find method which allows for searching for multiple names with specific version.
/// Name: supports wildcards
/// Version: no wildcard support
/// Examples: Search "PowerShellGet", "Package*", "PSReadLine" "3.0.0.0"
/// </summary>
/// PSResourceInfo FindNamesGlobbingAndVersion(string[] packageNames, NuGetVersion version, PSRepositoryInfo repository);

/// <summary>
/// *** Note: would just iterate through names client side, and call FindVersionGlobbing() for each and discard (error) for name with globbing) ***
/// Find method which allows for searching for multiple names with version range.
/// Name: supports wildcards
/// Version: support wildcards
/// Examples: Search "PowerShellGet", "Package*", "PSReadLine" "[3.0.0.0, 5.0.0.0]" --> do it for first, write error for second, do it for third
/// Search "PowerShellGet", "Package*", "PSReadLine" "3.*" --> do it for first, write error for second, do it for third
/// Search "Package*", "PSReadLin*" "3.*" --> not supported
/// </summary>
/// PSResourceInfo FindNamesAndVersionGlobbing(string[] packageNames, VersionRange versionRange, PSRepositoryInfo repository, bool includePrerelease);

// <summary>
/// Find method which allows for searching for single name with specific version.
/// Name: no wildcard support
Expand Down
Loading