Skip to content

Improve PostgreSql #13077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 27, 2020
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
178 changes: 178 additions & 0 deletions src/PostgreSql/custom/New-AzPostgreSqlFirewallRule.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@

# ----------------------------------------------------------------------------------
#
# Copyright Microsoft Corporation
# 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.
# ----------------------------------------------------------------------------------

<#
.Synopsis
Creates a new firewall rule or updates an existing firewall rule.
.Description
Creates a new firewall rule or updates an existing firewall rule.
#>
function New-AzPostgreSqlFirewallRule {
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Models.Api20171201.IFirewallRule])]
[CmdletBinding(DefaultParameterSetName='CreateExpanded', PositionalBinding=$false, SupportsShouldProcess, ConfirmImpact='Medium')]
param(
[Parameter()]
[Alias('FirewallRuleName')]
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Path')]
[System.String]
# The name of the server firewall rule.
${Name},

[Parameter(Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Path')]
[System.String]
# The name of the resource group.
# The name is case insensitive.
${ResourceGroupName},

[Parameter(Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Path')]
[System.String]
# The name of the server.
${ServerName},

[Parameter()]
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Path')]
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Runtime.DefaultInfo(Script='(Get-AzContext).Subscription.Id')]
[System.String]
# The ID of the target subscription.
${SubscriptionId},

[Parameter(ParameterSetName='CreateExpanded', Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Body')]
[System.String]
# The end IP address of the server firewall rule.
# Must be IPv4 format.
${EndIPAddress},

[Parameter(ParameterSetName='CreateExpanded', Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Body')]
[System.String]
# The start IP address of the server firewall rule.
# Must be IPv4 format.
${StartIPAddress},

[Parameter(ParameterSetName='ClientIPAddress', Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Body')]
[System.String]
# Client specified single IP of the server firewall rule.
# Must be IPv4 format.
${ClientIPAddress},

[Parameter(ParameterSetName='AllowAll', Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Body')]
[System.Management.Automation.SwitchParameter]
# Present to allow all range IPs, from 0.0.0.0 to 255.255.255.255.
${AllowAll},

[Parameter()]
[Alias('AzureRMContext', 'AzureCredential')]
[ValidateNotNull()]
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Azure')]
[System.Management.Automation.PSObject]
# The credentials, account, tenant, and subscription used for communication with Azure.
${DefaultProfile},

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

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

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

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

[Parameter()]
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Runtime')]
[System.Management.Automation.SwitchParameter]
# Run the command asynchronously
${NoWait},

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

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

[Parameter(DontShow)]
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Runtime')]
[System.Management.Automation.SwitchParameter]
# Use the default credentials for the proxy
${ProxyUseDefaultCredentials}
)

process {
try {
if($PSBoundParameters.ContainsKey('AllowAll'))
{
if(!$PSBoundParameters.ContainsKey('Name'))
{
$PSBoundParameters['Name'] = Get-Date -Format "AllowAll_yyyy-MM-dd_HH-mm-ss"
}
$PSBoundParameters['StartIPAddress'] = "0.0.0.0"
$PSBoundParameters['EndIPAddress'] = "255.255.255.255"

$null = $PSBoundParameters.Remove('AllowAll')
}
elseif($PSBoundParameters.ContainsKey('ClientIPAddress'))
{
$PSBoundParameters['StartIPAddress'] = $PSBoundParameters['ClientIPAddress']
$PSBoundParameters['EndIPAddress'] = $PSBoundParameters['ClientIPAddress']

if(!$PSBoundParameters.ContainsKey('Name'))
{
$PSBoundParameters['Name'] = "ClientIPAddress_" + (Get-Date -Format "yyyy-MM-dd_HH-mm-ss")
}

$null = $PSBoundParameters.Remove('ClientIPAddress')
}
else
{
if(!$PSBoundParameters.ContainsKey('Name'))
{
$PSBoundParameters['Name'] = "undefined"
}
}

Az.PostgreSql.internal\New-AzPostgreSqlFirewallRule @PSBoundParameters
} catch {
throw
}
}
}
17 changes: 12 additions & 5 deletions src/PostgreSql/custom/New-AzPostgreSqlReplica.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ function New-AzPostgreSqlReplica {
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Description('Creates a new replica from an existing database.')]
param(
[Parameter(Mandatory, HelpMessage = 'The name of the server.')]
[Alias('ReplicaServerName')]
[Alias('ReplicaServerName', 'Name')]
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Path')]
[System.String]
${Name},
${ReplicaName},

[Parameter(Mandatory, HelpMessage = 'The name of the resource group that contains the resource, You can obtain this value from the Azure Resource Manager API or the portal.')]
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Path')]
Expand All @@ -36,9 +36,10 @@ function New-AzPostgreSqlReplica {
${SubscriptionId},

[Parameter(Mandatory, ValueFromPipeline, HelpMessage = 'The source server object to create replica from.')]
[Alias('InputObject')]
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Body')]
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Models.Api20171201.IServer]
${InputObject},
${Master},

[Parameter(HelpMessage = 'The location the resource resides in.')]
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Body')]
Expand Down Expand Up @@ -112,10 +113,10 @@ function New-AzPostgreSqlReplica {
$Parameter.Property = [Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Models.Api20171201.ServerPropertiesForReplica]::new()
$Parameter.CreateMode = [Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Support.CreateMode]::Replica

$server = $PSBoundParameters['InputObject']
$server = $PSBoundParameters['Master']
$Parameter.Property.SourceServerId = $server.Id
$Parameter.Location = $server.Location
$null = $PSBoundParameters.Remove('InputObject')
$null = $PSBoundParameters.Remove('Master')

if ($PSBoundParameters.ContainsKey('Location')) {
$Parameter.Location = $PSBoundParameters['Location']
Expand All @@ -127,6 +128,12 @@ function New-AzPostgreSqlReplica {
$null = $PSBoundParameters.Remove('Sku')
}

if ($PSBoundParameters.ContainsKey('ReplicaName'))
{
$PSBoundParameters['Name'] = $PSBoundParameters['ReplicaName']
$null = $PSBoundParameters.Remove('ReplicaName')
}

$PSBoundParameters.Add('Parameter', $Parameter)

Az.PostgreSql.internal\New-AzPostgreSqlServer @PSBoundParameters
Expand Down
3 changes: 2 additions & 1 deletion src/PostgreSql/custom/New-AzPostgreSqlServer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ function New-AzPostgreSqlServer {

[Parameter(HelpMessage = 'Enable Storage Auto Grow.')]
[ArgumentCompleter([Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Support.StorageAutogrow])]
[Validateset('Enabled', 'Disabled')]
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Body')]
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Support.StorageAutogrow]
${StorageAutogrow},
Expand Down Expand Up @@ -211,7 +212,7 @@ function New-AzPostgreSqlServer {
$Parameter.Property.AdministratorLogin = $PSBoundParameters['AdministratorUserName']
$null = $PSBoundParameters.Remove('AdministratorUserName')

$Parameter.Property.AdministratorLoginPassword = [System.Runtime.InteropServices.marshal]::PtrToStringAuto([System.Runtime.InteropServices.marshal]::SecureStringToBSTR($PSBoundParameters['AdministratorLoginPassword']))
$Parameter.Property.AdministratorLoginPassword = . "$PSScriptRoot/../utils/Unprotect-SecureString.ps1" $PSBoundParameters['AdministratorLoginPassword']
$null = $PSBoundParameters.Remove('AdministratorLoginPassword')

$PSBoundParameters.Add('Parameter', $Parameter)
Expand Down
143 changes: 143 additions & 0 deletions src/PostgreSql/custom/Update-AzPostgreSqlConfiguration.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@

# ----------------------------------------------------------------------------------
#
# Copyright Microsoft Corporation
# 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.
# ----------------------------------------------------------------------------------

<#
.Synopsis
Updates a configuration of a server.
Use Update-AzPostgreSqlServer instead if you want update AdministratorLoginPassword, sku, etc.
.Description
Updates a configuration of a server.
Use Update-AzPostgreSqlServer instead if you want update AdministratorLoginPassword, sku, etc.
#>
function Update-AzPostgreSqlConfiguration {
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Models.Api20171201.IConfiguration])]
[CmdletBinding(DefaultParameterSetName='UpdateExpanded', PositionalBinding=$false, SupportsShouldProcess, ConfirmImpact='Medium')]
param(
[Parameter(ParameterSetName='UpdateExpanded', Mandatory)]
[Alias('ConfigurationName')]
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Path')]
[System.String]
# The name of the server configuration.
${Name},

[Parameter(ParameterSetName='UpdateExpanded', Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Path')]
[System.String]
# The name of the resource group.
# The name is case insensitive.
${ResourceGroupName},

[Parameter(ParameterSetName='UpdateExpanded', Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Path')]
[System.String]
# The name of the server.
${ServerName},

[Parameter(ParameterSetName='UpdateExpanded')]
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Path')]
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Runtime.DefaultInfo(Script='(Get-AzContext).Subscription.Id')]
[System.String]
# The ID of the target subscription.
${SubscriptionId},

[Parameter(ParameterSetName='UpdateViaIdentityExpanded', Mandatory, ValueFromPipeline)]
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Path')]
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Models.IPostgreSqlIdentity]
# Identity Parameter
# To construct, see NOTES section for INPUTOBJECT properties and create a hash table.
${InputObject},

[Parameter(ParameterSetName='UpdateExpanded')]
[Parameter(ParameterSetName='UpdateViaIdentityExpanded')]
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Body')]
[System.String]
# Source of the configuration.
${Source},

[Parameter(ParameterSetName='UpdateExpanded')]
[Parameter(ParameterSetName='UpdateViaIdentityExpanded')]
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Body')]
[System.String]
# Value of the configuration.
${Value},

[Parameter()]
[Alias('AzureRMContext', 'AzureCredential')]
[ValidateNotNull()]
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Azure')]
[System.Management.Automation.PSObject]
# The credentials, account, tenant, and subscription used for communication with Azure.
${DefaultProfile},

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

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

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

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

[Parameter()]
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Runtime')]
[System.Management.Automation.SwitchParameter]
# Run the command asynchronously
${NoWait},

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

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

[Parameter(DontShow)]
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Runtime')]
[System.Management.Automation.SwitchParameter]
# Use the default credentials for the proxy
${ProxyUseDefaultCredentials}
)

process {
try {
Az.PostgreSql.internal\Update-AzPostgreSqlConfiguration @PSBoundParameters
} catch {
throw
}
}
}
Loading