private IList <ServiceAccessPolicyEntry> GetAccessPolicies(ServicesDescription healthcareApisAccount) { List <ServiceAccessPolicyEntry> accessPolicies = new List <ServiceAccessPolicyEntry>(); if (AccessPolicyObjectId != null && AccessPolicyObjectId.Length > 0) { foreach (string objectId in AccessPolicyObjectId) { HealthcareApisArgumentValidator.ValidateObjectId(objectId); accessPolicies.Add(new ServiceAccessPolicyEntry(objectId)); } return(accessPolicies); } return(healthcareApisAccount.Properties.AccessPolicies); }
private IList <string> MergeLoginServers(ServicesDescription healthcareApisAccount) { var mergedLoginServers = healthcareApisAccount. Properties. AcrConfiguration?. LoginServers ?? new List <string>(); foreach (string loginServer in AcrLoginServer) { if (!mergedLoginServers.Contains(loginServer)) { mergedLoginServers.Add(loginServer); } } return(mergedLoginServers); }
public PSHealthcareApisService(ServicesDescription serviceDescription) { this.ResourceGroupName = ParseResourceGroupFromId(serviceDescription.Id); this.Name = serviceDescription.Name; this.Id = serviceDescription.Id; this.Location = serviceDescription.Location; this.ResourceType = serviceDescription.Type; this.Tags = serviceDescription.Tags; this.CosmosDbKeyVaultKeyUri = serviceDescription.Properties.CosmosDbConfiguration?.KeyVaultKeyUri; this.CosmosDbOfferThroughput = serviceDescription.Properties.CosmosDbConfiguration?.OfferThroughput; this.CorsOrigins = serviceDescription.Properties.CorsConfiguration?.Origins; this.CorsHeaders = serviceDescription.Properties.CorsConfiguration?.Headers; this.CorsMethods = serviceDescription.Properties.CorsConfiguration?.Methods; this.CorsMaxAge = serviceDescription.Properties.CorsConfiguration?.MaxAge; this.CorsAllowCredentials = serviceDescription.Properties.CorsConfiguration?.AllowCredentials; this.Authority = serviceDescription.Properties.AuthenticationConfiguration?.Authority; this.Audience = serviceDescription.Properties.AuthenticationConfiguration?.Audience; this.SmartProxyEnabled = serviceDescription.Properties.AuthenticationConfiguration?.SmartProxyEnabled; this.Etag = serviceDescription.Etag; this.Kind = GetKindValue(serviceDescription.Kind); this.ExportStorageAccountName = serviceDescription.Properties.ExportConfiguration?.StorageAccountName; this.AcrLoginServers = serviceDescription.Properties.AcrConfiguration?.LoginServers; this.IdentityType = serviceDescription.Identity?.Type; this.IdentityPrincipalId = serviceDescription.Identity?.PrincipalId; this.IdentityTenantId = serviceDescription.Identity?.TenantId; this.PublicNetworkAccess = serviceDescription.Properties.PublicNetworkAccess; this.PrivateEndpointConnections = serviceDescription.Properties.PrivateEndpointConnections; var psAccessPolicies = new List <PSHealthcareApisFhirServiceAccessPolicyEntry>(); foreach (ServiceAccessPolicyEntry accessPolicy in serviceDescription.Properties.AccessPolicies) { psAccessPolicies.Add(new PSHealthcareApisFhirServiceAccessPolicyEntry(accessPolicy)); } this.AccessPolicies = psAccessPolicies; }
public static void VerifyAccountProperties(ServicesDescription account, bool useDefaults, string location = "westus") { // verifies that the account is actually created Assert.NotNull(account); Assert.NotNull(account.Id); Assert.NotNull(account.Location); Assert.NotNull(account.Name); Assert.NotNull(account.Etag); Assert.NotNull(account.Properties); Assert.Equal(ProvisioningState.Succeeded, account.Properties.ProvisioningState); if (!useDefaults) { Assert.NotNull(account.Properties.AuthenticationConfiguration); Assert.NotNull(account.Properties.CosmosDbConfiguration); Assert.NotNull(account.Properties.AccessPolicies); Assert.Equal("https://login.microsoftonline.com/common", account.Properties.AuthenticationConfiguration.Authority); Assert.Equal("https://azurehealthcareapis.com", account.Properties.AuthenticationConfiguration.Audience); Assert.False(account.Properties.AuthenticationConfiguration.SmartProxyEnabled); Assert.Equal(400, account.Properties.CosmosDbConfiguration.OfferThroughput); Assert.Equal(1, account.Properties.AccessPolicies.Count); Assert.Equal(ProvisioningState.Succeeded, account.Properties.ProvisioningState); } }
public static ServicesDescription GetServiceDescription(Kind kind) { var serviceDescription = new ServicesDescription(kind, DefaultLocation); return(serviceDescription); }
public override void ExecuteCmdlet() { try { base.ExecuteCmdlet(); RunCmdLet(() => { switch (ParameterSetName) { case ServiceNameParameterSet: case ResourceIdParameterSet: { string rgName = null; string name = null; if (ParameterSetName.Equals(ResourceIdParameterSet)) { ValidateAndExtractName(this.ResourceId, out rgName, out name); } else if (ParameterSetName.Equals(ServiceNameParameterSet)) { rgName = this.ResourceGroupName; name = this.Name; } var healthcareApisAccount = this.HealthcareApisClient.Services.Get(rgName, name); IList <ServiceAccessPolicyEntry> accessPolicies = GetAccessPolicies(healthcareApisAccount); ServicesDescription servicesDescription = GenerateServiceDescription(healthcareApisAccount, accessPolicies); try { var healthcareApisFhirServiceUpdateAccount = this.HealthcareApisClient.Services.CreateOrUpdate( rgName, name, servicesDescription); var healthCareFhirService = this.HealthcareApisClient.Services.Get(rgName, name); WriteHealthcareApisAccount(healthCareFhirService); } catch (ErrorDetailsException wex) { WriteError(WriteErrorforBadrequest(wex)); } break; } case InputObjectParameterSet: { IList <PSHealthcareApisFhirServiceAccessPolicyEntry> entries = InputObject.AccessPolicies; List <ServiceAccessPolicyEntry> accessPolicies = new List <ServiceAccessPolicyEntry>(); foreach (PSHealthcareApisFhirServiceAccessPolicyEntry entry in entries) { accessPolicies.Add(new ServiceAccessPolicyEntry(entry.ObjectId)); } var healthcareApisAccount = this.HealthcareApisClient.Services.Get(InputObject.ResourceGroupName, InputObject.Name); ServicesDescription servicesDescription = InputObjectToServiceDescription(healthcareApisAccount, accessPolicies); try { var healthcareApisFhirServiceUpdateAccount = this.HealthcareApisClient.Services.CreateOrUpdate( InputObject.ResourceGroupName, InputObject.Name, servicesDescription); WriteHealthcareApisAccount(healthcareApisFhirServiceUpdateAccount); } catch (ErrorDetailsException wex) { WriteError(WriteErrorforBadrequest(wex)); } break; } } }); } catch (KeyNotFoundException ex) { WriteError(new ErrorRecord(ex, Resources.keyNotFoundExceptionMessage, ErrorCategory.OpenError, ex)); } catch (NullReferenceException ex) { WriteError(new ErrorRecord(ex, Resources.nullPointerExceptionMessage, ErrorCategory.OpenError, ex)); } }
public static PSHealthcareApisService Create(ServicesDescription healthcareApisAccount) { return(new PSHealthcareApisService(healthcareApisAccount)); }
private ServicesDescription GenerateServiceDescription(ServicesDescription healthcareApisAccount, IList <ServiceAccessPolicyEntry> accessPolicies) { ServicesDescription servicesDescription = new ServicesDescription() { Location = healthcareApisAccount.Location, Properties = new ServicesProperties() { AuthenticationConfiguration = new ServiceAuthenticationConfigurationInfo() { Authority = Authority ?? healthcareApisAccount.Properties.AuthenticationConfiguration.Authority, Audience = Audience ?? healthcareApisAccount.Properties.AuthenticationConfiguration.Audience, SmartProxyEnabled = IsSmartOnFhirEnabled(healthcareApisAccount.Properties.AuthenticationConfiguration.SmartProxyEnabled) }, CosmosDbConfiguration = new ServiceCosmosDbConfigurationInfo() { KeyVaultKeyUri = CosmosKeyVaultKeyUri ?? healthcareApisAccount.Properties.CosmosDbConfiguration.KeyVaultKeyUri, OfferThroughput = CosmosOfferThroughput ?? healthcareApisAccount.Properties.CosmosDbConfiguration.OfferThroughput }, CorsConfiguration = new ServiceCorsConfigurationInfo() { Origins = CorsOrigin ?? healthcareApisAccount.Properties.CorsConfiguration.Origins, Headers = CorsHeader ?? healthcareApisAccount.Properties.CorsConfiguration.Headers, Methods = CorsMethod ?? healthcareApisAccount.Properties.CorsConfiguration.Methods, MaxAge = CorsMaxAge ?? healthcareApisAccount.Properties.CorsConfiguration.MaxAge, AllowCredentials = IsCorsCredentialsAllowed(healthcareApisAccount.Properties.CorsConfiguration.AllowCredentials) }, ExportConfiguration = new ServiceExportConfigurationInfo() { StorageAccountName = ExportStorageAccountName ?? healthcareApisAccount.Properties.ExportConfiguration.StorageAccountName }, AcrConfiguration = new ServiceAcrConfigurationInfo() { LoginServers = AcrLoginServer ?? healthcareApisAccount.Properties.AcrConfiguration?.LoginServers }, AccessPolicies = accessPolicies, PublicNetworkAccess = PublicNetworkAccess ?? healthcareApisAccount.Properties.PublicNetworkAccess }, Kind = healthcareApisAccount.Kind, Tags = GetTags(healthcareApisAccount) }; if (this.EnableManagedIdentity.ToBool() && healthcareApisAccount.Identity == null) { servicesDescription.Identity = new ServicesResourceIdentity() { Type = "SystemAssigned" }; } else if (!this.DisableManagedIdentity.ToBool()) { servicesDescription.Identity = healthcareApisAccount.Identity; } else { servicesDescription.Identity = new ServicesResourceIdentity() { Type = "None" }; } return(servicesDescription); }
/// <summary> /// Create or update the metadata of a service instance. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group that contains the service instance. /// </param> /// <param name='resourceName'> /// The name of the service instance. /// </param> /// <param name='serviceDescription'> /// The service instance metadata. /// </param> public static ServicesDescription CreateOrUpdate(this IServicesOperations operations, string resourceGroupName, string resourceName, ServicesDescription serviceDescription) { return(operations.CreateOrUpdateAsync(resourceGroupName, resourceName, serviceDescription).GetAwaiter().GetResult()); }
/// <summary> /// Create or update the metadata of a service instance. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group that contains the service instance. /// </param> /// <param name='resourceName'> /// The name of the service instance. /// </param> /// <param name='serviceDescription'> /// The service instance metadata. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <ServicesDescription> BeginCreateOrUpdateAsync(this IServicesOperations operations, string resourceGroupName, string resourceName, ServicesDescription serviceDescription, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.BeginCreateOrUpdateWithHttpMessagesAsync(resourceGroupName, resourceName, serviceDescription, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
public override void ExecuteCmdlet() { try { base.ExecuteCmdlet(); RunCmdLet(() => { List <ServiceAccessPolicyEntry> accessPolicies = GetAccessPolicies(); ServicesDescription servicesDescription = new ServicesDescription() { Kind = GetKind(), Location = Location, Tags = this.GetTags(), Properties = new ServicesProperties() { AuthenticationConfiguration = new ServiceAuthenticationConfigurationInfo() { Authority = GetAuthority(), Audience = GetAudience(), SmartProxyEnabled = EnableSmartProxy.ToBool() }, CosmosDbConfiguration = new ServiceCosmosDbConfigurationInfo() { OfferThroughput = GetCosmosDBThroughput(), KeyVaultKeyUri = GetCosmosDBKeyVaultKeyUri() }, CorsConfiguration = new ServiceCorsConfigurationInfo() { Origins = CorsOrigin, Headers = CorsHeader, Methods = CorsMethod, MaxAge = CorsMaxAge, AllowCredentials = AllowCorsCredential }, ExportConfiguration = new ServiceExportConfigurationInfo() { StorageAccountName = ExportStorageAccountName }, AccessPolicies = accessPolicies, } }; if (this.ManagedIdentity.IsPresent) { servicesDescription.Identity = new ServicesResourceIdentity() { Type = "SystemAssigned" }; } if (!string.IsNullOrEmpty(PublicNetworkAccess)) { servicesDescription.Properties.PublicNetworkAccess = PublicNetworkAccess; } if (ShouldProcess(this.Name, Resources.createService)) { this.EnsureNameAvailabilityOrThrow(); try { var createAccountResponse = this.HealthcareApisClient.Services.CreateOrUpdate( this.ResourceGroupName, this.Name, servicesDescription); var healthCareFhirService = this.HealthcareApisClient.Services.Get(this.ResourceGroupName, this.Name); WriteHealthcareApisAccount(healthCareFhirService); } catch (ErrorDetailsException wex) { WriteError(WriteErrorforBadrequest(wex)); } } }); } catch (KeyNotFoundException ex) { WriteError(new ErrorRecord(ex, Resources.keyNotFoundExceptionMessage, ErrorCategory.OpenError, ex)); } catch (NullReferenceException ex) { WriteError(new ErrorRecord(ex, Resources.nullPointerExceptionMessage, ErrorCategory.OpenError, ex)); } }
public static PSHealthcareApisService ToPSFhirService(ServicesDescription serviceDescription) { return(new PSHealthcareApisService(serviceDescription)); }
public override void ExecuteCmdlet() { base.ExecuteCmdlet(); RunCmdLet(() => { switch (ParameterSetName) { case ServiceNameParameterSet: { var healthcareApisAccount = this.HealthcareApisClient.Services.Get(this.ResourceGroupName, this.Name); IList <ServiceAccessPolicyEntry> accessPolicies = GetAccessPolicies(healthcareApisAccount); ServicesDescription servicesDescription = GenerateServiceDescription(healthcareApisAccount, accessPolicies); try { var createAccountResponse = this.HealthcareApisClient.Services.CreateOrUpdate(this.ResourceGroupName, this.Name, servicesDescription); } catch (ErrorDetailsException wex) { WriteError(WriteErrorforBadrequest(wex)); } break; } case ResourceIdParameterSet: { string rgName = null; string name = null; ValidateAndExtractName(this.ResourceId, out rgName, out name); var healthcareApisAccount = this.HealthcareApisClient.Services.Get(rgName, name); IList <ServiceAccessPolicyEntry> accessPolicies = GetAccessPolicies(healthcareApisAccount); ServicesDescription servicesDescription = GenerateServiceDescription(healthcareApisAccount, accessPolicies); try { var healthcareApisFhirServiceUpdateAccount = this.HealthcareApisClient.Services.CreateOrUpdate( rgName, name, servicesDescription); WriteObject(healthcareApisFhirServiceUpdateAccount); } catch (ErrorDetailsException wex) { WriteError(WriteErrorforBadrequest(wex)); } break; } case InputObjectParameterSet: { IList <PSHealthcareApisFhirServiceAccessPolicyEntry> entries = InputObject.Properties.AccessPolicies; List <ServiceAccessPolicyEntry> accessPolicies = new List <ServiceAccessPolicyEntry>(); foreach (PSHealthcareApisFhirServiceAccessPolicyEntry entry in entries) { accessPolicies.Add(new ServiceAccessPolicyEntry(entry.ObjectId)); } var healthcareApisAccount = this.HealthcareApisClient.Services.Get(InputObject.ResourceGroupName, InputObject.Name); ServicesDescription servicesDescription = InputObjectToServiceDescription(healthcareApisAccount, accessPolicies); try { var healthcareApisFhirServiceUpdateAccount = this.HealthcareApisClient.Services.CreateOrUpdate( InputObject.ResourceGroupName, InputObject.Name, servicesDescription); WriteObject(healthcareApisFhirServiceUpdateAccount); } catch (ErrorDetailsException wex) { WriteError(WriteErrorforBadrequest(wex)); } break; } } }); }
public override void ExecuteCmdlet() { base.ExecuteCmdlet(); RunCmdLet(() => { switch (ParameterSetName) { case ServiceNameParameterSet: { List <ServiceAccessPolicyEntry> accessPolicies = new List <ServiceAccessPolicyEntry>(); var healthcareApisAccount = this.HealthcareApisClient.Services.Get(this.ResourceGroupName, this.Name); if (AccessPolicyObjectId != null && AccessPolicyObjectId.Length > 0) { foreach (string objectId in AccessPolicyObjectId) { accessPolicies.Add(new ServiceAccessPolicyEntry(objectId)); } } else { foreach (ServiceAccessPolicyEntry objectId in healthcareApisAccount.Properties.AccessPolicies) { accessPolicies.Add(objectId); } } ServicesDescription servicesDescription = GenerateServiceDescription(healthcareApisAccount, accessPolicies); var createAccountResponse = this.HealthcareApisClient.Services.CreateOrUpdate(this.ResourceGroupName, this.Name, servicesDescription); break; } case ResourceIdParameterSet: { string rgName = null; string name = null; ValidateAndExtractName(this.ResourceId, out rgName, out name); var healthcareApisAccount = this.HealthcareApisClient.Services.Get(rgName, name); List <ServiceAccessPolicyEntry> accessPolicies = new List <ServiceAccessPolicyEntry>(); if (AccessPolicyObjectId != null && AccessPolicyObjectId.Length > 0) { foreach (string objectId in AccessPolicyObjectId) { accessPolicies.Add(new ServiceAccessPolicyEntry(objectId)); } } else { foreach (ServiceAccessPolicyEntry objectId in healthcareApisAccount.Properties.AccessPolicies) { accessPolicies.Add(objectId); } } ServicesDescription servicesDescription = GenerateServiceDescription(healthcareApisAccount, accessPolicies); var healthcareApisFhirServiceUpdateAccount = this.HealthcareApisClient.Services.CreateOrUpdate( rgName, name, servicesDescription); WriteObject(healthcareApisFhirServiceUpdateAccount); break; } case InputObjectParameterSet: { IList <PSHealthcareApisFhirServiceAccessPolicyEntry> entries = InputObject.Properties.AccessPolicies; List <ServiceAccessPolicyEntry> accessPolicies = new List <ServiceAccessPolicyEntry>(); foreach (PSHealthcareApisFhirServiceAccessPolicyEntry entry in entries) { accessPolicies.Add(new ServiceAccessPolicyEntry(entry.ObjectId)); } var healthcareApisAccount = this.HealthcareApisClient.Services.Get(InputObject.ResourceGroupName, InputObject.Name); ServicesDescription servicesDescription = InputObjectToServiceDescription(healthcareApisAccount, accessPolicies); var healthcareApisFhirServiceUpdateAccount = this.HealthcareApisClient.Services.CreateOrUpdate( InputObject.ResourceGroupName, InputObject.Name, servicesDescription); WriteObject(healthcareApisFhirServiceUpdateAccount); break; } } }); }
public static ServicesDescription GetServiceDescription() { var serviceDescription = new ServicesDescription(DefaultLocation); return(serviceDescription); }