Skip to content
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

Idea for ability to optionally override default modules and scripts install path - Duscussion and contribution is welcome! #1673

Draft
wants to merge 63 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
ce4d559
Return path override if present
o-l-a-v Jul 13, 2024
166bf07
Make more robust
o-l-a-v Jul 13, 2024
37417de
Get empty/non-existent env variable is not expected to throw
o-l-a-v Jul 13, 2024
de08199
More robust
o-l-a-v Jul 13, 2024
acecb75
Expand, not resolve
o-l-a-v Jul 13, 2024
2713e4f
Add verbose message
o-l-a-v Jul 13, 2024
3556f80
Don't get paths twice
o-l-a-v Jul 13, 2024
f3abadd
Add newline before comments
o-l-a-v Jul 13, 2024
49db4bb
Remove empty newline
o-l-a-v Jul 14, 2024
802184e
Added new cmdlet
o-l-a-v Jul 14, 2024
a6352fe
"using System;" was written twice
o-l-a-v Jul 14, 2024
386bcf3
Only for Windows because env variables is very different on Unix + Ma…
o-l-a-v Jul 14, 2024
6ada4c6
Sort using alphabetically
o-l-a-v Jul 14, 2024
30bdf6a
Made code easier to navigate in VSCode
o-l-a-v Jul 14, 2024
3583604
Added ability to set the override env variable
o-l-a-v Jul 14, 2024
69863bb
Finished barebone functionality
o-l-a-v Jul 14, 2024
2d1ed6f
Simplified expression, thanks C# extension
o-l-a-v Jul 14, 2024
f451010
Treat -Path more like in Save-PSResource
o-l-a-v Jul 14, 2024
90ccdc9
Looks better this way IMO
o-l-a-v Jul 14, 2024
16339a1
Comment update
o-l-a-v Jul 14, 2024
398b2a6
Don't think ExpandEnvironmentVariables throws if some %VAR% does not …
o-l-a-v Jul 14, 2024
ec79901
Added -WhatIf support
o-l-a-v Jul 14, 2024
c80a398
Remove unneccessary "using"
o-l-a-v Jul 14, 2024
ba7b5f4
Fixed adding scripts dir to PATH
o-l-a-v Jul 14, 2024
ce7d0f7
PATH is named Path
o-l-a-v Jul 14, 2024
69c88ad
Big oops, set Path not PSModulePath for scripts dir
o-l-a-v Jul 14, 2024
8026053
Fixed verbose message
o-l-a-v Jul 14, 2024
853fb56
Simplify some more
o-l-a-v Jul 14, 2024
e5d145d
Return path override if present
o-l-a-v Jul 13, 2024
fb1d306
Make more robust
o-l-a-v Jul 13, 2024
7289dee
Get empty/non-existent env variable is not expected to throw
o-l-a-v Jul 13, 2024
76d75e2
More robust
o-l-a-v Jul 13, 2024
288edec
Expand, not resolve
o-l-a-v Jul 13, 2024
89f3dfc
Add verbose message
o-l-a-v Jul 13, 2024
9b4b60f
Don't get paths twice
o-l-a-v Jul 13, 2024
9e8617c
Add newline before comments
o-l-a-v Jul 13, 2024
02b79b7
Remove empty newline
o-l-a-v Jul 14, 2024
82e501c
Added new cmdlet
o-l-a-v Jul 14, 2024
4b02c09
"using System;" was written twice
o-l-a-v Jul 14, 2024
a86eae5
Only for Windows because env variables is very different on Unix + Ma…
o-l-a-v Jul 14, 2024
abb819e
Sort using alphabetically
o-l-a-v Jul 14, 2024
8ad86c5
Made code easier to navigate in VSCode
o-l-a-v Jul 14, 2024
92a72cf
Added ability to set the override env variable
o-l-a-v Jul 14, 2024
d067987
Finished barebone functionality
o-l-a-v Jul 14, 2024
8f2cc35
Simplified expression, thanks C# extension
o-l-a-v Jul 14, 2024
f278bb8
Treat -Path more like in Save-PSResource
o-l-a-v Jul 14, 2024
eabf85d
Looks better this way IMO
o-l-a-v Jul 14, 2024
8b1bdce
Comment update
o-l-a-v Jul 14, 2024
fc20175
Don't think ExpandEnvironmentVariables throws if some %VAR% does not …
o-l-a-v Jul 14, 2024
854e599
Added -WhatIf support
o-l-a-v Jul 14, 2024
2682b98
Remove unneccessary "using"
o-l-a-v Jul 14, 2024
e2e8d0b
Fixed adding scripts dir to PATH
o-l-a-v Jul 14, 2024
d51bdef
PATH is named Path
o-l-a-v Jul 14, 2024
3e243a4
Big oops, set Path not PSModulePath for scripts dir
o-l-a-v Jul 14, 2024
1b2bf32
Fixed verbose message
o-l-a-v Jul 14, 2024
be6d635
Simplify some more
o-l-a-v Jul 14, 2024
b0d7261
Merge branch 'install-path-override' of https://github.com/o-l-a-v/Po…
o-l-a-v Aug 21, 2024
c0f6dba
Merge branch 'master' into install-path-override
o-l-a-v Aug 21, 2024
9b84e89
Remove unneccessary using
o-l-a-v Aug 21, 2024
2f371a2
Merge branch 'master' into install-path-override
o-l-a-v Oct 23, 2024
71db23c
Format on save
o-l-a-v Oct 23, 2024
7cd3a1b
Removed unused "using"
o-l-a-v Oct 23, 2024
3b9ed21
Remove unused using and run formatting
o-l-a-v Oct 23, 2024
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
12 changes: 6 additions & 6 deletions src/Microsoft.PowerShell.PSResourceGet.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
FunctionsToExport = @(
'Import-PSGetRepository'
)
VariablesToExport = 'PSGetPath'
AliasesToExport = @(
VariablesToExport = 'PSGetPath'
AliasesToExport = @(
'Get-PSResource',
'fdres',
'isres',
'pbres',
'udres')
PrivateData = @{
PrivateData = @{
PSData = @{
Prerelease = 'RC1'
Tags = @('PackageManagement',
Expand All @@ -66,7 +66,7 @@

- Fix packaging name matching when searching in local repositories (#1731)
- `Compress-PSResource` `-PassThru` now passes `FileInfo` instead of string (#1720)
- Fix for `Compress-PSResource` not properly compressing scripts (#1719)
- Fix for `Compress-PSResource` not properly compressing scripts (#1719)
- Add `AcceptLicense` to Save-PSResource (#1718 Thanks @o-l-a-v!)
- Better support for NuGet v2 feeds (#1713 Thanks @o-l-a-v!)
- Better handling of `-WhatIf` support in `Install-PSResource` (#1531 Thanks @o-l-a-v!)
Expand All @@ -92,7 +92,7 @@

### New Features

- Support for Azure Container Registries (#1495, #1497-#1499, #1501, #1502, #1505, #1522, #1545, #1548, #1550, #1554, #1560, #1567,
- Support for Azure Container Registries (#1495, #1497-#1499, #1501, #1502, #1505, #1522, #1545, #1548, #1550, #1554, #1560, #1567,
#1573, #1576, #1587, #1588, #1589, #1594, #1598, #1600, #1602, #1604, #1615)

### Bug Fixes
Expand Down Expand Up @@ -173,7 +173,7 @@
- Bug fix Artifactory v2 endpoint failures (#1428)
- Bug fix Artifactory v3 endpoint failures (#1427)
- Bug fix `-RequiredResource` silent failures (#1426)
- Bug fix for v2 repository returning extra packages for `-Tag` based search with `-Prerelease` (#1405)
- Bug fix for v2 repository returning extra packages for `-Tag` based search with `-Prerelease` (#1405)

See change log (CHANGELOG) at https://github.com/PowerShell/PSResourceGet
'@
Expand Down
5 changes: 2 additions & 3 deletions src/code/GetInstalledPSResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ protected override void BeginProcessing()
{
ThrowTerminatingError(new ErrorRecord(
new PSArgumentException($"Error: Could not resolve provided Path argument '{Path}' into a single path."),

"ErrorInvalidPathArgument",
ErrorCategory.InvalidArgument,
this));
Expand Down Expand Up @@ -119,7 +118,7 @@ protected override void BeginProcessing()

protected override void ProcessRecord()
{
var namesToSearch = Utils.ProcessNameWildcards(Name, removeWildcardEntries:false, 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 Expand Up @@ -153,7 +152,7 @@ protected override void ProcessRecord()
List<string> pkgsNotFound = new List<string>();
foreach (string name in namesToSearch)
{
if (!pkgsFound.Contains(name, StringComparer.OrdinalIgnoreCase))
if (!pkgsFound.Contains(name, StringComparer.OrdinalIgnoreCase))
{
if (name.Contains('*'))
{
Expand Down
45 changes: 24 additions & 21 deletions src/code/InstallPSResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ namespace Microsoft.PowerShell.PSResourceGet.Cmdlets
/// The Install-PSResource cmdlet installs a resource.
/// It returns nothing.
/// </summary>
[Cmdlet(VerbsLifecycle.Install,
"PSResource",
DefaultParameterSetName = "NameParameterSet",
[Cmdlet(VerbsLifecycle.Install,
"PSResource",
DefaultParameterSetName = "NameParameterSet",
SupportsShouldProcess = true)]
[Alias("isres")]
public sealed
class InstallPSResource : PSCmdlet
{
#region Parameters
#region Parameters

/// <summary>
/// Specifies the exact names of resources to install from a repository.
Expand All @@ -42,7 +42,7 @@ class InstallPSResource : PSCmdlet
[Parameter(ParameterSetName = NameParameterSet, ValueFromPipelineByPropertyName = true)]
[ValidateNotNullOrEmpty]
public string Version { get; set; }

/// <summary>
/// Specifies to allow installation of prerelease versions
/// </summary>
Expand Down Expand Up @@ -83,9 +83,9 @@ public string TemporaryPath

set
{
if (WildcardPattern.ContainsWildcardCharacters(value))
{
throw new PSArgumentException("Wildcard characters are not allowed in the temporary path.");
if (WildcardPattern.ContainsWildcardCharacters(value))
{
throw new PSArgumentException("Wildcard characters are not allowed in the temporary path.");
}

// This will throw if path cannot be resolved
Expand All @@ -99,7 +99,7 @@ public string TemporaryPath
/// </summary>
[Parameter]
public SwitchParameter TrustRepository { get; set; }

/// <summary>
/// Overwrites a previously installed resource with the same name and version.
/// </summary>
Expand Down Expand Up @@ -130,7 +130,7 @@ public string TemporaryPath
/// </summary>
[Parameter]
public SwitchParameter SkipDependencyCheck { get; set; }

/// <summary>
/// Check validation for signed and catalog files
/// </summary>
Expand Down Expand Up @@ -256,7 +256,7 @@ private enum ResourceFileType

#endregion

#region Method Overrides
#region Method override - Begin

protected override void BeginProcessing()
{
Expand All @@ -265,7 +265,7 @@ protected override void BeginProcessing()
RepositorySettings.CheckRepositoryStore();

_pathsToInstallPkg = Utils.GetAllInstallationPaths(this, Scope);
List<string> pathsToSearch = Utils.GetAllResourcePaths(this, Scope);
List<string> pathsToSearch = _pathsToInstallPkg;
// Only need to find packages installed if -Reinstall is not passed in
_packagesOnMachine = Reinstall ? new HashSet<string>(StringComparer.CurrentCultureIgnoreCase) : Utils.GetInstalledPackages(pathsToSearch, this);

Expand All @@ -274,6 +274,9 @@ protected override void BeginProcessing()
_installHelper = new InstallHelper(cmdletPassedIn: this, networkCredential: networkCred);
}

#endregion

#region Method Override - Process
protected override void ProcessRecord()
{
switch (ParameterSetName)
Expand All @@ -287,7 +290,7 @@ protected override void ProcessRecord()
pkgCredential: Credential,
reqResourceParams: null);
break;

case InputObjectParameterSet:
foreach (var inputObj in InputObject) {
string normalizedVersionString = Utils.GetNormalizedVersionString(inputObj.Version.ToString(), inputObj.Prerelease);
Expand Down Expand Up @@ -357,12 +360,12 @@ protected override void ProcessRecord()
catch (Exception)
{
ThrowTerminatingError(new ErrorRecord(
new ArgumentException($"Argument for parameter -RequiredResourceFile is not in proper json or hashtable format. Make sure argument is either a valid .json or .psd1 file."),
new ArgumentException($"Argument for parameter -RequiredResourceFile is not in proper json or hashtable format. Make sure argument is either a valid .json or .psd1 file."),
"RequiredResourceFileNotInProperJsonFormat",
ErrorCategory.InvalidData,
this));
}

RequiredResourceHelper(pkgsInFile);
break;

Expand All @@ -379,7 +382,7 @@ protected override void ProcessRecord()
}
}
*/

Hashtable pkgsHash = null;
try
{
Expand Down Expand Up @@ -441,7 +444,7 @@ private void RequiredResourceHelper(Hashtable reqResourceHash)
{
var pkgNameEmptyOrWhitespaceError = new ErrorRecord(
new ArgumentException($"The package name '{pkgName}' provided cannot be an empty string or whitespace."),
"pkgNameEmptyOrWhitespaceError",
"pkgNameEmptyOrWhitespaceError",
ErrorCategory.InvalidArgument,
this);

Expand All @@ -454,7 +457,7 @@ private void RequiredResourceHelper(Hashtable reqResourceHash)
{
var requiredResourceHashtableInputFormatError = new ErrorRecord(
new ArgumentException($"The RequiredResource input with name '{pkgName}' does not have a valid value, the value must be a hashtable."),
"RequiredResourceHashtableInputFormatError",
"RequiredResourceHashtableInputFormatError",
ErrorCategory.InvalidArgument,
this);

Expand Down Expand Up @@ -483,7 +486,7 @@ private void RequiredResourceHelper(Hashtable reqResourceHash)
ThrowTerminatingError(ParameterParsingError);
}
}

if (pkgParams.Scope == ScopeType.AllUsers)
{
_pathsToInstallPkg = Utils.GetAllInstallationPaths(this, pkgParams.Scope);
Expand Down Expand Up @@ -513,10 +516,10 @@ private void ProcessInstallHelper(string[] pkgNames, string pkgVersion, bool pkg
"NameContainsWildcard",
ErrorCategory.InvalidArgument,
this));

return;
}

foreach (string error in errorMsgs)
{
WriteError(new ErrorRecord(
Expand Down
14 changes: 8 additions & 6 deletions src/code/ServerApiCall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
// Licensed under the MIT License.

using Microsoft.PowerShell.PSResourceGet.UtilClasses;
using NuGet.Versioning;
using System;
using System.IO;
using System.Net.Http;
using NuGet.Versioning;
using System.Management.Automation;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Runtime.ExceptionServices;
using System.Management.Automation;


namespace Microsoft.PowerShell.PSResourceGet.Cmdlets
{
Expand All @@ -31,7 +31,7 @@ public ServerApiCall(PSRepositoryInfo repository, NetworkCredential networkCrede
HttpClientHandler handler = new HttpClientHandler();
bool token = false;

if(networkCredential != null)
if (networkCredential != null)
{
token = String.Equals("token", networkCredential.UserName) ? true : false;
};
Expand All @@ -43,7 +43,9 @@ public ServerApiCall(PSRepositoryInfo repository, NetworkCredential networkCrede

_sessionClient = new HttpClient(handler);
_sessionClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
} else {
}
else
{

handler.Credentials = networkCredential;

Expand Down
Loading