"ng-block-ui": "3.0.2",
"ng-click-outside": "7.0.0",
"ng2-charts": "4.1.1",
+ "ngx-cookie-service": "17.1.0",
"ngx-pipe-function": "1.0.0",
"ngx-toastr": "17.0.2",
"rxjs": "6.6.3",
"rxjs": "^6.5.3 || ^7.4.0"
}
},
+ "node_modules/ngx-cookie-service": {
+ "version": "17.1.0",
+ "resolved": "https://registry.npmjs.org/ngx-cookie-service/-/ngx-cookie-service-17.1.0.tgz",
+ "integrity": "sha512-m4YI9IEgTaEBDMCz7oeVsO6UX14EmCzg29cTL6yxW8f7oye9wv56egi+3C4wAVSRPkI+cWlqnIOr+XyHwYQYmg==",
+ "dependencies": {
+ "tslib": "^2.6.2"
+ },
+ "peerDependencies": {
+ "@angular/common": "^17.0.0",
+ "@angular/core": "^17.0.0"
+ }
+ },
+ "node_modules/ngx-cookie-service/node_modules/tslib": {
+ "version": "2.6.2",
+ "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz",
+ "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q=="
+ },
"node_modules/ngx-pipe-function": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/ngx-pipe-function/-/ngx-pipe-function-1.0.0.tgz",
"ng-block-ui": "3.0.2",
"ng-click-outside": "7.0.0",
"ng2-charts": "4.1.1",
+ "ngx-cookie-service": "17.1.0",
"ngx-pipe-function": "1.0.0",
"ngx-toastr": "17.0.2",
"rxjs": "6.6.3",
import { MultiCluster } from '~/app/shared/models/multi-cluster';
import { SummaryService } from '~/app/shared/services/summary.service';
import { Router } from '@angular/router';
+import { CookiesService } from '~/app/shared/services/cookie.service';
@Component({
selector: 'cd-multi-cluster-list',
public actionLabels: ActionLabelsI18n,
private notificationService: NotificationService,
private authStorageService: AuthStorageService,
- private modalService: ModalService
+ private modalService: ModalService,
+ private cookieService: CookiesService
) {
this.tableActions = [
{
itemNames: [cluster['cluster_alias'] + ' - ' + cluster['user']],
submitAction: () =>
this.multiClusterService.deleteCluster(cluster['name'], cluster['user']).subscribe(() => {
+ this.cookieService.deleteToken(`${cluster['name']}-${cluster['user']}`);
this.modalRef.close();
this.notificationService.show(
NotificationType.success,
import { MultiCluster } from '~/app/shared/models/multi-cluster';
import { Permissions } from '~/app/shared/models/permissions';
import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
+import { CookiesService } from '~/app/shared/services/cookie.service';
import {
FeatureTogglesMap$,
FeatureTogglesService
private featureToggles: FeatureTogglesService,
private telemetryNotificationService: TelemetryNotificationService,
public prometheusAlertService: PrometheusAlertService,
- private motdNotificationService: MotdNotificationService
+ private motdNotificationService: MotdNotificationService,
+ private cookieService: CookiesService
) {
this.permissions = this.authStorageService.getPermissions();
this.enabledFeature$ = this.featureToggles.get();
onClusterSelection(value: object) {
this.multiClusterService.setCluster(value).subscribe(
(resp: any) => {
- localStorage.setItem('cluster_api_url', value['url']);
+ if (value['cluster_alias'] === 'local-cluster') {
+ localStorage.setItem('cluster_api_url', '');
+ } else {
+ localStorage.setItem('current_cluster_name', `${value['name']}-${value['user']}`);
+ localStorage.setItem('cluster_api_url', value['url']);
+ }
this.selectedCluster = this.clustersMap.get(`${value['url']}-${value['user']}`) || {};
const clustersConfig = resp['config'];
if (clustersConfig && typeof clustersConfig === 'object') {
if (
clusterName === this.selectedCluster['name'] &&
- clusterUser === this.selectedCluster['user']
+ clusterUser === this.selectedCluster['user'] &&
+ clusterDetails['cluster_alias'] !== 'local-cluster'
) {
- localStorage.setItem('token_of_selected_cluster', clusterToken);
+ this.cookieService.setToken(`${clusterName}-${clusterUser}`, clusterToken);
}
});
});
import { MultiClusterService } from '../api/multi-cluster.service';
import { SummaryService } from './summary.service';
import { AuthStorageService } from './auth-storage.service';
+import { CookiesService } from './cookie.service';
export class CdHttpErrorResponse extends HttpErrorResponse {
preventDefault: Function;
public notificationService: NotificationService,
private summaryService: SummaryService,
private authStorageService: AuthStorageService,
- private multiClusterService: MultiClusterService
+ private multiClusterService: MultiClusterService,
+ private cookieService: CookiesService
) {
this.multiClusterService.subscribe((resp: any) => {
const clustersConfig = resp['config'];
'api/multi-cluster/auth'
];
- const token = localStorage.getItem('token_of_selected_cluster');
-
if (
!currentRoute.includes('login') &&
!ALWAYS_TO_HUB_APIs.includes(request.url) &&
apiUrl &&
!apiUrl.includes(origin)
) {
+ const token = this.cookieService.getToken(localStorage.getItem('current_cluster_name'));
reqWithVersion = reqWithVersion.clone({
url: `${apiUrl}${reqWithVersion.url}`,
setHeaders: {
--- /dev/null
+import { TestBed } from '@angular/core/testing';
+
+import { CookiesService } from './cookie.service';
+
+describe('CookieService', () => {
+ let service: CookiesService;
+
+ beforeEach(() => {
+ TestBed.configureTestingModule({});
+ service = TestBed.inject(CookiesService);
+ });
+
+ it('should be created', () => {
+ expect(service).toBeTruthy();
+ });
+});
--- /dev/null
+import { Injectable } from '@angular/core';
+import { CookieService } from 'ngx-cookie-service';
+
+@Injectable({
+ providedIn: 'root'
+})
+export class CookiesService {
+ constructor(private cookieService: CookieService) {}
+
+ setToken(name: string, token: string) {
+ this.cookieService.set(name, token, null, null, null, true, 'Strict');
+ }
+
+ getToken(name: string): string {
+ return this.cookieService.get(name);
+ }
+
+ deleteToken(name: string) {
+ this.cookieService.delete(name);
+ }
+}