diff --git a/step-templates/mariadb-add-database-user-to-role.json b/step-templates/mariadb-add-database-user-to-role.json index f1a57d6f..95197604 100644 --- a/step-templates/mariadb-add-database-user-to-role.json +++ b/step-templates/mariadb-add-database-user-to-role.json @@ -3,13 +3,13 @@ "Name": "MariaDB - Add Database User To Role", "Description": "Adds a database user to a role", "ActionType": "Octopus.Script", - "Version": 5, + "Version": 6, "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-UserInRole\n{\n\t# Define parameters\n param ($UserHostname,\n $Username,\n $RoleHostName,\n $RoleName)\n \n\t# Execute query\n $grants = Invoke-SqlQuery \"SHOW GRANTS FOR '$Username'@'$UserHostName';\"\n\n # Loop through Grants\n foreach ($grant in $grants.ItemArray)\n {\n # Check grant\n if ($grant -eq \"GRANT $RoleName TO '$Username'@'$UserHostName'\")\n {\n # They're in the group\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# Declare initial connection string\n$connectionString = \"Server=$addMariaDBServerName;Port=$addMariaDBServerPort;\"\n\n# Update the connection string based on authentication method\nswitch ($mariaDbAuthenticationMethod) {\n \"awsiam\" {\n # Region is part of the RDS endpoint, extract\n $region = ($addMariaDBServerName.Split(\".\"))[2]\n\n Write-Host \"Generating AWS IAM token ...\"\n $addLoginPasswordWithAddRoleRights = (aws rds generate-db-auth-token --hostname $addMariaDBServerName --region $region --port $addMariaDBServerPort --username $addLoginWithAddRoleRights)\n \n # Append remaining portion of connection string\n $connectionString += \";Uid=$addLoginWithAddRoleRights;Pwd=`\"$addLoginPasswordWithAddRoleRights`\";\"\n\n break\n }\n \"usernamepassword\" {\n # Append remaining portion of connection string\n $connectionString += \";Uid=$addLoginWithAddRoleRights;Pwd=`\"$addLoginPasswordWithAddRoleRights`\";\"\n \n break \n }\n \"windowsauthentication\" {\n # Append remaining portion of connection string\n $connectionString += \";IntegratedSecurity=yes;Uid=$addLoginWithAddRoleRights;\"\n\n break\n }\n}\n\n# Import the module\nImport-Module -Name $PowerShellModuleName\n\ntry\n{\n # Connect to MySQL\n Open-MySqlConnection -ConnectionString $connectionString\n\n # See if database exists\n $userInRole = Get-UserInRole -UserHostname $addUserHostname -Username $addUsername -RoleName $addRoleName\n\n if ($userInRole -eq $false)\n {\n # Create database\n Write-Output \"Adding user $addUsername@$addUserHostName to role $addRoleName ...\"\n $executionResults = Invoke-SqlUpdate \"GRANT $addRoleName TO '$addUsername'@'$addUserHostName';\"\n\n # See if it was created\n $userInRole = Get-UserInRole -UserHostname $addUserHostname -Username $addUsername -RoleName $addRoleName\n \n # Check array\n if ($userInRole -eq $true)\n {\n # Success\n Write-Output \"$addUserName@$addUserHostName added to $addRoleName successfully!\"\n }\n else\n {\n # Failed\n Write-Error \"Failure adding $addUserName@$addUserHostName to $addRoleName!\"\n }\n }\n else\n {\n \t# Display message\n Write-Output \"User $addUsername@$addUserHostName is already in role $addRoleName\"\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-UserInRole\n{\n\t# Define parameters\n param ($UserHostname,\n $Username,\n $RoleHostName,\n $RoleName)\n \n\t# Execute query\n $grants = Invoke-SqlQuery \"SHOW GRANTS FOR '$Username'@'$UserHostName';\" -ConnectionName $connectionName\n\n # Loop through Grants\n foreach ($grant in $grants.ItemArray)\n {\n # Check grant\n if ($grant -eq \"GRANT $RoleName TO '$Username'@'$UserHostName'\")\n {\n # They're in the group\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# Declare initial connection string\n$connectionString = \"Server=$addMariaDBServerName;Port=$addMariaDBServerPort;\"\n\n# Update the connection string based on authentication method\nswitch ($mariaDbAuthenticationMethod) {\n \"awsiam\" {\n # Region is part of the RDS endpoint, extract\n $region = ($addMariaDBServerName.Split(\".\"))[2]\n\n Write-Host \"Generating AWS IAM token ...\"\n $addLoginPasswordWithAddRoleRights = (aws rds generate-db-auth-token --hostname $addMariaDBServerName --region $region --port $addMariaDBServerPort --username $addLoginWithAddRoleRights)\n \n # Append remaining portion of connection string\n $connectionString += \";Uid=$addLoginWithAddRoleRights;Pwd=`\"$addLoginPasswordWithAddRoleRights`\";\"\n\n break\n }\n \"usernamepassword\" {\n # Append remaining portion of connection string\n $connectionString += \";Uid=$addLoginWithAddRoleRights;Pwd=`\"$addLoginPasswordWithAddRoleRights`\";\"\n \n break \n }\n \"windowsauthentication\" {\n # Append remaining portion of connection string\n $connectionString += \";IntegratedSecurity=yes;Uid=$addLoginWithAddRoleRights;\"\n\n break\n }\n}\n\n# Import the module\nImport-Module -Name $PowerShellModuleName\n\ntry\n{\n # Connect to MySQL\n Open-MySqlConnection -ConnectionString $connectionString -ConnectionName $connectionName\n\n # See if database exists\n $userInRole = Get-UserInRole -UserHostname $addUserHostname -Username $addUsername -RoleName $addRoleName\n\n if ($userInRole -eq $false)\n {\n # Create database\n Write-Output \"Adding user $addUsername@$addUserHostName to role $addRoleName ...\"\n $executionResults = Invoke-SqlUpdate \"GRANT $addRoleName TO '$addUsername'@'$addUserHostName';\" -ConnectionName $connectionName\n\n # See if it was created\n $userInRole = Get-UserInRole -UserHostname $addUserHostname -Username $addUsername -RoleName $addRoleName\n \n # Check array\n if ($userInRole -eq $true)\n {\n # Success\n Write-Output \"$addUserName@$addUserHostName added to $addRoleName successfully!\"\n }\n else\n {\n # Failed\n Write-Error \"Failure adding $addUserName@$addUserHostName to $addRoleName!\"\n }\n }\n else\n {\n \t# Display message\n Write-Output \"User $addUsername@$addUserHostName is already in role $addRoleName\"\n }\n}\nfinally\n{\n if ((Test-Connection -ConnectionName $connectionName) -eq $true)\n {\n Close-SqlConnection -ConnectionName $connectionName\n }\n}\n\n\n" }, "Parameters": [ { @@ -97,9 +97,9 @@ "LastModifiedBy": "coryreid", "StepPackageId": "Octopus.Script", "$Meta": { - "ExportedAt": "2022-07-12T19:52:36.677Z", - "OctopusVersion": "2022.3.2617-hotfix.4278", - "Type": "ActionTemplate" + "ExportedAt": "2026-02-19T01:10:27.925Z", + "OctopusVersion": "2025.4.10425", + "Type": "ActionTemplate" }, "Category": "mariadb" } diff --git a/step-templates/mariadb-create-database.json b/step-templates/mariadb-create-database.json index cdd0fb00..b6c3320d 100644 --- a/step-templates/mariadb-create-database.json +++ b/step-templates/mariadb-create-database.json @@ -3,13 +3,13 @@ "Name": "MariaDB - Create Database If Not Exists", "Description": "Creates a MariaDB database if it doesn't already exist.", "ActionType": "Octopus.Script", - "Version": 6, + "Version": 7, "Author": "twerthi", "Packages": [], "Properties": { "Octopus.Action.Script.ScriptSource": "Inline", "Octopus.Action.Script.Syntax": "PowerShell", - "Octopus.Action.Script.ScriptBody": "# Define functions\nfunction Get-ModuleInstalled {\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 # It is installed\n return $true\n }\n else {\n # Module not installed\n return $false\n }\n}\n\nfunction Install-PowerShellModule {\n # Define parameters\n param(\n $PowerShellModuleName,\n $LocalModulesPath\n )\n\n # Check to see if the package provider has been installed\n if ((Get-NugetPackageProviderNotInstalled) -ne $false) {\n # 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 # Save the module in the temporary location\n Save-Module -Name $PowerShellModuleName -Path $LocalModulesPath -Force\n}\n\nfunction Get-NugetPackageProviderNotInstalled {\n # See if the nuget package provider has been installed\n return ($null -eq (Get-PackageProvider -ListAvailable -Name Nuget -ErrorAction SilentlyContinue))\n}\n\nfunction Get-DatabaseExists {\n # Define parameters\n param ($DatabaseName)\n \n # Execute query\n return Invoke-SqlQuery \"SHOW DATABASES LIKE '$DatabaseName';\"\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 # 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 # Use specific location\n $PowerShellModuleName = \"$LocalModules\\$PowerShellModuleName\"\n}\n\n\n# Declare initial connection string\n$connectionString = \"Server=$createMariaDBServerName;Port=$createPort;\"\n\n# Update the connection string based on authentication method\nswitch ($mariaDbAuthenticationMethod) {\n \"awsiam\" {\n # Region is part of the RDS endpoint, extract\n $region = ($createMariaDBServerName.Split(\".\"))[2]\n\n Write-Host \"Generating AWS IAM token ...\"\n $createUserPassword = (aws rds generate-db-auth-token --hostname $createMariaDBServerName --region $region --port $createPort --username $createUsername)\n \n # Append remaining portion of connection string\n $connectionString += \";Uid=$createUsername;Pwd=`\"$createUserPassword`\";\"\n\n break\n }\n \"usernamepassword\" {\n # Append remaining portion of connection string\n $connectionString += \";Uid=$createUsername;Pwd=`\"$createUserPassword`\";\"\n \n break \n }\n \"windowsauthentication\" {\n # Append remaining portion of connection string\n $connectionString += \";IntegratedSecurity=yes;Uid=$createUsername;\"\n\n break\n }\n}\n\n# Import the module\nImport-Module -Name $PowerShellModuleName\n\ntry {\n # Connect to MySQL\n Open-MySqlConnection -ConnectionString $connectionString\n\n # See if database exists\n $databaseExists = Get-DatabaseExists -DatabaseName $createDatabaseName\n\n if ($databaseExists.ItemArray.Count -eq 0) {\n # Create database\n Write-Output \"Creating database $createDatabaseName ...\"\n $executionResult = Invoke-SqlUpdate \"CREATE DATABASE $createDatabaseName;\"\n\n # Check result\n if ($executionResult -ne 1) {\n # Commit transaction\n Write-Error \"Create schema failed.\"\n }\n else {\n # See if it was created\n $databaseExists = Get-DatabaseExists -DatabaseName $createDatabaseName\n \n # Check array\n if ($databaseExists.ItemArray.Count -eq 1) {\n # Success\n Write-Output \"$createDatabaseName created successfully!\"\n }\n else {\n # Failed\n Write-Error \"$createDatabaseName was not created!\"\n }\n }\n }\n else {\n # Display message\n Write-Output \"Database $createDatabaseName already exists.\"\n }\n}\nfinally {\n Close-SqlConnection\n}\n" + "Octopus.Action.Script.ScriptBody": "# Define variables\n$connectionName = \"OctopusDeploy\"\n\n# Define functions\nfunction Get-ModuleInstalled {\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 # It is installed\n return $true\n }\n else {\n # Module not installed\n return $false\n }\n}\n\nfunction Install-PowerShellModule {\n # Define parameters\n param(\n $PowerShellModuleName,\n $LocalModulesPath\n )\n\n # Check to see if the package provider has been installed\n if ((Get-NugetPackageProviderNotInstalled) -ne $false) {\n # 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 # Save the module in the temporary location\n Save-Module -Name $PowerShellModuleName -Path $LocalModulesPath -Force\n}\n\nfunction Get-NugetPackageProviderNotInstalled {\n # See if the nuget package provider has been installed\n return ($null -eq (Get-PackageProvider -ListAvailable -Name Nuget -ErrorAction SilentlyContinue))\n}\n\nfunction Get-DatabaseExists {\n # Define parameters\n param ($DatabaseName)\n \n # Execute query\n return Invoke-SqlQuery \"SHOW DATABASES LIKE '$DatabaseName';\" -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 # 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 # Use specific location\n $PowerShellModuleName = \"$LocalModules\\$PowerShellModuleName\"\n}\n\n\n# Declare initial connection string\n$connectionString = \"Server=$createMariaDBServerName;Port=$createPort;\"\n\n# Update the connection string based on authentication method\nswitch ($mariaDbAuthenticationMethod) {\n \"awsiam\" {\n # Region is part of the RDS endpoint, extract\n $region = ($createMariaDBServerName.Split(\".\"))[2]\n\n Write-Host \"Generating AWS IAM token ...\"\n $createUserPassword = (aws rds generate-db-auth-token --hostname $createMariaDBServerName --region $region --port $createPort --username $createUsername)\n \n # Append remaining portion of connection string\n $connectionString += \";Uid=$createUsername;Pwd=`\"$createUserPassword`\";\"\n\n break\n }\n \"usernamepassword\" {\n # Append remaining portion of connection string\n $connectionString += \";Uid=$createUsername;Pwd=`\"$createUserPassword`\";\"\n \n break \n }\n \"windowsauthentication\" {\n # Append remaining portion of connection string\n $connectionString += \";IntegratedSecurity=yes;Uid=$createUsername;\"\n\n break\n }\n}\n\n# Import the module\nImport-Module -Name $PowerShellModuleName\n\ntry {\n # Connect to MySQL\n Open-MySqlConnection -ConnectionString $connectionString -ConnectionName $connectionName\n\n # See if database exists\n $databaseExists = Get-DatabaseExists -DatabaseName $createDatabaseName\n\n if ($databaseExists.ItemArray.Count -eq 0) {\n # Create database\n Write-Output \"Creating database $createDatabaseName ...\"\n $executionResult = Invoke-SqlUpdate \"CREATE DATABASE $createDatabaseName;\" -ConnectionName $connectionName\n\n # Check result\n if ($executionResult -ne 1) {\n # Commit transaction\n Write-Error \"Create schema failed.\"\n }\n else {\n # See if it was created\n $databaseExists = Get-DatabaseExists -DatabaseName $createDatabaseName\n \n # Check array\n if ($databaseExists.ItemArray.Count -eq 1) {\n # Success\n Write-Output \"$createDatabaseName created successfully!\"\n }\n else {\n # Failed\n Write-Error \"$createDatabaseName was not created!\"\n }\n }\n }\n else {\n # Display message\n Write-Output \"Database $createDatabaseName already exists.\"\n }\n}\nfinally {\n # Test to see if connection is open\n if ((Test-SqlConnection -ConnectionName $connectionName) -eq $true)\n {\n Write-Host \"Closing connection ...\"\n Close-SqlConnection -ConnectionName $connectionName\n }\n}\n" }, "Parameters": [ { @@ -77,9 +77,9 @@ "LastModifiedBy": "coryreid", "StepPackageId": "Octopus.Script", "$Meta": { - "ExportedAt": "2022-07-12T19:34:19.067Z", - "OctopusVersion": "2022.3.2617-hotfix.4278", - "Type": "ActionTemplate" + "ExportedAt": "2026-02-19T01:19:04.871Z", + "OctopusVersion": "2025.4.10425", + "Type": "ActionTemplate" }, "Category": "mariadb" } diff --git a/step-templates/mariadb-create-user.json b/step-templates/mariadb-create-user.json index e8cf048c..2304fa33 100644 --- a/step-templates/mariadb-create-user.json +++ b/step-templates/mariadb-create-user.json @@ -3,13 +3,13 @@ "Name": "MariaDB - Create User If Not Exists", "Description": "Creates a new user account on a MariaDB database server", "ActionType": "Octopus.Script", - "Version": 5, + "Version": 6, "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 mysql.user WHERE Host = '$Hostname' AND User = '$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# Declare initial connection string\n$connectionString = \"Server=$createMariaDBServerName;Port=$createPort;\"\n\n# Update the connection string based on authentication method\nswitch ($mariaDbAuthenticationMethod) {\n \"awsiam\" {\n # Region is part of the RDS endpoint, extract\n $region = ($createMariaDBServerName.Split(\".\"))[2]\n\n Write-Host \"Generating AWS IAM token ...\"\n $createUserPassword = (aws rds generate-db-auth-token --hostname $createMariaDBServerName --region $region --port $createPort --username $createUsername)\n \n # Append remaining portion of connection string\n $connectionString += \";Uid=$createUsername;Pwd=`\"$createUserPassword`\";\"\n\n break\n }\n \"usernamepassword\" {\n # Append remaining portion of connection string\n $connectionString += \";Uid=$createUsername;Pwd=`\"$createUserPassword`\";\"\n \n break \n }\n \"windowsauthentication\" {\n # Append remaining portion of connection string\n $connectionString += \";IntegratedSecurity=yes;Uid=$createUsername;\"\n\n break\n }\n}\n\n# Import the module\nImport-Module -Name $PowerShellModuleName\n\ntry\n{\n # Connect to MySQL\n Open-MySqlConnection -ConnectionString $connectionString\n\n # See if database exists\n $userExists = Get-UserExists -Hostname $createUserHostname -Username $createNewUsername\n\n if ($userExists -eq $null)\n {\n # Create database\n Write-Output \"Creating user $createNewUsername ...\"\n $executionResults = Invoke-SqlUpdate \"CREATE USER '$createNewUsername'@'$createUserHostname' IDENTIFIED BY '$createNewUserPassword';\"\n\n # See if it was created\n $userExists = Get-UserExists -Hostname $createUserHostname -Username $createNewUsername\n \n # Check array\n if ($userExists -ne $null)\n {\n # Success\n Write-Output \"$createNewUsername created successfully!\"\n }\n else\n {\n # Failed\n Write-Error \"$createNewUsername was not created!\"\n }\n }\n else\n {\n \t# Display message\n Write-Output \"User $createNewUsername on $createUserHostname 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 mysql.user WHERE Host = '$Hostname' AND User = '$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# Declare initial connection string\n$connectionString = \"Server=$($createMariaDBServerName);Port=$($createMariaDBServerPort);\"\n\n# Update the connection string based on authentication method\nswitch ($mariaDbAuthenticationMethod) {\n \"awsiam\" {\n # Region is part of the RDS endpoint, extract\n $region = ($createMariaDBServerName.Split(\".\"))[2]\n\n Write-Host \"Generating AWS IAM token ...\"\n $createUserPassword = (aws rds generate-db-auth-token --hostname $createMariaDBServerName --region $region --port $createPort --username $createLoginWithAddUserRights)\n \n # Append remaining portion of connection string\n $connectionString += \";Uid=$($createLoginWithAddUserRights);Pwd=`\"$($createUserPassword)`\";\"\n\n break\n }\n \"usernamepassword\" {\n # Append remaining portion of connection string\n $connectionString += \";Uid=$($createLoginWithAddUserRights);Pwd=`\"$($createLoginPasswordWithAddUserRights)`\";\"\n \n break \n }\n \"windowsauthentication\" {\n # Append remaining portion of connection string\n $connectionString += \";IntegratedSecurity=yes;Uid=$($createLoginWithAddUserRights);\"\n\n break\n }\n}\n\n# Import the module\nImport-Module -Name $PowerShellModuleName\n\ntry\n{\n # Connect to MySQL\n Open-MySqlConnection -ConnectionString $connectionString -ConnectionName $connectionName\n\n # See if database exists\n $userExists = Get-UserExists -Hostname $createUserHostname -Username $createNewUsername\n\n if ($userExists -eq $null)\n {\n # Create database\n Write-Output \"Creating user $createNewUsername ...\"\n $executionResults = Invoke-SqlUpdate \"CREATE USER '$createNewUsername'@'$createUserHostname' IDENTIFIED BY '$createNewUserPassword';\" -ConnectionName $connectionName\n\n # See if it was created\n $userExists = Get-UserExists -Hostname $createUserHostname -Username $createNewUsername\n \n # Check array\n if ($userExists -ne $null)\n {\n # Success\n Write-Output \"$createNewUsername created successfully!\"\n }\n else\n {\n # Failed\n Write-Error \"$createNewUsername was not created!\"\n }\n }\n else\n {\n \t# Display message\n Write-Output \"User $createNewUsername on $createUserHostname already exists.\"\n }\n}\nfinally\n{\n # Test to see if connection is open\n if ((Test-SqlConnection -ConnectionName $connectionName) -eq $true)\n {\n Write-Host \"Closing connection ...\"\n Close-SqlConnection -ConnectionName $connectionName\n }\n}\n\n\n" }, "Parameters": [ { @@ -97,9 +97,9 @@ "LastModifiedBy": "coryreid", "StepPackageId": "Octopus.Script", "$Meta": { - "ExportedAt": "2022-07-12T19:41:41.956Z", - "OctopusVersion": "2022.3.2617-hotfix.4278", - "Type": "ActionTemplate" + "ExportedAt": "2026-02-19T01:20:22.243Z", + "OctopusVersion": "2025.4.10425", + "Type": "ActionTemplate" }, "Category": "mariadb" }