Skip to content

Commit

Permalink
Added Set-CouchDBMaintenanceMode cmdlet
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoGuadrini committed May 28, 2021
1 parent 7a7645b commit 983d4f7
Show file tree
Hide file tree
Showing 14 changed files with 131 additions and 4 deletions.
4 changes: 3 additions & 1 deletion PSCouchDB/PSCouchDB.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
"Set-CouchDBRevisionLimit",
"Set-CouchDBSession",
"Set-CouchDBProxy",
"Set-CouchDBMaintenanceMode",
"Grant-CouchDBDatabasePermission",
"Revoke-CouchDBDatabasePermission",
"Request-CouchDBReplication",
Expand Down Expand Up @@ -290,7 +291,8 @@
"rmdoc",
"rmuser",
"rmadmin",
"cdsa"
"cdsa",
"cdbmaint"
)

# DSC resources to export from this module
Expand Down
1 change: 1 addition & 0 deletions PSCouchDB/alias/CouchDBalias.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ New-Alias -Name "scrpl" -Value Set-CouchDBReplication -Option ReadOnly
New-Alias -Name "scrl" -Value Set-CouchDBRevisionLimit -Option ReadOnly
New-Alias -Name "scs" -Value Set-CouchDBSession -Option ReadOnly
New-Alias -Name "sps" -Value Set-CouchDBProxy -Option ReadOnly
New-Alias -Name "cdbmaint" -Value Set-CouchDBMaintenanceMode -Option ReadOnly
New-Alias -Name "gcdbp" -Value Grant-CouchDBDatabasePermission -Option ReadOnly
New-Alias -Name "rcdbp" -Value Revoke-CouchDBDatabasePermission -Option ReadOnly
New-Alias -Name "rcdbr" -Value Request-CouchDBReplication -Option ReadOnly
Expand Down
65 changes: 65 additions & 0 deletions PSCouchDB/functions/CouchDBserver.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1046,3 +1046,68 @@ function Remove-CouchDBProxy () {
$Global:PSDefaultParameterValues["*CouchDB*:ProxyCredential"] = $null
$Global:PSDefaultParameterValues["*CouchDB*:ProxyServer"] = $null
}

function Set-CouchDBMaintenanceMode () {
<#
.SYNOPSIS
Enable/Disable maintenance mode.
.DESCRIPTION
Enable/Disable maintenance mode.
.NOTES
CouchDB API:
GET /_db_updates
.PARAMETER Server
The CouchDB server name. Default is localhost.
.PARAMETER Port
The CouchDB server port. Default is 5984.
.PARAMETER Node
The CouchDB node of cluster. Default is couchdb@localhost.
.PARAMETER Maintenance
Maintenance on/off. Default is $true.
.PARAMETER Authorization
The CouchDB authorization form; user and password.
Authorization format like this: user:password
ATTENTION: if the password is not specified, it will be prompted.
.PARAMETER Ssl
Set ssl connection on CouchDB server.
This modify protocol to https and port to 6984.
.PARAMETER ProxyServer
Proxy server through which all non-local calls pass.
Ex. ... -ProxyServer 'http://myproxy.local:8080' ...
.PARAMETER ProxyCredential
Proxy server credential. It must be specified with a PSCredential object.
.EXAMPLE
Set-CouchDBMaintenanceMode -Authorization admin:password
Enable maintenance mode.
.EXAMPLE
Set-CouchDBMaintenanceMode -Maintenance:$false -Authorization admin:password
Disable maintenance mode.
.LINK
https://pscouchdb.readthedocs.io/en/latest/server.html#server-operation
#>
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline = $true)]
[string] $Server,
[int] $Port,
[string] $Node,
[bool] $Maintenance = $true,
$Authorization,
[switch] $Ssl,
[string] $ProxyServer,
[pscredential] $ProxyCredential
)
# Compose doc
if (-not($Node)) {
if ((Get-CouchDBNode -Server $Server -Port $Port -Authorization $Authorization -Ssl:$Ssl -ProxyServer $ProxyServer -ProxyCredential $ProxyCredential).name) {
$Node = (Get-CouchDBNode -Server $Server -Port $Port -Authorization $Authorization -Ssl:$Ssl -ProxyServer $ProxyServer -ProxyCredential $ProxyCredential).name
} else {
$Node = Read-Host "Enter the node name (ex. couchdb@localhost)"
}
}
$Database = "_node"
$Document = "$Node/_config/couchdb/maintenance_mode"
$Data = $Maintenance | ConvertTo-Json
# Request
Send-CouchDBRequest -Server $Server -Port $Port -Method "PUT" -Database $Database -Document $Document -Data $Data -Authorization $Authorization -Ssl:$Ssl -ProxyServer $ProxyServer -ProxyCredential $ProxyCredential
}
Binary file modified docs/build/doctrees/cmdlets.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/build/doctrees/server.doctree
Binary file not shown.
6 changes: 6 additions & 0 deletions docs/build/html/_sources/cmdlets.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@ Server
Remove-CouchDBReshards [[-Server] <String>] [[-Port] <Int32>] [-JobId] <String> [[-Authorization] <Object>] [-Ssl] [[-ProxyServer] <String>] [[-ProxyCredential] <PSCredential>] [<CommonParameters>]
**Set-CouchDBMaintenanceMode**

