@@ -256,105 +256,123 @@ public override void ExecuteCmdlet()
256
256
}
257
257
258
258
}
259
-
260
-
259
+
261
260
SharingUpdate sharingUpdate = new SharingUpdate ( ) ;
261
+ if ( this . Reset . IsPresent )
262
+ {
263
+ sharingUpdate . OperationType = "Reset" ;
264
+ }
265
+ else if ( this . Community . IsPresent )
266
+ {
267
+ sharingUpdate . OperationType = "EnableCommunity" ;
268
+ }
269
+
270
+
262
271
if ( this . Share . IsPresent )
263
272
{
264
273
if ( this . Reset . IsPresent )
265
274
{
266
275
// if sub or tenant is present return error
267
- if ( this . IsParameterBound ( c => c . Subscription ) || this . IsParameterBound ( c => c . Tenant ) )
268
- {
269
- throw new Exception ( "Parameter '-Reset' cannot be used with parameters '-Tenant', '-Subscription' or 'Community'." ) ;
270
- }
271
- else
272
- {
273
- sharingUpdate . OperationType = "Reset" ;
274
- }
276
+ //if (this.IsParameterBound(c => c.Subscription) || this.IsParameterBound(c => c.Tenant) || this.IsParameterBound(c => c.RemoveTenant) || this.IsParameterBound(c => c.RemoveSubscription))
277
+ //{
278
+ // throw new Exception("Parameter '-Reset' cannot be used with parameters '-Tenant', '-Subscription' or '-Community'.");
279
+ //}
280
+ sharingUpdate . OperationType = "Reset" ;
275
281
}
276
- if ( this . IsParameterBound ( c => c . Subscription ) )
282
+ else if ( this . IsParameterBound ( c => c . Community ) )
277
283
{
278
- if ( sharingUpdate . Groups == null )
284
+ if ( this . Community . IsPresent )
279
285
{
280
- sharingUpdate . Groups = new List < SharingProfileGroup > ( ) ;
281
- }
282
- SharingProfileGroup sharingProfile = new SharingProfileGroup ( ) ;
283
- sharingProfile . Type = "Subscriptions" ;
284
- sharingProfile . Ids = new List < string > ( ) ;
285
- foreach ( var id in this . Subscription )
286
- {
287
- sharingProfile . Ids . Add ( id ) ;
288
- }
289
- sharingUpdate . Groups . Add ( sharingProfile ) ;
290
- sharingUpdate . OperationType = "Add" ;
291
- }
292
- if ( this . IsParameterBound ( c => c . Tenant ) )
293
- {
294
- if ( sharingUpdate . Groups == null )
295
- {
296
- sharingUpdate . Groups = new List < SharingProfileGroup > ( ) ;
297
- }
298
- SharingProfileGroup sharingProfile = new SharingProfileGroup ( ) ;
299
- sharingProfile . Type = "AADTenants" ;
300
- sharingProfile . Ids = new List < string > ( ) ;
301
- foreach ( var id in this . Tenant )
302
- {
303
- sharingProfile . Ids . Add ( id ) ;
286
+ sharingUpdate . OperationType = "EnableCommunity" ;
304
287
}
305
- sharingUpdate . Groups . Add ( sharingProfile ) ;
306
- sharingUpdate . OperationType = "Add" ;
307
288
}
308
- if ( this . IsParameterBound ( c => c . RemoveTenant ) )
289
+ else if ( this . IsParameterBound ( c => c . Subscription ) || this . IsParameterBound ( c => c . Tenant ) || this . IsParameterBound ( c => c . RemoveTenant ) || this . IsParameterBound ( c => c . RemoveSubscription ) )
309
290
{
310
- if ( sharingUpdate . Groups == null )
291
+ if ( this . IsParameterBound ( c => c . Subscription ) )
311
292
{
312
- sharingUpdate . Groups = new List < SharingProfileGroup > ( ) ;
293
+ if ( sharingUpdate . Groups == null )
294
+ {
295
+ sharingUpdate . Groups = new List < SharingProfileGroup > ( ) ;
296
+ }
297
+ SharingProfileGroup sharingProfile = new SharingProfileGroup ( ) ;
298
+ sharingProfile . Type = "Subscriptions" ;
299
+ sharingProfile . Ids = new List < string > ( ) ;
300
+ foreach ( var id in this . Subscription )
301
+ {
302
+ sharingProfile . Ids . Add ( id ) ;
303
+ }
304
+ sharingUpdate . Groups . Add ( sharingProfile ) ;
305
+ sharingUpdate . OperationType = "Add" ;
313
306
}
314
- SharingProfileGroup sharingProfile = new SharingProfileGroup ( ) ;
315
- sharingProfile . Type = "AADTenants" ;
316
- sharingProfile . Ids = new List < string > ( ) ;
317
- foreach ( var id in this . RemoveTenant )
307
+ if ( this . IsParameterBound ( c => c . Tenant ) )
318
308
{
319
- sharingProfile . Ids . Add ( id ) ;
309
+ if ( sharingUpdate . Groups == null )
310
+ {
311
+ sharingUpdate . Groups = new List < SharingProfileGroup > ( ) ;
312
+ }
313
+ SharingProfileGroup sharingProfile = new SharingProfileGroup ( ) ;
314
+ sharingProfile . Type = "AADTenants" ;
315
+ sharingProfile . Ids = new List < string > ( ) ;
316
+ foreach ( var id in this . Tenant )
317
+ {
318
+ sharingProfile . Ids . Add ( id ) ;
319
+ }
320
+ sharingUpdate . Groups . Add ( sharingProfile ) ;
321
+ sharingUpdate . OperationType = "Add" ;
320
322
}
321
- sharingUpdate . Groups . Add ( sharingProfile ) ;
322
- sharingUpdate . OperationType = "Remove" ;
323
- }
324
- if ( this . IsParameterBound ( c => c . RemoveSubscription ) )
325
- {
326
- if ( sharingUpdate . Groups == null )
323
+ if ( this . IsParameterBound ( c => c . RemoveTenant ) )
327
324
{
328
- sharingUpdate . Groups = new List < SharingProfileGroup > ( ) ;
325
+ if ( sharingUpdate . Groups == null )
326
+ {
327
+ sharingUpdate . Groups = new List < SharingProfileGroup > ( ) ;
328
+ }
329
+ SharingProfileGroup sharingProfile = new SharingProfileGroup ( ) ;
330
+ sharingProfile . Type = "AADTenants" ;
331
+ sharingProfile . Ids = new List < string > ( ) ;
332
+ foreach ( var id in this . RemoveTenant )
333
+ {
334
+ sharingProfile . Ids . Add ( id ) ;
335
+ }
336
+ sharingUpdate . Groups . Add ( sharingProfile ) ;
337
+ sharingUpdate . OperationType = "Remove" ;
329
338
}
330
- SharingProfileGroup sharingProfile = new SharingProfileGroup ( ) ;
331
- sharingProfile . Type = "Subscriptions" ;
332
- sharingProfile . Ids = new List < string > ( ) ;
333
- foreach ( var id in this . RemoveSubscription )
339
+ if ( this . IsParameterBound ( c => c . RemoveSubscription ) )
334
340
{
335
- sharingProfile . Ids . Add ( id ) ;
341
+ if ( sharingUpdate . Groups == null )
342
+ {
343
+ sharingUpdate . Groups = new List < SharingProfileGroup > ( ) ;
344
+ }
345
+ SharingProfileGroup sharingProfile = new SharingProfileGroup ( ) ;
346
+ sharingProfile . Type = "Subscriptions" ;
347
+ sharingProfile . Ids = new List < string > ( ) ;
348
+ foreach ( var id in this . RemoveSubscription )
349
+ {
350
+ sharingProfile . Ids . Add ( id ) ;
351
+ }
352
+ sharingUpdate . Groups . Add ( sharingProfile ) ;
353
+ sharingUpdate . OperationType = "Remove" ;
336
354
}
337
- sharingUpdate . Groups . Add ( sharingProfile ) ;
338
- sharingUpdate . OperationType = "Remove" ;
339
355
}
340
- if ( this . IsParameterBound ( c => c . Community ) )
356
+ else
341
357
{
342
- if ( this . Community . IsPresent )
343
- sharingUpdate . OperationType = "EnableCommunity" ;
358
+ throw new Exception ( "Parameters '-Subscription', '-Tenant', '-RemoveSubscription', '-RemoveTenant', '-Community' or '-Reset' must be used with '-Share' parameter." ) ;
344
359
}
345
-
346
360
}
347
- else if ( this . IsParameterBound ( c => c . Subscription ) || this . IsParameterBound ( c => c . Tenant ) || this . Reset . IsPresent || this . IsParameterBound ( c => c . RemoveSubscription ) || this . IsParameterBound ( c => c . RemoveTenant ) )
361
+ else if ( this . IsParameterBound ( c => c . Subscription ) || this . IsParameterBound ( c => c . Tenant ) || this . IsParameterBound ( c => c . RemoveTenant ) || this . IsParameterBound ( c => c . RemoveSubscription ) )
348
362
{
349
- throw new Exception ( "Parameters '-Subscription', '-Tenant', '-RemoveSubscription', '-RemoveTenant', and '-Reset' must be used with '-Share' parameter." ) ;
363
+ throw new Exception ( "Parameters '-Subscription', '-Tenant', '-RemoveSubscription' or '-RemoveTenant' must be used with '-Share' parameter." ) ;
350
364
}
351
-
352
- var result = GalleriesClient . CreateOrUpdate ( resourceGroupName , galleryName , gallery ) ;
353
- if ( this . Share . IsPresent )
365
+
366
+ Gallery result = new Gallery ( ) ;
367
+ if ( this . Share . IsPresent || this . Community . IsPresent || this . Reset . IsPresent )
354
368
{
355
369
GallerySharingProfileClient . Update ( resourceGroupName , galleryName , sharingUpdate ) ;
356
370
result = GalleriesClient . Get ( ResourceGroupName , galleryName , "Permissions" ) ;
357
371
}
372
+ else
373
+ {
374
+ GalleriesClient . CreateOrUpdate ( resourceGroupName , galleryName , gallery ) ;
375
+ }
358
376
var psObject = new PSGallery ( ) ;
359
377
ComputeAutomationAutoMapperProfile . Mapper . Map < Gallery , PSGallery > ( result , psObject ) ;
360
378
WriteObject ( psObject ) ;
0 commit comments