Skip to content

Commit

Permalink
Updating oracle create user template
Browse files Browse the repository at this point in the history
  • Loading branch information
twerthi committed Oct 15, 2024
1 parent a0a6e7b commit 6ccae70
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
34 changes: 34 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"moment": "^2.13.0",
"node-uuid": "^1.4.7",
"normalize.css": "^4.1.1",
"octopus-library": "file:",
"prettier": "^2.6.2",
"prop-types": "^15.6.0",
"pug": "^3.0.2",
Expand Down
10 changes: 5 additions & 5 deletions step-templates/oracle-create-user-if-not-exists.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"Name": "Oracle - Create User If Not Exists",
"Description": "Creates a new user account on a Oracle database server",
"ActionType": "Octopus.Script",
"Version": 2,
"Version": 3,
"Author": "twerthi",
"Packages": [],
"Properties": {
"Octopus.Action.Script.ScriptSource": "Inline",
"Octopus.Action.Script.Syntax": "PowerShell",
"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-UserExists\n{\n\t# Define parameters\n param ($Hostname,\n $Username)\n \n\t# Execute query\n return Invoke-SqlQuery \"SELECT * FROM ALL_USERS WHERE USERNAME = '$UserName'\"\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 $oracleLoginPasswordWithAddUserRights -AsPlainText -Force\n$ServerCredential = New-Object System.Management.Automation.PSCredential ($oracleLoginWithAddUserRights, $SecurePassword)\n\ntry\n{\n\t# Connect to MySQL\n Open-OracleConnection -Datasource $oracleDBServerName -Credential $ServerCredential -Port $oracleDBServerPort -ServiceName $oracleServiceName\n\n # See if database exists\n $userExists = Get-UserExists -Username $oracleNewUsername\n\n if ($userExists -eq $null)\n {\n # Create database\n Write-Output \"Creating user $oracleNewUsername ...\"\n $executionResults = Invoke-SqlUpdate \"CREATE USER `\"$oracleNewUsername`\" IDENTIFIED BY `\"$oracleNewUserPassword`\"\"\n\n # See if it was created\n $userExists = Get-UserExists -Username $oracleNewUsername\n \n # Check array\n if ($userExists -ne $null)\n {\n # Success\n Write-Output \"$oracleNewUsername created successfully!\"\n }\n else\n {\n # Failed\n Write-Error \"$oracleNewUsername was not created!\"\n }\n }\n else\n {\n \t# Display message\n Write-Output \"User $oracleNewUsername already exists.\"\n }\n}\nfinally\n{\n Close-SqlConnection\n}\n\n\n",
"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-UserExists\n{\n\t# Define parameters\n param ($Hostname,\n $Username)\n \n\t# Execute query\n return Invoke-SqlQuery \"SELECT * FROM ALL_USERS WHERE USERNAME = '$UserName'\" -ConnectionName $connectionName\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 $oracleLoginPasswordWithAddUserRights -AsPlainText -Force\n$ServerCredential = New-Object System.Management.Automation.PSCredential ($oracleLoginWithAddUserRights, $SecurePassword)\n\ntry\n{\n\t# Connect to MySQL\n Open-OracleConnection -Datasource $oracleDBServerName -Credential $ServerCredential -Port $oracleDBServerPort -ServiceName $oracleServiceName -ConnectionName $connectionName\n\n # See if database exists\n $userExists = Get-UserExists -Username $oracleNewUsername\n\n if ($userExists -eq $null)\n {\n # Create database\n Write-Output \"Creating user $oracleNewUsername ...\"\n $executionResults = Invoke-SqlUpdate \"CREATE USER `\"$oracleNewUsername`\" IDENTIFIED BY `\"$oracleNewUserPassword`\"\" -ConnectionName $connectionName\n\n # See if it was created\n $userExists = Get-UserExists -Username $oracleNewUsername\n \n # Check array\n if ($userExists -ne $null)\n {\n # Success\n Write-Output \"$oracleNewUsername created successfully!\"\n }\n else\n {\n # Failed\n Write-Error \"$oracleNewUsername was not created!\"\n }\n }\n else\n {\n \t# Display message\n Write-Output \"User $oracleNewUsername already exists.\"\n }\n}\nfinally \n{\n\t# Close connection if open\n if ((Test-SqlConnection -ConnectionName $connectionName) -eq $true)\n {\n \tClose-SqlConnection -ConnectionName $connectionName\n }\n}\n\n",
"Octopus.Action.EnabledFeatures": ""
},
"Parameters": [
Expand Down Expand Up @@ -85,10 +85,10 @@
}
],
"$Meta": {
"ExportedAt": "2020-08-21T21:52:45.217Z",
"OctopusVersion": "2020.3.2",
"ExportedAt": "2024-10-15T20:26:00.556Z",
"OctopusVersion": "2024.3.12828",
"Type": "ActionTemplate"
},
"LastModifiedBy": "twerthi",
"Category": "oracle"
}
}

0 comments on commit 6ccae70

Please sign in to comment.