-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencodeSecr.ps1
More file actions
54 lines (44 loc) · 1.19 KB
/
encodeSecr.ps1
File metadata and controls
54 lines (44 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Paths to the key files
$privateKeyPath = "./auth/secr.pem"
$publicKeyPath = "./auth/pub.pem"
$secretYamlPath = "./infra/k8s/jwt-secret.yaml"
# Function to encode a key file
function Encode-KeyFile {
param (
[string]$keyPath
)
# Read the key from the file
$key = Get-Content -Path $keyPath -Raw
# Check if the file was read successfully
if ($null -eq $key) {
Write-Error "Failed to read the key file: $keyPath"
return $null
}
$bytes = [System.Text.Encoding]::UTF8.GetBytes($key)
$encoded = [Convert]::ToBase64String($bytes)
return $encoded
}
# Encode private key
$privateKeyEncoded = Encode-KeyFile -keyPath $privateKeyPath
if ($null -eq $privateKeyEncoded) {
exit 1
}
# Encode public key
$publicKeyEncoded = Encode-KeyFile -keyPath $publicKeyPath
if ($null -eq $publicKeyEncoded) {
exit 1
}
# Create the Kubernetes Secret YAML
$secretYaml = @"
apiVersion: v1
kind: Secret
metadata:
name: jwt-secret
type: Opaque
data:
secr-key: $privateKeyEncoded
pub-key: $publicKeyEncoded
"@
# Save the YAML to a file
$secretYaml | Out-File -FilePath $secretYamlPath -Encoding utf8
Write-Host "Kubernetes Secret YAML file created: $secretYamlPath"