Rename host to baseUrl

Signed-off-by: Tomas Dabasinskas <tomas@dabasinskas.net>
This commit is contained in:
Tomas Dabasinskas
2023-03-01 08:29:12 +02:00
parent abdb9aed3e
commit aabfc0305b
10 changed files with 64 additions and 58 deletions
@@ -48,8 +48,8 @@ catalog:
providers:
puppetdb:
default:
# (Required) The host of PuppetDB API instance:
host: https://puppetdb.example.com
# (Required) The base URL of PuppetDB API instance:
baseUrl: https://puppetdb.example.com
# (Optional) Query to filter PuppetDB nodes:
#query: '["=","certname","example.com"]'
@@ -43,7 +43,7 @@ export class PuppetDbEntityProvider implements EntityProvider {
// @public
export type PuppetDbEntityProviderConfig = {
id: string;
host: string;
baseUrl: string;
query?: string;
schedule?: TaskScheduleDefinition;
};
+4 -4
View File
@@ -34,9 +34,9 @@ export interface Config {
puppetdb?:
| {
/**
* (Required) The host of PuppetDB API instance.
* (Required) The base URL of PuppetDB API instance.
*/
host: string;
baseUrl: string;
/**
* (Optional) PQL query to filter PuppetDB nodes.
*/
@@ -50,9 +50,9 @@ export interface Config {
string,
{
/**
* (Required) The host of PuppetDB API instance.
* (Required) The base URL of PuppetDB API instance.
*/
host: string;
baseUrl: string;
/**
* (Optional) PQL query to filter PuppetDB nodes.
*/
@@ -53,7 +53,7 @@ describe('PuppetEntityProvider', () => {
catalog: {
providers: {
puppetdb: {
host: 'http://puppetdb:8080',
baseUrl: 'http://puppetdb:8080',
schedule: {
frequency: {
minutes: 10,
@@ -165,10 +165,10 @@ describe('PuppetEntityProvider', () => {
annotations: {
[ANNOTATION_PUPPET_CERTNAME]: 'node1',
[ANNOTATION_LOCATION]: `url:${config.getString(
'catalog.providers.puppetdb.host',
'catalog.providers.puppetdb.baseUrl',
)}/${ENDPOINT_NODES}/node1`,
[ANNOTATION_ORIGIN_LOCATION]: `url:${config.getString(
'catalog.providers.puppetdb.host',
'catalog.providers.puppetdb.baseUrl',
)}/${ENDPOINT_NODES}/node1`,
},
tags: ['windows'],
@@ -193,10 +193,10 @@ describe('PuppetEntityProvider', () => {
annotations: {
[ANNOTATION_PUPPET_CERTNAME]: 'node2',
[ANNOTATION_LOCATION]: `url:${config.getString(
'catalog.providers.puppetdb.host',
'catalog.providers.puppetdb.baseUrl',
)}/${ENDPOINT_NODES}/node2`,
[ANNOTATION_ORIGIN_LOCATION]: `url:${config.getString(
'catalog.providers.puppetdb.host',
'catalog.providers.puppetdb.baseUrl',
)}/${ENDPOINT_NODES}/node2`,
},
tags: ['linux'],
@@ -176,7 +176,7 @@ export class PuppetDbEntityProvider implements EntityProvider {
type: 'full',
entities: [...entities].map(entity => ({
locationKey: this.getProviderName(),
entity: withLocations(this.config.host, entity),
entity: withLocations(this.config.baseUrl, entity),
})),
});
markCommitComplete(entities);
@@ -186,13 +186,13 @@ export class PuppetDbEntityProvider implements EntityProvider {
/**
* Ensures the entities have required annotation data.
*
* @param host - The host of the PuppetDB instance.
* @param baseUrl - The base URL of the PuppetDB instance.
* @param entity - The entity to add the annotations to.
*
* @returns Entity with @{@link ANNOTATION_LOCATION} and @{@link ANNOTATION_ORIGIN_LOCATION} annotations.
*/
function withLocations(host: string, entity: Entity): Entity {
const location = `${host}/${ENDPOINT_NODES}/${entity.metadata?.name}`;
function withLocations(baseUrl: string, entity: Entity): Entity {
const location = `${baseUrl}/${ENDPOINT_NODES}/${entity.metadata?.name}`;
return merge(
{
@@ -33,7 +33,7 @@ describe('readProviderConfigs', () => {
catalog: {
providers: {
puppetdb: {
host: 'https://puppetdb',
baseUrl: 'https://puppetdb',
},
},
},
@@ -43,7 +43,7 @@ describe('readProviderConfigs', () => {
expect(providerConfigs).toHaveLength(1);
expect(providerConfigs[0].id).toEqual('default');
expect(providerConfigs[0].host).toEqual('https://puppetdb');
expect(providerConfigs[0].baseUrl).toEqual('https://puppetdb');
});
it('single specific provider config', () => {
@@ -52,7 +52,7 @@ describe('readProviderConfigs', () => {
providers: {
puppetdb: {
'my-provider': {
host: 'https://puppetdb',
baseUrl: 'https://puppetdb',
},
},
},
@@ -63,7 +63,7 @@ describe('readProviderConfigs', () => {
expect(providerConfigs).toHaveLength(1);
expect(providerConfigs[0].id).toEqual('my-provider');
expect(providerConfigs[0].host).toEqual('https://puppetdb');
expect(providerConfigs[0].baseUrl).toEqual('https://puppetdb');
});
it('multiple provider configs', () => {
@@ -72,11 +72,11 @@ describe('readProviderConfigs', () => {
providers: {
puppetdb: {
'my-provider': {
host: 'https://my-puppet/',
baseUrl: 'https://my-puppet/',
query: 'my-query',
},
'your-provider': {
host: 'https://your-puppet',
baseUrl: 'https://your-puppet',
query: 'your-query',
},
},
@@ -89,12 +89,12 @@ describe('readProviderConfigs', () => {
expect(providerConfigs).toHaveLength(2);
expect(providerConfigs[0]).toEqual({
id: 'my-provider',
host: 'https://my-puppet',
baseUrl: 'https://my-puppet',
query: 'my-query',
});
expect(providerConfigs[1]).toEqual({
id: 'your-provider',
host: 'https://your-puppet',
baseUrl: 'https://your-puppet',
query: 'your-query',
});
});
@@ -104,7 +104,7 @@ describe('readProviderConfigs', () => {
catalog: {
providers: {
puppetdb: {
host: 'https://puppetdb',
baseUrl: 'https://puppetdb',
schedule: {
frequency: 'PT30M',
timeout: {
@@ -32,9 +32,9 @@ export type PuppetDbEntityProviderConfig = {
*/
id: string;
/**
* (Required) The host of PuppetDB API instance.
* (Required) The base URL of PuppetDB API instance.
*/
host: string;
baseUrl: string;
/**
* (Optional) PQL query to filter PuppetDB nodes.
*/
@@ -62,7 +62,7 @@ export function readProviderConfigs(
return [];
}
if (providersConfig.has('host')) {
if (providersConfig.has('baseUrl')) {
return [readProviderConfig(DEFAULT_PROVIDER_ID, providersConfig)];
}
@@ -83,7 +83,7 @@ function readProviderConfig(
id: string,
config: Config,
): PuppetDbEntityProviderConfig {
const host = config.getString('host').replace(/\/+$/, '');
const baseUrl = config.getString('baseUrl').replace(/\/+$/, '');
const query = config.getOptionalString('query');
const schedule = config.has('schedule')
@@ -92,7 +92,7 @@ function readProviderConfig(
return {
id,
host,
baseUrl,
query,
schedule,
};
@@ -35,13 +35,13 @@ describe('readPuppetNodes', () => {
describe('where no query is specified', () => {
const config: PuppetDbEntityProviderConfig = {
host: 'https://puppetdb',
baseUrl: 'https://puppetdb',
id: DEFAULT_PROVIDER_ID,
};
beforeEach(async () => {
worker.use(
rest.get(`${config.host}/${ENDPOINT_FACTSETS}`, (_req, res, ctx) => {
rest.get(`${config.baseUrl}/${ENDPOINT_FACTSETS}`, (_req, res, ctx) => {
return res(
ctx.status(200),
ctx.set('Content-Type', 'application/json'),
@@ -186,7 +186,7 @@ describe('readPuppetNodes', () => {
describe('where query is specified', () => {
const config: PuppetDbEntityProviderConfig = {
host: 'https://puppetdb',
baseUrl: 'https://puppetdb',
id: DEFAULT_PROVIDER_ID,
query: '["=", "certname", "node1"]',
};
@@ -194,13 +194,16 @@ describe('readPuppetNodes', () => {
describe('where no results are matched', () => {
beforeEach(async () => {
worker.use(
rest.get(`${config.host}/${ENDPOINT_FACTSETS}`, (_req, res, ctx) => {
return res(
ctx.status(200),
ctx.set('Content-Type', 'application/json'),
ctx.json([]),
);
}),
rest.get(
`${config.baseUrl}/${ENDPOINT_FACTSETS}`,
(_req, res, ctx) => {
return res(
ctx.status(200),
ctx.set('Content-Type', 'application/json'),
ctx.json([]),
);
},
),
);
});
@@ -213,22 +216,25 @@ describe('readPuppetNodes', () => {
describe('where results are matched', () => {
beforeEach(async () => {
worker.use(
rest.get(`${config.host}/${ENDPOINT_FACTSETS}`, (_req, res, ctx) => {
return res(
ctx.status(200),
ctx.set('Content-Type', 'application/json'),
ctx.json([
{
certname: 'node1',
timestamp: 'time1',
hash: 'hash1',
producer_timestamp: 'producer_time1',
producer: 'producer1',
environment: 'environment1',
},
]),
);
}),
rest.get(
`${config.baseUrl}/${ENDPOINT_FACTSETS}`,
(_req, res, ctx) => {
return res(
ctx.status(200),
ctx.set('Content-Type', 'application/json'),
ctx.json([
{
certname: 'node1',
timestamp: 'time1',
hash: 'hash1',
producer_timestamp: 'producer_time1',
producer: 'producer1',
environment: 'environment1',
},
]),
);
},
),
);
});
@@ -37,7 +37,7 @@ export async function readPuppetNodes(
},
): Promise<ResourceEntity[]> {
const transformFn = opts?.transformer ?? defaultResourceTransformer;
const url = new URL(ENDPOINT_FACTSETS, config.host);
const url = new URL(ENDPOINT_FACTSETS, config.baseUrl);
if (config.query) {
url.searchParams.set('query', config.query);
@@ -23,7 +23,7 @@ import { ANNOTATION_PUPPET_CERTNAME, DEFAULT_ENTITY_OWNER } from './constants';
describe('defaultResourceTransformer', () => {
it('should transform a puppet node to a resource entity', async () => {
const config: PuppetDbEntityProviderConfig = {
host: '',
baseUrl: '',
id: '',
};
const node: PuppetNode = {