Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save paulobalonye/b40927c033742ae28bf8ced48064a86f to your computer and use it in GitHub Desktop.

Select an option

Save paulobalonye/b40927c033742ae28bf8ced48064a86f to your computer and use it in GitHub Desktop.
Sitecore Kubernetes - Generate Self Signed Certificate and fill out secrets
$prefix = ""
function ConvertTo-CompressedBase64String {
[CmdletBinding()]
Param (
[Parameter(Mandatory)]
[ValidateScript({
if (-Not ($_ | Test-Path) ) {
throw "The file or folder $_ does not exist"
}
if (-Not ($_ | Test-Path -PathType Leaf) ) {
throw "The Path argument must be a file. Folder paths are not allowed."
}
return $true
})]
[string] $Path
)
$fileBytes = [System.IO.File]::ReadAllBytes($Path)
[System.IO.MemoryStream] $memoryStream = New-Object System.IO.MemoryStream
$gzipStream = New-Object System.IO.Compression.GzipStream $memoryStream, ([IO.Compression.CompressionMode]::Compress)
$gzipStream.Write($fileBytes, 0, $fileBytes.Length)
$gzipStream.Close()
$memoryStream.Close()
$compressedFileBytes = $memoryStream.ToArray()
$encodedCompressedFileData = [Convert]::ToBase64String($compressedFileBytes)
$gzipStream.Dispose()
$memoryStream.Dispose()
return $encodedCompressedFileData
}
ConvertTo-CompressedBase64String -Path C:\license.xml | Out-File -Encoding ascii -NoNewline -Confirm -FilePath .\secrets\sitecore-license.txt
$certificatePassword = "Test123!"
$certificatePassword | Out-File -Encoding ascii -NoNewline -Confirm -FilePath .\secrets\sitecore-identitycertificatepassword.txt
$newCert = New-SelfSignedCertificate -DnsName "localhost" -FriendlyName "Sitecore Identity Token Signing" -NotAfter (Get-Date).AddYears(5)
Export-PfxCertificate -Cert $newCert -FilePath .\SitecoreIdentityTokenSigning.pfx -Password (ConvertTo-SecureString -String $certificatePassword -Force -AsPlainText)
[System.Convert]::ToBase64String([System.IO.File]::ReadAllBytes((Get-Item .\SitecoreIdentityTokenSigning.pfx))) | Out-File -Encoding ascii -NoNewline -Confirm -FilePath .\secrets\sitecore-identitycertificate.txt
Function Set-RandomString {
[CmdletBinding()]
Param (
[int] $length = 8,
[string] $path
)
Begin{
}
Process{
( -join ((0x30..0x39) + ( 0x41..0x5A) + ( 0x61..0x7A) | Get-Random -Count $length | % {[char]$_}) ) | Out-File -Encoding ascii -NoNewline -Confirm -FilePath .\secrets\$path
}
}
Set-RandomString -length 64 -path "sitecore-telerikencryptionkey.txt"
Set-RandomString -length 64 -path "sitecore-identitysecret.txt"
Set-RandomString -length 64 -path "sitecore-reportingapikey.txt"
Set-RandomString -length 16 -path "sitecore-databasepassword.txt"
Set-RandomString -length 16 -path "sitecore-core-database-password.txt"
Set-RandomString -length 16 -path "sitecore-master-database-password.txt"
Set-RandomString -length 16 -path "sitecore-web-database-password.txt"
Set-RandomString -length 16 -path "sitecore-reporting-database-password.txt"
Set-RandomString -length 16 -path "sitecore-forms-database-password.txt"
Set-RandomString -length 16 -path "sitecore-exm-master-database-password.txt"
Set-RandomString -length 16 -path "sitecore-messaging-database-password.txt"
Set-RandomString -length 16 -path "sitecore-marketing-automation-database-password.txt"
Set-RandomString -length 16 -path "sitecore-processing-engine-storage-database-password.txt"
Set-RandomString -length 16 -path "sitecore-processing-engine-tasks-database-password.txt"
Set-RandomString -length 16 -path "sitecore-processing-pools-database-password.txt"
Set-RandomString -length 16 -path "sitecore-processing-tasks-database-password.txt"
Set-RandomString -length 16 -path "sitecore-reference-data-database-password.txt"
Set-RandomString -length 16 -path "sitecore-collection-shardmapmanager-database-password.txt"
Set-RandomString -length 12 -path "sitecore-adminpassword.txt"
"$prefix-elasticpool" | Out-File -Encoding ascii -NoNewline -Confirm -FilePath .\secrets\sitecore-database-elastic-pool-name.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment