-
Notifications
You must be signed in to change notification settings - Fork 100
Add support for credential persistence #480
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
anamnavi
merged 22 commits into
PowerShell:master
from
cansuerdogan:credential-persistence
Jan 14, 2022
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
c9c472f
add support for credential persistence by having a soft dependency on…
63f3477
fix tests by comparing URL.LocalPaths
adf7617
Add new line
alerickson f4a267d
Update test/SetPSResourceRepository.Tests.ps1
alerickson 1924def
Update .gitignore
alerickson f08ef0d
Update src/code/AuthenticationHelper.cs
alerickson d5474e4
Update src/code/RegisterPSResourceRepository.cs
alerickson 15d8f63
Update test/testRepositoriesWithAuthentication.xml
alerickson 4dada70
Merge branch 'master' of https://github.com/PowerShell/PowerShellGet …
f598313
rename Authentication parameter to CredentialInfo
f5a4cf0
replace type Hashtable with PSCredentialInfo for the CredentialInfo p…
ce16394
add save repository credential functionality and secret management er…
dcbbb5c
add PSRepositoryInfo to PSGet.Format.ps1xml to not display Credential…
5051876
Merge branch 'master' of https://github.com/PowerShell/PowerShellGet …
27d8a75
address outstanding merge conflicts
a955eff
change valid type to only PSCredential
1d28767
fix error id after parameter rename
c3d81dd
add tests for SecretManagement setup validation, fix error and warnin…
f7e7a1f
make style adjustments
37e402c
check for null values explicitly
343b820
check for errorid in tests
24e64c0
remove pester results file from gitignore, add new line
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
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
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
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
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,107 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Management.Automation; | ||
|
||
namespace Microsoft.PowerShell.PowerShellGet.UtilClasses | ||
{ | ||
/// <summary> | ||
/// This class contains information for a repository's authentication credential. | ||
/// </summary> | ||
public sealed class PSCredentialInfo | ||
{ | ||
#region Constructor | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the PSCredentialInfo class with | ||
/// vaultName and secretName of type string, and | ||
/// (optionally) credential of type PSCredential. | ||
/// </summary> | ||
/// <param name="vaultName"></param> | ||
/// <param name="secretName"></param> | ||
/// <param name="credential"></param> | ||
public PSCredentialInfo(string vaultName, string secretName, PSCredential credential = null) | ||
{ | ||
VaultName = vaultName; | ||
SecretName = secretName; | ||
Credential = credential; | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the PSCredentialInfo class with | ||
/// vaultName and secretName of type string, and | ||
/// (optionally) credential of type PSCredential from a PSObject. | ||
/// </summary> | ||
/// <param name="psObject"></param> | ||
public PSCredentialInfo(PSObject psObject) | ||
{ | ||
if (psObject == null) | ||
{ | ||
throw new ArgumentNullException(nameof(psObject)); | ||
} | ||
|
||
VaultName = (string) psObject.Properties[PSCredentialInfo.VaultNameAttribute]?.Value; | ||
SecretName = (string) psObject.Properties[PSCredentialInfo.SecretNameAttribute]?.Value; | ||
Credential = (PSCredential) psObject.Properties[PSCredentialInfo.CredentialAttribute]?.Value; | ||
} | ||
|
||
#endregion | ||
|
||
#region Members | ||
|
||
private string _vaultName; | ||
/// <summary> | ||
/// the Name of the SecretManagement Vault | ||
/// </summary> | ||
public string VaultName { | ||
get | ||
{ | ||
return _vaultName; | ||
} | ||
|
||
private set | ||
{ | ||
if (string.IsNullOrEmpty(value)) | ||
{ | ||
throw new ArgumentException($"Invalid CredentialInfo, {PSCredentialInfo.VaultNameAttribute} must be a non-empty string"); | ||
} | ||
|
||
_vaultName = value; | ||
} | ||
} | ||
|
||
private string _secretName; | ||
/// <summary> | ||
/// the Name of the Secret | ||
/// </summary> | ||
public string SecretName { | ||
get | ||
{ | ||
return _secretName; | ||
} | ||
|
||
private set | ||
PaulHigin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
if (string.IsNullOrEmpty(value)) | ||
{ | ||
throw new ArgumentException($"Invalid CredentialInfo, {PSCredentialInfo.SecretNameAttribute} must be a non-empty string"); | ||
} | ||
|
||
_secretName = value; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// optional Credential object to save in a SecretManagement Vault | ||
/// for authenticating to repositories | ||
/// </summary> | ||
public PSCredential Credential { get; private set; } | ||
|
||
internal static readonly string VaultNameAttribute = nameof(VaultName); | ||
internal static readonly string SecretNameAttribute = nameof(SecretName); | ||
internal static readonly string CredentialAttribute = nameof(Credential); | ||
|
||
#endregion | ||
} | ||
} |
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
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.