├── PSArangoDB.psm1 ├── public ├── func_Get-Databases.ps1 ├── func_Remove-Document.ps1 ├── func_New-Document.ps1 ├── func_Update-Document.ps1 ├── func_New-AQLQuery.ps1 ├── func_Set-Environment.ps1 └── func_Get-Document.ps1 ├── private └── func_Test-Environment.ps1 ├── README.md └── PSArangoDB.psd1 /PSArangoDB.psm1: -------------------------------------------------------------------------------- 1 | Get-ChildItem (Split-Path $script:MyInvocation.MyCommand.Path) -Filter 'func_*.ps1' -Recurse | ForEach-Object { 2 | . $_.FullName 3 | } 4 | Get-ChildItem "$(Split-Path $script:MyInvocation.MyCommand.Path)\public\*" -Filter 'func_*.ps1' -Recurse | ForEach-Object { 5 | Export-ModuleMember -Function ($_.BaseName -Split "_")[1] 6 | } 7 | Get-ChildItem "$(Split-Path $script:MyInvocation.MyCommand.Path)\private\*" -Filter 'func_*.ps1' -Recurse | ForEach-Object { 8 | Export-ModuleMember -Function ($_.BaseName -Split "_")[1] 9 | } -------------------------------------------------------------------------------- /public/func_Get-Databases.ps1: -------------------------------------------------------------------------------- 1 | function Get-Databases { 2 | <# 3 | .SYNOPSIS 4 | Get's all databases that the user has access to 5 | .DESCRIPTION 6 | Get's all databases that the user has access to 7 | .NOTES 8 | Name: Get-Databases 9 | Author: Morten Johansen 10 | Version: 0.0.1 11 | DateCreated: 2022-June-11 12 | DateUpdated: XXXX-XXX-XX 13 | .EXAMPLE 14 | Get-Databases 15 | Will return the databases that the user has access to 16 | #> 17 | if(!(Test-Environment)) { 18 | $_ 19 | } 20 | try { 21 | (Invoke-RestMethod -Uri $Global:ArangoDBURL":"$Global:ArangoDBPort/_api/database/user -Headers $Global:ArangoDBHeader).result 22 | } 23 | catch { 24 | Write-Host "There was an error in your web request!" -ForegroundColor red 25 | Write-Host "Exception Message: $($_.Exception.Message)" -ForegroundColor Red 26 | break 27 | } 28 | } -------------------------------------------------------------------------------- /private/func_Test-Environment.ps1: -------------------------------------------------------------------------------- 1 | function Test-Environment { 2 | <# 3 | .SYNOPSIS 4 | Private function to check if the environment values are set 5 | .DESCRIPTION 6 | Private function to check if the environment values are set 7 | .NOTES 8 | Name: Test-Environment 9 | Author: Morten Johansen 10 | Version: 0.0.1 11 | DateCreated: 2022-June-11 12 | DateUpdated: XXXX-XXX-XX 13 | .EXAMPLE 14 | Test-Environment 15 | Will test if the ArangoDB API environment is set 16 | #> 17 | if (!$Global:ArangoDBToken -or !$Global:ArangoDBHeader -or !$Global:ArangoDBURL -or !$Global:ArangoDBPort -or !$Global:ArangoDBDatabase -or !$Global:ArangoDBAPIUrl) { 18 | Write-Host "ArangoDBToken, ArangoDBHeader, ArangoDBURL, ArangoDBPort, ArangoDBDatabase or ArangoDBAPIUrl are not set (one or more), please use Set-Environment before running this function" -ForegroundColor Red 19 | break 20 | } else { 21 | $true 22 | } 23 | } -------------------------------------------------------------------------------- /public/func_Remove-Document.ps1: -------------------------------------------------------------------------------- 1 | function Remove-Document { 2 | <# 3 | .SYNOPSIS 4 | Remove document in a collection 5 | .DESCRIPTION 6 | Remove document in a collection 7 | .NOTES 8 | Name: Remove-Document 9 | Author: Morten Johansen 10 | Version: 0.0.1 11 | DateCreated: 2022-June-12 12 | DateUpdated: XXXX-XXX-XX 13 | .PARAMETER Collection 14 | Collection where the document is located 15 | .PARAMETER Key 16 | Key of the document to remove 17 | .EXAMPLE 18 | Remove-Document -Collection 'test_collection' -Key '9436' 19 | Remove document 9436 in the collection test_collection 20 | #> 21 | [CmdletBinding()] 22 | param ( 23 | [Parameter(Mandatory=$true,Position=0,HelpMessage='Enter collection where the document is located.')] 24 | [string]$Collection, 25 | [Parameter(Mandatory=$true,Position=1,HelpMessage='Enter key of the document to delete.')] 26 | [string]$Key 27 | ) 28 | if(!(Test-Environment)) { 29 | $_ 30 | } 31 | try { 32 | Invoke-RestMethod -Uri $Global:ArangoDBAPIUrl"document/"$Collection"/"$Key -Headers $Global:ArangoDBHeader -Method Delete 33 | } 34 | catch { 35 | Write-Host "There was an error in your web request!" -ForegroundColor red 36 | Write-Host "Exception Message: $($_.Exception.Message)" -ForegroundColor Red 37 | break 38 | } 39 | } -------------------------------------------------------------------------------- /public/func_New-Document.ps1: -------------------------------------------------------------------------------- 1 | function New-Document { 2 | <# 3 | .SYNOPSIS 4 | Create new document in collection 5 | .DESCRIPTION 6 | Create new document in collection 7 | .NOTES 8 | Name: New-Document 9 | Author: Morten Johansen 10 | Version: 0.0.1 11 | DateCreated: 2022-June-11 12 | DateUpdated: XXXX-XXX-XX 13 | .PARAMETER Collection 14 | Collection to add the document to 15 | .PARAMETER Data 16 | Data to add (as json) 17 | .EXAMPLE 18 | $json = @{display_name="John Doe";title="Director";email="john@doe.com";} | ConvertTo-Json 19 | New-Document -Collection 'test_collection' -Data $json 20 | Add a new document to the collection test_collection 21 | #> 22 | [CmdletBinding()] 23 | param ( 24 | [Parameter(Mandatory=$true,Position=0,HelpMessage='Enter collection to add the document to.')] 25 | [string]$Collection, 26 | [Parameter(Mandatory=$true,Position=1,HelpMessage='Data to add (json).')] 27 | [string]$Data 28 | ) 29 | if(!(Test-Environment)) { 30 | $_ 31 | } 32 | try { 33 | Invoke-RestMethod -Uri $Global:ArangoDBAPIUrl"document/"$Collection -Headers $Global:ArangoDBHeader -Method Post -Body $Data -ContentType 'application/json; charset=utf-8' 34 | } 35 | catch { 36 | Write-Host "There was an error in your web request!" -ForegroundColor red 37 | Write-Host "Exception Message: $($_.Exception.Message)" -ForegroundColor Red 38 | break 39 | } 40 | } -------------------------------------------------------------------------------- /public/func_Update-Document.ps1: -------------------------------------------------------------------------------- 1 | function Update-Document { 2 | <# 3 | .SYNOPSIS 4 | Update document in a collection 5 | .DESCRIPTION 6 | Update document in a collection 7 | .NOTES 8 | Name: Update-Document 9 | Author: Morten Johansen 10 | Version: 0.0.1 11 | DateCreated: 2022-June-12 12 | DateUpdated: XXXX-XXX-XX 13 | .PARAMETER Collection 14 | Collection where the document is located 15 | .PARAMETER Key 16 | Key of the document to update 17 | .PARAMETER Data 18 | Data to update (as json) 19 | .EXAMPLE 20 | $json = @{display_name="John Doe";} | ConvertTo-Json 21 | Update-Document -Collection 'test_collection' -Key '9436' -Data $json 22 | Update document 9436 in the collection test_collection 23 | #> 24 | [CmdletBinding()] 25 | param ( 26 | [Parameter(Mandatory=$true,Position=0,HelpMessage='Enter collection where the document is located.')] 27 | [string]$Collection, 28 | [Parameter(Mandatory=$true,Position=1,HelpMessage='Enter key of the document to update.')] 29 | [string]$Key, 30 | [Parameter(Mandatory=$true,Position=2,HelpMessage='Data to update (json).')] 31 | [string]$Data 32 | ) 33 | if(!(Test-Environment)) { 34 | $_ 35 | } 36 | try { 37 | Invoke-RestMethod -Uri $Global:ArangoDBAPIUrl"document/"$Collection"/"$Key -Headers $Global:ArangoDBHeader -Method Patch -Body $Data -ContentType 'application/json; charset=utf-8' 38 | } 39 | catch { 40 | Write-Host "There was an error in your web request!" -ForegroundColor red 41 | Write-Host "Exception Message: $($_.Exception.Message)" -ForegroundColor Red 42 | break 43 | } 44 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
5 | 9 | 10 | # PSArangoDB - PowerShell Module 11 | 12 | This module provides a series of functions to work with the [ArangoDB](https://www.arangodb.com) API. Use Get-Help on the functions to get further details of usage. 13 | 14 | ## Requirements 15 | 16 | Requires PowerShell 5.1 or above. 17 | 18 | ## Usage 19 | 20 | ### 1. PSGallery 21 | Install module from PSGallery. 22 | `Find-Module PSArangoDB -Repository PSGallery | Install-Module` 23 | ### 2. Manual 24 | Download or clone the latest files and place the module folder in your PowerShell profile directory (i.e. the `Modules` directory under wherever `$profile` points to in your PS console) and run: 25 | `Import-Module PSArangoDB` 26 | Once you've done this, all the cmdlets will be at your disposal, you can see a full list using `Get-Command -Module PSArangoDB`. Remember to run Set-Environment before beginning to work with ArangoDB. 27 | 28 | ## Functions 29 | 30 | * Get-Database 31 | * Get-Document 32 | * New-AQLQuery 33 | * New-Document 34 | * Remove-Document 35 | * Set-Environment 36 | * Update-Document 37 | 38 | ## Changelog 39 | 40 | * 0.0.4 - 10-11-2022 41 | * Fix content-type/utf8 with -ContentType 42 | * 0.0.3 - 10-11-2022 43 | * Fix content-type/utf8 for header in Set-Environment 44 | * 0.0.2 - 17-06-2022 45 | * Added pagination support for Get-Document 46 | * 0.0.1 - 11-06-2022 47 | * Initial release of module -------------------------------------------------------------------------------- /public/func_New-AQLQuery.ps1: -------------------------------------------------------------------------------- 1 | function New-AQLQuery { 2 | <# 3 | .SYNOPSIS 4 | Run AQL query against ArangoDB 5 | .DESCRIPTION 6 | Run AQL query against ArangoDB 7 | .NOTES 8 | Name: New-AQLQuery 9 | Author: Morten Johansen 10 | Version: 0.0.1 11 | DateCreated: 2022-June-12 12 | DateUpdated: XXXX-XXX-XX 13 | .PARAMETER Query 14 | AQL query to run 15 | .EXAMPLE 16 | New-AQLQuery -Query 'RETURN DOCUMENT("some_collection/4608")' 17 | Return document 4608 from some_collection 18 | .EXAMPLE 19 | New-AQLQuery -Query 'FOR x IN some_collection RETURN x' 20 | Iterate thru alle documents in the collection some_collection 21 | .EXAMPLE 22 | New-AQLQuery -Query 'INSERT { display_name: "Katie Foster", title: "Student", email: "kf@domain.com" } INTO some_collection' 23 | Create a new document in the collection some_collection 24 | .EXAMPLE 25 | New-AQLQuery -Query 'INSERT { display_name: "Katie Foster", title: "Student", email: "kf@domain.com" } INTO some_collection RETURN NEW' 26 | Create a new document in the collection some_collection and return the newly created document 27 | .EXAMPLE 28 | New-AQLQuery -Query 'UPDATE "77420" WITH { display_name: "Luke Skywalker" } IN some_collection RETURN NEW' 29 | Update document 77420 in some_collection and return the updated document 30 | #> 31 | [CmdletBinding()] 32 | param ( 33 | [Parameter(Mandatory=$true,Position=0,HelpMessage='AQL query to run')] 34 | [string]$Query 35 | ) 36 | if(!(Test-Environment)) { 37 | $_ 38 | } 39 | try { 40 | $body = @{query=$Query;} | ConvertTo-Json 41 | (Invoke-RestMethod -Uri $Global:ArangoDBAPIUrl"/cursor" -Headers $Global:ArangoDBHeader -Method Post -Body $body -ContentType 'application/json; charset=utf-8').result 42 | } 43 | catch { 44 | Write-Host "There was an error in your web request!" -ForegroundColor red 45 | Write-Host "Exception Message: $($_.Exception.Message)" -ForegroundColor Red 46 | break 47 | } 48 | } -------------------------------------------------------------------------------- /public/func_Set-Environment.ps1: -------------------------------------------------------------------------------- 1 | function Set-Environment { 2 | <# 3 | .SYNOPSIS 4 | Set's the ArangoDBToken, ArangoDBHeader and ArangoDBURL for calls against the ArangoDB API 5 | .DESCRIPTION 6 | Set's the ArangoDBToken, ArangoDBHeader and ArangoDBURL for calls against the ArangoDB API 7 | .NOTES 8 | Name: Set-Environment 9 | Author: Morten Johansen 10 | Version: 0.0.1 11 | DateCreated: 2022-June-11 12 | DateUpdated: 2022-November-10 13 | .PARAMETER Url 14 | Url of ArangoDB 15 | .PARAMETER Port 16 | Port of ArangoDB 17 | .PARAMETER User 18 | Username for accessing ArangoDB 19 | .PARAMETER Pass 20 | Password for accessing ArangoDB 21 | .PARAMETER Database 22 | Name of the database to work against 23 | .EXAMPLE 24 | Set-Environment -Url 'https://arangodb.domain.com' -Port '8529' -User 'sa_someuser' -Pass 'secret_password' -Database 'test_DB' 25 | Will set all global variables for the ArangoDB environment 26 | #> 27 | [CmdletBinding()] 28 | param ( 29 | [Parameter(Mandatory=$true,Position=0,HelpMessage='Enter url of ArangoDB.')] 30 | [string]$Url, 31 | [Parameter(Mandatory=$true,Position=1,HelpMessage='Enter port of ArangoDB.')] 32 | [string]$Port, 33 | [Parameter(Mandatory=$true,Position=2,HelpMessage='Enter username of ArangoDB.')] 34 | [string]$User, 35 | [Parameter(Mandatory=$true,Position=3,HelpMessage='Enter password of ArangoDB.')] 36 | [string]$Pass, 37 | [Parameter(Mandatory=$true,Position=4,HelpMessage='Enter name of the database to work against.')] 38 | [string]$Database 39 | ) 40 | try { 41 | $json = @{username="$($User)";password="$($Pass)";} | ConvertTo-Json 42 | $jwt = (Invoke-RestMethod $Url":"$Port/_open/auth -Body $json -Method Post).jwt 43 | $headers = @{ 44 | "Authorization" = "Bearer $jwt" 45 | "Content-Type" = "application/json; charset=utf-8" 46 | } 47 | Set-Variable -Name ArangoDBToken -Scope Global -Value $jwt 48 | Set-Variable -Name ArangoDBHeader -Scope Global -Value $headers 49 | Set-Variable -Name ArangoDBURL -Scope Global -Value $Url 50 | Set-Variable -Name ArangoDBPort -Scope Global -Value $Port 51 | Set-Variable -Name ArangoDBDatabase -Scope Global -Value $Database 52 | Set-Variable -Name ArangoDBAPIUrl -Scope Global -Value $Url":"$Port"/_db/"$Database"/_api/" 53 | } 54 | catch { 55 | Write-Host "Failed to set the global variables!" -ForegroundColor red 56 | Write-Host "Exception Message: $($_.Exception.Message)" -ForegroundColor Red 57 | break 58 | } 59 | } -------------------------------------------------------------------------------- /public/func_Get-Document.ps1: -------------------------------------------------------------------------------- 1 | function Get-Document { 2 | <# 3 | .SYNOPSIS 4 | Get's a single or more documents from a collection 5 | .DESCRIPTION 6 | Get's a single or more documents from a collection 7 | .NOTES 8 | Name: Get-Document 9 | Author: Morten Johansen 10 | Version: 0.0.2 11 | DateCreated: 2022-June-11 12 | DateUpdated: 2022-June-17 13 | .PARAMETER Collection 14 | Collection to query in ArangoDB 15 | .PARAMETER Key 16 | Key to query in ArangoDB 17 | .PARAMETER All 18 | Switch to query all entries in ArangoDB collection 19 | .EXAMPLE 20 | Get-Document -Collection 'test_collection' -Key '1234' 21 | Get document with id 1234 from the collection test_collection 22 | .EXAMPLE 23 | Get-Document -Collection 'test_collection' -All 24 | Get all documents from the collection test_collection 25 | #> 26 | [CmdletBinding()] 27 | param ( 28 | [Parameter(Mandatory=$true,Position=0,HelpMessage='Enter the collection to query.')] 29 | [string]$Collection, 30 | [Parameter(Mandatory=$true,Position=1,ParameterSetName='singleDocument',HelpMessage='Enter the collection Key to query.')] 31 | [string]$Key, 32 | [Parameter(Mandatory=$false,Position=2,ParameterSetName='multiDocument',HelpMessage='Switch to list all documents from the collection.')] 33 | [switch]$All 34 | ) 35 | if(!(Test-Environment)) { 36 | $_ 37 | } 38 | if ($PSCmdlet.ParameterSetName -eq 'singleDocument') { 39 | try { 40 | Invoke-RestMethod -Uri $Global:ArangoDBAPIUrl"/document/"$Collection"/"$Key -Headers $Global:ArangoDBHeader 41 | } 42 | catch { 43 | Write-Host "There was an error in your web request!" -ForegroundColor red 44 | Write-Host "Exception Message: $($_.Exception.Message)" -ForegroundColor Red 45 | break 46 | } 47 | } 48 | if($All -and $PSCmdlet.ParameterSetName -eq 'multiDocument') { 49 | try { 50 | $query = @{query="FOR x IN $Collection RETURN x";} | ConvertTo-Json 51 | $query = Invoke-RestMethod -Uri $Global:ArangoDBAPIUrl"/cursor" -Headers $Global:ArangoDBHeader -Method Post -Body $query 52 | $results = [System.Collections.ArrayList]@() 53 | $query.foreach({$results.add($_)}) | Out-Null 54 | if($query.hasMore -eq $true) { 55 | do { 56 | $query = Invoke-RestMethod -Uri $Global:ArangoDBAPIUrl"/cursor/$($query.id)" -Headers $Global:ArangoDBHeader -Method Post -Body $query 57 | $query.foreach({$results.add($_)}) | Out-Null 58 | } until ($query.hasMore -eq $false) 59 | return $results.result 60 | } else { 61 | return $results.result 62 | } 63 | } 64 | catch { 65 | Write-Host "There was an error in your web request!" -ForegroundColor red 66 | Write-Host "Exception Message: $($_.Exception.Message)" -ForegroundColor Red 67 | break 68 | } 69 | } 70 | } -------------------------------------------------------------------------------- /PSArangoDB.psd1: -------------------------------------------------------------------------------- 1 | # 2 | # Module manifest for module 'PSArangoDB' 3 | # 4 | # Generated by: Morten Johansen 5 | # 6 | # Generated on: 11-06-2022 7 | # 8 | 9 | @{ 10 | 11 | # Script module or binary module file associated with this manifest. 12 | RootModule = 'PSArangoDB.psm1' 13 | 14 | # Version number of this module. 15 | ModuleVersion = '0.0.4' 16 | 17 | # Supported PSEditions 18 | CompatiblePSEditions = 'Desktop', 'Core' 19 | 20 | # ID used to uniquely identify this module 21 | GUID = 'e14d88d0-b74c-4bcf-a050-9d3a5e9ee58f' 22 | 23 | # Author of this module 24 | Author = 'Morten Johansen' 25 | 26 | # Company or vendor of this module 27 | # CompanyName = '' 28 | 29 | # Copyright statement for this module 30 | Copyright = '(c) 2022 Morten Johansen. All rights reserved.' 31 | 32 | # Description of the functionality provided by this module 33 | Description = 'PowerShell module for working with ArangoDB' 34 | 35 | # Minimum version of the PowerShell engine required by this module 36 | PowerShellVersion = '5.1' 37 | 38 | # Name of the PowerShell host required by this module 39 | # PowerShellHostName = '' 40 | 41 | # Minimum version of the PowerShell host required by this module 42 | # PowerShellHostVersion = '' 43 | 44 | # Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. 45 | # DotNetFrameworkVersion = '' 46 | 47 | # Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. 48 | # ClrVersion = '' 49 | 50 | # Processor architecture (None, X86, Amd64) required by this module 51 | # ProcessorArchitecture = '' 52 | 53 | # Modules that must be imported into the global environment prior to importing this module 54 | # RequiredModules = @() 55 | 56 | # Assemblies that must be loaded prior to importing this module 57 | # RequiredAssemblies = @() 58 | 59 | # Script files (.ps1) that are run in the caller's environment prior to importing this module. 60 | # ScriptsToProcess = @() 61 | 62 | # Type files (.ps1xml) to be loaded when importing this module 63 | # TypesToProcess = @() 64 | 65 | # Format files (.ps1xml) to be loaded when importing this module 66 | # FormatsToProcess = @() 67 | 68 | # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess 69 | # NestedModules = @() 70 | 71 | # 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. 72 | FunctionsToExport = 'Set-Environment','Get-Databases','Get-Document','New-Document','New-AQLQuery','Update-Document','Remove-Document' 73 | 74 | # 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. 75 | CmdletsToExport = @() 76 | 77 | # Variables to export from this module 78 | # VariablesToExport = @() 79 | 80 | # 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. 81 | AliasesToExport = @() 82 | 83 | # DSC resources to export from this module 84 | # DscResourcesToExport = @() 85 | 86 | # List of all modules packaged with this module 87 | # ModuleList = @() 88 | 89 | # List of all files packaged with this module 90 | # FileList = @() 91 | 92 | # 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. 93 | PrivateData = @{ 94 | 95 | PSData = @{ 96 | 97 | # Tags applied to this module. These help with module discovery in online galleries. 98 | Tags = 'powershell','module','arangodb','api','database','rest','aql','nosql','PSEdition_Desktop','PSEdition_Core','Windows','Linux','MacOS' 99 | 100 | # A URL to the license for this module. 101 | LicenseUri = 'http://www.apache.org/licenses/LICENSE-2.0' 102 | 103 | # A URL to the main website for this project. 104 | ProjectUri = 'https://github.com/mojoaar/psarangodb' 105 | 106 | # A URL to an icon representing this module. 107 | # IconUri = '' 108 | 109 | # ReleaseNotes of this module 110 | # ReleaseNotes = '' 111 | 112 | # Prerelease string of this module 113 | # Prerelease = '' 114 | 115 | # Flag to indicate whether the module requires explicit user acceptance for install/update/save 116 | # RequireLicenseAcceptance = $false 117 | 118 | # External dependent modules of this module 119 | # ExternalModuleDependencies = @() 120 | 121 | } # End of PSData hashtable 122 | 123 | } # End of PrivateData hashtable 124 | 125 | # HelpInfo URI of this module 126 | HelpInfoURI = 'https://github.com/mojoaar/psarangodb' 127 | 128 | # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. 129 | # DefaultCommandPrefix = '' 130 | 131 | } 132 | 133 | --------------------------------------------------------------------------------