Skip to content

Commit 076875c

Browse files
Third minor release of version 2
Fix PSCouchDBDocument guid. Added Partition parameter on Set-CouchDBDocument. Added Set-CouchDBMaintenanceMode cmdlet.
2 parents bc1a758 + dd5231e commit 076875c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+11637
-460
lines changed

CHANGES.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Release notes
22

3+
## 2.3.0
4+
May 28, 2021
5+
6+
- Fix **PSCouchDBDocument** guid.
7+
- Add *Partition* parameter on **Set-CouchDBDocument**.
8+
- Add **Set-CouchDBMaintenanceMode** cmdlet.
9+
310
## 2.2.0
411
Sep 19, 2020
512

PSCouchDB/PSCouchDB.psd1

+4-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
)
2929

3030
# Version number of this module.
31-
ModuleVersion = '2.2.0'
31+
ModuleVersion = '2.3.0'
3232

3333
# Supported PSEditions
3434
# CompatiblePSEditions = @()
@@ -144,6 +144,7 @@
144144
"Set-CouchDBRevisionLimit",
145145
"Set-CouchDBSession",
146146
"Set-CouchDBProxy",
147+
"Set-CouchDBMaintenanceMode",
147148
"Grant-CouchDBDatabasePermission",
148149
"Revoke-CouchDBDatabasePermission",
149150
"Request-CouchDBReplication",
@@ -290,7 +291,8 @@
290291
"rmdoc",
291292
"rmuser",
292293
"rmadmin",
293-
"cdsa"
294+
"cdsa",
295+
"cdbmaint"
294296
)
295297

296298
# DSC resources to export from this module

