public async Task <bool> IsActiveAsync(string featureName) { var active = false; var headerName = await _runtimeParameterAccessor .GetValueAsync <string>(featureName, _descriptors[0]); var percentage = await _runtimeParameterAccessor .GetValueAsync <double>(featureName, _descriptors[1]); if (headerName != null) { var headerValues = _httpContextAccessor.HttpContext.Request .Headers[headerName]; var value = headerValues[0] ?? DEFAULT_HEADER_VALUE; var assignedPartition = JenkinsPartitioner.ResolveToLogicalPartition(value, NUMBER_OF_PARTITIONS); return(assignedPartition <= ((NUMBER_OF_PARTITIONS * percentage) / 100)); } else { _logger.LogWarning($"The header name {_descriptors[0].Name} for feature {featureName} on RollupHeaderValueActivator is not configured correctly."); } return(active); }
public async Task <bool> IsActiveAsync(string featureName) { var active = false; var locations = await _runtimeParameterAccessor .GetValueAsync <string>(featureName, _descriptors[0]); if (!String.IsNullOrWhiteSpace(locations)) { var splittedLocations = locations.Split(';'); var requestIp = _httpContextAccessor.HttpContext .Connection .RemoteIpAddress .MapToIPv4() .ToString(); var location = await _geoLocationProvider.FindLocationAsync(requestIp); if (location != null) { active = splittedLocations .Any(item => item.Equals(location, StringComparison.CurrentCultureIgnoreCase)); } } return(active); }
public async Task <bool> IsActiveAsync(string featureName) { var percentage = await _runtimeParameterAccessor .GetValueAsync <double>(featureName, _descriptors[0]); var username = await _userProvider .GetUserNameAsync() ?? ANONYMOUS_USER; var assignedPartition = JenkinsPartitioner.ResolveToLogicalPartition(username, NUMBER_OF_PARTITIONS); return(assignedPartition <= ((NUMBER_OF_PARTITIONS * percentage) / 100)); }
public async Task <bool> IsActiveAsync(string featureName) { DateTime releaseFromDate, releaseToDate; var from = await _runtimeParameterAccessor.GetValueAsync <string>(featureName, _descriptors[0]); var to = await _runtimeParameterAccessor.GetValueAsync <string>(featureName, _descriptors[1]); var format = await _runtimeParameterAccessor.GetValueAsync <string>(featureName, _descriptors[2]); var now = DateTime.UtcNow; if (from != null && to != null) { if (format != null) { releaseFromDate = DateTime.ParseExact(from, format, null, DateTimeStyles.AssumeUniversal); releaseToDate = DateTime.ParseExact(to, format, null, DateTimeStyles.AssumeUniversal); } else { releaseFromDate = DateTime.Parse(from, null, DateTimeStyles.AssumeUniversal); releaseToDate = DateTime.Parse(to, null, DateTimeStyles.AssumeUniversal); } return(now >= releaseFromDate && now <= releaseToDate); } return(false); }
public async Task <bool> IsActiveAsync(string featureName) { bool active = false; DateTime configuredDate; var releaseDate = await _runtimeParameterAccessor .GetValueAsync <string>(featureName, _descriptors[0]); var format = await _runtimeParameterAccessor .GetValueAsync <string>(featureName, _descriptors[1]); if (releaseDate != null) { if (format != null) { configuredDate = DateTime.ParseExact((string)releaseDate, (string)format, null, DateTimeStyles.AssumeUniversal); } else { _logger.LogInformation($"The value for format date is not specified on UTCActivator, the current culture format is applied"); configuredDate = DateTime.Parse((string)releaseDate, null, DateTimeStyles.AssumeUniversal); } active = configuredDate <= DateTime.UtcNow; } else { _logger.LogWarning($"The UTCActivator can't parse {releaseDate} as valid date time"); } return(active); }
public async Task <bool> IsActiveAsync(string featureName) { var active = false; var httpContext = _httpContextAccessor.HttpContext; var headerName = await _runtimeParameterAccessor .GetValueAsync <string>(featureName, _descriptors[0]); if (headerName != null) { var headerValue = await _runtimeParameterAccessor .GetValueAsync <string>(featureName, _descriptors[1]); if (headerValue != null) { var headerValues = httpContext.Request .Headers[headerName]; if (headerValues.Count > 0) { return(headerValues.Any(s => s.Equals(headerValue, StringComparison.CurrentCultureIgnoreCase))); } } else { _logger.LogWarning($"The header value {_descriptors[1].Name} for feature {featureName} on HeaderValueActivator is not configured correctly."); } } else { _logger.LogWarning($"The header name {_descriptors[0].Name} for feature {featureName} on HeaderValueActivator is not configured correctly."); } return(active); }
public async Task <bool> IsActiveAsync(string featureName) { var active = false; var roles = await _runtimeParameterAccessor .GetValueAsync <string>(featureName, _descriptors[0]); if (!String.IsNullOrWhiteSpace(roles)) { var splittedRoles = roles.Split(';'); var currentRole = await _roleProvider.GetRoleAsync(); return(splittedRoles.Any(s => String.Equals(s, currentRole, StringComparison.CurrentCultureIgnoreCase))); } else { _logger.LogWarning($"The parameter ROLE on feature {featureName} is not configured properly."); } return(active); }