.. code-block:: powershell
Set-CouchDBMaintenanceMode [[-Server] <String>] [[-Port] <Int32>] [[-Node] <String>] [[-Maintenance] <Boolean>] [[-Authorization] <Object>] [-Ssl] [[-ProxyServer] <String>] [[-ProxyCredential] <PSCredential>] [<CommonParameters>]
Replication
***********

Expand Down
17 changes: 16 additions & 1 deletion docs/build/html/_sources/server.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -309,4 +309,19 @@ Request, configure, or stop, a replication operation.
using module PSCouchDB
$rep = New-Object PSCouchDBReplication -ArgumentList 'test','test_dump'
$rep.AddDocIds(@("Hitchhikers","Hitchhikers_Guide"))
Request-CouchDBReplication -Data $rep -Authorization "admin:password"
Request-CouchDBReplication -Data $rep -Authorization "admin:password"
Enable/Disable Maintenance
__________________________

Enable maintenance mode.

.. code-block:: powershell
Set-CouchDBMaintenanceMode -Authorization "admin:password"
Disable maintenance mode.

.. code-block:: powershell
Set-CouchDBMaintenanceMode -Maintenance $false -Authorization "admin:password"
4 changes: 4 additions & 0 deletions docs/build/html/cmdlets.html
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,10 @@ <h3>Server<a class="headerlink" href="#server" title="Permalink to this headline
<div class="highlight-powershell notranslate"><div class="highlight"><pre><span></span><span class="nb">Remove-CouchDBReshards</span> <span class="p">[[</span><span class="n">-Server</span><span class="p">]</span> <span class="p">&lt;</span><span class="n">String</span><span class="p">&gt;]</span> <span class="p">[[</span><span class="n">-Port</span><span class="p">]</span> <span class="p">&lt;</span><span class="n">Int32</span><span class="p">&gt;]</span> <span class="p">[</span><span class="n">-JobId</span><span class="p">]</span> <span class="p">&lt;</span><span class="n">String</span><span class="p">&gt;</span> <span class="p">[[</span><span class="n">-Authorization</span><span class="p">]</span> <span class="p">&lt;</span><span class="n">Object</span><span class="p">&gt;]</span> <span class="p">[</span><span class="n">-Ssl</span><span class="p">]</span> <span class="p">[[</span><span class="n">-ProxyServer</span><span class="p">]</span> <span class="p">&lt;</span><span class="n">String</span><span class="p">&gt;]</span> <span class="p">[[</span><span class="n">-ProxyCredential</span><span class="p">]</span> <span class="p">&lt;</span><span class="n">PSCredential</span><span class="p">&gt;]</span> <span class="p">[&lt;</span><span class="n">CommonParameters</span><span class="p">&gt;]</span>
</pre></div>
</div>
<p><strong>Set-CouchDBMaintenanceMode</strong></p>
<div class="highlight-powershell notranslate"><div class="highlight"><pre><span></span><span class="nb">Set-CouchDBMaintenanceMode</span> <span class="p">[[</span><span class="n">-Server</span><span class="p">]</span> <span class="p">&lt;</span><span class="n">String</span><span class="p">&gt;]</span> <span class="p">[[</span><span class="n">-Port</span><span class="p">]</span> <span class="p">&lt;</span><span class="n">Int32</span><span class="p">&gt;]</span> <span class="p">[[</span><span class="n">-Node</span><span class="p">]</span> <span class="p">&lt;</span><span class="n">String</span><span class="p">&gt;]</span> <span class="p">[[</span><span class="n">-Maintenance</span><span class="p">]</span> <span class="p">&lt;</span><span class="n">Boolean</span><span class="p">&gt;]</span> <span class="p">[[</span><span class="n">-Authorization</span><span class="p">]</span> <span class="p">&lt;</span><span class="n">Object</span><span class="p">&gt;]</span> <span class="p">[</span><span class="n">-Ssl</span><span class="p">]</span> <span class="p">[[</span><span class="n">-ProxyServer</span><span class="p">]</span> <span class="p">&lt;</span><span class="n">String</span><span class="p">&gt;]</span> <span class="p">[[</span><span class="n">-ProxyCredential</span><span class="p">]</span> <span class="p">&lt;</span><span class="n">PSCredential</span><span class="p">&gt;]</span> <span class="p">[&lt;</span><span class="n">CommonParameters</span><span class="p">&gt;]</span>
</pre></div>
</div>
</div>
<div class="section" id="replication">
<h3>Replication<a class="headerlink" href="#replication" title="Permalink to this headline"></a></h3>
Expand Down
1 change: 1 addition & 0 deletions docs/build/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ <h1>Welcome to PSCouchDB’s documentation!<a class="headerlink" href="#welcome-
<li class="toctree-l2"><a class="reference internal" href="server.html#modify-replica">Modify replica</a></li>
<li class="toctree-l2"><a class="reference internal" href="server.html#remove-replica">Remove replica</a></li>
<li class="toctree-l2"><a class="reference internal" href="server.html#replication-request">Replication request</a></li>
<li class="toctree-l2"><a class="reference internal" href="server.html#enable-disable-maintenance">Enable/Disable Maintenance</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="auth.html">Authentication</a></li>
Expand Down
2 changes: 1 addition & 1 deletion docs/build/html/searchindex.js

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions docs/build/html/server.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
<li class="toctree-l2"><a class="reference internal" href="#modify-replica">Modify replica</a></li>
<li class="toctree-l2"><a class="reference internal" href="#remove-replica">Remove replica</a></li>
<li class="toctree-l2"><a class="reference internal" href="#replication-request">Replication request</a></li>
<li class="toctree-l2"><a class="reference internal" href="#enable-disable-maintenance">Enable/Disable Maintenance</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="auth.html">Authentication</a></li>
Expand Down Expand Up @@ -410,6 +411,17 @@ <h2>Replication request<a class="headerlink" href="#replication-request" title="
</pre></div>
</div>
</div>
<div class="section" id="enable-disable-maintenance">
<h2>Enable/Disable Maintenance<a class="headerlink" href="#enable-disable-maintenance" title="Permalink to this headline"></a></h2>
<p>Enable maintenance mode.</p>
<div class="highlight-powershell notranslate"><div class="highlight"><pre><span></span><span class="nb">Set-CouchDBMaintenanceMode</span> <span class="n">-Authorization</span> <span class="s2">&quot;admin:password&quot;</span>
</pre></div>
</div>
<p>Disable maintenance mode.</p>
<div class="highlight-powershell notranslate"><div class="highlight"><pre><span></span><span class="nb">Set-CouchDBMaintenanceMode</span> <span class="n">-Maintenance</span> <span class="nv">$false</span> <span class="n">-Authorization</span> <span class="s2">&quot;admin:password&quot;</span>
</pre></div>
</div>
</div>
</div>


