Skip to content

Commit

Permalink
Resolving Submit-Request.ps1 conflict.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Fal committed Jan 2, 2018
2 parents 6164094 + 8e5eff0 commit 4fff0c9
Show file tree
Hide file tree
Showing 77 changed files with 1,378 additions and 120 deletions.
37 changes: 37 additions & 0 deletions .github/ISSUE_TEMPLATE.md
@@ -0,0 +1,37 @@
# Expected Behavior

Please describe the behavior you are expecting.

# Current Behavior

What is the current behavior?

# Failure Information (for bugs)

Please help provide information about the failure if this is a bug by issuing the command using the `-Verbose` command.

```
Paste the verbose output from the command here
```

**_If it is not a bug, please remove the rest of this template._**

## Steps to Reproduce

Please provide detailed steps for reproducing the issue.

1. Step 1
1. Step 2
1. Step 3 (and so on)

## Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

* **Rubrik PowerShell Module Version**: Use `Get-Module -ListAvailable Rubrik`
* **PowerShell Version**: Use `Get-PSVersion`
* **Operating System**:

## Failure Logs

Please include any relevant log snippets or files here.
41 changes: 41 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
@@ -0,0 +1,41 @@
# Description

Please describe your pull request in detail.

## Related Issue

This project only accepts pull requests related to open issues.

* If suggesting a new feature or change, please discuss it in an issue first.
* If fixing a bug, there should be an issue describing it with steps to reproduce

_Please link to the issue here_

## Motivation and Context

Why is this change required? What problem does it solve?

## How Has This Been Tested?

* Please describe in detail how you tested your changes.
* Include details of your testing environment, and the tests you ran to see how your change affects other areas of the code, etc.

## Screenshots (if appropriate):

## Types of changes

What types of changes does your code introduce? Put an `x` in all the boxes that apply:
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)

## Checklist:

