Skip to content

Commit 0195956

Browse files
authored
Updating connection name for oracle (#1705)
1 parent 30d3967 commit 0195956

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

‎step-templates/oracle-add-user-to-role.json‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
"Name": "Oracle - Add Database User To Role",
44
"Description": "Adds database user to a role",
55
"ActionType": "Octopus.Script",
6-
"Version": 2,
6+
"Version": 3,
77
"Author": "twerthi",
88
"Packages": [],
99
"Properties": {
1010
"Octopus.Action.Script.ScriptSource": "Inline",
1111
"Octopus.Action.Script.Syntax": "PowerShell",
12-
"Octopus.Action.Script.ScriptBody": "# Define functions\nfunction Get-ModuleInstalled\n{\n # Define parameters\n param(\n $PowerShellModuleName\n )\n\n # Check to see if the module is installed\n if ($null -ne (Get-Module -ListAvailable -Name $PowerShellModuleName))\n {\n # It is installed\n return $true\n }\n else\n {\n # Module not installed\n return $false\n }\n}\n\nfunction Install-PowerShellModule\n{\n # Define parameters\n param(\n $PowerShellModuleName,\n $LocalModulesPath\n )\n\n\t# Check to see if the package provider has been installed\n if ((Get-NugetPackageProviderNotInstalled) -ne $false)\n {\n \t# Display that we need the nuget package provider\n Write-Host \"Nuget package provider not found, installing ...\"\n \n # Install Nuget package provider\n Install-PackageProvider -Name Nuget -Force\n }\n\n\t# Save the module in the temporary location\n Save-Module -Name $PowerShellModuleName -Path $LocalModulesPath -Force\n}\n\nfunction Get-NugetPackageProviderNotInstalled\n{\n\t# See if the nuget package provider has been installed\n return ($null -eq (Get-PackageProvider -ListAvailable -Name Nuget -ErrorAction SilentlyContinue))\n}\n\nfunction Get-UserInRole\n{\n\t# Define parameters\n param (\n $Username,\n $RoleName)\n \n\t# Execute query\n $userRole = Invoke-SqlQuery \"SELECT * FROM DBA_ROLE_PRIVS WHERE GRANTEE = '$Username' AND GRANTED_ROLE = '$RoleName'\"\n\n # Check to see if anything was returned\n if ($userRole.ItemArray.Count -gt 0)\n {\n # Found\n return $true\n }\n \n\n # Not found\n return $false\n}\n\n# Define PowerShell Modules path\n$LocalModules = (New-Item \"$PSScriptRoot\\Modules\" -ItemType Directory -Force).FullName\n$env:PSModulePath = \"$LocalModules$([System.IO.Path]::PathSeparator)$env:PSModulePath\"\n$PowerShellModuleName = \"SimplySql\"\n\n# Set secure protocols\n[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls11 -bor [System.Net.SecurityProtocolType]::Tls12\n\n# Check to see if SimplySql module is installed\nif ((Get-ModuleInstalled -PowerShellModuleName $PowerShellModuleName) -ne $true)\n{\n # Tell user what we're doing\n Write-Output \"PowerShell module $PowerShellModuleName is not installed, downloading temporary copy ...\"\n\n # Install temporary copy\n Install-PowerShellModule -PowerShellModuleName $PowerShellModuleName -LocalModulesPath $LocalModules\n}\n\n# Display\nWrite-Output \"Importing module $PowerShellModuleName ...\"\n\n# Check to see if it was downloaded\nif ((Test-Path -Path \"$LocalModules\\$PowerShellModuleName\") -eq $true)\n{\n\t# Use specific location\n $PowerShellModuleName = \"$LocalModules\\$PowerShellModuleName\"\n}\n\n# Import the module\nImport-Module -Name $PowerShellModuleName\n\n# Create credential object for the connection\n$SecurePassword = ConvertTo-SecureString $oracleLoginPasswordWithAddRoleRights -AsPlainText -Force\n$ServerCredential = New-Object System.Management.Automation.PSCredential ($oracleLoginWithAddRoleRights, $SecurePassword)\n\ntry\n{\n\t# Connect to MySQL\n Open-OracleConnection -Datasource $oracleServerName -Credential $ServerCredential -Port $oracleServerPort -ServiceName $oracleServiceName\n\n # See if database exists\n $userInRole = Get-UserInRole -Username $oracleUsername -RoleName $oracleRoleName\n\n if ($userInRole -eq $false)\n {\n # Create database\n Write-Output \"Adding user $oracleUsername to role $oracleRoleName ...\"\n $executionResults = Invoke-SqlUpdate \"GRANT `\"$oracleRoleName`\" TO `\"$oracleUsername`\"\"\n\n # See if it was created\n $userInRole = Get-UserInRole -Username $oracleUsername -RoleName $oracleRoleName\n \n # Check array\n if ($userInRole -eq $true)\n {\n # Success\n Write-Output \"$oracleUserName added to $oracleRoleName successfully!\"\n }\n else\n {\n # Failed\n Write-Error \"Failure adding $oracleUserName to $oracleRoleName!\"\n }\n }\n else\n {\n \t# Display message\n Write-Output \"User $oracleUsername is already in role $oracleRoleName\"\n }\n}\nfinally\n{\n Close-SqlConnection\n}\n\n\n",
12+
"Octopus.Action.Script.ScriptBody": "# Define variables\n$connectionName = \"OctopusDeploy\"\n\n# Define functions\nfunction Get-ModuleInstalled\n{\n # Define parameters\n param(\n $PowerShellModuleName\n )\n\n # Check to see if the module is installed\n if ($null -ne (Get-Module -ListAvailable -Name $PowerShellModuleName))\n {\n # It is installed\n return $true\n }\n else\n {\n # Module not installed\n return $false\n }\n}\n\nfunction Install-PowerShellModule\n{\n # Define parameters\n param(\n $PowerShellModuleName,\n $LocalModulesPath\n )\n\n\t# Check to see if the package provider has been installed\n if ((Get-NugetPackageProviderNotInstalled) -ne $false)\n {\n \t# Display that we need the nuget package provider\n Write-Host \"Nuget package provider not found, installing ...\"\n \n # Install Nuget package provider\n Install-PackageProvider -Name Nuget -Force\n }\n\n\t# Save the module in the temporary location\n Save-Module -Name $PowerShellModuleName -Path $LocalModulesPath -Force\n}\n\nfunction Get-NugetPackageProviderNotInstalled\n{\n\t# See if the nuget package provider has been installed\n return ($null -eq (Get-PackageProvider -ListAvailable -Name Nuget -ErrorAction SilentlyContinue))\n}\n\nfunction Get-UserInRole\n{\n\t# Define parameters\n param (\n $Username,\n $RoleName)\n \n\t# Execute query\n $userRole = Invoke-SqlQuery \"SELECT * FROM DBA_ROLE_PRIVS WHERE GRANTEE = '$Username' AND GRANTED_ROLE = '$RoleName'\" -ConnectionName $connectionName\n\n # Check to see if anything was returned\n if ($userRole.ItemArray.Count -gt 0)\n {\n # Found\n return $true\n }\n \n\n # Not found\n return $false\n}\n\n# Define PowerShell Modules path\n$LocalModules = (New-Item \"$PSScriptRoot\\Modules\" -ItemType Directory -Force).FullName\n$env:PSModulePath = \"$LocalModules$([System.IO.Path]::PathSeparator)$env:PSModulePath\"\n$PowerShellModuleName = \"SimplySql\"\n\n# Set secure protocols\n[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls11 -bor [System.Net.SecurityProtocolType]::Tls12\n\n# Check to see if SimplySql module is installed\nif ((Get-ModuleInstalled -PowerShellModuleName $PowerShellModuleName) -ne $true)\n{\n # Tell user what we're doing\n Write-Output \"PowerShell module $PowerShellModuleName is not installed, downloading temporary copy ...\"\n\n # Install temporary copy\n Install-PowerShellModule -PowerShellModuleName $PowerShellModuleName -LocalModulesPath $LocalModules\n}\n\n# Display\nWrite-Output \"Importing module $PowerShellModuleName ...\"\n\n# Check to see if it was downloaded\nif ((Test-Path -Path \"$LocalModules\\$PowerShellModuleName\") -eq $true)\n{\n\t# Use specific location\n $PowerShellModuleName = \"$LocalModules\\$PowerShellModuleName\"\n}\n\n# Import the module\nImport-Module -Name $PowerShellModuleName\n\n# Create credential object for the connection\n$SecurePassword = ConvertTo-SecureString $oracleLoginPasswordWithAddRoleRights -AsPlainText -Force\n$ServerCredential = New-Object System.Management.Automation.PSCredential ($oracleLoginWithAddRoleRights, $SecurePassword)\n\ntry\n{\n\t# Connect to MySQL\n Open-OracleConnection -Datasource $oracleServerName -Credential $ServerCredential -Port $oracleServerPort -ServiceName $oracleServiceName -ConnectionName $connectionName\n\n # See if database exists\n $userInRole = Get-UserInRole -Username $oracleUsername -RoleName $oracleRoleName\n\n if ($userInRole -eq $false)\n {\n # Create database\n Write-Output \"Adding user $oracleUsername to role $oracleRoleName ...\"\n $executionResults = Invoke-SqlUpdate \"GRANT `\"$oracleRoleName`\" TO `\"$oracleUsername`\"\" -ConnectionName $connectionName\n\n # See if it was created\n $userInRole = Get-UserInRole -Username $oracleUsername -RoleName $oracleRoleName\n \n # Check array\n if ($userInRole -eq $true)\n {\n # Success\n Write-Output \"$oracleUserName added to $oracleRoleName successfully!\"\n }\n else\n {\n # Failed\n Write-Error \"Failure adding $oracleUserName to $oracleRoleName!\"\n }\n }\n else\n {\n \t# Display message\n Write-Output \"User $oracleUsername is already in role $oracleRoleName\"\n }\n}\nfinally\n{\n # Close connection if open\n if ((Test-SqlConnection -ConnectionName $connectionName) -eq $true)\n {\n Close-SqlConnection -ConnectionName $connectionName\n }\n}\n\n\n",
1313
"Octopus.Action.EnabledFeatures": ""
1414
},
1515
"Parameters": [
@@ -84,11 +84,11 @@
8484
}
8585
}
8686
],
87-
"$Meta": {
88-
"ExportedAt": "2020-08-21T21:54:08.753Z",
89-
"OctopusVersion": "2020.3.2",
90-
"Type": "ActionTemplate"
91-
},
87+
"$Meta": {
88+
"ExportedAt": "2026-08-31T19:34:47.075Z",
89+
"OctopusVersion": "2026.2.13364",
90+
"Type": "ActionTemplate"
91+
},
9292
"LastModifiedBy": "twerthi",
9393
"Category": "oracle"
94-
}
94+
}

0 commit comments

Comments
 (0)