Expand Down
6 changes: 6 additions & 0 deletions docs/source/cmdlets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@ Server
Remove-CouchDBReshards [[-Server] <String>] [[-Port] <Int32>] [-JobId] <String> [[-Authorization] <Object>] [-Ssl] [[-ProxyServer] <String>] [[-ProxyCredential] <PSCredential>] [<CommonParameters>]
**Set-CouchDBMaintenanceMode**

.. code-block:: powershell
Set-CouchDBMaintenanceMode [[-Server] <String>] [[-Port] <Int32>] [[-Node] <String>] [[-Maintenance] <Boolean>] [[-Authorization] <Object>] [-Ssl] [[-ProxyServer] <String>] [[-ProxyCredential] <PSCredential>] [<CommonParameters>]
Replication
***********

Expand Down
17 changes: 16 additions & 1 deletion docs/source/server.rst
Original file line number Diff line number Diff line change
Expand Up @@ -309,4 +309,19 @@ Request, configure, or stop, a replication operation.
using module PSCouchDB
$rep = New-Object PSCouchDBReplication -ArgumentList 'test','test_dump'
$rep.AddDocIds(@("Hitchhikers","Hitchhikers_Guide"))
Request-CouchDBReplication -Data $rep -Authorization "admin:password"
Request-CouchDBReplication -Data $rep -Authorization "admin:password"
Enable/Disable Maintenance
__________________________

Enable maintenance mode.

.. code-block:: powershell
Set-CouchDBMaintenanceMode -Authorization "admin:password"
Disable maintenance mode.

.. code-block:: powershell
Set-CouchDBMaintenanceMode -Maintenance $false -Authorization "admin:password"

0 comments on commit 983d4f7

Please sign in to comment.