From 6ccae70b0af93ea4241791b6fe1fdc48cbffff68 Mon Sep 17 00:00:00 2001 From: twerthi Date: Tue, 15 Oct 2024 13:27:03 -0700 Subject: [PATCH] Updating oracle create user template --- package-lock.json | 34 +++++++++++++++++++ package.json | 1 + .../oracle-create-user-if-not-exists.json | 10 +++--- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8f941a72..acd06ce4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,6 +26,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", @@ -10513,6 +10514,39 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/octopus-library": { + "version": "2.0.0", + "resolved": "file:", + "license": "Apache-2.0", + "dependencies": { + "@babel/core": "^7.24.4", + "@babel/node": "^7.23.9", + "@babel/preset-env": "^7.24.3", + "@babel/preset-react": "^7.24.1", + "@babel/register": "^7.23.7", + "compression": "^1.6.1", + "eslint-config-prettier": "^4.3.0", + "events": "^1.1.0", + "express": "^4.13.4", + "font-awesome": "^4.6.1", + "frameguard": "^3.0.0", + "history": "^2.1.0", + "isomorphic-dompurify": "^0.17.0", + "marked": "^4.0.10", + "moment": "^2.13.0", + "node-uuid": "^1.4.7", + "normalize.css": "^4.1.1", + "prettier": "^2.6.2", + "prop-types": "^15.6.0", + "pug": "^3.0.2", + "react": "^15.0.1", + "react-copy-to-clipboard": "^5.0.2", + "react-dom": "^15.0.1", + "react-router": "^2.3.0", + "react-syntax-highlighter": "^15.4.5", + "underscore": "^1.12.1" + } + }, "node_modules/on-finished": { "version": "2.3.0", "license": "MIT", diff --git a/package.json b/package.json index d7dc1db8..913ee46b 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/step-templates/oracle-create-user-if-not-exists.json b/step-templates/oracle-create-user-if-not-exists.json index 7d85aec3..462d8bf1 100644 --- a/step-templates/oracle-create-user-if-not-exists.json +++ b/step-templates/oracle-create-user-if-not-exists.json @@ -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": [ @@ -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" - } \ No newline at end of file + }