azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

Az.App (Container App) feature - Secrets handling with cmdlets new-azcontainerappsecretobject & update-azcontainerapp

Open larswurm opened this issue 3 years ago • 5 comments

Description

How should one append a additional secret to an existing container app that is already one or several secrets assigned to it? If I manually configure multiple secrets to one container app - I can retrieve it using the corresponding get-azcontainerappsecret cmdlet. However, if I try to build a new secret object and then insert that secret using the update-azcontainerapp -ConfigurationSecret - it will overwrite existing secrets (no append avail). Please advice or confirm issue.

Script or Debug output

No response

Environment data

No response

Module versions

PS C:\Users\lawur> get-command *secre* | where {$_.Source -eq "Az.App"}

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Function        Get-AzContainerAppManagedEnvDaprSecret             0.1.0      Az.App
Function        Get-AzContainerAppSecret                           0.1.0      Az.App
Function        New-AzContainerAppSecretObject                     0.1.0      Az.App

Error output

No response

larswurm avatar Jul 23 '22 14:07 larswurm

@lijinpei2008 , could you help to look into it?

dingmeng-xue avatar Jul 25 '22 06:07 dingmeng-xue

Hi @larswurm, You can solve the issue by using the following example:

$secretObject = Get-AzContainerAppSecret -ContainerAppName containerappName -ResourceGroupName testgroup
$newSecretObject = @(0..($secretObject.Count-1))
[array]::copy($secretObject,$newSecretObject,$secretObject.Count)
$secretObject += New-AzContainerAppSecretObject -Name "yourkey" -Value "yourvalue"
Update-AzContainerApp -ContainerAppName containerappName -ResourceGroupName testgroup -Location canadacentral -ConfigurationSecret $secretObject

lijinpei2008 avatar Jul 26 '22 09:07 lijinpei2008

Awesome - thanks for the feedback / example. Might be good as an example for the general public in order to accomplish (Add) since there is no add-azcontainerappsecret cmdlet as of now...

larswurm avatar Jul 26 '22 13:07 larswurm

3 things we have learned from this case.

  1. We will add example to tell user how to use that.
  2. Cmdlet of Get should return a non-fixed size array. Then user can add new property just in one line. https://github.com/Azure/autorest.powershell/issues/978
  3. We will look into the usage of secret. If usage is high, we should introduce additional cmdlet to serve Add-AzContainerAppSecret and Remove-AzContainerAppSecret

dingmeng-xue avatar Jul 28 '22 03:07 dingmeng-xue

Hi @larswurm, You can solve the issue by using the following example:

$secretObject = Get-AzContainerAppSecret -ContainerAppName containerappName -ResourceGroupName testgroup
$newSecretObject = @(0..($secretObject.Count-1))
[array]::copy($secretObject,$newSecretObject,$secretObject.Count)
$secretObject += New-AzContainerAppSecretObject -Name "yourkey" -Value "yourvalue"
Update-AzContainerApp -ContainerAppName containerappName -ResourceGroupName testgroup -Location canadacentral -ConfigurationSecret $secretObject

As per testing solution, I get error: InvalidOperation: Method invocation failed because [Microsoft.Azure.PowerShell.Cmdlets.App.Models.Api20220301.ContainerAppSecret] does not contain a method named 'op_Addition'.

Checking on $secretObject | gm

TypeName: Microsoft.Azure.PowerShell.Cmdlets.App.Models.Api20220301.ContainerAppSecret

Name MemberType Definition


Equals Method bool Equals(System.Object obj) GetHashCode Method int GetHashCode() GetType Method type GetType() ToJson Method Microsoft.Azure.PowerShell.Cmdlets.App.Runtime.Json.JsonNode ToJson(Microsoft.Azure.PowerShell.Cmdlets.App.Runtime.Json.JsonObject… ToJsonString Method string ToJsonString() ToString Method string ToString() Name Property string Name {get;} Value Property string Value {get;}

larswurm avatar Aug 01 '22 07:08 larswurm

A new version of Az.App has been released! (https://www.powershellgallery.com/packages/Az.App/1.0.0) Documentation has been updated, and hopefully the updated documentation will help you. https://learn.microsoft.com/en-us/powershell/module/az.app/update-azcontainerapp?view=azps-11.1.0#example-2-update-container-app

lijinpei2008 avatar Dec 13 '23 01:12 lijinpei2008