PSCouchDB/PSCouchDB.psm1

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class PSCouchDBDocument {
2323
# Constructors
2424
# No specified _id
2525
PSCouchDBDocument () {
26-
$this._id = (New-CouchDBUuids -Count 1).uuids[0]
26+
$this._id = (New-Guid).Guid.Replace('-', $null)
2727
$this.doc.Add('_id', $this._id)
2828
}
2929

@@ -1394,6 +1394,7 @@ class PSCouchDBRequest {
13941394
}
13951395
try {
13961396
[System.Net.WebResponse] $resp = $this.client.GetResponse()
1397+
$resp.Close()
13971398
$this.uri.LastStatusCode = $resp.StatusCode
13981399
} catch [System.Net.WebException] {
13991400
[System.Net.HttpWebResponse] $errcode = $_.Exception.Response

PSCouchDB/alias/CouchDBalias.ps1

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ New-Alias -Name "scrpl" -Value Set-CouchDBReplication -Option ReadOnly
5656
New-Alias -Name "scrl" -Value Set-CouchDBRevisionLimit -Option ReadOnly
5757
New-Alias -Name "scs" -Value Set-CouchDBSession -Option ReadOnly
5858
New-Alias -Name "sps" -Value Set-CouchDBProxy -Option ReadOnly
59+
New-Alias -Name "cdbmaint" -Value Set-CouchDBMaintenanceMode -Option ReadOnly
5960
New-Alias -Name "gcdbp" -Value Grant-CouchDBDatabasePermission -Option ReadOnly
6061
New-Alias -Name "rcdbp" -Value Revoke-CouchDBDatabasePermission -Option ReadOnly
6162
New-Alias -Name "rcdbr" -Value Request-CouchDBReplication -Option ReadOnly

PSCouchDB/functions/CouchDBdocument.ps1

+5
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,8 @@ function Set-CouchDBDocument () {
569569
The CouchDB revision document.
570570
.PARAMETER Data
571571
The data in Json format, PSCouchDBDocument or hastable.
572+
.PARAMETER Partition
573+
The CouchDB partition.
572574
.PARAMETER Replace
573575
Overwrite data.
574576
.PARAMETER Attachment
@@ -618,6 +620,7 @@ function Set-CouchDBDocument () {
618620
[Parameter(mandatory = $true)]
619621
[string] $Revision,
620622
$Data,
623+
[string] $Partition,
621624
[switch] $Replace,
622625
[string] $Attachment,
623626
[switch] $BatchMode,
@@ -679,6 +682,8 @@ function Set-CouchDBDocument () {
679682
$parameters += "new_edits=false"
680683
$Revision = $null
681684
}
685+
# Check Partition
686+
if ($Partition) { $Document = "${Partition}:${Document}" }
682687
# Convert doc object to json
683688
$Data = $Data.ToJson(99)
684689
Send-CouchDBRequest -Server $Server -Port $Port -Method "PUT" -Database $Database -Document $Document -Revision $Revision -Params $parameters -Data $Data -Authorization $Authorization -Ssl:$Ssl -ProxyServer $ProxyServer -ProxyCredential $ProxyCredential

PSCouchDB/functions/CouchDBserver.ps1

+65
Original file line numberDiff line numberDiff line change
@@ -1046,3 +1046,68 @@ function Remove-CouchDBProxy () {
10461046
$Global:PSDefaultParameterValues["*CouchDB*:ProxyCredential"] = $null
10471047
$Global:PSDefaultParameterValues["*CouchDB*:ProxyServer"] = $null
10481048
}
1049+
1050+
function Set-CouchDBMaintenanceMode () {
1051+
<#
1052+
.SYNOPSIS
1053+
Enable/Disable maintenance mode.
1054+
.DESCRIPTION
1055+
Enable/Disable maintenance mode.
1056+
.NOTES
1057+
CouchDB API:
1058+
GET /_db_updates
1059+
.PARAMETER Server
1060+
The CouchDB server name. Default is localhost.
1061+
.PARAMETER Port
1062+
The CouchDB server port. Default is 5984.
1063+
.PARAMETER Node
1064+
The CouchDB node of cluster. Default is couchdb@localhost.
1065+
.PARAMETER Maintenance
1066+
Maintenance on/off. Default is $true.
1067+
.PARAMETER Authorization
1068+
The CouchDB authorization form; user and password.
1069+
Authorization format like this: user:password
1070+
ATTENTION: if the password is not specified, it will be prompted.
1071+
.PARAMETER Ssl
1072+
Set ssl connection on CouchDB server.
1073+
This modify protocol to https and port to 6984.
1074+
.PARAMETER ProxyServer
1075+
Proxy server through which all non-local calls pass.
1076+
Ex. ... -ProxyServer 'http://myproxy.local:8080' ...
1077+
.PARAMETER ProxyCredential
1078+
Proxy server credential. It must be specified with a PSCredential object.
1079+
.EXAMPLE
1080+
Set-CouchDBMaintenanceMode -Authorization admin:password
1081+
Enable maintenance mode.
1082+
.EXAMPLE
1083+
Set-CouchDBMaintenanceMode -Maintenance:$false -Authorization admin:password
1084+
Disable maintenance mode.
1085+
.LINK
1086+
https://pscouchdb.readthedocs.io/en/latest/server.html#server-operation
1087+
#>
1088+
[CmdletBinding()]
1089+
param(
1090+
[Parameter(ValueFromPipeline = $true)]
1091+
[string] $Server,
1092+
[int] $Port,
1093+
[string] $Node,
1094+
[bool] $Maintenance = $true,
1095+
$Authorization,
1096+
[switch] $Ssl,
1097+
[string] $ProxyServer,
1098+
[pscredential] $ProxyCredential
1099+
)
1100+
# Compose doc
1101+
if (-not($Node)) {
1102+
if ((Get-CouchDBNode -Server $Server -Port $Port -Authorization $Authorization -Ssl:$Ssl -ProxyServer $ProxyServer -ProxyCredential $ProxyCredential).name) {
1103+
$Node = (Get-CouchDBNode -Server $Server -Port $Port -Authorization $Authorization -Ssl:$Ssl -ProxyServer $ProxyServer -ProxyCredential $ProxyCredential).name
1104+
} else {
1105+
$Node = Read-Host "Enter the node name (ex. couchdb@localhost)"
1106+
}
1107+
}
1108+
$Database = "_node"
1109+
$Document = "$Node/_config/couchdb/maintenance_mode"
1110+
$Data = $Maintenance | ConvertTo-Json
1111+
# Request
1112+
Send-CouchDBRequest -Server $Server -Port $Port -Method "PUT" -Database $Database -Document $Document -Data $Data -Authorization $Authorization -Ssl:$Ssl -ProxyServer $ProxyServer -ProxyCredential $ProxyCredential
1113+
}

docs/build/doctrees/auth.doctree

20 Bytes
Binary file not shown.

docs/build/doctrees/classes.doctree

-548 Bytes
Binary file not shown.

docs/build/doctrees/cmdlets.doctree

-1.18 KB
Binary file not shown.

docs/build/doctrees/config.doctree

-43 Bytes
Binary file not shown.

docs/build/doctrees/databases.doctree

1 Byte
Binary file not shown.

docs/build/doctrees/ddoc.doctree

-91 Bytes
Binary file not shown.

docs/build/doctrees/documents.doctree

115 Bytes
Binary file not shown.
1.01 KB
Binary file not shown.

docs/build/doctrees/index.doctree

15 Bytes
Binary file not shown.

docs/build/doctrees/intro.doctree

-251 Bytes
Binary file not shown.
-81 Bytes
Binary file not shown.

docs/build/doctrees/server.doctree

1.04 KB
Binary file not shown.

docs/build/doctrees/support.doctree

68 Bytes
Binary file not shown.

docs/build/doctrees/uses.doctree

-94 Bytes
Binary file not shown.

docs/build/html/.buildinfo

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Sphinx build info version 1
22
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
3-
config: aa916f445d3f5a8bbc098f4ea69de939
3+
config: 7842dbe2cdf77bebdb8cc379df60cf5c
44
tags: 645f666f9bcd5a90fca523b33c5a78b7

docs/build/html/_sources/cmdlets.rst.txt

+7-1
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,12 @@ Server
245245
246246
Remove-CouchDBReshards [[-Server] <String>] [[-Port] <Int32>] [-JobId] <String> [[-Authorization] <Object>] [-Ssl] [[-ProxyServer] <String>] [[-ProxyCredential] <PSCredential>] [<CommonParameters>]
247247
248+
**Set-CouchDBMaintenanceMode**
249+
250+
.. code-block:: powershell
251+
252+
Set-CouchDBMaintenanceMode [[-Server] <String>] [[-Port] <Int32>] [[-Node] <String>] [[-Maintenance] <Boolean>] [[-Authorization] <Object>] [-Ssl] [[-ProxyServer] <String>] [[-ProxyCredential] <PSCredential>] [<CommonParameters>]
253+
248254
Replication
249255
***********
250256

@@ -489,7 +495,7 @@ Documents
489495

490496
.. code-block:: powershell
491497
492-
Set-CouchDBDocument [[-Server] <String>] [[-Port] <Int32>] [-Database] <String> [-Document] <String> [-Revision] <String> [[-Data] <Object>] [-Replace] [[-Attachment] <String>] [-BatchMode] [-NoConflict] [[-Authorization] <String>] [-Ssl] [[-ProxyServer] <String>] [[-ProxyCredential] <Object>] [<CommonParameters>]
498+
Set-CouchDBDocument [[-Server] <String>] [[-Port] <Int32>] [-Database] <String> [-Document] <String> [-Revision] <String> [[-Data] <Object>] [[-Partition] <String>] [-Replace] [[-Attachment] <String>] [-BatchMode] [-NoConflict] [[-Authorization] <Object>] [-Ssl] [[-ProxyServer] <String>] [[-ProxyCredential] <PSCredential>] [<CommonParameters>]
493499
494500
**Remove-CouchDBDocument**
495501

docs/build/html/_sources/documents.rst.txt

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Latest Forces retrieving latest “leaf” revision, no matter what
5252
LocalSequence Includes last update sequence for the document.
5353
Metadata Acts same as specifying all conflicts, deleted_conflicts and revs_info query parameters.
5454
OpenRevisions Retrieves documents of specified leaf revisions. Additionally, value all id default and to return all leaf revisions.
55+
Partition CouchDB partition name
5556
================ ===========
5657

5758
And if use **_all_docs** view, in this table you can find all the possible parameters.

docs/build/html/_sources/server.rst.txt

+16-1
Original file line numberDiff line numberDiff line change
@@ -309,4 +309,19 @@ Request, configure, or stop, a replication operation.
309309
using module PSCouchDB
310310
$rep = New-Object PSCouchDBReplication -ArgumentList 'test','test_dump'
311311
$rep.AddDocIds(@("Hitchhikers","Hitchhikers_Guide"))
312-
Request-CouchDBReplication -Data $rep -Authorization "admin:password"
312+
Request-CouchDBReplication -Data $rep -Authorization "admin:password"
313+
314+
Enable/Disable Maintenance
315+
__________________________
316+
317+
Enable maintenance mode.
318+
319+
.. code-block:: powershell
320+
321+
Set-CouchDBMaintenanceMode -Authorization "admin:password"
322+
323+
Disable maintenance mode.
324+
325+
.. code-block:: powershell
326+
327+
Set-CouchDBMaintenanceMode -Maintenance $false -Authorization "admin:password"

0 commit comments

Comments
 (0)