/// <summary> /// Clears the delegated Id for a specific tenant and service. /// </summary> /// <param name="tenant"> /// The tenant who was able to make calls to the service represented by the specified Service Tenant. /// </param> /// <param name="serviceTenant">The Service Tenant which was using the Delegated Tenant.</param> /// <remarks> /// This method does not persist the tenant. Calling code should pass the resulting list to /// <see cref="ITenantStore.UpdateTenantAsync(string, string?, IEnumerable{KeyValuePair{string, object}}?, IEnumerable{string}?)"/>. /// </remarks> /// <returns> /// A single-entry list of properties that can be passed to /// <see cref="ITenantStore.UpdateTenantAsync(string, string?, IEnumerable{KeyValuePair{string, object}}?, IEnumerable{string}?)"/> /// to remove the delegate Id. /// </returns> internal static IEnumerable <string> GetPropertiesToRemoveDelegatedTenantForService( this ITenant tenant, ITenant serviceTenant) { tenant.EnsureTenantIsOfType(MarainTenantType.Client, MarainTenantType.Delegated); if (serviceTenant == null) { throw new ArgumentNullException(nameof(serviceTenant)); } serviceTenant.EnsureTenantIsOfType(MarainTenantType.Service); return(new string[] { TenantPropertyKeys.DelegatedTenantId(serviceTenant.Id) }); }
/// <summary> /// Gets the Id of the delegated tenant that has been created for a service to use when accessing a dependent service /// on the tenant's behalf. /// </summary> /// <param name="tenant"> /// The tenant who is able to make calls to the service represented by the specified Service Tenant. /// </param> /// <param name="serviceTenantId">The Id of the Service Tenant which will uses the Delegated Tenant.</param> /// <returns>The Id of the delegated tenant.</returns> public static string GetDelegatedTenantIdForServiceId(this ITenant tenant, string serviceTenantId) { tenant.EnsureTenantIsOfType(MarainTenantType.Client, MarainTenantType.Delegated); if (string.IsNullOrWhiteSpace(serviceTenantId)) { throw new ArgumentException(nameof(serviceTenantId)); } if (tenant.Properties.TryGet(TenantPropertyKeys.DelegatedTenantId(serviceTenantId), out string delegatedTenantId)) { if (!string.IsNullOrEmpty(delegatedTenantId)) { return(delegatedTenantId); } } throw new ArgumentException($"Tenant '{tenant.Name}' with Id '{tenant.Id}' does not contain a delegated tenant Id for service tenant with Id '{serviceTenantId}'"); }
/// <summary> /// Stores the Id of a delegated tenant that has been created for a service to use when accessing a dependent service /// on the tenant's behalf. /// </summary> /// <param name="values">Existing configuration values to which to append these.</param> /// <param name="tenant"> /// The tenant who is able to make calls to the service represented by the specified Service Tenant. /// </param> /// <param name="serviceTenant">The Service Tenant which will be using the Delegated Tenant.</param> /// <param name="delegatedTenant">The tenant that has been created for the service to use.</param> /// <remarks> /// This method does not persist the tenant. Calling code should pass the resulting list to /// <see cref="ITenantStore.UpdateTenantAsync(string, string?, IEnumerable{KeyValuePair{string, object}}?, IEnumerable{string}?)"/>. /// </remarks> /// <returns> /// Properties to pass to /// <see cref="ITenantStore.UpdateTenantAsync(string, string?, IEnumerable{KeyValuePair{string, object}}?, IEnumerable{string}?)"/>. /// </returns> internal static IEnumerable <KeyValuePair <string, object> > SetDelegatedTenantForService( this IEnumerable <KeyValuePair <string, object> > values, ITenant tenant, ITenant serviceTenant, ITenant delegatedTenant) { tenant.EnsureTenantIsOfType(MarainTenantType.Client, MarainTenantType.Delegated); if (serviceTenant == null) { throw new ArgumentNullException(nameof(serviceTenant)); } serviceTenant.EnsureTenantIsOfType(MarainTenantType.Service); if (delegatedTenant == null) { throw new ArgumentNullException(nameof(delegatedTenant)); } delegatedTenant.EnsureTenantIsOfType(MarainTenantType.Delegated); return(values.Append(new KeyValuePair <string, object>(TenantPropertyKeys.DelegatedTenantId(serviceTenant.Id), delegatedTenant.Id))); }