Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyg-1 authored Sep 14, 2023
1 parent aae058d commit 33eda34
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Functions/Get-KubernetesSecretMetadata.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,4 @@ function Get-KubernetesSecretMetadata {
}
}
}
}
}
37 changes: 29 additions & 8 deletions Functions/Set-KubernetesSecretData.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ function Set-KubernetesSecretData {
Set-KubernetesSecretData -SecretName "my-secret" -SecretData $secretDataCred
Sets a Kubernetes secret in the default namespace with a name of 'my-secret' with a key of 'myapikey' and a value of '2@GaImh59O3C8!TMwLSf$gVrjsuiDZAEveKxkd'.
.EXAMPLE
$secret = "my-secret"
$annotations = @{"config-management.tool/version" = "1.2.3"; "config-management.tool/managed" = $true }
$sd = New-KubernetesSecretData -SecretDataKey "myapikey" -SecretDataValue '$U#C9nGDiXJ6To3SY78NZjlr'
Set-KubernetesSecretData -SecretName $secret -SecretData $sd -Annotation $annotations
Sets a Kubernetes secret in the default namespace with a name of 'my-secret' with a key of 'myapikey' and a value of '$U#C9nGDiXJ6To3SY78NZjlr' with the following annotations:
config-management.tool/version: 1.2.3
config-management.tool/managed: true
.EXAMPLE
$secretDataName = "mysecondapikey"
$secretDataCred = New-KubernetesSecretData -SecretDataKey $secretDataName -SecretDataValue 'NRHnXj#DG&sJA*7IYgl$r!aO'
Expand Down Expand Up @@ -70,6 +79,8 @@ function Set-KubernetesSecretData {

[Parameter(Mandatory = $false)][Alias('a')][Switch]$Add,

[Parameter(Mandatory = $false)][ValidateNotNull()][Alias('an', 'Annotations')][System.Collections.Hashtable]$Annotation,

[Parameter(Mandatory = $false)][Alias('json', 'j')][Switch]$AsJson
)
BEGIN {
Expand Down Expand Up @@ -134,19 +145,29 @@ function Set-KubernetesSecretData {
if (-not($PSBoundParameters.ContainsKey("Add"))) {
Write-Verbose -Message ("Added new data with a key of {0} to the following generic secret: {1}:{2}" -f $secretKeyName, $Namespace, $SecretName)
}
}
catch {
$ArgumentException = [ArgumentException]::new("Unable to update the following secret in the $Namespace namespace: $SecretName")
Write-Error -Exception $ArgumentException -ErrorAction Stop
}

if ($PSBoundParameters.ContainsKey("AsJson")) {
$secretObjectMetadata = Get-KubernetesSecretMetadata -Namespace $Namespace -SecretName $SecretName -AsJson
if ($PSBoundParameters.ContainsKey("Annotation")) {
try {
Set-KubernetesSecretAnnotation -Namespace $Namespace -SecretName $SecretName -Annotation $Annotation -ErrorAction Stop
}
else {
$secretObjectMetadata = Get-KubernetesSecretMetadata -Namespace $Namespace -SecretName $SecretName
catch {
Write-Error -Exception $_.Exception -ErrorAction Stop
}
}

Write-Output -InputObject $secretObjectMetadata
[System.Management.Automation.PSObject]$secretObjectMetadata = $null
if ($PSBoundParameters.ContainsKey("AsJson")) {
$secretObjectMetadata = Get-KubernetesSecretMetadata -Namespace $Namespace -SecretName $SecretName -AsJson
}
catch {
$ArgumentException = [ArgumentException]::new("Unable to update the following secret in the $Namespace namespace: $SecretName")
Write-Error -Exception $ArgumentException -ErrorAction Stop
else {
$secretObjectMetadata = Get-KubernetesSecretMetadata -Namespace $Namespace -SecretName $SecretName
}

Write-Output -InputObject $secretObjectMetadata
}
}

0 comments on commit 33eda34

Please sign in to comment.