Commit 7107b1ea authored by FORESTIER Fabien's avatar FORESTIER Fabien
Browse files

Set separated conf for dev and rec environment, factorise oidc/glc login...

Set separated conf for dev and rec environment, factorise oidc/glc login components into login component
parent 646918bd
......@@ -20,7 +20,7 @@ build_development:
- sandbox
script:
- export NGINX_PORT=8081
- docker-compose --project-name data-reloaded-dev build
- docker-compose --project-name data-reloaded-dev build --build-arg env=dev nginx-app
deploy_development:
stage: deploy
......@@ -52,7 +52,7 @@ build_staging:
- staging
script:
- export NGINX_PORT=8080
- docker-compose --project-name data-reloaded-rec build
- docker-compose --project-name data-reloaded-rec build --build-arg env=rec nginx-app
deploy_staging:
stage: deploy
......
......@@ -9,8 +9,10 @@ RUN npm install
# Copy the project
COPY . /app
ARG env
# Building the Angular app /dist i18n
RUN npm run build-i18n
RUN npm run build-i18n:${env}
# Stage 1, based on Nginx, to have only the compiled app
FROM nginx
......
......@@ -77,11 +77,11 @@
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
"with": "src/environments/environment.rec.ts"
}
]
},
"production-fr": {
"development-fr": {
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
......@@ -94,11 +94,67 @@
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
"with": "src/environments/environment.dev.ts"
},
{
"replace": "src/i18n/geosource/geosource.ts",
"with": "src/i18n/geosource/geosource.fr.ts"
},
{
"replace": "src/i18n/error-messages/error-messages.ts",
"with": "src/i18n/error-messages/error-messages.fr.ts"
}
],
"outputPath": "dist/fr",
"i18nFile": "src/i18n/messages.fr.xlf",
"i18nFormat": "xlf",
"i18nLocale": "fr",
"baseHref": "/fr/"
},
"development-en": {
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": false,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.dev.ts"
}
],
"outputPath": "dist/en",
"i18nFile": "src/i18n/messages.en.xlf",
"i18nFormat": "xlf",
"i18nLocale": "en",
"baseHref": "/en/"
},
"recette-fr": {
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": false,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.rec.ts"
},
{
"replace": "src/i18n/geosource/geosource.ts",
"with": "src/i18n/geosource/geosource.fr.ts"
},
{
"replace": "src/i18n/error-messages/error-messages.ts",
"with": "src/i18n/error-messages/error-messages.fr.ts"
}
],
"outputPath": "dist/fr",
......@@ -107,7 +163,7 @@
"i18nLocale": "fr",
"baseHref": "/fr/"
},
"production-en": {
"recette-en": {
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
......@@ -120,7 +176,7 @@
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
"with": "src/environments/environment.rec.ts"
}
],
"outputPath": "dist/en",
......
......@@ -6,9 +6,10 @@
"ng": "ng",
"start-aot-fr": "ng serve --configuration=aot-fr",
"start-aot-en": "ng serve --configuration=aot-en",
"build-i18n": "for lang in en fr; do ng build --prod --build-optimizer --configuration=production-$lang; done",
"win-build-i18n:fr": "ng build --prod --build-optimizer --configuration=production-fr",
"win-build-i18n:en": "ng build --prod --build-optimizer --configuration=production-en",
"build-i18n:dev": "for lang in en fr; do ng build --prod --build-optimizer --configuration=develoment-$lang; done",
"build-i18n:rec": "for lang in en fr; do ng build --prod --build-optimizer --configuration=recette-$lang; done",
"win-build-i18n:fr": "ng build --prod --build-optimizer --configuration=recette-fr",
"win-build-i18n:en": "ng build --prod --build-optimizer --configuration=recette-en",
"win-build-i18n": "npm run win-build-i18n:en && npm run win-build-i18n:fr",
"test": "ng test --browsers=Chrome --code-coverage=true",
"test:ci": "ng test --browsers=ChromeHeadlessCI --code-coverage=true --watch=false",
......
......@@ -4,12 +4,10 @@ import { FooterComponent } from './footer/footer.component';
import { NotificationsComponent } from './notifications/notifications.component';
import { ErrorComponent } from './error/error.component';
import { LoginComponent } from './login/login.component';
import { AuthGlcComponent } from './login/auth-glc/auth-glc.component';
import { AuthOidcComponent } from './login/auth-oidc/auth-oidc.component';
import { LogoutComponent } from './logout/logout.component';
export { HeaderComponent, MainComponent, FooterComponent, NotificationsComponent,
ErrorComponent, LoginComponent, AuthGlcComponent, AuthOidcComponent, LogoutComponent };
ErrorComponent, LoginComponent, LogoutComponent };
// tslint:disable-next-line:variable-name
export const CoreComponents = [
......@@ -19,7 +17,5 @@ export const CoreComponents = [
NotificationsComponent,
ErrorComponent,
LoginComponent,
AuthGlcComponent,
AuthOidcComponent,
LogoutComponent,
];
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { AuthGlcComponent } from './auth-glc.component';
describe('AuthGlcComponent', () => {
let component: AuthGlcComponent;
let fixture: ComponentFixture<AuthGlcComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ AuthGlcComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(AuthGlcComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { AuthService } from '../../../services';
@Component({
selector: 'app-auth-glc',
templateUrl: './auth-glc.component.html',
styleUrls: ['./auth-glc.component.scss'],
})
export class AuthGlcComponent implements OnInit {
constructor(
private _activatedRoute: ActivatedRoute,
private _authService: AuthService,
private _router: Router,
) { }
ngOnInit() {
this._activatedRoute
.queryParams
.subscribe((params) => {
// Defaults to 0 if no query param provided.
console.log('[x] Code: ', params['code']);
if (params['code'] !== undefined) {
this._authService.exchangeGlcCode(params['code']).subscribe((res) => {
console.log('[x] Back in the component: ', res);
this._router.navigate(['']);
});
}
});
}
}
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { AuthOidcComponent } from './auth-oidc.component';
describe('AuthOidcComponent', () => {
let component: AuthOidcComponent;
let fixture: ComponentFixture<AuthOidcComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ AuthOidcComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(AuthOidcComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { AuthService } from '../../../services';
@Component({
selector: 'app-auth-oidc',
templateUrl: './auth-oidc.component.html',
styleUrls: ['./auth-oidc.component.scss'],
})
export class AuthOidcComponent implements OnInit {
constructor(
private _activatedRoute: ActivatedRoute,
private _authService: AuthService,
private _router: Router,
) { }
ngOnInit() {
this._activatedRoute
.queryParams
.subscribe((params) => {
// Defaults to 0 if no query param provided.
console.log('[x] Code: ', params['code']);
if (params['code'] !== undefined) {
this._authService.exchangeOidcCode(params['code']).subscribe((res) => {
console.log('[x] Back in the component: ', res);
this._router.navigate(['']);
});
}
});
}
}
......@@ -60,6 +60,4 @@
<button class="button is-success" (click)="login()" [disabled]="form.invalid" i18n="@@login.signInBtn">Sign In</button>
</div>
</form>
</div>
<router-outlet></router-outlet>
\ No newline at end of file
</div>
\ No newline at end of file
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { AuthService } from '../../services';
import { Router } from '@angular/router';
import { Router, ActivatedRoute } from '@angular/router';
import { environment } from '../../../../environments/environment';
@Component({
......@@ -9,7 +9,7 @@ import { environment } from '../../../../environments/environment';
templateUrl: './login.component.html',
styleUrls: ['./login.component.scss'],
})
export class LoginComponent {
export class LoginComponent implements OnInit {
form: FormGroup;
errorLogin = false;
......@@ -19,6 +19,7 @@ export class LoginComponent {
private _fb: FormBuilder,
private _authService: AuthService,
private _router: Router,
private _activatedRoute: ActivatedRoute,
) {
this.form = this._fb.group({
......@@ -27,6 +28,19 @@ export class LoginComponent {
});
}
ngOnInit() {
this._activatedRoute
.queryParams
.subscribe((params) => {
// Defaults to 0 if no query param provided.
if (params['code'] !== undefined && params['state'] !== undefined) {
this._authService.exchangeCode(params['code'], params['state']).subscribe((res) => {
this._router.navigate(['']);
});
}
});
}
login() {
const val = this.form.value;
......
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { AppRoutes } from '../routes';
import { ErrorComponent, LoginComponent, AuthOidcComponent, LogoutComponent } from './components';
import { AuthGlcComponent } from './components/login/auth-glc/auth-glc.component';
import { ErrorComponent, LoginComponent, LogoutComponent } from './components';
export const routes: Routes = [
{
......@@ -23,22 +22,6 @@ export const routes: Routes = [
data: {
title: AppRoutes.signin.title,
},
children: [
{
path: 'glc',
component: AuthGlcComponent,
data: {
title: AppRoutes.signin.title,
},
},
{
path: 'oidc',
component: AuthOidcComponent,
data: {
title: AppRoutes.signin.title,
},
},
],
},
{
path: AppRoutes.error.uri,
......
......@@ -23,7 +23,6 @@ export class HttpErrorResponseInterceptor implements HttpInterceptor {
}
},
(err) => {
console.log(err);
if (err instanceof HttpErrorResponse) {
switch (err.status) {
case 401:
......
......@@ -29,34 +29,14 @@ export class AuthService {
);
}
exchangeOidcCode(code: string): Observable<boolean> {
console.log('[x] Exchanging code');
const url = `${env.kongUrl}/authentication/oidc/token?code=${code}`;
exchangeCode(code: string, state: string): Observable<boolean> {
const url = `${env.kongUrl}/authentication/token?code=${code}&state=${state}`;
return this._http.get<ILoginResponse>(url).pipe(
map(
(res) => {
console.log('Exchange response: ', res);
return this.setSession(res);
},
(err) => {
console.log('Error exchanging code: ', err);
return false;
},
),
);
}
exchangeGlcCode(code: string): Observable<boolean> {
console.log('[x] Exchanging code');
const url = `${env.kongUrl}/authentication/glc/token?code=${code}`;
return this._http.get<ILoginResponse>(url).pipe(
map(
(res) => {
console.log('Exchange response: ', res);
return this.setSession(res);
},
(err) => {
console.log('Error exchanging code: ', err);
return false;
},
),
......@@ -96,7 +76,6 @@ export class AuthService {
try {
const payload = JwtDecode(token);
console.log(payload);
idToken = payload['id_token'];
identityProvider = payload['identity_provider'];
} catch (error) {
......
......@@ -10,9 +10,9 @@ const kongBaseUrl = 'https://kong.alpha.grandlyon.com';
export const environment = {
production: true,
kongUrl: kongBaseUrl,
oidcLoginEndpoint: kongBaseUrl + '/authentication/oidc/login',
glcLoginEndpoint: kongBaseUrl + '/authentication/glc/login',
logoutEndpoint: kongBaseUrl + '/authentication/logout',
oidcLoginEndpoint: kongBaseUrl + '/authentication/dev/login/oidc',
glcLoginEndpoint: kongBaseUrl + '/authentication/dev/login/glc',
logoutEndpoint: kongBaseUrl + '/authentication/dev/logout',
// ElasticSearch
elasticsearchUrl: {
......
import { AppRoutes } from '../app/routes';
// The file contents for the current environment will overwrite these during build.
// The build system defaults to the dev environment which uses `environment.ts`, but if you do
// `ng build --env=prod` then `environment.prod.ts` will be used instead.
// The list of which env maps to which file can be found in `.angular-cli.json`.
const servicesProxyUrl = 'https://data-intothesky.alpha.grandlyon.com';
const kongBaseUrl = 'https://kong.alpha.grandlyon.com';
export const environment = {
production: true,
kongUrl: kongBaseUrl,
oidcLoginEndpoint: kongBaseUrl + '/authentication/rec/login/oidc',
glcLoginEndpoint: kongBaseUrl + '/authentication/rec/login/glc',
logoutEndpoint: kongBaseUrl + '/authentication/rec/logout',
// ElasticSearch
elasticsearchUrl: {
full: kongBaseUrl + '/es-consumer-aware',
meta: kongBaseUrl + '/elasticsearch/*.meta',
},
enableEsFrontCache: false,
matomo: {
url: 'https://matomo-intothesky.alpha.grandlyon.com',
},
organizations: {
url: kongBaseUrl + '/organizations',
},
// Path to the built app in a particular language
angularAppHost: {
fr: '/fr',
en: '/en',
},
// Wordpress
wordpressUrl: servicesProxyUrl + '/wordpress/wp-json/wp/v2/',
wordpressStaticPages: {},
wordpressContent: {
categoryIdUniqueContent: 5,
slugPostVideo: 'video-dgl',
},
// Map
defaultBaseLayer: 0,
baseLayers: [
{
id: 1,
maxzoom: 21,
fileName: 'etalab.json',
labels: {
fr: 'Etalab',
en: 'Etalab',
},
},
{
id: 2,
maxzoom: 21,
fileName: 'vector.json',
labels: {
fr: 'Vecteur',
en: 'Vector',
},
},
{
id: 3,
maxzoom: 17,
fileName: 'plan.json',
labels: {
fr: 'Plan',
en: 'Plan',
},
},
{
id: 4,
maxzoom: 21,
fileName: 'satellite.json',
labels: {
fr: 'Satellite',
en: 'Satellite',
},
},
],
};
// Use variable route names (AppRoutes.approach...) for each static page to attribute the corresponding
// wordpress page in order to make sure that if the name of the route change in the config file (routes.ts),
// the wordpress page will still be served.
environment.wordpressStaticPages[AppRoutes.approach.uri] = 'la-demarche';
environment.wordpressStaticPages[AppRoutes.accessibility.uri] = 'accessibilite';
environment.wordpressStaticPages[AppRoutes.siteMap.uri] = 'plan-du-site';
environment.wordpressStaticPages[AppRoutes.legalNotices.uri] = 'mentions-legales';
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment