initial commit of module (#14)
* initial commit of module * address feedback and move module into worker * address Dongbo's feedback * remove psd1 fields and change Set logic * don't expose vars in psd1 * alpha sort functions * helper function refactoring
This commit is contained in:
Родитель
dba9cfd1e2
Коммит
195a7b644b
|
@ -0,0 +1,84 @@
|
|||
@{
|
||||
|
||||
# Script module or binary module file associated with this manifest.
|
||||
RootModule = 'Azure.Functions.PowerShell.Worker.Module.psm1'
|
||||
|
||||
# Version number of this module.
|
||||
ModuleVersion = '0.1.0'
|
||||
|
||||
# Supported PSEditions
|
||||
CompatiblePSEditions = @('Desktop', 'Core')
|
||||
|
||||
# ID used to uniquely identify this module
|
||||
GUID = 'f0149ba6-bd6f-4dbd-afe5-2a95bd755d6c'
|
||||
|
||||
# Author of this module
|
||||
Author = 'Microsoft Corporation'
|
||||
|
||||
# Company or vendor of this module
|
||||
CompanyName = 'Microsoft Corporation'
|
||||
|
||||
# Copyright statement for this module
|
||||
Copyright = '(c) Microsoft Corporation. All rights reserved.'
|
||||
|
||||
# Description of the functionality provided by this module
|
||||
Description = 'The module used in an Azure Functions environment for setting and retrieving Output Bindings.'
|
||||
|
||||
# Minimum version of the PowerShell engine required by this module
|
||||
PowerShellVersion = '5.1'
|
||||
|
||||
# Modules that must be imported into the global environment prior to importing this module
|
||||
RequiredModules = @()
|
||||
|
||||
# Assemblies that must be loaded prior to importing this module
|
||||
RequiredAssemblies = @()
|
||||
|
||||
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
|
||||
ScriptsToProcess = @()
|
||||
|
||||
# Type files (.ps1xml) to be loaded when importing this module
|
||||
TypesToProcess = @()
|
||||
|
||||
# Format files (.ps1xml) to be loaded when importing this module
|
||||
FormatsToProcess = @()
|
||||
|
||||
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
|
||||
NestedModules = @()
|
||||
|
||||
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
|
||||
FunctionsToExport = @('Push-OutputBinding', 'Get-OutputBinding')
|
||||
|
||||
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
|
||||
CmdletsToExport = @()
|
||||
|
||||
# Variables to export from this module
|
||||
VariablesToExport = @()
|
||||
|
||||
# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
|
||||
AliasesToExport = @()
|
||||
|
||||
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
|
||||
PrivateData = @{
|
||||
|
||||
PSData = @{
|
||||
|
||||
# Tags applied to this module. These help with module discovery in online galleries.
|
||||
Tags = @('Microsoft', 'Azure', 'Functions', 'Serverless', 'Cloud')
|
||||
|
||||
# A URL to the license for this module.
|
||||
LicenseUri = 'https://github.com/Azure/azure-functions-powershell-worker/blob/dev/LICENSE'
|
||||
|
||||
# A URL to the main website for this project.
|
||||
ProjectUri = 'https://github.com/Azure/azure-functions-powershell-worker'
|
||||
|
||||
# A URL to an icon representing this module.
|
||||
# IconUri = ''
|
||||
|
||||
# ReleaseNotes of this module
|
||||
ReleaseNotes = '# 0.1.0
|
||||
Initial Release.
|
||||
'
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,126 @@
|
|||
#
|
||||
# Copyright (c) Microsoft. All rights reserved.
|
||||
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
#
|
||||
|
||||
# This holds the current state of the output bindings
|
||||
$script:_OutputBindings = @{}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Gets the hashtable of the output bindings set so far.
|
||||
.DESCRIPTION
|
||||
Gets the hashtable of the output bindings set so far.
|
||||
.EXAMPLE
|
||||
PS > Get-OutputBinding
|
||||
Gets the hashtable of all the output bindings set so far.
|
||||
.EXAMPLE
|
||||
PS > Get-OutputBinding -Name res
|
||||
Gets the hashtable of specific output binding.
|
||||
.EXAMPLE
|
||||
PS > Get-OutputBinding -Name r*
|
||||
Gets the hashtable of output bindings that match the wildcard.
|
||||
.PARAMETER Name
|
||||
The name of the output binding you want to get. Supports wildcards.
|
||||
.OUTPUTS
|
||||
The hashtable of binding names to their respective value.
|
||||
#>
|
||||
function Get-OutputBinding {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)]
|
||||
[string[]]
|
||||
$Name = '*'
|
||||
)
|
||||
begin {
|
||||
$bindings = @{}
|
||||
}
|
||||
process {
|
||||
$script:_OutputBindings.GetEnumerator() | Where-Object Name -Like $Name | ForEach-Object { $null = $bindings.Add($_.Name, $_.Value) }
|
||||
}
|
||||
end {
|
||||
return $bindings
|
||||
}
|
||||
}
|
||||
|
||||
# Helper private function that sets an OutputBinding.
|
||||
function Push-KeyValueOutputBinding {
|
||||
param (
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]
|
||||
$Name,
|
||||
|
||||
[Parameter(Mandatory=$true)]
|
||||
[object]
|
||||
$Value,
|
||||
|
||||
[switch]
|
||||
$Force
|
||||
)
|
||||
if(!$script:_OutputBindings.ContainsKey($Name) -or $Force.IsPresent) {
|
||||
$script:_OutputBindings[$Name] = $Value
|
||||
} else {
|
||||
throw "Output binding '$Name' is already set. To override the value, use -Force."
|
||||
}
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Sets the value for the specified output binding.
|
||||
.DESCRIPTION
|
||||
Sets the value for the specified output binding.
|
||||
.EXAMPLE
|
||||
PS > Push-OutputBinding -Name res -Value "my output"
|
||||
The output binding of "res" will have the value of "my output"
|
||||
.PARAMETER Name
|
||||
The name of the output binding you want to set.
|
||||
.PARAMETER Value
|
||||
The value of the output binding you want to set.
|
||||
.PARAMETER InputObject
|
||||
The hashtable that contains the output binding names to their respective value.
|
||||
.PARAMETER Force
|
||||
(Optional) If specified, will force the value to be set for a specified output binding.
|
||||
#>
|
||||
function Push-OutputBinding {
|
||||
[CmdletBinding()]
|
||||
param (
|
||||
[Parameter(
|
||||
Mandatory=$true,
|
||||
ParameterSetName="NameValue",
|
||||
Position=0,
|
||||
ValueFromPipelineByPropertyName=$true)]
|
||||
[string]
|
||||
$Name,
|
||||
|
||||
[Parameter(
|
||||
Mandatory=$true,
|
||||
ParameterSetName="NameValue",
|
||||
Position=1,
|
||||
ValueFromPipelineByPropertyName=$true)]
|
||||
[object]
|
||||
$Value,
|
||||
|
||||
[Parameter(
|
||||
Mandatory=$true,
|
||||
ParameterSetName="InputObject",
|
||||
Position=0,
|
||||
ValueFromPipeline=$true)]
|
||||
[hashtable]
|
||||
$InputObject,
|
||||
|
||||
[switch]
|
||||
$Force
|
||||
)
|
||||
process {
|
||||
switch ($PSCmdlet.ParameterSetName) {
|
||||
NameValue {
|
||||
Push-KeyValueOutputBinding -Name $Name -Value $Value -Force:$Force.IsPresent
|
||||
}
|
||||
InputObject {
|
||||
$InputObject.GetEnumerator() | ForEach-Object {
|
||||
Push-KeyValueOutputBinding -Name $_.Name -Value $_.Value -Force:$Force.IsPresent
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -29,6 +29,9 @@
|
|||
<None Include="worker.config.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Azure.Functions.PowerShell.Worker.Module\**">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
Загрузка…
Ссылка в новой задаче