IProcessorEnvironment.cs (9827B)
1 // ----------------------------------------------------------------------------- 2 // <copyright file="IProcessorEnvironment.cs" company="Microsoft Corporation"> 3 // Copyright (c) Microsoft Corporation. Licensed under the MIT License. 4 // </copyright> 5 // ----------------------------------------------------------------------------- 6 7 namespace Microsoft.Management.Configuration.Processor.PowerShell.ProcessorEnvironments 8 { 9 using System.Collections.Generic; 10 using System.Management.Automation; 11 using Microsoft.Management.Configuration.Processor.Helpers; 12 using Microsoft.Management.Configuration.Processor.PowerShell.DscResourcesInfo; 13 using Microsoft.Management.Configuration.Processor.PowerShell.Helpers; 14 using Microsoft.PowerShell.Commands; 15 using Windows.Foundation.Collections; 16 using Windows.Security.Cryptography.Certificates; 17 18 /// <summary> 19 /// IProcessorEnvironment. Provides interaction with PowerShell. 20 /// </summary> 21 internal interface IProcessorEnvironment 22 { 23 /// <summary> 24 /// Gets the runspace. 25 /// </summary> 26 System.Management.Automation.Runspaces.Runspace Runspace { get; } 27 28 /// <summary> 29 /// Validates the runspace. 30 /// </summary> 31 void ValidateRunspace(); 32 33 /// <summary> 34 /// Gets all DSC resource. 35 /// </summary> 36 /// <returns>A list with the DSC resource.</returns> 37 IReadOnlyList<DscResourceInfoInternal> GetAllDscResources(); 38 39 /// <summary> 40 /// Gets all resources in a module. 41 /// </summary> 42 /// <param name="moduleSpecification">Module specification.</param> 43 /// <returns>List of resources.</returns> 44 IReadOnlyList<DscResourceInfoInternal> GetDscResourcesInModule(ModuleSpecification moduleSpecification); 45 46 /// <summary> 47 /// Gets a DSC Resource. 48 /// </summary> 49 /// <param name="unitInternal">Configuration unit internal.</param> 50 /// <returns>DSC Resource.</returns> 51 DscResourceInfoInternal? GetDscResource(ConfigurationUnitAndModule unitInternal); 52 53 /// <summary> 54 /// Calls Invoke-DscResource -Method Get from this module. 55 /// </summary> 56 /// <param name="settings">Settings.</param> 57 /// <param name="name">Name.</param> 58 /// <param name="moduleSpecification">Module specification.</param> 59 /// <returns>Properties of resource.</returns> 60 ValueSet InvokeGetResource(ValueSet settings, string name, ModuleSpecification? moduleSpecification); 61 62 /// <summary> 63 /// Calls Invoke-DscResource -Method Test from this module. 64 /// </summary> 65 /// <param name="settings">Settings.</param> 66 /// <param name="name">Name.</param> 67 /// <param name="moduleSpecification">Module specification.</param> 68 /// <returns>Is in desired state.</returns> 69 bool InvokeTestResource(ValueSet settings, string name, ModuleSpecification? moduleSpecification); 70 71 /// <summary> 72 /// Calls Invoke-DscResource -Method Set from this module. 73 /// </summary> 74 /// <param name="settings">Settings.</param> 75 /// <param name="name">Name.</param> 76 /// <param name="moduleSpecification">Module specification.</param> 77 /// <returns>If a reboot is required.</returns> 78 bool InvokeSetResource(ValueSet settings, string name, ModuleSpecification? moduleSpecification); 79 80 /// <summary> 81 /// Calls Get-Module with fully qualified name. 82 /// </summary> 83 /// <param name="moduleSpecification">Module name.</param> 84 /// <returns>PSModuleInfo, null if not imported.</returns> 85 PSModuleInfo? GetImportedModule(ModuleSpecification moduleSpecification); 86 87 /// <summary> 88 /// Calls Get-Module with the fully qualified name and using ListAvailable. 89 /// </summary> 90 /// <param name="moduleSpecification">Module specification.</param> 91 /// <returns>PSModuleInfo, null if not found.</returns> 92 PSModuleInfo? GetAvailableModule(ModuleSpecification moduleSpecification); 93 94 /// <summary> 95 /// Calls Get-Module from a path using ListAvailable. 96 /// </summary> 97 /// <param name="path">Path.</param> 98 /// <returns>The first module returned, null if none.</returns> 99 PSModuleInfo? GetAvailableModule(string path); 100 101 /// <summary> 102 /// Calls Import-Module with the fully qualified name. 103 /// </summary> 104 /// <param name="moduleSpecification">Module specification.</param> 105 void ImportModule(ModuleSpecification moduleSpecification); 106 107 /// <summary> 108 /// Calls Import-Module with a file path. 109 /// </summary> 110 /// <param name="path">Module file path.</param> 111 void ImportModule(string path); 112 113 /// <summary> 114 /// Calls Get-InstalledModule. 115 /// </summary> 116 /// <param name="moduleSpecification">Module specification.</param> 117 /// <returns>Module info, null if not installed.</returns> 118 PSObject? GetInstalledModule(ModuleSpecification moduleSpecification); 119 120 /// <summary> 121 /// Calls Find-Module. 122 /// </summary> 123 /// <param name="unitInternal">Configuration unit internal.</param> 124 /// <returns>Module info, null if not found.</returns> 125 PSObject? FindModule(ConfigurationUnitInternal unitInternal); 126 127 /// <summary> 128 /// Calls Find-DscResource. 129 /// </summary> 130 /// <param name="unitInternal">Configuration unit internal.</param> 131 /// <returns>Dsc Resource info, null if not found.</returns> 132 PSObject? FindDscResource(ConfigurationUnitInternal unitInternal); 133 134 /// <summary> 135 /// Calls Save-Module -InputObject object -Path location. 136 /// Input object must be the result of Find cmdlets of PowerShellGet. 137 /// </summary> 138 /// <param name="inputObject">Input object.</param> 139 /// <param name="location">Location to save module.</param> 140 void SaveModule(PSObject inputObject, string location); 141 142 /// <summary> 143 /// Calls Save-Module. 144 /// </summary> 145 /// <param name="moduleSpecification">Module specification.</param> 146 /// <param name="location">Location to save module.</param> 147 void SaveModule(ModuleSpecification moduleSpecification, string location); 148 149 /// <summary> 150 /// Calls Install-Module -InputObject object. 151 /// Input object must be the result of Find cmdlets of PowerShellGet. 152 /// </summary> 153 /// <param name="inputObject">Input object.</param> 154 void InstallModule(PSObject inputObject); 155 156 /// <summary> 157 /// Calls Install-Module with a module specification. 158 /// </summary> 159 /// <param name="moduleSpecification">Module specification.</param> 160 void InstallModule(ModuleSpecification moduleSpecification); 161 162 /// <summary> 163 /// Get unique certificates of valid signed files from the specified paths. 164 /// </summary> 165 /// <param name="paths">Path.</param> 166 /// <returns>List with valid signatures.</returns> 167 List<Certificate> GetCertsOfValidSignedFiles(string[] paths); 168 169 /// <summary> 170 /// Gets the value of a variable. 171 /// </summary> 172 /// <typeparam name="TType">Type of the variable.</typeparam> 173 /// <param name="name">Name of variable.</param> 174 /// <returns>The value of a variable, null if doesn't exist.</returns> 175 TType GetVariable<TType>(string name); 176 177 /// <summary> 178 /// Sets a variable with its value. 179 /// </summary> 180 /// <param name="name">Name of variable.</param> 181 /// <param name="value">Value of variable.</param> 182 void SetVariable(string name, object value); 183 184 /// <summary> 185 /// Overwrites PSModulePath with the specified path. 186 /// </summary> 187 /// <param name="path">Path.</param> 188 void SetPSModulePath(string path); 189 190 /// <summary> 191 /// Overwrites PSModulePath with the specified paths. 192 /// </summary> 193 /// <param name="paths">Paths.</param> 194 void SetPSModulePaths(IReadOnlyList<string> paths); 195 196 /// <summary> 197 /// Prepends path to the PSModulePath. 198 /// </summary> 199 /// <param name="path">Path.</param> 200 void PrependPSModulePath(string path); 201 202 /// <summary> 203 /// Prepends paths to the PSModulePath. 204 /// </summary> 205 /// <param name="paths">Paths.</param> 206 void PrependPSModulePaths(IReadOnlyList<string> paths); 207 208 /// <summary> 209 /// Append path to the PSModulePath. 210 /// </summary> 211 /// <param name="path">Path.</param> 212 void AppendPSModulePath(string path); 213 214 /// <summary> 215 /// Append paths to the PSModulePath. 216 /// </summary> 217 /// <param name="paths">Path.</param> 218 void AppendPSModulePaths(IReadOnlyList<string> paths); 219 220 /// <summary> 221 /// Removes a path from the module path. 222 /// </summary> 223 /// <param name="path">Path.</param> 224 void CleanupPSModulePath(string path); 225 226 /// <summary> 227 /// Sets the location for installing modules. 228 /// </summary> 229 /// <param name="location">Location.</param> 230 /// <param name="customLocation">Path for custom location.</param> 231 void SetLocation(PowerShellConfigurationProcessorLocation location, string? customLocation); 232 } 233 }