|
9 | 9 | using System.Management.Automation; |
10 | 10 | using System.Xml; |
11 | 11 | using System.Xml.Linq; |
| 12 | +using Microsoft.PowerShell.PSResourceGet.Cmdlets; |
12 | 13 | using static Microsoft.PowerShell.PSResourceGet.UtilClasses.PSRepositoryInfo; |
13 | 14 |
|
14 | 15 | namespace Microsoft.PowerShell.PSResourceGet.UtilClasses |
@@ -279,7 +280,9 @@ public static PSRepositoryInfo Add(string repoName, Uri repoUri, int repoPriorit |
279 | 280 | throw new PSInvalidOperationException(String.Format("Adding to repository store failed: {0}", e.Message)); |
280 | 281 | } |
281 | 282 |
|
282 | | - return new PSRepositoryInfo(repoName, repoUri, repoPriority, repoTrusted, repoCredentialInfo, apiVersion); |
| 283 | + bool isAllowed = GroupPolicyRepositoryEnforcement.IsGroupPolicyEnabled() ? GroupPolicyRepositoryEnforcement.IsRepositoryAllowed(repoUri) : true; |
| 284 | + |
| 285 | + return new PSRepositoryInfo(repoName, repoUri, repoPriority, repoTrusted, repoCredentialInfo, apiVersion, isAllowed); |
283 | 286 | } |
284 | 287 |
|
285 | 288 | /// <summary> |
@@ -436,13 +439,22 @@ public static PSRepositoryInfo Update(string repoName, Uri repoUri, int repoPrio |
436 | 439 | node.Attribute(PSCredentialInfo.SecretNameAttribute).Value); |
437 | 440 | } |
438 | 441 |
|
| 442 | + if (GroupPolicyRepositoryEnforcement.IsGroupPolicyEnabled()) |
| 443 | + { |
| 444 | + var allowedList = GroupPolicyRepositoryEnforcement.GetAllowedRepositoryURIs(); |
| 445 | + |
| 446 | + } |
| 447 | + |
| 448 | + bool isAllowed = GroupPolicyRepositoryEnforcement.IsGroupPolicyEnabled() ? GroupPolicyRepositoryEnforcement.IsRepositoryAllowed(thisUrl) : true; |
| 449 | + |
439 | 450 | RepositoryProviderType repositoryProvider= GetRepositoryProviderType(thisUrl); |
440 | 451 | updatedRepo = new PSRepositoryInfo(repoName, |
441 | 452 | thisUrl, |
442 | 453 | Int32.Parse(node.Attribute("Priority").Value), |
443 | 454 | Boolean.Parse(node.Attribute("Trusted").Value), |
444 | 455 | thisCredentialInfo, |
445 | | - resolvedAPIVersion); |
| 456 | + resolvedAPIVersion, |
| 457 | + isAllowed); |
446 | 458 |
|
447 | 459 | // Close the file |
448 | 460 | root.Save(FullRepositoryPath); |
@@ -522,14 +534,18 @@ public static List<PSRepositoryInfo> Remove(string[] repoNames, out string[] err |
522 | 534 |
|
523 | 535 | string attributeUrlUriName = urlAttributeExists ? "Url" : "Uri"; |
524 | 536 | Uri repoUri = new Uri(node.Attribute(attributeUrlUriName).Value); |
| 537 | + |
| 538 | + bool isAllowed = GroupPolicyRepositoryEnforcement.IsGroupPolicyEnabled() ? GroupPolicyRepositoryEnforcement.IsRepositoryAllowed(repoUri) : true; |
| 539 | + |
525 | 540 | RepositoryProviderType repositoryProvider= GetRepositoryProviderType(repoUri); |
526 | 541 | removedRepos.Add( |
527 | 542 | new PSRepositoryInfo(repo, |
528 | 543 | new Uri(node.Attribute(attributeUrlUriName).Value), |
529 | 544 | Int32.Parse(node.Attribute("Priority").Value), |
530 | 545 | Boolean.Parse(node.Attribute("Trusted").Value), |
531 | 546 | repoCredentialInfo, |
532 | | - (PSRepositoryInfo.APIVersion)Enum.Parse(typeof(PSRepositoryInfo.APIVersion), node.Attribute("APIVersion").Value, ignoreCase: true))); |
| 547 | + (PSRepositoryInfo.APIVersion)Enum.Parse(typeof(PSRepositoryInfo.APIVersion), node.Attribute("APIVersion").Value, ignoreCase: true), |
| 548 | + isAllowed)); |
533 | 549 |
|
534 | 550 | // Remove item from file |
535 | 551 | node.Remove(); |
@@ -654,12 +670,16 @@ public static List<PSRepositoryInfo> Read(string[] repoNames, out string[] error |
654 | 670 | } |
655 | 671 |
|
656 | 672 | RepositoryProviderType repositoryProvider= GetRepositoryProviderType(thisUrl); |
| 673 | + |
| 674 | + bool isAllowed = GroupPolicyRepositoryEnforcement.IsGroupPolicyEnabled() ? GroupPolicyRepositoryEnforcement.IsRepositoryAllowed(thisUrl) : true; |
| 675 | + |
657 | 676 | PSRepositoryInfo currentRepoItem = new PSRepositoryInfo(repo.Attribute("Name").Value, |
658 | 677 | thisUrl, |
659 | 678 | Int32.Parse(repo.Attribute("Priority").Value), |
660 | 679 | Boolean.Parse(repo.Attribute("Trusted").Value), |
661 | 680 | thisCredentialInfo, |
662 | | - (PSRepositoryInfo.APIVersion)Enum.Parse(typeof(PSRepositoryInfo.APIVersion), repo.Attribute("APIVersion").Value, ignoreCase: true)); |
| 681 | + (PSRepositoryInfo.APIVersion)Enum.Parse(typeof(PSRepositoryInfo.APIVersion), repo.Attribute("APIVersion").Value, ignoreCase: true), |
| 682 | + isAllowed); |
663 | 683 |
|
664 | 684 | foundRepos.Add(currentRepoItem); |
665 | 685 | } |
@@ -758,12 +778,16 @@ public static List<PSRepositoryInfo> Read(string[] repoNames, out string[] error |
758 | 778 | } |
759 | 779 |
|
760 | 780 | RepositoryProviderType repositoryProvider= GetRepositoryProviderType(thisUrl); |
| 781 | + |
| 782 | + bool isAllowed = GroupPolicyRepositoryEnforcement.IsGroupPolicyEnabled() ? GroupPolicyRepositoryEnforcement.IsRepositoryAllowed(thisUrl) : true; |
| 783 | + |
761 | 784 | PSRepositoryInfo currentRepoItem = new PSRepositoryInfo(node.Attribute("Name").Value, |
762 | 785 | thisUrl, |
763 | 786 | Int32.Parse(node.Attribute("Priority").Value), |
764 | 787 | Boolean.Parse(node.Attribute("Trusted").Value), |
765 | 788 | thisCredentialInfo, |
766 | | - (PSRepositoryInfo.APIVersion)Enum.Parse(typeof(PSRepositoryInfo.APIVersion), node.Attribute("APIVersion").Value, ignoreCase: true)); |
| 789 | + (PSRepositoryInfo.APIVersion)Enum.Parse(typeof(PSRepositoryInfo.APIVersion), node.Attribute("APIVersion").Value, ignoreCase: true), |
| 790 | + isAllowed); |
767 | 791 |
|
768 | 792 | foundRepos.Add(currentRepoItem); |
769 | 793 | } |
|
0 commit comments