Skip to content

Commit 195a7b6

Browse files
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
1 parent dba9cfd commit 195a7b6

File tree

3 files changed

+213
-0
lines changed

3 files changed

+213
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
@{
2+
3+
# Script module or binary module file associated with this manifest.
4+
RootModule = 'Azure.Functions.PowerShell.Worker.Module.psm1'
5+
6+
# Version number of this module.
7+
ModuleVersion = '0.1.0'
8+
9+
# Supported PSEditions
10+
CompatiblePSEditions = @('Desktop', 'Core')
11+
12+
# ID used to uniquely identify this module
13+
GUID = 'f0149ba6-bd6f-4dbd-afe5-2a95bd755d6c'
14+
15+
# Author of this module
16+
Author = 'Microsoft Corporation'
17+
18+
# Company or vendor of this module
19+
CompanyName = 'Microsoft Corporation'
20+
21+
# Copyright statement for this module
22+
Copyright = '(c) Microsoft Corporation. All rights reserved.'
23+
24+
# Description of the functionality provided by this module
25+
Description = 'The module used in an Azure Functions environment for setting and retrieving Output Bindings.'
26+
27+
# Minimum version of the PowerShell engine required by this module
28+
PowerShellVersion = '5.1'
29+
30+
# Modules that must be imported into the global environment prior to importing this module
31+
RequiredModules = @()
32+
33+
# Assemblies that must be loaded prior to importing this module
34+
RequiredAssemblies = @()
35+
36+
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
37+
ScriptsToProcess = @()
38+
39+
# Type files (.ps1xml) to be loaded when importing this module
40+
TypesToProcess = @()
41+
42+
# Format files (.ps1xml) to be loaded when importing this module
43+
FormatsToProcess = @()
44+
45+
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
46+
NestedModules = @()
47+
48+
# 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.
49+
FunctionsToExport = @('Push-OutputBinding', 'Get-OutputBinding')
50+
51+
# 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.
52+
CmdletsToExport = @()
53+
54+
# Variables to export from this module
55+
VariablesToExport = @()
56+
57+
# 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.
58+
AliasesToExport = @()
59+
60+
# 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.
61+
PrivateData = @{
62+
63+
PSData = @{
64+
65+
# Tags applied to this module. These help with module discovery in online galleries.
66+
Tags = @('Microsoft', 'Azure', 'Functions', 'Serverless', 'Cloud')
67+
68+
# A URL to the license for this module.
69+
LicenseUri = 'https://github.com/Azure/azure-functions-powershell-worker/blob/dev/LICENSE'
70+
71+
# A URL to the main website for this project.
72+
ProjectUri = 'https://github.com/Azure/azure-functions-powershell-worker'
73+
74+
# A URL to an icon representing this module.
75+
# IconUri = ''
76+
77+
# ReleaseNotes of this module
78+
ReleaseNotes = '# 0.1.0
79+
Initial Release.
80+
'
81+
82+
}
83+
}
84+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#
2+
# Copyright (c) Microsoft. All rights reserved.
3+
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
#
5+
6+
# This holds the current state of the output bindings
7+
$script:_OutputBindings = @{}
8+
9+
<#
10+
.SYNOPSIS
11+
Gets the hashtable of the output bindings set so far.
12+
.DESCRIPTION
13+
Gets the hashtable of the output bindings set so far.
14+
.EXAMPLE
15+
PS > Get-OutputBinding
16+
Gets the hashtable of all the output bindings set so far.
17+
.EXAMPLE
18+
PS > Get-OutputBinding -Name res
19+
Gets the hashtable of specific output binding.
20+
.EXAMPLE
21+
PS > Get-OutputBinding -Name r*
22+
Gets the hashtable of output bindings that match the wildcard.
23+
.PARAMETER Name
24+
The name of the output binding you want to get. Supports wildcards.
25+
.OUTPUTS
26+
The hashtable of binding names to their respective value.
27+
#>
28+
function Get-OutputBinding {
29+
[CmdletBinding()]
30+
param(
31+
[Parameter(ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)]
32+
[string[]]
33+
$Name = '*'
34+
)
35+
begin {
36+
$bindings = @{}
37+
}
38+
process {
39+
$script:_OutputBindings.GetEnumerator() | Where-Object Name -Like $Name | ForEach-Object { $null = $bindings.Add($_.Name, $_.Value) }
40+
}
41+
end {
42+
return $bindings
43+
}
44+
}
45+
46+
# Helper private function that sets an OutputBinding.
47+
function Push-KeyValueOutputBinding {
48+
param (
49+
[Parameter(Mandatory=$true)]
50+
[string]
51+
$Name,
52+
53+
[Parameter(Mandatory=$true)]
54+
[object]
55+
$Value,
56+
57+
[switch]
58+
$Force
59+
)
60+
if(!$script:_OutputBindings.ContainsKey($Name) -or $Force.IsPresent) {
61+
$script:_OutputBindings[$Name] = $Value
62+
} else {
63+
throw "Output binding '$Name' is already set. To override the value, use -Force."
64+
}
65+
}
66+
67+
<#
68+
.SYNOPSIS
69+
Sets the value for the specified output binding.
70+
.DESCRIPTION
71+
Sets the value for the specified output binding.
72+
.EXAMPLE
73+
PS > Push-OutputBinding -Name res -Value "my output"
74+
The output binding of "res" will have the value of "my output"
75+
.PARAMETER Name
76+
The name of the output binding you want to set.
77+
.PARAMETER Value
78+
The value of the output binding you want to set.
79+
.PARAMETER InputObject
80+
The hashtable that contains the output binding names to their respective value.
81+
.PARAMETER Force
82+
(Optional) If specified, will force the value to be set for a specified output binding.
83+
#>
84+
function Push-OutputBinding {
85+
[CmdletBinding()]
86+
param (
87+
[Parameter(
88+
Mandatory=$true,
89+
ParameterSetName="NameValue",
90+
Position=0,
91+
ValueFromPipelineByPropertyName=$true)]
92+
[string]
93+
$Name,
94+
95+
[Parameter(
96+
Mandatory=$true,
97+
ParameterSetName="NameValue",
98+
Position=1,
99+
ValueFromPipelineByPropertyName=$true)]
100+
[object]
101+
$Value,
102+
103+
[Parameter(
104+
Mandatory=$true,
105+
ParameterSetName="InputObject",
106+
Position=0,
107+
ValueFromPipeline=$true)]
108+
[hashtable]
109+
$InputObject,
110+
111+
[switch]
112+
$Force
113+
)
114+
process {
115+
switch ($PSCmdlet.ParameterSetName) {
116+
NameValue {
117+
Push-KeyValueOutputBinding -Name $Name -Value $Value -Force:$Force.IsPresent
118+
}
119+
InputObject {
120+
$InputObject.GetEnumerator() | ForEach-Object {
121+
Push-KeyValueOutputBinding -Name $_.Name -Value $_.Value -Force:$Force.IsPresent
122+
}
123+
}
124+
}
125+
}
126+
}

src/Azure.Functions.PowerShell.Worker/Azure.Functions.PowerShell.Worker.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
<None Include="worker.config.json">
3030
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
3131
</None>
32+
<None Include="Azure.Functions.PowerShell.Worker.Module\**">
33+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
34+
</None>
3235
</ItemGroup>
3336

3437
</Project>

0 commit comments

Comments
 (0)