/// <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> /// Triggers the certificate rollover. /// </summary> /// <param name="resourceGroupName">Name of the resource group.</param> /// <param name="subscriptionId">The subscription identifier.</param> /// <param name="storageSyncServiceName">Name of the storage sync service.</param> private void TriggerCertificateRollover(string resourceGroupName, Guid subscriptionId, string storageSyncServiceName) { using (ISyncServerCertificateRollover certificateRolloverClient = new SyncServerCertificateRolloverClient(StorageSyncClientWrapper.StorageSyncResourceManager.CreateEcsManagement())) { certificateRolloverClient.RolloverServerCertificate( ManagementInteropConstants.CertificateProviderName, ManagementInteropConstants.CertificateHashAlgorithm, ManagementInteropConstants.CertificateKeyLength, (certificate, serverId) => PerformTriggerRolloverInCloud(certificate, serverId, resourceGroupName, storageSyncServiceName), (inputLogData) => StorageSyncClientWrapper.VerboseLogger(inputLogData)); } }
/// <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); } }); }