@@ -35,7 +35,7 @@ namespace Microsoft.Azure.Commands.WebApps.Cmdlets.DeploymentSlots
3535 public class NewAzureWebAppSlotCmdlet : WebAppBaseClientCmdLet
3636 {
3737
38- [ Parameter ( Position = 0 , Mandatory = true , HelpMessage = "The name of the resource group." ) ]
38+ [ Parameter ( Position = 0 , Mandatory = true , HelpMessage = "The name of the resource group." ) ]
3939 [ ResourceGroupCompleter ]
4040 [ ValidateNotNullOrEmpty ]
4141 public string ResourceGroupName { get ; set ; }
@@ -77,98 +77,102 @@ public class NewAzureWebAppSlotCmdlet : WebAppBaseClientCmdLet
7777 [ ValidateNotNullOrEmpty ]
7878 public string AseResourceGroupName { get ; set ; }
7979
80- [ Parameter ( Mandatory = false , HelpMessage = "Container Image Name and optional tag, for example (image:tag)" ) ]
81- [ ValidateNotNullOrEmpty ]
82- public string ContainerImageName { get ; set ; }
83-
84- [ Parameter ( Mandatory = false , HelpMessage = "Private Container Registry Server Url" ) ]
85- [ ValidateNotNullOrEmpty ]
86- public string ContainerRegistryUrl { get ; set ; }
87-
88- [ Parameter ( Mandatory = false , HelpMessage = "Private Container Registry Username" ) ]
89- [ ValidateNotNullOrEmpty ]
90- public string ContainerRegistryUser { get ; set ; }
91-
92- [ Parameter ( Mandatory = false , HelpMessage = "Private Container Registry Password" ) ]
93- [ ValidateNotNullOrEmpty ]
94- public SecureString ContainerRegistryPassword { get ; set ; }
95-
96- [ Parameter ( Mandatory = false , HelpMessage = "Enables/Disables container continuous deployment webhook" ) ]
97- public SwitchParameter EnableContainerContinuousDeployment { get ; set ; }
98-
99-
100- [ Parameter ( Mandatory = false , HelpMessage = "Run cmdlet in the background" ) ]
101- public SwitchParameter AsJob { get ; set ; }
102-
103- [ Parameter ( Mandatory = false , HelpMessage = "Tags are name/value pairs that enable you to categorize resources" ) ]
104- public Hashtable Tag { get ; set ; }
105-
106- private Hashtable GetAppSettingsToUpdate ( )
107- {
108- Hashtable appSettings = new Hashtable ( ) ;
109- if ( ContainerRegistryUrl != null )
110- {
111- appSettings [ CmdletHelpers . DockerRegistryServerUrl ] = ContainerRegistryUrl ;
112- }
113- if ( ContainerRegistryUser != null )
114- {
115- appSettings [ CmdletHelpers . DockerRegistryServerUserName ] = ContainerRegistryUser ;
116- }
117- if ( ContainerRegistryPassword != null )
118- {
119- appSettings [ CmdletHelpers . DockerRegistryServerPassword ] = ContainerRegistryPassword . ConvertToString ( ) ;
120- }
121- if ( EnableContainerContinuousDeployment . IsPresent )
122- {
123- appSettings [ CmdletHelpers . DockerEnableCI ] = "true" ;
124- }
125- return appSettings ;
126- }
127-
128- private void UpdateConfigIfNeeded ( Site site )
129- {
130- SiteConfig siteConfig = site . SiteConfig ;
131-
132- bool configUpdateRequired = false ;
80+ [ Parameter ( Mandatory = false , HelpMessage = "Container Image Name and optional tag, for example (image:tag)" ) ]
81+ [ ValidateNotNullOrEmpty ]
82+ public string ContainerImageName { get ; set ; }
83+
84+ [ Parameter ( Mandatory = false , HelpMessage = "Private Container Registry Server Url" ) ]
85+ [ ValidateNotNullOrEmpty ]
86+ public string ContainerRegistryUrl { get ; set ; }
87+
88+ [ Parameter ( Mandatory = false , HelpMessage = "Private Container Registry Username" ) ]
89+ [ ValidateNotNullOrEmpty ]
90+ public string ContainerRegistryUser { get ; set ; }
91+
92+ [ Parameter ( Mandatory = false , HelpMessage = "Private Container Registry Password" ) ]
93+ [ ValidateNotNullOrEmpty ]
94+ public SecureString ContainerRegistryPassword { get ; set ; }
95+
96+ [ Parameter ( Mandatory = false , HelpMessage = "Enables/Disables container continuous deployment webhook" ) ]
97+ public SwitchParameter EnableContainerContinuousDeployment { get ; set ; }
98+
99+ [ Parameter ( Mandatory = false , HelpMessage = "Copies the managed identity from the parent or source WebApp" ) ]
100+ [ ValidateNotNullOrEmpty ]
101+ public SwitchParameter CopyIdentity { get ; set ; }
102+
103+ [ Parameter ( Mandatory = false , HelpMessage = "Run cmdlet in the background" ) ]
104+ public SwitchParameter AsJob { get ; set ; }
105+
106+ [ Parameter ( Mandatory = false , HelpMessage = "Tags are name/value pairs that enable you to categorize resources" ) ]
107+ public Hashtable Tag { get ; set ; }
108+
109+ private Hashtable GetAppSettingsToUpdate ( )
110+ {
111+ Hashtable appSettings = new Hashtable ( ) ;
112+ if ( ContainerRegistryUrl != null )
113+ {
114+ appSettings [ CmdletHelpers . DockerRegistryServerUrl ] = ContainerRegistryUrl ;
115+ }
116+ if ( ContainerRegistryUser != null )
117+ {
118+ appSettings [ CmdletHelpers . DockerRegistryServerUserName ] = ContainerRegistryUser ;
119+ }
120+ if ( ContainerRegistryPassword != null )
121+ {
122+ appSettings [ CmdletHelpers . DockerRegistryServerPassword ] = ContainerRegistryPassword . ConvertToString ( ) ;
123+ }
124+ if ( EnableContainerContinuousDeployment . IsPresent )
125+ {
126+ appSettings [ CmdletHelpers . DockerEnableCI ] = "true" ;
127+ }
128+ return appSettings ;
129+ }
130+
131+ private void UpdateConfigIfNeeded ( Site site )
132+ {
133+ SiteConfig siteConfig = site . SiteConfig ;
134+
135+ bool configUpdateRequired = false ;
133136
134- if ( ContainerImageName != null )
135- {
136- if ( site . IsXenon . GetValueOrDefault ( ) )
137- {
138- siteConfig . WindowsFxVersion = CmdletHelpers . DockerImagePrefix + ContainerImageName ;
139- configUpdateRequired = true ;
140- }
141- }
142-
143- Hashtable appSettings = GetAppSettingsToUpdate ( ) ;
144- if ( appSettings . Count > 0 )
145- {
146- configUpdateRequired = true ;
147- }
148-
149- if ( configUpdateRequired && siteConfig . AppSettings != null )
150- {
151- foreach ( NameValuePair nameValuePair in siteConfig . AppSettings )
152- {
153- if ( ! appSettings . ContainsKey ( nameValuePair . Name ) )
154- {
155- appSettings [ nameValuePair . Name ] = nameValuePair . Value ;
156- }
157- }
158- }
159-
160- if ( configUpdateRequired )
161- {
162- WebsitesClient . UpdateWebAppConfiguration ( ResourceGroupName , site . Location , Name , Slot , siteConfig , appSettings . ConvertToStringDictionary ( ) ) ;
163- site = WebsitesClient . GetWebApp ( ResourceGroupName , Name , Slot ) ;
164- }
165- WriteObject ( site ) ;
166- }
167- public override void ExecuteCmdlet ( )
137+ if ( ContainerImageName != null )
138+ {
139+ if ( site . IsXenon . GetValueOrDefault ( ) )
140+ {
141+ siteConfig . WindowsFxVersion = CmdletHelpers . DockerImagePrefix + ContainerImageName ;
142+ configUpdateRequired = true ;
143+ }
144+ }
145+
146+ Hashtable appSettings = GetAppSettingsToUpdate ( ) ;
147+ if ( appSettings . Count > 0 )
148+ {
149+ configUpdateRequired = true ;
150+ }
151+
152+ if ( configUpdateRequired && siteConfig . AppSettings != null )
153+ {
154+ foreach ( NameValuePair nameValuePair in siteConfig . AppSettings )
155+ {
156+ if ( ! appSettings . ContainsKey ( nameValuePair . Name ) )
157+ {
158+ appSettings [ nameValuePair . Name ] = nameValuePair . Value ;
159+ }
160+ }
161+ }
162+
163+ if ( configUpdateRequired )
164+ {
165+ WebsitesClient . UpdateWebAppConfiguration ( ResourceGroupName , site . Location , Name , Slot , siteConfig , appSettings . ConvertToStringDictionary ( ) ) ;
166+ site = WebsitesClient . GetWebApp ( ResourceGroupName , Name , Slot ) ;
167+ }
168+ WriteObject ( site ) ;
169+ }
170+
171+ public override void ExecuteCmdlet ( )
168172 {
169173 base . ExecuteCmdlet ( ) ;
170-
171- CloningInfo cloningInfo = null ;
174+ ManagedServiceIdentity sourceIdentity = null ;
175+ CloningInfo cloningInfo = null ;
172176 if ( SourceWebApp != null )
173177 {
174178 cloningInfo = new CloningInfo
@@ -181,11 +185,13 @@ public override void ExecuteCmdlet()
181185 AppSettingsOverrides = AppSettingsOverrides == null ? null : AppSettingsOverrides . Cast < DictionaryEntry > ( ) . ToDictionary ( kvp => kvp . Key . ToString ( ) , kvp => kvp . Value . ToString ( ) , StringComparer . Ordinal )
182186 } ;
183187 cloningInfo = new PSCloningInfo ( cloningInfo ) ;
184- }
188+ if ( CopyIdentity . IsPresent ) sourceIdentity = SourceWebApp . Identity ;
189+ }
185190
186191 var webApp = new PSSite ( WebsitesClient . GetWebApp ( ResourceGroupName , Name , null ) ) ;
187- var site = new PSSite ( WebsitesClient . CreateWebApp ( ResourceGroupName , Name , Slot , webApp . Location , AppServicePlan == null ? webApp . ServerFarmId : AppServicePlan , cloningInfo , AseName , AseResourceGroupName , ( IDictionary < string , string > ) CmdletHelpers . ConvertToStringDictionary ( Tag ) ) ) ;
188- UpdateConfigIfNeeded ( site ) ;
192+ if ( CopyIdentity . IsPresent && sourceIdentity == null ) sourceIdentity = webApp . Identity ;
193+ var site = new PSSite ( WebsitesClient . CreateWebApp ( ResourceGroupName , Name , Slot , webApp . Location , AppServicePlan == null ? webApp . ServerFarmId : AppServicePlan , cloningInfo , AseName , AseResourceGroupName , ( IDictionary < string , string > ) CmdletHelpers . ConvertToStringDictionary ( Tag ) , sourceIdentity ) ) ;
194+ UpdateConfigIfNeeded ( site ) ;
189195 }
190196 }
191197}
0 commit comments