Skip to content

Commit

Permalink
Fix #377 by loading creds from session unless provided (#378)
Browse files Browse the repository at this point in the history
* Fix #377 by loading creds from session unless provided

* Don't use plain text password when getting creds

* Replace tabs with spaces

* Use $null checks instead

Co-authored-by: Vytautas Krivickas <[email protected]>
  • Loading branch information
vytux-com and vytux-com authored Jun 9, 2022
1 parent c22b27e commit 164d604
Show file tree
Hide file tree
Showing 24 changed files with 96 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ function Get-RsRestPublicServerSetting
Begin
{
$WebSession = New-RsRestSessionHelper -BoundParameters $PSBoundParameters
if ($null -ne $WebSession.Credentials -and $null -eq $Credential) {
Write-Verbose "Using credentials from WebSession"
$Credential = New-Object System.Management.Automation.PSCredential "$($WebSession.Credentials.UserName)@$($WebSession.Credentials.Domain)", $WebSession.Credentials.SecurePassword
}
$ReportPortalUri = Get-RsPortalUriHelper -WebSession $WebSession
$systemPropertiesUri = $ReportPortalUri + "api/$RestApiVersion/System/Properties?properties={0}"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ function Get-RsRestCacheRefreshPlan
Begin
{
$WebSession = New-RsRestSessionHelper -BoundParameters $PSBoundParameters
if ($null -ne $WebSession.Credentials -and $null -eq $Credential) {
Write-Verbose "Using credentials from WebSession"
$Credential = New-Object System.Management.Automation.PSCredential "$($WebSession.Credentials.UserName)@$($WebSession.Credentials.Domain)", $WebSession.Credentials.SecurePassword
}
$ReportPortalUri = Get-RsPortalUriHelper -WebSession $WebSession
$CacheRefreshPlanUri = $ReportPortalUri + "api/$RestApiVersion/PowerBIReports({0})/CacheRefreshPlans"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ function Get-RsRestCacheRefreshPlanHistory
Begin
{
$WebSession = New-RsRestSessionHelper -BoundParameters $PSBoundParameters
if ($null -ne $WebSession.Credentials -and $null -eq $Credential) {
Write-Verbose "Using credentials from WebSession"
$Credential = New-Object System.Management.Automation.PSCredential "$($WebSession.Credentials.UserName)@$($WebSession.Credentials.Domain)", $WebSession.Credentials.SecurePassword
}
$ReportPortalUri = Get-RsPortalUriHelper -WebSession $WebSession
}
Process
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ function Get-RsRestFolderContent
Begin
{
$WebSession = New-RsRestSessionHelper -BoundParameters $PSBoundParameters
if ($null -ne $WebSession.Credentials -and $null -eq $Credential) {
Write-Verbose "Using credentials from WebSession"
$Credential = New-Object System.Management.Automation.PSCredential "$($WebSession.Credentials.UserName)@$($WebSession.Credentials.Domain)", $WebSession.Credentials.SecurePassword
}
$ReportPortalUri = Get-RsPortalUriHelper -WebSession $WebSession
$catalogItemsUri = $ReportPortalUri + "api/$RestApiVersion/Folders(Path='{0}')/CatalogItems?`$expand=Properties"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ function Get-RsRestItem
Begin
{
$WebSession = New-RsRestSessionHelper -BoundParameters $PSBoundParameters
if ($null -ne $WebSession.Credentials -and $null -eq $Credential) {
Write-Verbose "Using credentials from WebSession"
$Credential = New-Object System.Management.Automation.PSCredential "$($WebSession.Credentials.UserName)@$($WebSession.Credentials.Domain)", $WebSession.Credentials.SecurePassword
}
$ReportPortalUri = Get-RsPortalUriHelper -WebSession $WebSession
$catalogItemsUri = $ReportPortalUri + "api/$RestApiVersion/CatalogItems(Path='{0}')"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ function Get-RsRestItemDataModelParameter
Begin
{
$WebSession = New-RsRestSessionHelper -BoundParameters $PSBoundParameters
if ($null -ne $WebSession.Credentials -and $null -eq $Credential) {
Write-Verbose "Using credentials from WebSession"
$Credential = New-Object System.Management.Automation.PSCredential "$($WebSession.Credentials.UserName)@$($WebSession.Credentials.Domain)", $WebSession.Credentials.SecurePassword
}
$ReportPortalUri = Get-RsPortalUriHelper -WebSession $WebSession
$catalogItemsUri = $ReportPortalUri + "api/$RestApiVersion/CatalogItems(Path='{0}')"
$parametersUri = $ReportPortalUri + "api/$RestApiVersion/{0}(Path='{1}')?`$expand=DataModelParameters"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ function Get-RsRestItemDataSource
Begin
{
$WebSession = New-RsRestSessionHelper -BoundParameters $PSBoundParameters
if ($null -ne $WebSession.Credentials -and $null -eq $Credential) {
Write-Verbose "Using credentials from WebSession"
$Credential = New-Object System.Management.Automation.PSCredential "$($WebSession.Credentials.UserName)@$($WebSession.Credentials.Domain)", $WebSession.Credentials.SecurePassword
}
$ReportPortalUri = Get-RsPortalUriHelper -WebSession $WebSession
$catalogItemsUri = $ReportPortalUri + "api/$RestApiVersion/CatalogItems(Path='{0}')"
$dataSourcesUri = $ReportPortalUri + "api/$RestApiVersion/{0}(Path='{1}')?`$expand=DataSources"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ function New-RsRestCacheRefreshPlan
Begin
{
$WebSession = New-RsRestSessionHelper -BoundParameters $PSBoundParameters
if ($null -ne $WebSession.Credentials -and $null -eq $Credential) {
Write-Verbose "Using credentials from WebSession"
$Credential = New-Object System.Management.Automation.PSCredential "$($WebSession.Credentials.UserName)@$($WebSession.Credentials.Domain)", $WebSession.Credentials.SecurePassword
}
$ReportPortalUri = Get-RsPortalUriHelper -WebSession $WebSession
$refreshplansUri = $ReportPortalUri + "api/$RestApiVersion/CacheRefreshPlans"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ function New-RsRestFolder
Begin
{
$WebSession = New-RsRestSessionHelper -BoundParameters $PSBoundParameters
if ($null -ne $WebSession.Credentials -and $null -eq $Credential) {
Write-Verbose "Using credentials from WebSession"
$Credential = New-Object System.Management.Automation.PSCredential "$($WebSession.Credentials.UserName)@$($WebSession.Credentials.Domain)", $WebSession.Credentials.SecurePassword
}
$ReportPortalUri = Get-RsPortalUriHelper -WebSession $WebSession
$foldersUri = $ReportPortalUri + "api/$RestApiVersion/Folders"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ function Out-RsRestCatalogItem
Begin
{
$WebSession = New-RsRestSessionHelper -BoundParameters $PSBoundParameters
if ($null -ne $WebSession.Credentials -and $null -eq $Credential) {
Write-Verbose "Using credentials from WebSession"
$Credential = New-Object System.Management.Automation.PSCredential "$($WebSession.Credentials.UserName)@$($WebSession.Credentials.Domain)", $WebSession.Credentials.SecurePassword
}
$ReportPortalUri = Get-RsPortalUriHelper -WebSession $WebSession
if ($RestApiVersion -eq 'v1.0')
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ function Out-RsRestCatalogItemId
Begin
{
$WebSession = New-RsRestSessionHelper -BoundParameters $PSBoundParameters
if ($null -ne $WebSession.Credentials -and $null -eq $Credential) {
Write-Verbose "Using credentials from WebSession"
$Credential = New-Object System.Management.Automation.PSCredential "$($WebSession.Credentials.UserName)@$($WebSession.Credentials.Domain)", $WebSession.Credentials.SecurePassword
}
$ReportPortalUri = Get-RsPortalUriHelper -WebSession $WebSession
$catalogItemContentApi = $ReportPortalUri + "api/$RestApiVersion/CatalogItems({0})/Content/`$value"
$DestinationFullPath = Convert-Path -LiteralPath $Destination
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ function Out-RsRestFolderContent
Begin
{
$WebSession = New-RsRestSessionHelper -BoundParameters $PSBoundParameters
if ($null -ne $WebSession.Credentials -and $null -eq $Credential) {
Write-Verbose "Using credentials from WebSession"
$Credential = New-Object System.Management.Automation.PSCredential "$($WebSession.Credentials.UserName)@$($WebSession.Credentials.Domain)", $WebSession.Credentials.SecurePassword
}
$ReportPortalUri = Get-RsPortalUriHelper -WebSession $WebSession
$catalogItemsByPathApiV1 = $ReportPortalUri + "api/v1.0/CatalogItemByPath(path=@path)?@path=%27{0}%27"
$folderCatalogItemsApiV1 = $ReportPortalUri + "api/v1.0/CatalogItems({0})/Model.Folder/CatalogItems"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ function Remove-RsRestCacheRefreshPlan {
Begin
{
$WebSession = New-RsRestSessionHelper -BoundParameters $PSBoundParameters
if ($null -ne $WebSession.Credentials -and $null -eq $Credential) {
Write-Verbose "Using credentials from WebSession"
$Credential = New-Object System.Management.Automation.PSCredential "$($WebSession.Credentials.UserName)@$($WebSession.Credentials.Domain)", $WebSession.Credentials.SecurePassword
}
$ReportPortalUri = Get-RsPortalUriHelper -WebSession $WebSession
$CacheRefreshPlansUri = $ReportPortalUri + "api/$RestApiVersion/CacheRefreshPlans({0})"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ function Remove-RsRestCatalogItem
Begin
{
$WebSession = New-RsRestSessionHelper -BoundParameters $PSBoundParameters
if ($null -ne $WebSession.Credentials -and $null -eq $Credential) {
Write-Verbose "Using credentials from WebSession"
$Credential = New-Object System.Management.Automation.PSCredential "$($WebSession.Credentials.UserName)@$($WebSession.Credentials.Domain)", $WebSession.Credentials.SecurePassword
}
$ReportPortalUri = Get-RsPortalUriHelper -WebSession $WebSession
$catalogItemsUri = $ReportPortalUri + "api/$RestApiVersion/CatalogItems(Path='{0}')"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ function Remove-RsRestFolder
Begin
{
$WebSession = New-RsRestSessionHelper -BoundParameters $PSBoundParameters
if ($null -ne $WebSession.Credentials -and $null -eq $Credential) {
Write-Verbose "Using credentials from WebSession"
$Credential = New-Object System.Management.Automation.PSCredential "$($WebSession.Credentials.UserName)@$($WebSession.Credentials.Domain)", $WebSession.Credentials.SecurePassword
}
$ReportPortalUri = Get-RsPortalUriHelper -WebSession $WebSession
$foldersUri = $ReportPortalUri + "api/$RestApiVersion/Folders(Path='{0}')"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ function Set-RsRestItemDataModelParameter
Begin
{
$WebSession = New-RsRestSessionHelper -BoundParameters $PSBoundParameters
if ($null -ne $WebSession.Credentials -and $null -eq $Credential) {
Write-Verbose "Using credentials from WebSession"
$Credential = New-Object System.Management.Automation.PSCredential "$($WebSession.Credentials.UserName)@$($WebSession.Credentials.Domain)", $WebSession.Credentials.SecurePassword
}
$ReportPortalUri = Get-RsPortalUriHelper -WebSession $WebSession
$dataModelParametersUri = $ReportPortalUri + "api/$RestApiVersion/PowerBIReports(Path='{0}')/DataModelParameters"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ function Set-RsRestItemDataSource
Begin
{
$WebSession = New-RsRestSessionHelper -BoundParameters $PSBoundParameters
if ($null -ne $WebSession.Credentials -and $null -eq $Credential) {
Write-Verbose "Using credentials from WebSession"
$Credential = New-Object System.Management.Automation.PSCredential "$($WebSession.Credentials.UserName)@$($WebSession.Credentials.Domain)", $WebSession.Credentials.SecurePassword
}
$ReportPortalUri = Get-RsPortalUriHelper -WebSession $WebSession
$dataSourcesUri = $ReportPortalUri + "api/$RestApiVersion/{0}(Path='{1}')/DataSources"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ function Start-RsRestCacheRefreshPlan
Begin
{
$WebSession = New-RsRestSessionHelper -BoundParameters $PSBoundParameters
if ($null -ne $WebSession.Credentials -and $null -eq $Credential) {
Write-Verbose "Using credentials from WebSession"
$Credential = New-Object System.Management.Automation.PSCredential "$($WebSession.Credentials.UserName)@$($WebSession.Credentials.Domain)", $WebSession.Credentials.SecurePassword
}
$ReportPortalUri = Get-RsPortalUriHelper -WebSession $WebSession
$CacheRefreshPlansUri = $ReportPortalUri + "api/$RestApiVersion/CacheRefreshPlans({0})/Model.Execute"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ function Test-RsRestItemDataSource
Begin
{
$WebSession = New-RsRestSessionHelper -BoundParameters $PSBoundParameters
if ($null -ne $WebSession.Credentials -and $null -eq $Credential) {
Write-Verbose "Using credentials from WebSession"
$Credential = New-Object System.Management.Automation.PSCredential "$($WebSession.Credentials.UserName)@$($WebSession.Credentials.Domain)", $WebSession.Credentials.SecurePassword
}
$ReportPortalUri = Get-RsPortalUriHelper -WebSession $WebSession
}
Process
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ function Write-RsRestCatalogItem
Begin
{
$WebSession = New-RsRestSessionHelper -BoundParameters $PSBoundParameters
if ($null -ne $WebSession.Credentials -and $null -eq $Credential) {
Write-Verbose "Using credentials from WebSession"
$Credential = New-Object System.Management.Automation.PSCredential "$($WebSession.Credentials.UserName)@$($WebSession.Credentials.Domain)", $WebSession.Credentials.SecurePassword
}
$ReportPortalUri = Get-RsPortalUriHelper -WebSession $WebSession
$catalogItemsUri = $ReportPortalUri + "api/$RestApiVersion/CatalogItems"
if ($RestApiVersion -eq "v1.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ function Write-RsRestFolderContent
Begin
{
$WebSession = New-RsRestSessionHelper -BoundParameters $PSBoundParameters
if ($null -ne $WebSession.Credentials -and $null -eq $Credential) {
Write-Verbose "Using credentials from WebSession"
$Credential = New-Object System.Management.Automation.PSCredential "$($WebSession.Credentials.UserName)@$($WebSession.Credentials.Domain)", $WebSession.Credentials.SecurePassword
}
$ReportPortalUri = Get-RsPortalUriHelper -WebSession $WebSession
$catalogItemsUri = $ReportPortalUri + "api/$RestApiVersion/CatalogItems"
$folderUri = $ReportPortalUri + "api/$RestApiVersion/Folders(Path='{0}')"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ function Get-RsRestItemAccessPolicy
Begin
{
$WebSession = New-RsRestSessionHelper -BoundParameters $PSBoundParameters
if ($null -ne $WebSession.Credentials -and $null -eq $Credential) {
Write-Verbose "Using credentials from WebSession"
$Credential = New-Object System.Management.Automation.PSCredential "$($WebSession.Credentials.UserName)@$($WebSession.Credentials.Domain)", $WebSession.Credentials.SecurePassword
}
$ReportPortalUri = Get-RsPortalUriHelper -WebSession $WebSession
$PolicyUri = $ReportPortalUri + "api/$RestApiVersion/CatalogItems({0})/Policies"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ function Grant-RsRestItemAccessPolicy
Begin
{
$WebSession = New-RsRestSessionHelper -BoundParameters $PSBoundParameters
if ($null -ne $WebSession.Credentials -and $null -eq $Credential) {
Write-Verbose "Using credentials from WebSession"
$Credential = New-Object System.Management.Automation.PSCredential "$($WebSession.Credentials.UserName)@$($WebSession.Credentials.Domain)", $WebSession.Credentials.SecurePassword
}
$ReportPortalUri = Get-RsPortalUriHelper -WebSession $WebSession
}
Process
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ function Revoke-RsRestItemAccessPolicy
Begin
{
$WebSession = New-RsRestSessionHelper -BoundParameters $PSBoundParameters
if ($null -ne $WebSession.Credentials -and $null -eq $Credential) {
Write-Verbose "Using credentials from WebSession"
$Credential = New-Object System.Management.Automation.PSCredential "$($WebSession.Credentials.UserName)@$($WebSession.Credentials.Domain)", $WebSession.Credentials.SecurePassword
}
$ReportPortalUri = Get-RsPortalUriHelper -WebSession $WebSession
}
Process
Expand Down

0 comments on commit 164d604

Please sign in to comment.