Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/KeyVault/KeyVault.Autorest/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
16 changes: 16 additions & 0 deletions src/KeyVault/KeyVault.Autorest/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
bin
obj
.vs
generated
internal
exports
tools
custom/*.psm1
custom/autogen-model-cmdlets
test/*-TestResults.xml
/*.ps1
/*.ps1xml
/*.psm1
/*.snk
/*.csproj
/*.nuspec
23 changes: 23 additions & 0 deletions src/KeyVault/KeyVault.Autorest/Az.KeyVault.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@{
GUID = 'e0f28b9c-6a6b-4b66-833e-c01780a5577b'
RootModule = './Az.KeyVault.psm1'
ModuleVersion = '0.1.0'
CompatiblePSEditions = 'Core', 'Desktop'
Author = 'Microsoft Corporation'
CompanyName = 'Microsoft Corporation'
Copyright = 'Microsoft Corporation. All rights reserved.'
Description = 'Microsoft Azure PowerShell: KeyVault cmdlets'
PowerShellVersion = '5.1'
DotNetFrameworkVersion = '4.7.2'
RequiredAssemblies = './bin/Az.KeyVault.private.dll'
FormatsToProcess = './Az.KeyVault.format.ps1xml'
FunctionsToExport = 'Add-AzKeyVaultManagedHsmRegion', 'Get-AzKeyVaultManagedHsmRegion', 'Remove-AzKeyVaultManagedHsmRegion', 'Test-AzKeyVaultManagedHsmNameAvailability', 'Test-AzKeyVaultNameAvailability'
PrivateData = @{
PSData = @{
Tags = 'Azure', 'ResourceManager', 'ARM', 'PSModule', 'KeyVault'
LicenseUri = 'https://aka.ms/azps-license'
ProjectUri = 'https://github.com/Azure/azure-powershell'
ReleaseNotes = ''
}
}
}
102 changes: 102 additions & 0 deletions src/KeyVault/KeyVault.Autorest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<!-- region Generated -->
# Az.KeyVault
This directory contains the PowerShell module for the KeyVault service.

---
## Status
[![Az.KeyVault](https://img.shields.io/powershellgallery/v/Az.KeyVault.svg?style=flat-square&label=Az.KeyVault "Az.KeyVault")](https://www.powershellgallery.com/packages/Az.KeyVault/)

## Info
- Modifiable: yes
- Generated: all
- Committed: yes
- Packaged: yes

---
## Detail
This module was primarily generated via [AutoRest](https://github.com/Azure/autorest) using the [PowerShell](https://github.com/Azure/autorest.powershell) extension.

## Module Requirements
- [Az.Accounts module](https://www.powershellgallery.com/packages/Az.Accounts/), version 2.7.5 or greater

## Authentication
AutoRest does not generate authentication code for the module. Authentication is handled via Az.Accounts by altering the HTTP payload before it is sent.

## Development
For information on how to develop for `Az.KeyVault`, see [how-to.md](how-to.md).
<!-- endregion -->

### AutoRest Configuration
> see https://aka.ms/autorest

``` yaml
# Please specify the commit id that includes your features to make sure generated codes stable.
branch: 8fa9b5051129dd4808c9be1f5b753af226b044db
require:
# readme.azure.noprofile.md is the common configuration file
- $(this-folder)/../../readme.azure.noprofile.md

input-file:
# You need to specify your swagger files here.
- $(repo)/specification/keyvault/resource-manager/Microsoft.KeyVault/stable/2023-02-01/keyvault.json
- $(repo)/specification/keyvault/resource-manager/Microsoft.KeyVault/stable/2023-02-01/managedHsm.json
# If the swagger has not been put in the repo, you may uncomment the following line and refer to it locally
# - (this-folder)/relative-path-to-your-swagger

# For new RP, the version is 0.1.0
module-version: 0.1.0
# Normally, title is the service name
title: KeyVault
subject-prefix: $(service-name)
use-extension:
"@autorest/powershell": "4.x"

# If there are post APIs for some kinds of actions in the RP, you may need to
# uncomment following line to support viaIdentity for these post APIs
# identity-correction-for-post: true

directive:
# Following is two common directive which are normally required in all the RPs
# 1. Remove the unexpanded parameter set
# 2. For New-* cmdlets, ViaIdentity is not required, so CreateViaIdentityExpanded is removed as well
- where:
variant: ^Create$|^CreateViaIdentity$|^CreateViaIdentityExpanded$|^Check$|^CheckViaIdentity$|^CheckViaIdentityExpanded$
remove: true
# Remove the set-* cmdlet
- where:
verb: Set
remove: true
# Combine Test-AzKeyVaultNameAvailability and Test-AzKeyVaultManagedHsmNameAvailability
- from: swagger-document
where: $.paths..operationId
transform: return $.replace(/^ManagedHsms_CheckMhsmNameAvailability$/g, "ManagedHsms_CheckNameAvailability")
- no-inline:
- Error
# Remove all commands except Test-AzKeyVault*NameAvailability, *-AzKeyVaultManagedHsm, *-AzKeyVaultRegion
- where:
subject: ^((?!MhsmRegion|ManagedHsm|NameAvailability).)*$
remove: true
# Rename *-AzKeyVaultMhsmRegion to *-AzKeyVaultManagedHsmRegion
- where:
subject: ^MhsmRegion$
set:
subject: ManagedHsmRegion
- where:
subject: ^ManagedHsmRegion$
parameter-name: Name
set:
parameter-name: HsmName
# Remove *-AzKeyVaultManagedHsmDeleted
- where:
subject: ^ManagedHsmDeleted$
remove: true
# Hide *-AzKeyVaultManagedHsm
- where:
subject: ^ManagedHsm$
hide: true
# Remove New|Remove-AzKeyVaultManagedHsm
- where:
verb: New|Remove
subject: ^ManagedHsm$
remove: true
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@

# ----------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Code generated by Microsoft (R) AutoRest Code Generator.Changes may cause incorrect behavior and will be lost if the code
# is regenerated.
# ----------------------------------------------------------------------------------

<#
.Synopsis
The List operation gets information about the regions associated with the managed HSM Pool.
.Description
The List operation gets information about the regions associated with the managed HSM Pool.
.Example
{{ Add code here }}
.Example
{{ Add code here }}

.Outputs
Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Models.IMhsmGeoReplicatedRegion
.Link
https://learn.microsoft.com/powershell/module/az.keyvault/add-azkeyvaultmanagedhsmregion
#>
function Add-AzKeyVaultManagedHsmRegion {
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Models.IMhsmGeoReplicatedRegion])]
[CmdletBinding(PositionalBinding=$false, SupportsShouldProcess, ConfirmImpact='Medium')]
param(
[Parameter(Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Category('Path')]
[System.String]
# Name of the managed HSM Pool
${HsmName},

[Parameter(Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Category('Path')]
[System.String]
# Name of the resource group that contains the managed HSM pool.
${ResourceGroupName},

[Parameter(Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Category('Body')]
[System.String[]]
# List of regions to be added associated with the managed hsm pool.
# To construct, see NOTES section for REGION properties and create a hash table.
${Region},

[Parameter()]
[Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Category('Runtime')]
[System.Management.Automation.SwitchParameter]
# Run the command as a job
${AsJob},

[Parameter()]
[Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Category('Path')]
[Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Runtime.DefaultInfo(Script='(Get-AzContext).Subscription.Id')]
[System.String]
# Subscription credentials which uniquely identify Microsoft Azure subscription.
# The subscription ID forms part of the URI for every service call.
${SubscriptionId},

[Parameter()]
[Alias('AzureRMContext', 'AzureCredential')]
[ValidateNotNull()]
[Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Category('Azure')]
[System.Management.Automation.PSObject]
# The DefaultProfile parameter is not functional.
# Use the SubscriptionId parameter when available if executing the cmdlet against a different subscription.
${DefaultProfile},

[Parameter(DontShow)]
[Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Category('Runtime')]
[System.Management.Automation.SwitchParameter]
# Wait for .NET debugger to attach
${Break},

[Parameter(DontShow)]
[ValidateNotNull()]
[Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Category('Runtime')]
[Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Runtime.SendAsyncStep[]]
# SendAsync Pipeline Steps to be appended to the front of the pipeline
${HttpPipelineAppend},

[Parameter(DontShow)]
[ValidateNotNull()]
[Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Category('Runtime')]
[Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Runtime.SendAsyncStep[]]
# SendAsync Pipeline Steps to be prepended to the front of the pipeline
${HttpPipelinePrepend},

[Parameter(DontShow)]
[Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Category('Runtime')]
[System.Uri]
# The URI for the proxy server to use
${Proxy},

[Parameter(DontShow)]
[ValidateNotNull()]
[Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Category('Runtime')]
[System.Management.Automation.PSCredential]
# Credentials for a proxy server to use for the remote call
${ProxyCredential},

[Parameter(DontShow)]
[Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Category('Runtime')]
[System.Management.Automation.SwitchParameter]
# Use the default credentials for the proxy
${ProxyUseDefaultCredentials}
)
process {
try {
$null = $PSBoundParameters.Remove('HsmName')
$null = $PSBoundParameters.Add('Name', $HsmName)
$null = $PSBoundParameters.Remove('Region')
$Parameter = Az.KeyVault.internal\Get-AzKeyVaultManagedHsm @PSBoundParameters
for ($i = 0; $i -lt $Region.Count; $i++) {
$Parameter.Region += New-Object Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Models.MhsmGeoReplicatedRegion -Property @{Name = $Region[$i]}
}
$null = $PSBoundParameters.Add('Parameter', $Parameter)
$null = Az.KeyVault.internal\Update-AzKeyVaultManagedHsm @PSBoundParameters
$null = $PSBoundParameters.Remove('Parameter')
$null = $PSBoundParameters.Remove('Name')
$null = $PSBoundParameters.Add('HsmName', $HsmName)
Az.KeyVault\Get-AzKeyVaultManagedHsmRegion @PSBoundParameters
} catch {
throw
}
}
}
20 changes: 20 additions & 0 deletions src/KeyVault/KeyVault.Autorest/custom/ManagedHsm.json.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// Code generated by Microsoft (R) AutoRest Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is regenerated.

namespace Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Models
{
using static Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Runtime.Extensions;

/// <summary>Resource information with extended details.</summary>
public partial class ManagedHsm
{
partial void AfterToJson(ref Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Runtime.Json.JsonObject container)
{
if (this.Tag != null && this.Tag.Count == 0) {
container.Add("tags", new Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Runtime.Json.JsonObject());
}
}
}
}
41 changes: 41 additions & 0 deletions src/KeyVault/KeyVault.Autorest/custom/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Custom
This directory contains custom implementation for non-generated cmdlets for the `Az.KeyVault` module. Both scripts (`.ps1`) and C# files (`.cs`) can be implemented here. They will be used during the build process in `build-module.ps1`, and create cmdlets into the `..\exports` folder. The only generated file into this folder is the `Az.KeyVault.custom.psm1`. This file should not be modified.

## Info
- Modifiable: yes
- Generated: partial
- Committed: yes
- Packaged: yes

## Details
For `Az.KeyVault` to use custom cmdlets, it does this two different ways. We **highly recommend** creating script cmdlets, as they are easier to write and allow access to the other exported cmdlets. C# cmdlets *cannot access exported cmdlets*.

For C# cmdlets, they are compiled with the rest of the generated low-level cmdlets into the `./bin/Az.KeyVault.private.dll`. The names of the cmdlets (methods) and files must follow the `[cmdletName]_[variantName]` syntax used for generated cmdlets. The `variantName` is used as the `ParameterSetName`, so use something appropriate that doesn't clash with already created variant or parameter set names. You cannot use the `ParameterSetName` property in the `Parameter` attribute on C# cmdlets. Each cmdlet must be separated into variants using the same pattern as seen in the `generated/cmdlets` folder.

For script cmdlets, these are loaded via the `Az.KeyVault.custom.psm1`. Then, during the build process, this module is loaded and processed in the same manner as the C# cmdlets. The fundamental difference is the script cmdlets use the `ParameterSetName` attribute and C# cmdlets do not. To create a script cmdlet variant of a generated cmdlet, simply decorate all parameters in the script with the new `ParameterSetName` in the `Parameter` attribute. This will appropriately treat each parameter set as a separate variant when processed to be exported during the build.

## Purpose
This allows the modules to have cmdlets that were not defined in the REST specification. It also allows combining logic using generated cmdlets. This is a level of customization beyond what can be done using the [readme configuration options](https://github.com/Azure/autorest/blob/master/docs/powershell/options.md) that are currently available. These custom cmdlets are then referenced by the cmdlets created at build-time in the `..\exports` folder.

## Usage
The easiest way currently to start developing custom cmdlets is to copy an existing cmdlet. For C# cmdlets, copy one from the `generated/cmdlets` folder. For script cmdlets, build the project using `build-module.ps1` and copy one of the scripts from the `..\exports` folder. After that, if you want to add new parameter sets, follow the guidelines in the `Details` section above. For implementing a new cmdlets, at minimum, please keep these parameters:
- Break
- DefaultProfile
- HttpPipelineAppend
- HttpPipelinePrepend
- Proxy
- ProxyCredential
- ProxyUseDefaultCredentials

These provide functionality to our HTTP pipeline and other useful features. In script, you can forward these parameters using `$PSBoundParameters` to the other cmdlets you're calling within `Az.KeyVault`. For C#, follow the usage seen in the `ProcessRecordAsync` method.

### Attributes
For processing the cmdlets, we've created some additional attributes:
- `Microsoft.Azure.PowerShell.Cmdlets.KeyVault.DescriptionAttribute`
- Used in C# cmdlets to provide a high-level description of the cmdlet. This is propagated to reference documentation via [help comments](https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_comment_based_help) in the exported scripts.
- `Microsoft.Azure.PowerShell.Cmdlets.KeyVault.DoNotExportAttribute`
- Used in C# and script cmdlets to suppress creating an exported cmdlet at build-time. These cmdlets will *not be exposed* by `Az.KeyVault`.
- `Microsoft.Azure.PowerShell.Cmdlets.KeyVault.InternalExportAttribute`
- Used in C# cmdlets to route exported cmdlets to the `..\internal`, which are *not exposed* by `Az.KeyVault`. For more information, see [README.md](..\internal/README.md) in the `..\internal` folder.
- `Microsoft.Azure.PowerShell.Cmdlets.KeyVault.ProfileAttribute`
- Used in C# and script cmdlets to define which Azure profiles the cmdlet supports. This is only supported for Azure (`--azure`) modules.
Loading