Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions DOrcDeployModule.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
RootModule = 'DOrcDeployModule.psm1'

# Version number of this module.
ModuleVersion = '19.4.30.1'
ModuleVersion = '25.4.3.101'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down Expand Up @@ -96,7 +96,7 @@
# Tags = @()

# A URL to the license for this module.
# LicenseUri = ''
LicenseUri = 'https://github.com/sefe/DOrcDeployModule/blob/main/LICENSE.md'

# A URL to the main website for this project.
# ProjectUri = ''
Expand All @@ -107,8 +107,12 @@
# ReleaseNotes of this module
# ReleaseNotes = ''

# Prerelease string of this module
# Prerelease = ''
# Flag to indicate whether the module requires explicit user acceptance for install/update/save
# RequireLicenseAcceptance = $false
# External dependent modules of this module
# ExternalModuleDependencies = ''
# ExternalModuleDependencies = @()

} # End of PSData hashtable

Expand Down
72 changes: 62 additions & 10 deletions DOrcDeployModule.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -496,12 +496,16 @@ function GACAdder([string] $strAction, [string] $strServer, [string] $strLibrary
}

function GetDbInfoByTypeForEnv([string] $strEnvironment, [string] $strType) {
$DOrcToken = Get-DorcToken
$DorcAPIHeaders = @{
"Authorization" = "Bearer $DOrcToken"
}
$securePassword = ConvertTo-SecureString $DorcApiAccessPassword -AsPlainText -Force
$credentials = New-Object System.Management.Automation.PSCredential ($DorcApiAccessAccount, $securePassword)
$uri=$RefDataApiUrl + 'RefDataEnvironments?env=' + $strEnvironment
$EnvId=(Invoke-RestMethod -Uri $uri -method Get -Credential $credentials -ContentType 'application/json').EnvironmentId
$EnvId=(Invoke-RestMethod -Uri $uri -method Get -Headers $DorcAPIHeaders -ContentType 'application/json').EnvironmentId
$uri=$RefDataApiUrl + 'RefDataEnvironmentsDetails/' + $EnvId
$table=Invoke-RestMethod -Uri $uri -method Get -Credential $credentials -ContentType 'application/json'
$table=Invoke-RestMethod -Uri $uri -method Get -Headers $DorcAPIHeaders -ContentType 'application/json'
$table=$table.DbServers | where {$_.Type -eq $strType} | Select Name, ServerName
$strResult="Invalid"
if ($table.Name.count -eq 0) {
Expand Down Expand Up @@ -944,7 +948,7 @@ function Stop-Services {
write-host " Attempt to stop number:" ($i + 1)
Invoke-Command -ComputerName $strComputer { param($strService) Stop-Service $strService -Force} -Args $strService
Start-Sleep $retryTime
$oService = Get-Service $strRemServiceName -computer $strComputer
$oService = Get-Service $strServiceNameGen -computer $strComputer
$strRemServiceStatus = $oService.Status
if ($strRemServiceStatus -eq "Stopped") {break}
if ($i -eq $retryCount) {
Expand All @@ -954,7 +958,7 @@ function Stop-Services {
Invoke-Command -ComputerName $strComputer {param($ServicePID) Stop-Process $ServicePID -Force} -Args $ServicePID -ErrorAction SilentlyContinue
}
}
$oService = Get-Service $strRemServiceName -computer $strComputer
$oService = Get-Service $strServiceNameGen -computer $strComputer
$strRemServiceStatus = $oService.Status
if ($strRemServiceStatus -ne "Stopped") {throw " " + $strRemServiceName + "is still" + $oService.Status}
else {write-host " "$strRemServiceName "has been stopped"}
Expand Down Expand Up @@ -1217,13 +1221,18 @@ function Restart-Servers {
}

function GetServersOfType([string] $strEnvironment, [string] $strType = "") {
$DOrcToken = Get-DorcToken
$DorcAPIHeaders = @{
"Authorization" = "Bearer $DOrcToken"
}

$securePassword = ConvertTo-SecureString $DorcApiAccessPassword -AsPlainText -Force
$credentials = New-Object System.Management.Automation.PSCredential ($DorcApiAccessAccount, $securePassword)
$uri=$RefDataApiUrl + 'RefDataEnvironments?env=' + $strEnvironment
$EnvInfo = Invoke-RestMethod -Uri $uri -method Get -Credential $credentials -ContentType 'application/json'
$EnvInfo = Invoke-RestMethod -Uri $uri -method Get -Headers $DorcAPIHeaders -ContentType 'application/json'
$EnvId = $EnvInfo.EnvironmentId
$uri = $RefDataApiUrl + 'RefDataEnvironmentsDetails/' + $EnvId
$EnvDetailsInfo = Invoke-RestMethod -Uri $uri -method Get -Credential $credentials -ContentType 'application/json'
$EnvDetailsInfo = Invoke-RestMethod -Uri $uri -method Get -Headers $DorcAPIHeaders -ContentType 'application/json'
$Servers=$EnvDetailsInfo.AppServers.Name
$table=new-object "System.Data.DataTable"
$ColumnNames='Env_ID','Env_Name','Owner','Thin_Client_Server','Restored_From_Backup','Last_Update','File_Share','Env_Note','Description','Build_ID','Locked','Env_ID1','Server_ID','Server_ID1','Server_Name','OS_Version','Application_Server_Name'
Expand Down Expand Up @@ -2722,15 +2731,19 @@ function Get-EndurDbVersion
}

function GetDbInfoByTypeForEnvWithArray([string] $strEnvironment, [string] $strType) {
$DOrcToken = Get-DorcToken
$DorcAPIHeaders = @{
"Authorization" = "Bearer $DOrcToken"
}
$securePassword = ConvertTo-SecureString $DorcApiAccessPassword -AsPlainText -Force
$credentials = New-Object System.Management.Automation.PSCredential ($DorcApiAccessAccount, $securePassword)
$uri=$RefDataApiUrl + 'RefDataEnvironments?env=' + $strEnvironment
write-host "GetDbInfoByTypeForEnvWithArray Uri is:" $uri
$EnvId=(Invoke-RestMethod -Uri $uri -method Get -Credential $credentials -ContentType 'application/json').EnvironmentId
$EnvId=(Invoke-RestMethod -Uri $uri -method Get -Headers $DorcAPIHeaders -ContentType 'application/json').EnvironmentId
write-host "EnvId" $EnvId
$uri=$RefDataApiUrl + 'RefDataEnvironmentsDetails/' + $EnvId
write-host "EnvironmentDetails Uri is:" $uri
$table=Invoke-RestMethod -Uri $uri -method Get -Credential $credentials -ContentType 'application/json'
$table=Invoke-RestMethod -Uri $uri -method Get -Headers $DorcAPIHeaders -ContentType 'application/json'
$table=$table.DbServers | where {$_.Type -eq $strType} | Select Name, ServerName, ArrayName
$strResult="Invalid"
if ($table.Name.count -eq 0) {
Expand Down Expand Up @@ -3187,6 +3200,12 @@ function Set-SSISPackageParamters
$catalog = $integrationServices.Catalogs.get_Item($ssisDb)
$folder = $catalog.Folders[$environment]
$envVarsSet = $false

$DOrcToken = Get-DorcToken
$DorcAPIHeaders = @{
"Authorization" = "Bearer $DOrcToken"
}

if ($catalog.Name.ToLower() -eq $ssisDb.ToLower()) {
$isConfigs = Get-Childitem $packageFolderRoot -Recurse -File -Filter *.json
if ($isConfigs.Count -gt 0) {
Expand All @@ -3204,7 +3223,7 @@ function Set-SSISPackageParamters
$value = (get-variable $jsonParameter.DeployProperty -ErrorAction SilentlyContinue -WarningAction SilentlyContinue).Value
$url = $DORC_PropertiesUrl #+ $jsonParameter.DeployProperty
$ProgressPreference = "SilentlyContinue"
$propInfo = Invoke-WebRequest -UseDefaultCredentials $url | ConvertFrom-Json
$propInfo = Invoke-WebRequest $url -Headers $DorcAPIHeaders -UseBasicParsing | ConvertFrom-Json
$propInfo = $propInfo| where {$_.Name -eq $jsonParameter.DeployProperty}
$ProgressPreference = "Continue"
$isSecure = $propInfo.Secure #IsSecured
Expand Down Expand Up @@ -3246,7 +3265,7 @@ function Set-SSISPackageParamters
$value = (get-variable $jsonParameter.DeployProperty -ErrorAction SilentlyContinue -WarningAction SilentlyContinue).Value
$url = $DORC_PropertiesUrl #+ $jsonParameter.DeployProperty
$ProgressPreference = "SilentlyContinue"
$propInfo = Invoke-WebRequest -UseDefaultCredentials $url | ConvertFrom-Json
$propInfo = Invoke-WebRequest $url -Headers $DorcAPIHeaders -UseBasicParsing | ConvertFrom-Json
$propInfo = $propInfo| where {$_.Name -eq $jsonParameter.DeployProperty}
$ProgressPreference = "Continue"
$isSecure = $propInfo.Secure #IsSecured
Expand Down Expand Up @@ -4116,6 +4135,7 @@ function Get-AzAccessTokenToResource {
$AccessTokenToResource = Get-AzAccessToken -ResourceUrl $ResourceUrl
return $AccessTokenToResource
}

function DeployDACPACToAzureSQL {
[CmdletBinding()]
param (
Expand Down Expand Up @@ -4174,3 +4194,35 @@ function DeployDACPACToAzureSQL {
}
}

function Get-DorcToken {
$DorcIDSsecret = $DorcCliSecret

if ([string]::IsNullOrWhiteSpace($DorcIDSsecret)) {
Write-Error "The DorcIDSsecret is empty or null. Please provide a valid value."
return $null
}
$IDSHeaders = @{
"Content-Type" = "application/x-www-form-urlencoded"
}
$IDSFormData = @{
"grant_type" = "client_credentials"
"client_id" = "dorc-cli"
"client_secret" = "$DorcIDSsecret"
"scope" = "dorc-api.manage"
}

try {
$DorcApiUrl = "https://deploymentportal:8443"
$DorcApiUrl = $DorcApiUrl.TrimEnd('/')
$IDSBaseURL = Invoke-WebRequest -Uri "$DorcApiUrl/ApiConfig" -UseBasicParsing | ConvertFrom-Json
$IDSBaseURL = $IDSBaseURL.OAuthAuthority + "/connect/token"
Write-Host "Token endpoint is: $IDSBaseURL"
$IDSResponse = Invoke-WebRequest -Uri $IDSBaseURL -Method POST -Headers $IDSHeaders -Body $IDSFormData -UseBasicParsing
$TokenResponse = $IDSResponse.Content | ConvertFrom-Json
return $TokenResponse.access_token
} catch {
Write-Error "Failed to retrieve token. Please check DorcIDSsecret variable value! Error: $_"
Throw
return $null
}
}