/// <summary> /// Executes the cmdlet. /// </summary> public override void ExecuteCmdlet() { base.ExecuteCmdlet(); ExecuteClientAction(() => { // Validate Storage Account Resource Id var storageAccountResourceIdentifier = new ResourceIdentifier(StorageAccountResourceId); if (string.IsNullOrEmpty(storageAccountResourceIdentifier?.ResourceName)) { throw new PSArgumentException(nameof(StorageAccountResourceId)); } PSADServicePrincipal servicePrincipal = StorageSyncClientWrapper.EnsureServicePrincipal(); RoleAssignment roleAssignment = StorageSyncClientWrapper.EnsureRoleAssignment(servicePrincipal, StorageAccountResourceId); var parentResourceIdentifier = default(ResourceIdentifier); if (this.IsParameterBound(c => c.ParentResourceId)) { parentResourceIdentifier = new ResourceIdentifier(ParentResourceId); if (!string.Equals(StorageSyncConstants.SyncGroupType, parentResourceIdentifier.ResourceType, System.StringComparison.OrdinalIgnoreCase)) { throw new PSArgumentException(StorageSyncResources.MissingParentResourceIdErrorMessage); } } var createParameters = new CloudEndpointCreateParameters() { StorageAccountResourceId = StorageAccountResourceId, AzureFileShareName = AzureFileShareName, StorageAccountTenantId = (StorageAccountTenantId ?? DefaultContext.Tenant?.Id) }; string resourceGroupName = ResourceGroupName ?? ParentObject?.ResourceGroupName ?? parentResourceIdentifier.ResourceGroupName; string storageSyncServiceName = StorageSyncServiceName ?? ParentObject?.StorageSyncServiceName ?? parentResourceIdentifier.GetParentResourceName(StorageSyncConstants.StorageSyncServiceTypeName, 0); string syncGroupName = SyncGroupName ?? ParentObject?.SyncGroupName ?? parentResourceIdentifier.ResourceName; Target = string.Join("/", resourceGroupName, storageSyncServiceName, syncGroupName, Name); if (ShouldProcess(Target, ActionMessage)) { StorageSyncModels.CloudEndpoint resource = StorageSyncClientWrapper.StorageSyncManagementClient.CloudEndpoints.Create( resourceGroupName, storageSyncServiceName, syncGroupName, Name, createParameters); WriteObject(resource); } }); }
/// <summary> /// Create a new CloudEndpoint. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. The name is case insensitive. /// </param> /// <param name='storageSyncServiceName'> /// Name of Storage Sync Service resource. /// </param> /// <param name='syncGroupName'> /// Name of Sync Group resource. /// </param> /// <param name='cloudEndpointName'> /// Name of Cloud Endpoint object. /// </param> /// <param name='parameters'> /// Body of Cloud Endpoint resource. /// </param> public static CloudEndpoint BeginCreate(this ICloudEndpointsOperations operations, string resourceGroupName, string storageSyncServiceName, string syncGroupName, string cloudEndpointName, CloudEndpointCreateParameters parameters) { return(operations.BeginCreateAsync(resourceGroupName, storageSyncServiceName, syncGroupName, cloudEndpointName, parameters).GetAwaiter().GetResult()); }
/// <summary> /// Create a new CloudEndpoint. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. The name is case insensitive. /// </param> /// <param name='storageSyncServiceName'> /// Name of Storage Sync Service resource. /// </param> /// <param name='syncGroupName'> /// Name of Sync Group resource. /// </param> /// <param name='cloudEndpointName'> /// Name of Cloud Endpoint object. /// </param> /// <param name='parameters'> /// Body of Cloud Endpoint resource. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <CloudEndpoint> CreateAsync(this ICloudEndpointsOperations operations, string resourceGroupName, string storageSyncServiceName, string syncGroupName, string cloudEndpointName, CloudEndpointCreateParameters parameters, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.CreateWithHttpMessagesAsync(resourceGroupName, storageSyncServiceName, syncGroupName, cloudEndpointName, parameters, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Executes the cmdlet. /// </summary> public override void ExecuteCmdlet() { base.ExecuteCmdlet(); ExecuteClientAction(() => { // Validate Storage Account Resource Id var storageAccountResourceIdentifier = new ResourceIdentifier(StorageAccountResourceId); if (string.IsNullOrEmpty(storageAccountResourceIdentifier?.ResourceName)) { throw new PSArgumentException(nameof(StorageAccountResourceId)); } if (this.IsParameterBound(c => c.StorageAccountTenantId)) { if (StorageAccountTenantId != AzureContext.Tenant.Id) { throw new PSArgumentException(string.Format(StorageSyncResources.NewCloudEndpointCrossTenantErrorFormat, StorageAccountTenantId, AzureContext.Tenant.Id)); } } if (storageAccountResourceIdentifier.Subscription != AzureContext.Subscription.Id) { WriteWarning(string.Format(StorageSyncResources.NewCloudEndpointCrossSubscriptionWarningFormat, storageAccountResourceIdentifier.Subscription, AzureContext.Subscription.Id)); if (!StorageSyncClientWrapper.TryRegisterProvider(AzureContext.Subscription.Id, StorageSyncConstants.ResourceProvider, storageAccountResourceIdentifier.Subscription)) { WriteWarning(string.Format(StorageSyncResources.NewCloudEndpointUnableToRegisterErrorFormat, storageAccountResourceIdentifier.Subscription)); } } MicrosoftGraphServicePrincipal servicePrincipal = StorageSyncClientWrapper.GetServicePrincipalOrNull(); if (servicePrincipal == null) { throw new PSArgumentException(StorageSyncResources.MissingServicePrincipalResourceIdErrorMessage); } RoleAssignment roleAssignment = StorageSyncClientWrapper.EnsureRoleAssignment(servicePrincipal, storageAccountResourceIdentifier.Subscription, StorageAccountResourceId); var parentResourceIdentifier = default(ResourceIdentifier); if (this.IsParameterBound(c => c.ParentResourceId)) { parentResourceIdentifier = new ResourceIdentifier(ParentResourceId); if (!string.Equals(StorageSyncConstants.SyncGroupType, parentResourceIdentifier.ResourceType, System.StringComparison.OrdinalIgnoreCase)) { throw new PSArgumentException(StorageSyncResources.MissingParentResourceIdErrorMessage); } } var createParameters = new CloudEndpointCreateParameters() { StorageAccountResourceId = StorageAccountResourceId, AzureFileShareName = AzureFileShareName, StorageAccountTenantId = (StorageAccountTenantId ?? AzureContext.Tenant.Id) }; string resourceGroupName = ResourceGroupName ?? ParentObject?.ResourceGroupName ?? parentResourceIdentifier.ResourceGroupName; string storageSyncServiceName = StorageSyncServiceName ?? ParentObject?.StorageSyncServiceName ?? parentResourceIdentifier.GetParentResourceName(StorageSyncConstants.StorageSyncServiceTypeName, 0); string syncGroupName = SyncGroupName ?? ParentObject?.SyncGroupName ?? parentResourceIdentifier.ResourceName; Target = string.Join("/", resourceGroupName, storageSyncServiceName, syncGroupName, Name); if (ShouldProcess(Target, ActionMessage)) { StorageSyncModels.CloudEndpoint resource = StorageSyncClientWrapper.StorageSyncManagementClient.CloudEndpoints.Create( resourceGroupName, storageSyncServiceName, syncGroupName, Name, createParameters); WriteObject(resource); } }); }