renamed config and variables
Signed-off-by: Connor Younglund <younglund_connor@bah.com>
This commit is contained in:
@@ -2,4 +2,4 @@
|
||||
'@backstage/plugin-sonarqube-backend': minor
|
||||
---
|
||||
|
||||
Added optional `externalUrl` config for setting a different frontend URL
|
||||
Added optional `externalBaseUrl` config for setting a different frontend URL
|
||||
|
||||
@@ -141,14 +141,14 @@ sonarqube:
|
||||
#### Example - Different frontend and backend URLs
|
||||
|
||||
In some instances, you might want to use one URL for the backend and another for the frontend.
|
||||
This can be achieved by using the optional `externalUrl` property in the config.
|
||||
This can be achieved by using the optional `externalBaseUrl` property in the config.
|
||||
|
||||
##### Single instance config
|
||||
|
||||
```yaml
|
||||
sonarqube:
|
||||
baseUrl: https://sonarqube-internal.example.com
|
||||
externalUrl: https://sonarqube.example.com
|
||||
externalBaseUrl: https://sonarqube.example.com
|
||||
apiKey: 123456789abcdef0123456789abcedf012
|
||||
```
|
||||
|
||||
@@ -159,7 +159,7 @@ sonarqube:
|
||||
instances:
|
||||
- name: default
|
||||
baseUrl: https://default-sonarqube-internal.example.com
|
||||
externalUrl: https://default-sonarqube.example.com
|
||||
externalBaseUrl: https://default-sonarqube.example.com
|
||||
apiKey: 123456789abcdef0123456789abcedf012
|
||||
- name: specialProject
|
||||
baseUrl: https://special-project-sonarqube.example.com
|
||||
|
||||
@@ -15,7 +15,7 @@ export class DefaultSonarqubeInfoProvider implements SonarqubeInfoProvider {
|
||||
static fromConfig(config: Config): DefaultSonarqubeInfoProvider;
|
||||
getBaseUrl(options?: { instanceName?: string }): {
|
||||
baseUrl: string;
|
||||
externalUrl?: string;
|
||||
externalBaseUrl?: string;
|
||||
};
|
||||
getFindings(options: {
|
||||
componentKey: string;
|
||||
@@ -50,7 +50,7 @@ export interface SonarqubeFindings {
|
||||
export interface SonarqubeInfoProvider {
|
||||
getBaseUrl(options?: { instanceName?: string }): {
|
||||
baseUrl: string;
|
||||
externalUrl?: string;
|
||||
externalBaseUrl?: string;
|
||||
};
|
||||
getFindings(options: {
|
||||
componentKey: string;
|
||||
@@ -62,7 +62,7 @@ export interface SonarqubeInfoProvider {
|
||||
export interface SonarqubeInstanceConfig {
|
||||
apiKey: string;
|
||||
baseUrl: string;
|
||||
externalUrl?: string;
|
||||
externalBaseUrl?: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -28,7 +28,7 @@ export interface Config {
|
||||
* Use this if you want to use a different url for the frontend than the backend.
|
||||
* @visibility frontend
|
||||
*/
|
||||
externalUrl?: string;
|
||||
externalBaseUrl?: string;
|
||||
|
||||
/**
|
||||
* The api key to access the sonarqube instance under baseUrl.
|
||||
@@ -58,7 +58,7 @@ export interface Config {
|
||||
* Use this if you want to use a different url for the frontend than the backend.
|
||||
* @visibility frontend
|
||||
*/
|
||||
externalUrl?: string;
|
||||
externalBaseUrl?: string;
|
||||
|
||||
/**
|
||||
* The api key to access the sonarqube instance.
|
||||
|
||||
@@ -24,7 +24,7 @@ import { SonarqubeFindings } from './sonarqubeInfoProvider';
|
||||
describe('createRouter', () => {
|
||||
let app: express.Express;
|
||||
const getBaseUrlMock: jest.Mock<
|
||||
{ baseUrl: string; externalUrl?: string },
|
||||
{ baseUrl: string; externalBaseUrl?: string },
|
||||
[{ instanceName: string }]
|
||||
> = jest.fn();
|
||||
const getFindingsMock: jest.Mock<
|
||||
@@ -147,10 +147,10 @@ describe('createRouter', () => {
|
||||
expect(response.body).toEqual({ instanceUrl: DUMMY_INSTANCE_URL });
|
||||
});
|
||||
|
||||
it('returns the external url when provided', async () => {
|
||||
it('returns the external base url when provided', async () => {
|
||||
getBaseUrlMock.mockReturnValue({
|
||||
baseUrl: DUMMY_INSTANCE_URL,
|
||||
externalUrl: DUMMY_INSTANCE_EXTERNAL_URL,
|
||||
externalBaseUrl: DUMMY_INSTANCE_EXTERNAL_URL,
|
||||
});
|
||||
const response = await request(app).get('/instanceUrl').send();
|
||||
expect(response.status).toEqual(200);
|
||||
|
||||
@@ -81,11 +81,11 @@ export async function createRouter(
|
||||
? `Retrieving sonarqube instance URL for key ${instanceKey}`
|
||||
: `Retrieving default sonarqube instance URL as instanceKey is not provided`,
|
||||
);
|
||||
const { baseUrl, externalUrl } = sonarqubeInfoProvider.getBaseUrl({
|
||||
const { baseUrl, externalBaseUrl } = sonarqubeInfoProvider.getBaseUrl({
|
||||
instanceName: instanceKey,
|
||||
});
|
||||
response.json({
|
||||
instanceUrl: externalUrl || baseUrl,
|
||||
instanceUrl: externalBaseUrl || baseUrl,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -302,22 +302,22 @@ describe('DefaultSonarqubeInfoProvider', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('Provide external url for simple config', async () => {
|
||||
it('Provide external base url for simple config', async () => {
|
||||
const provider = configureProvider({
|
||||
sonarqube: {
|
||||
baseUrl: 'https://sonarqube-internal.example.com',
|
||||
externalUrl: 'https://sonarqube.example.com',
|
||||
externalBaseUrl: 'https://sonarqube.example.com',
|
||||
apiKey: '123456789abcdef0123456789abcedf012',
|
||||
},
|
||||
});
|
||||
|
||||
expect(provider.getBaseUrl()).toEqual({
|
||||
baseUrl: 'https://sonarqube-internal.example.com',
|
||||
externalUrl: 'https://sonarqube.example.com',
|
||||
externalBaseUrl: 'https://sonarqube.example.com',
|
||||
});
|
||||
});
|
||||
|
||||
it('Provide external url for named config', async () => {
|
||||
it('Provide external base url for named config', async () => {
|
||||
const provider = configureProvider({
|
||||
sonarqube: {
|
||||
instances: [
|
||||
@@ -329,7 +329,7 @@ describe('DefaultSonarqubeInfoProvider', () => {
|
||||
{
|
||||
name: 'other',
|
||||
baseUrl: 'https://sonarqube-other-internal.example.com',
|
||||
externalUrl: 'https://sonarqube-other.example.com',
|
||||
externalBaseUrl: 'https://sonarqube-other.example.com',
|
||||
apiKey: '123456789abcdef0123456789abcedf012',
|
||||
},
|
||||
],
|
||||
@@ -338,7 +338,7 @@ describe('DefaultSonarqubeInfoProvider', () => {
|
||||
|
||||
expect(provider.getBaseUrl({ instanceName: 'other' })).toEqual({
|
||||
baseUrl: 'https://sonarqube-other-internal.example.com',
|
||||
externalUrl: 'https://sonarqube-other.example.com',
|
||||
externalBaseUrl: 'https://sonarqube-other.example.com',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -32,7 +32,7 @@ export interface SonarqubeInfoProvider {
|
||||
*/
|
||||
getBaseUrl(options?: { instanceName?: string }): {
|
||||
baseUrl: string;
|
||||
externalUrl?: string;
|
||||
externalBaseUrl?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -102,7 +102,7 @@ export interface SonarqubeInstanceConfig {
|
||||
/**
|
||||
* External url to access the instance from the frontend
|
||||
*/
|
||||
externalUrl?: string;
|
||||
externalBaseUrl?: string;
|
||||
/**
|
||||
* Access token to access the sonarqube instance as generated in user profile.
|
||||
*/
|
||||
@@ -139,7 +139,7 @@ export class SonarqubeConfig {
|
||||
sonarqubeConfig.getOptionalConfigArray('instances')?.map(c => ({
|
||||
name: c.getString('name'),
|
||||
baseUrl: c.getString('baseUrl'),
|
||||
externalUrl: c.getOptionalString('externalUrl'),
|
||||
externalBaseUrl: c.getOptionalString('externalBaseUrl'),
|
||||
apiKey: c.getString('apiKey'),
|
||||
})) || [];
|
||||
|
||||
@@ -150,10 +150,11 @@ export class SonarqubeConfig {
|
||||
|
||||
// Get these as optional strings and check to give a better error message
|
||||
const baseUrl = sonarqubeConfig.getOptionalString('baseUrl');
|
||||
const externalUrl = sonarqubeConfig.getOptionalString('externalUrl');
|
||||
const externalBaseUrl =
|
||||
sonarqubeConfig.getOptionalString('externalBaseUrl');
|
||||
const apiKey = sonarqubeConfig.getOptionalString('apiKey');
|
||||
|
||||
if (hasNamedDefault && (baseUrl || externalUrl || apiKey)) {
|
||||
if (hasNamedDefault && (baseUrl || externalBaseUrl || apiKey)) {
|
||||
throw new Error(
|
||||
`Found both a named sonarqube instance with name ${DEFAULT_SONARQUBE_NAME} and top level baseUrl or apiKey config. Use only one style of config.`,
|
||||
);
|
||||
@@ -169,11 +170,11 @@ export class SonarqubeConfig {
|
||||
|
||||
if (unnamedAllPresent) {
|
||||
const unnamedInstanceConfig = [
|
||||
{ name: DEFAULT_SONARQUBE_NAME, baseUrl, externalUrl, apiKey },
|
||||
{ name: DEFAULT_SONARQUBE_NAME, baseUrl, externalBaseUrl, apiKey },
|
||||
] as {
|
||||
name: string;
|
||||
baseUrl: string;
|
||||
externalUrl?: string;
|
||||
externalBaseUrl?: string;
|
||||
apiKey: string;
|
||||
}[];
|
||||
|
||||
@@ -313,14 +314,14 @@ export class DefaultSonarqubeInfoProvider implements SonarqubeInfoProvider {
|
||||
*/
|
||||
getBaseUrl(options: { instanceName?: string } = {}): {
|
||||
baseUrl: string;
|
||||
externalUrl?: string;
|
||||
externalBaseUrl?: string;
|
||||
} {
|
||||
const instanceConfig = this.config.getInstanceConfig({
|
||||
sonarqubeName: options.instanceName,
|
||||
});
|
||||
return {
|
||||
baseUrl: instanceConfig.baseUrl,
|
||||
externalUrl: instanceConfig.externalUrl,
|
||||
externalBaseUrl: instanceConfig.externalBaseUrl,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user