-
Notifications
You must be signed in to change notification settings - Fork 1
feat: #60 Adding support for ring deployments #541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<router-outlet></router-outlet> | ||
<router-outlet></router-outlet> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,9 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { Component } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-reports', | ||
templateUrl: './reports.component.html', | ||
styleUrls: ['./reports.component.scss'] | ||
}) | ||
export class ReportsComponent implements OnInit { | ||
|
||
constructor() { } | ||
|
||
ngOnInit(): void { | ||
} | ||
|
||
export class ReportsComponent { | ||
} |
10 changes: 10 additions & 0 deletions
10
src/app/modules/shared/feature-toggles/feature-toggle-configuration.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { FeatureFilterConfiguration } from './filters/feature-filter-configuration'; | ||
|
||
export interface FeatureToggleConfiguration { | ||
id: string; | ||
enabled: boolean; | ||
description: string; | ||
conditions: { | ||
client_filters: FeatureFilterConfiguration[]; | ||
}; | ||
} |
94 changes: 94 additions & 0 deletions
94
src/app/modules/shared/feature-toggles/feature-toggle-manager.service.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { AppConfigurationClient } from '@azure/app-configuration'; | ||
import { of } from 'rxjs'; | ||
import { AzureAdB2CService } from '../../login/services/azure.ad.b2c.service'; | ||
import { FeatureManagerService } from './feature-toggle-manager.service'; | ||
import { FeatureToggleProvider } from './feature-toggle-provider.service'; | ||
import { FeatureToggleModel } from './feature-toggle.model'; | ||
import { FeatureFilterProvider } from './filters/feature-filter-provider.service'; | ||
import { TargetingFeatureFilterModel } from './filters/targeting/targeting-feature-filter.model'; | ||
|
||
|
||
describe('FeatureToggleManager', () => { | ||
const featureToggleKey = 'foo'; | ||
const featureToggleLabel = 'dev'; | ||
const fakeAppConfigurationConnectionString = 'Endpoint=http://fake.foo;Id=fake.id;Secret=fake.secret'; | ||
const aFeatureToggle = new FeatureToggleModel('any-id', true, []); | ||
let service: FeatureManagerService; | ||
let fakeFeatureToggleProvider; | ||
|
||
describe('Features without filters', () => { | ||
beforeEach(() => { | ||
|
||
fakeFeatureToggleProvider = new FeatureToggleProvider( | ||
new AppConfigurationClient(fakeAppConfigurationConnectionString), | ||
new FeatureFilterProvider(new AzureAdB2CService()) | ||
); | ||
spyOn(fakeFeatureToggleProvider, 'getFeatureToggle').and.returnValue(of(aFeatureToggle)); | ||
service = new FeatureManagerService(fakeFeatureToggleProvider); | ||
}); | ||
it('manager uses feature provider to build feature toggle model', async () => { | ||
service.isToggleEnabled(featureToggleKey, featureToggleLabel).subscribe((value) => { | ||
|
||
expect(fakeFeatureToggleProvider).toHaveBeenCalledWith(featureToggleKey, featureToggleLabel); | ||
}); | ||
}); | ||
|
||
it('manager extracts enabled attribute from feature toggle model', async () => { | ||
service.isToggleEnabled(featureToggleKey, featureToggleLabel).subscribe((value) => { | ||
expect(value).toEqual(aFeatureToggle.enabled); | ||
}); | ||
}); | ||
}); | ||
|
||
|
||
describe('Features with filters', () => { | ||
const anyMatchingFilter = new TargetingFeatureFilterModel( | ||
{ Audience: { Groups: ['group-a'], Users: ['user-a'] } }, | ||
{ username: 'user-b', group: 'group-a' } | ||
); | ||
const anyNotMatchingFilter = new TargetingFeatureFilterModel( | ||
{ Audience: { Groups: ['a-group'], Users: ['user-a'] } }, | ||
{ username: 'user-b', group: 'b-group' } | ||
); | ||
|
||
let aToggleWithFilters; | ||
let getFeatureToggleSpy; | ||
|
||
beforeEach(() => { | ||
aToggleWithFilters = new FeatureToggleModel('any-other-id', true, [anyMatchingFilter]); | ||
fakeFeatureToggleProvider = new FeatureToggleProvider( | ||
new AppConfigurationClient(fakeAppConfigurationConnectionString), | ||
new FeatureFilterProvider(new AzureAdB2CService()) | ||
); | ||
getFeatureToggleSpy = spyOn(fakeFeatureToggleProvider, 'getFeatureToggle').and.returnValue(of(aToggleWithFilters)); | ||
service = new FeatureManagerService(fakeFeatureToggleProvider); | ||
}); | ||
|
||
it('manager uses feature provider to build feature toggle model', async () => { | ||
service.isToggleEnabledForUser(featureToggleKey, featureToggleLabel).subscribe((value) => { | ||
expect(getFeatureToggleSpy).toHaveBeenCalledWith(featureToggleKey, featureToggleLabel); | ||
}); | ||
}); | ||
|
||
it('given a feature toggle with filters which match the verification, then the response is true', async () => { | ||
service.isToggleEnabledForUser(featureToggleKey, featureToggleLabel).subscribe((value) => { | ||
expect(value).toEqual(true); | ||
}); | ||
}); | ||
|
||
it('given a feature toggle with filters which do not match the verification, then the response is false', async () => { | ||
|
||
aToggleWithFilters = new FeatureToggleModel('any-other-id', true, [anyNotMatchingFilter]); | ||
fakeFeatureToggleProvider = new FeatureToggleProvider( | ||
new AppConfigurationClient(fakeAppConfigurationConnectionString), | ||
new FeatureFilterProvider(new AzureAdB2CService()) | ||
); | ||
spyOn(fakeFeatureToggleProvider, 'getFeatureToggle').and.returnValue(of(aToggleWithFilters)); | ||
service = new FeatureManagerService(fakeFeatureToggleProvider); | ||
|
||
service.isToggleEnabledForUser(featureToggleKey, featureToggleLabel).subscribe((value) => { | ||
expect(value).toEqual(false); | ||
}); | ||
}); | ||
}); | ||
}); |
27 changes: 27 additions & 0 deletions
27
src/app/modules/shared/feature-toggles/feature-toggle-manager.service.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Observable } from 'rxjs'; | ||
import { map } from 'rxjs/operators'; | ||
import { FeatureToggleProvider } from './feature-toggle-provider.service'; | ||
|
||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class FeatureManagerService { | ||
|
||
constructor(private featureToggleProvider: FeatureToggleProvider) { } | ||
|
||
public isToggleEnabled(toggleName: string, toggleLabel?: string): Observable<boolean> { | ||
return this.featureToggleProvider.getFeatureToggle(toggleName, toggleLabel).pipe( | ||
map(featureToggle => featureToggle.enabled) | ||
); | ||
} | ||
|
||
public isToggleEnabledForUser(toggleName: string, toggleLabel?: string): Observable<boolean> { | ||
return this.featureToggleProvider.getFeatureToggle(toggleName, toggleLabel).pipe( | ||
juanultimate marked this conversation as resolved.
Show resolved
Hide resolved
|
||
map(featureToggle => featureToggle.filters), | ||
map(filters => filters.map(filter => filter.evaluate())), | ||
map(filterEvaluations => filterEvaluations.includes(true)) | ||
); | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
src/app/modules/shared/feature-toggles/feature-toggle-provider.service.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { AppConfigurationClient, GetConfigurationSettingResponse } from '@azure/app-configuration'; | ||
import { of } from 'rxjs'; | ||
import { AzureAdB2CService } from '../../login/services/azure.ad.b2c.service'; | ||
import { FeatureToggleConfiguration } from './feature-toggle-configuration'; | ||
import { FeatureToggleProvider } from './feature-toggle-provider.service'; | ||
import { FeatureToggleModel } from './feature-toggle.model'; | ||
import { FeatureFilterProvider } from './filters/feature-filter-provider.service'; | ||
import { TargetingFeatureFilterModel } from './filters/targeting/targeting-feature-filter.model'; | ||
|
||
|
||
describe('FeatureToggleProvider', () => { | ||
const anyToggleResponse: FeatureToggleConfiguration = { | ||
id: '1', | ||
enabled: true, | ||
description: 'any description', | ||
conditions: { | ||
client_filters: [{ name: 'any-name', parameters: {} }] | ||
}, | ||
}; | ||
|
||
const fakeAppConfigurationConnectionString = 'Endpoint=http://fake.foo;Id=fake.id;Secret=fake.secret'; | ||
const featureToggleKey = 'foo'; | ||
const featureToggleLabel = 'dev'; | ||
const fakeResponse: GetConfigurationSettingResponse = { | ||
isReadOnly: true, | ||
key: featureToggleKey, | ||
_response: { | ||
request: null, | ||
bodyAsText: 'any-response', | ||
headers: null, | ||
parsedHeaders: null, | ||
status: 200 | ||
}, | ||
statusCode: 200, | ||
value: JSON.stringify(anyToggleResponse) | ||
}; | ||
const anyFilter = new TargetingFeatureFilterModel( | ||
{ Audience: { Groups: ['a-group'], Users: ['any-user'] } }, | ||
{ username: '[email protected]', group: 'fake-group' } | ||
); | ||
let fakeConfigurationClient; | ||
let fakeGetConfigurationSetting; | ||
let fakeFeatureFilterProvider; | ||
let getFilterConfigurationSpy; | ||
let service; | ||
|
||
|
||
|
||
beforeEach(() => { | ||
fakeConfigurationClient = new AppConfigurationClient(fakeAppConfigurationConnectionString); | ||
fakeGetConfigurationSetting = spyOn(fakeConfigurationClient, 'getConfigurationSetting').and.callFake( | ||
() => of(fakeResponse).toPromise()); | ||
|
||
fakeFeatureFilterProvider = new FeatureFilterProvider(new AzureAdB2CService()); | ||
getFilterConfigurationSpy = spyOn(fakeFeatureFilterProvider, 'getFilterFromConfiguration').and. | ||
returnValue(anyFilter); | ||
service = new FeatureToggleProvider(fakeConfigurationClient, fakeFeatureFilterProvider); | ||
}); | ||
|
||
it('toggles are read using azure configuration client', async () => { | ||
service.getFeatureToggle(featureToggleKey, featureToggleLabel).subscribe((value) => { | ||
|
||
expect(fakeGetConfigurationSetting).toHaveBeenCalledWith( | ||
{ key: `.appconfig.featureflag/${featureToggleKey}`, label: featureToggleLabel } | ||
); | ||
}); | ||
}); | ||
|
||
it('filters are built using the filterProvider', async () => { | ||
service.getFeatureToggle(featureToggleKey, featureToggleLabel).subscribe((value) => { | ||
expect(getFilterConfigurationSpy).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
it('toggle model is built', async () => { | ||
service.getFeatureToggle(featureToggleKey, featureToggleLabel).subscribe((value) => { | ||
expect(value).toEqual(new FeatureToggleModel(anyToggleResponse.id, anyToggleResponse.enabled, [anyFilter])); | ||
}); | ||
}); | ||
}); |
40 changes: 40 additions & 0 deletions
40
src/app/modules/shared/feature-toggles/feature-toggle-provider.service.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Inject, Injectable, InjectionToken } from '@angular/core'; | ||
import { AppConfigurationClient } from '@azure/app-configuration'; | ||
import { from, Observable } from 'rxjs'; | ||
import { map } from 'rxjs/operators'; | ||
import { AZURE_APP_CONFIGURATION_CONNECTION_STRING } from 'src/environments/environment'; | ||
import { FeatureToggleConfiguration } from './feature-toggle-configuration'; | ||
import { FeatureToggleModel } from './feature-toggle.model'; | ||
import { FeatureFilterProvider } from './filters/feature-filter-provider.service'; | ||
|
||
|
||
const APP_CONFIGURATION_CLIENT = new InjectionToken<AppConfigurationClient>('Azure configuration client', { | ||
providedIn: 'root', | ||
factory: () => new AppConfigurationClient(AZURE_APP_CONFIGURATION_CONNECTION_STRING) | ||
}); | ||
@Injectable({ | ||
providedIn: 'root', | ||
|
||
}) | ||
export class FeatureToggleProvider { | ||
constructor( | ||
@Inject(APP_CONFIGURATION_CLIENT) | ||
private client: AppConfigurationClient, | ||
private featureFilterProvider: FeatureFilterProvider | ||
) { } | ||
|
||
public getFeatureToggle(toggleName: string, toggleLabel?: string): Observable<FeatureToggleModel> { | ||
return from(this.client.getConfigurationSetting({ key: `.appconfig.featureflag/${toggleName}`, label: toggleLabel })).pipe( | ||
map(featureToggleResponse => JSON.parse(featureToggleResponse.value) as FeatureToggleConfiguration), | ||
map(featureToggleConfiguration => { | ||
const filters = featureToggleConfiguration.conditions.client_filters.map(filterConfiguration => | ||
this.featureFilterProvider.getFilterFromConfiguration(filterConfiguration)); | ||
return new FeatureToggleModel( | ||
featureToggleConfiguration.id, | ||
featureToggleConfiguration.enabled, | ||
filters); | ||
} | ||
) | ||
); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/app/modules/shared/feature-toggles/feature-toggle.model.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { FeatureFilterModel } from './filters/feature-filter.model'; | ||
|
||
export class FeatureToggleModel { | ||
constructor( | ||
public readonly name: string, | ||
public readonly enabled: boolean, | ||
public readonly filters: FeatureFilterModel[] | ||
) { } | ||
} |
4 changes: 4 additions & 0 deletions
4
src/app/modules/shared/feature-toggles/filters/feature-filter-configuration.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface FeatureFilterConfiguration { | ||
name: string; | ||
parameters: any; | ||
} |
26 changes: 26 additions & 0 deletions
26
src/app/modules/shared/feature-toggles/filters/feature-filter-provider.service.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { AzureAdB2CService } from 'src/app/modules/login/services/azure.ad.b2c.service'; | ||
import { FeatureFilterConfiguration } from './feature-filter-configuration'; | ||
import { FeatureFilterProvider } from './feature-filter-provider.service'; | ||
import { FeatureFilterTypes } from './feature-filter-types'; | ||
import { TargetingFeatureFilterModel } from './targeting/targeting-feature-filter.model'; | ||
|
||
|
||
describe('FeatureFilterProvider', () => { | ||
let fakeUserService: AzureAdB2CService; | ||
let service: FeatureFilterProvider; | ||
let featureFilterConfiguration: FeatureFilterConfiguration; | ||
|
||
beforeEach(() => { | ||
fakeUserService = new AzureAdB2CService(); | ||
spyOn(fakeUserService, 'getUserEmail').and.returnValue('any-user-email'); | ||
spyOn(fakeUserService, 'getUserGroup').and.returnValue('any-user-group'); | ||
service = new FeatureFilterProvider(fakeUserService); | ||
featureFilterConfiguration = { name: FeatureFilterTypes.TARGETING, parameters: {} }; | ||
}); | ||
|
||
it('filter model type is created based on the filter configuration', () => { | ||
const filter = service.getFilterFromConfiguration(featureFilterConfiguration); | ||
|
||
expect(filter.constructor.name).toBe(TargetingFeatureFilterModel.name); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.