Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(console): create portal configuration service
Browse files Browse the repository at this point in the history
(cherry picked from commit 6217a15)

# Conflicts:
#	gravitee-apim-console-webui/src/entities/portal/portalSettings.ts
jourdiw authored and mergify[bot] committed Jan 16, 2025
1 parent 6a742d0 commit 3b6fcd6
Showing 5 changed files with 125 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -13,10 +13,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { PortalSettings } from './portalSettings';
import { PortalConfiguration, PortalSettings } from './portalSettings';

export function fakePortalSettings(attributes?: Partial<PortalSettings>): PortalSettings {
const base: PortalSettings = {
...fakePortalConfiguration(),
cors: {
allowOrigin: ['test.entrypoint.dev', 'test.entrypoint.dev2'],
allowHeaders: ['Cache-Control', 'Pragma'],
allowMethods: ['GET', 'DELETE'],
exposedHeaders: ['ETag', 'X-Xsrf-Token'],
maxAge: 1728000,
},
};

return {
...base,
...attributes,
};
}

export function fakePortalConfiguration(attributes?: Partial<PortalConfiguration>): PortalConfiguration {
const base: PortalConfiguration = {
portal: {
entrypoint: 'https://api.company.com',
apikeyHeader: 'X-Gravitee-Api-Key',
Original file line number Diff line number Diff line change
@@ -16,7 +16,11 @@
/**
* TODO: to complete, contains only one part used in the Ui console
*/
export interface PortalSettings {
export interface PortalSettings extends PortalConfiguration {
cors?: PortalSettingsCors;
}

export interface PortalConfiguration {
portal?: PortalSettingsPortal;
metadata?: PortalSettingsMetadata;
application?: PortalSettingsApplication;
@@ -92,6 +96,7 @@ export interface PortalSettingsPortal {
};
}

<<<<<<< HEAD
export interface PortalApiQualityMetrics {
enabled: boolean;
functionalDocumentationWeight: number;
@@ -115,4 +120,12 @@ export interface PortalSettingsAuthentication {
localLogin?: {
enabled: boolean;
};
=======
export interface PortalSettingsCors {
allowOrigin: string[];
allowMethods: string[];
allowHeaders: string[];
exposedHeaders: string[];
maxAge: number;
>>>>>>> 6217a15407 (feat(console): create portal configuration service)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { TestBed } from '@angular/core/testing';
import { HttpTestingController } from '@angular/common/http/testing';

import { PortalConfigurationService } from './portal-configuration.service';

import { fakePortalConfiguration } from '../entities/portal/portalSettings.fixture';
import { CONSTANTS_TESTING, GioHttpTestingModule } from '../shared/testing';

describe('PortalConfigurationService', () => {
let service: PortalConfigurationService;
let httpTestingController: HttpTestingController;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [GioHttpTestingModule],
});

httpTestingController = TestBed.inject(HttpTestingController);
service = TestBed.inject(PortalConfigurationService);
});

describe('getEnvConfiguration', () => {
it('should call the API', (done) => {
const portalConfigurationToGet = fakePortalConfiguration();

service.get().subscribe((portalSettings) => {
expect(portalSettings).toMatchObject(portalConfigurationToGet);
done();
});

httpTestingController.expectOne({ method: 'GET', url: `${CONSTANTS_TESTING.env.baseURL}/portal` }).flush(portalConfigurationToGet);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Inject, Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';

import { Constants } from '../entities/Constants';
import { PortalConfiguration } from '../entities/portal/portalSettings';

/**
* Portal Configuration Service is to be used to read Portal settings regardless of user permissions
*/
@Injectable({
providedIn: 'root',
})
export class PortalConfigurationService {
constructor(
private readonly http: HttpClient,
@Inject('Constants') private readonly constants: Constants,
) {}

get(): Observable<PortalConfiguration> {
return this.http.get<PortalConfiguration>(`${this.constants.env.baseURL}/portal`);
}
}
Original file line number Diff line number Diff line change
@@ -23,6 +23,11 @@ import { EnvironmentSettingsService } from './environment-settings.service';
import { Constants } from '../entities/Constants';
import { PortalSettings } from '../entities/portal/portalSettings';

/**
* Portal Settings Service is used to return the settings for users that have the READ permission for settings at the org or env level
*
* Use {@link portal-configuration.service.ts} to access settings open to all users.
*/
@Injectable({
providedIn: 'root',
})

0 comments on commit 3b6fcd6

Please sign in to comment.