Go over all the following points, and put an `x` in all the boxes that apply. If you're unsure about any of these, don't hesitate to ask. We're here to help!
- [ ] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [ ] I have read the **[CONTRIBUTION](http://rubrikinc.github.io/PowerShell-Module/documentation/contribution.html)** document.
- [ ] I have updated the CHANGELOG file accordingly for the version that this merge modifies.
- [ ] I have added tests to cover my changes.
- [ ] All new and existing tests passed.
42 changes: 42 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,42 @@
# Change Log

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## Types of changes

* **Added** for new features.
* **Changed** for changes in existing functionality.
* **Deprecated** for soon-to-be removed features.
* **Removed** for now removed features.
* **Fixed** for any bug fixes.
* **Security** in case of vulnerabilities.

## [Unreleased]

### Added

* Testing for MacOS and Linux as per [143](https://github.com/rubrikinc/PowerShell-Module/issues/143)

## [4.0.0] - 2017-07-07

### Added

* `Set-RubrikSupportTunnel` - Modifies the configuration of the Support Tunnel.
* `Get-RubrikSupportTunnel` - Checks the status of the Support Tunnel.
* This Changelog - moving forward, related changes will be documented here in an easy to read format for human eyeballs.
* Dynamic documentation creation via GitBook.
* [GitHub Pull Request Template](https://github.com/rubrikinc/PowerShell-Module/pull/135).
* [GitHub Issue Template](https://github.com/rubrikinc/PowerShell-Module/commit/ca0a7fc1864c42162236b4e68af6f44d07f0a164).
* [Invoke-RubrikRESTCall](https://github.com/rubrikinc/PowerShell-Module/pull/118).

### Changed

* Track `user_error` responses in the `Submit-Request` private function
* The `Get-RubrikSnapshot` function supports HyperV VMs.

### Deprecated

* Dynamic documentation using ReadTheDocs and reStructuredText.
2 changes: 1 addition & 1 deletion README.md
@@ -1,7 +1,7 @@
Community PowerShell Module for Rubrik
============================

[![Build status](https://ci.appveyor.com/api/projects/status/52cv3jshak2w7624?svg=true)](https://ci.appveyor.com/project/chriswahl/powershell-module) [![Documentation Status](http://readthedocs.org/projects/powershell-module/badge/?version=latest)](http://powershell-module.readthedocs.io/en/latest/?badge=latest)
[![Build status](https://ci.appveyor.com/api/projects/status/52cv3jshak2w7624?svg=true)](https://ci.appveyor.com/project/chriswahl/powershell-module)

This is a community project that provides a Microsoft PowerShell module for managing and monitoring Rubrik's Cloud Data Management fabric by way of published RESTful APIs. If you're looking to perform interactive automation, setting up scheduled tasks, leverage an orchestration engine, or need ad-hoc operations, this module is intended to be valuable to your needs.

Expand Down
32 changes: 30 additions & 2 deletions Rubrik/Private/Get-RubrikAPIData.ps1
Expand Up @@ -295,6 +295,7 @@ function Get-RubrikAPIData($endpoint)
Fileset = '/api/v1/fileset/{id}/snapshot'
MSSQL = '/api/v1/mssql/db/{id}/snapshot'
VMware = '/api/v1/vmware/vm/{id}/snapshot'
HyperV = '/api/internal/hyperv/vm/{id}/snapshot'
}
Method = 'Get'
Body = ''
Expand Down Expand Up @@ -336,7 +337,19 @@ function Get-RubrikAPIData($endpoint)
}
Success = '200'
}
}
}
'Get-RubrikSupportTunnel' = @{
v1 = @{
Description = 'To be used by Admin to check status of the support tunnel.'
URI = '/api/internal/node/me/support_tunnel'
Method = 'Get'
Body = ''
Query = ''
Result = ''
Filter = ''
Success = '200'
}
}
'Get-RubrikUnmanagedObject' = @{
v1 = @{
Description = 'Get summary of all the objects with unmanaged snapshots'
Expand Down Expand Up @@ -770,7 +783,22 @@ function Get-RubrikAPIData($endpoint)
Filter = ''
Success = '200'
}
}
}
'Set-RubrikSupportTunnel' = @{
v1 = @{
Description = 'To be used by Admin to open or close a SSH tunnel for support.'
URI = '/api/internal/node/me/support_tunnel'
Method = 'Patch'
Body = @{
isTunnelEnabled = "isTunnelEnabled"
inactivityTimeoutInSeconds = "inactivityTimeoutInSeconds"
}
Query = ''
Result = ''
Filter = ''
Success = '200'
}
}
'Set-RubrikVM' = @{
v1 = @{
Description = 'Update VM with specified properties'
Expand Down
71 changes: 36 additions & 35 deletions Rubrik/Private/Submit-Request.ps1
@@ -1,40 +1,41 @@
function Submit-Request($uri,$header,$method = $($resources.Method) ,$body)
{
# The Submit-Request function is used to send data to an endpoint and then format the response for further use
# $uri = The endpoint's URI
# $header = The header containing authentication details
# $method = The action (method) to perform on the endpoint
# $body = Any optional body data being submitted to the endpoint
function Submit-Request($uri, $header, $method = $($resources.Method) , $body) {
# The Submit-Request function is used to send data to an endpoint and then format the response for further use
# $uri = The endpoint's URI
# $header = The header containing authentication details
# $method = The action (method) to perform on the endpoint
# $body = Any optional body data being submitted to the endpoint

if ($PSCmdlet.ShouldProcess($id,$resources.Description))
{
try
{
Write-Verbose -Message 'Submitting the request'
# Because some calls require more than the default payload limit of 2MB, ExpandPayload dynamically adjusts the payload limit
$result = ExpandPayload -response (Invoke-WebRequest -Uri $uri -Headers $header -Method $method -Body $body)
}
catch
{
switch -Wildcard ($_)
{
'Route not defined.'
{
Write-Warning -Message "The endpoint supplied to Rubrik is invalid. Likely this is due to an incompatible version of the API or references pointing to a non-existent endpoint. The URI passed was: $uri" -Verbose
throw $_.Exception
}
'Invalid ManagedId*'
{
Write-Warning -Message "The endpoint supplied to Rubrik is invalid. Likely this is due to an incompatible version of the API or references pointing to a non-existent endpoint. The URI passed was: $uri" -Verbose
throw $_.Exception
if ($PSCmdlet.ShouldProcess($id, $resources.Description)) {
try {
Write-Verbose -Message 'Submitting the request'
# Because some calls require more than the default payload limit of 2MB, ExpandPayload dynamically adjusts the payload limit
$result = ExpandPayload -response (Invoke-WebRequest -Uri $uri -Headers $header -Method $method -Body $body)
}
default
{
throw $_
catch {
switch -Wildcard ($_) {
'Route not defined.' {
Write-Warning -Message "The endpoint supplied to Rubrik is invalid. Likely this is due to an incompatible version of the API or references pointing to a non-existent endpoint. The URI passed was: $uri" -Verbose
throw $_.Exception
}
'Invalid ManagedId*' {
Write-Warning -Message "The endpoint supplied to Rubrik is invalid. Likely this is due to an incompatible version of the API or references pointing to a non-existent endpoint. The URI passed was: $uri" -Verbose
throw $_.Exception
}
'{"errorType":*' {
# Parses the Rubrik generated JSON warning into something a bit more human readable
# Fields are: errorType, message, and cause
[Array]$rubrikWarning = ConvertFrom-Json $_.ErrorDetails.Message
if ($rubrikWarning.errorType) {Write-Warning -Message $rubrikWarning.errorType}
if ($rubrikWarning.message) {Write-Warning -Message $rubrikWarning.message}
if ($rubrikWarning.cause) {Write-Warning -Message $rubrikWarning.cause}
throw $_.Exception
}
default {
throw $_
}
}
}
}
}

return $result
}
return $result
}
}
5 changes: 5 additions & 0 deletions Rubrik/Private/Test-QueryParam.ps1
Expand Up @@ -27,6 +27,11 @@
Write-Verbose -Message 'Loading VMware API data'
$uri = ('https://'+$Server+$resources.URI.VMware) -replace '{id}', $id
}
'HypervVirtualMachine:::*'
{
Write-Verbose -Message 'Loading HyperV API data'
$uri = ('https://'+$Server+$resources.URI.HyperV) -replace '{id}', $id
}
default
{
throw 'The supplied id value has no matching endpoint'
Expand Down
65 changes: 65 additions & 0 deletions Rubrik/Public/Get-RubrikSupportTunnel.ps1
@@ -0,0 +1,65 @@
#requires -Version 3
function Get-RubrikSupportTunnel
{
<#
.SYNOPSIS
Checks the status of the Support Tunnel
.DESCRIPTION
The Get-RubrikSupportTunnel cmdlet is used to query the Rubrik cluster to determine the status of the Support Tunnel
This tunnel is used by Rubrik's support team for providing remote assistance and is toggled on or off by the cluster administrator
.NOTES
Written by Chris Wahl for community usage
Twitter: @ChrisWahl
GitHub: chriswahl
.LINK
https://github.com/rubrikinc/PowerShell-Module
.EXAMPLE
Get-RubrikSupportTunnel
This will return details on the configuration of the Support Tunnel for the currently connected Rubrik cluster
#>

[CmdletBinding()]
Param(
# Rubrik server IP or FQDN
[String]$Server = $global:RubrikConnection.server,
# API version
[String]$api = $global:RubrikConnection.api
)

Begin {

# The Begin section is used to perform one-time loads of data necessary to carry out the function's purpose
# If a command needs to be run with each iteration or pipeline input, place it in the Process section

# Check to ensure that a session to the Rubrik cluster exists and load the needed header data for authentication
Test-RubrikConnection

# API data references the name of the function
# For convenience, that name is saved here to $function
$function = $MyInvocation.MyCommand.Name

# Retrieve all of the URI, method, body, query, result, filter, and success details for the API endpoint
Write-Verbose -Message "Gather API Data for $function"
$resources = (Get-RubrikAPIData -endpoint $function).$api
Write-Verbose -Message "Load API data for $($resources.Function)"
Write-Verbose -Message "Description: $($resources.Description)"

}

Process {

$uri = New-URIString -server $Server -endpoint ($resources.URI) -id $id
$uri = Test-QueryParam -querykeys ($resources.Query.Keys) -parameters ((Get-Command $function).Parameters.Values) -uri $uri
$body = New-BodyString -bodykeys ($resources.Body.Keys) -parameters ((Get-Command $function).Parameters.Values)
$result = Submit-Request -uri $uri -header $Header -method $($resources.Method) -body $body
$result = Test-ReturnFormat -api $api -result $result -location $resources.Result
$result = Test-FilterObject -filter ($resources.Filter) -result $result

return $result

} # End of process
} # End of function

0 comments on commit 4fff0c9

Please sign in to comment.