+1
-1
@@ -40,7 +40,7 @@ export interface Config {
|
||||
}
|
||||
|
||||
/**
|
||||
* Configuration of {@link PuppetDBEntityProvider}.
|
||||
* Configuration of {@link PuppetDbEntityProvider}.
|
||||
*/
|
||||
interface ProviderConfig {
|
||||
/**
|
||||
|
||||
+3
-3
@@ -17,7 +17,7 @@
|
||||
import { TaskInvocationDefinition, TaskRunner } from '@backstage/backend-tasks';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { PuppetDBEntityProvider } from './PuppetDBEntityProvider';
|
||||
import { PuppetDbEntityProvider } from './PuppetDbEntityProvider';
|
||||
import { EntityProviderConnection } from '@backstage/plugin-catalog-backend';
|
||||
import * as p from '../puppet/read';
|
||||
import { DEFAULT_OWNER } from './constants';
|
||||
@@ -79,7 +79,7 @@ describe('PuppetEntityProvider', () => {
|
||||
applyMutation: jest.fn(),
|
||||
refresh: jest.fn(),
|
||||
};
|
||||
const providers = PuppetDBEntityProvider.fromConfig(config, {
|
||||
const providers = PuppetDbEntityProvider.fromConfig(config, {
|
||||
logger,
|
||||
schedule: new PersistingTaskRunner(),
|
||||
});
|
||||
@@ -144,7 +144,7 @@ describe('PuppetEntityProvider', () => {
|
||||
applyMutation: jest.fn(),
|
||||
refresh: jest.fn(),
|
||||
};
|
||||
const providers = PuppetDBEntityProvider.fromConfig(config, {
|
||||
const providers = PuppetDbEntityProvider.fromConfig(config, {
|
||||
logger,
|
||||
schedule: new PersistingTaskRunner(),
|
||||
});
|
||||
+12
-12
@@ -20,9 +20,9 @@ import {
|
||||
} from '@backstage/plugin-catalog-backend';
|
||||
import { Logger } from 'winston';
|
||||
import {
|
||||
PuppetDBEntityProviderConfig,
|
||||
PuppetDbEntityProviderConfig,
|
||||
readProviderConfigs,
|
||||
} from './PuppetDBEntityProviderConfig';
|
||||
} from './PuppetDbEntityProviderConfig';
|
||||
import { Config } from '@backstage/config';
|
||||
import { PluginTaskScheduler, TaskRunner } from '@backstage/backend-tasks';
|
||||
import * as uuid from 'uuid';
|
||||
@@ -42,20 +42,20 @@ import { ENDPOINT_NODES } from '../puppet/constants';
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export class PuppetDBEntityProvider implements EntityProvider {
|
||||
private readonly config: PuppetDBEntityProviderConfig;
|
||||
export class PuppetDbEntityProvider implements EntityProvider {
|
||||
private readonly config: PuppetDbEntityProviderConfig;
|
||||
private readonly logger: Logger;
|
||||
private readonly scheduleFn: () => Promise<void>;
|
||||
private readonly transformer: ResourceTransformer;
|
||||
private connection?: EntityProviderConnection;
|
||||
|
||||
/**
|
||||
* Creates instances of {@link PuppetDBEntityProvider} from a configuration.
|
||||
* Creates instances of {@link PuppetDbEntityProvider} from a configuration.
|
||||
*
|
||||
* @param config - The configuration to read provider information from.
|
||||
* @param deps - The dependencies for {@link PuppetDBEntityProvider}.
|
||||
* @param deps - The dependencies for {@link PuppetDbEntityProvider}.
|
||||
*
|
||||
* @returns A list of {@link PuppetDBEntityProvider} instances.
|
||||
* @returns A list of {@link PuppetDbEntityProvider} instances.
|
||||
*/
|
||||
static fromConfig(
|
||||
config: Config,
|
||||
@@ -65,7 +65,7 @@ export class PuppetDBEntityProvider implements EntityProvider {
|
||||
scheduler?: PluginTaskScheduler;
|
||||
transformer?: ResourceTransformer;
|
||||
},
|
||||
): PuppetDBEntityProvider[] {
|
||||
): PuppetDbEntityProvider[] {
|
||||
if (!deps.schedule && !deps.scheduler) {
|
||||
throw new Error('Either schedule or scheduler must be provided.');
|
||||
}
|
||||
@@ -83,7 +83,7 @@ export class PuppetDBEntityProvider implements EntityProvider {
|
||||
|
||||
const transformer = deps.transformer ?? defaultResourceTransformer;
|
||||
|
||||
return new PuppetDBEntityProvider(
|
||||
return new PuppetDbEntityProvider(
|
||||
providerConfig,
|
||||
deps.logger,
|
||||
taskRunner,
|
||||
@@ -93,7 +93,7 @@ export class PuppetDBEntityProvider implements EntityProvider {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of {@link PuppetDBEntityProvider}.
|
||||
* Creates an instance of {@link PuppetDbEntityProvider}.
|
||||
*
|
||||
* @param config - Configuration of the provider.
|
||||
* @param logger - The instance of a {@link Logger}.
|
||||
@@ -103,7 +103,7 @@ export class PuppetDBEntityProvider implements EntityProvider {
|
||||
* @private
|
||||
*/
|
||||
private constructor(
|
||||
config: PuppetDBEntityProviderConfig,
|
||||
config: PuppetDbEntityProviderConfig,
|
||||
logger: Logger,
|
||||
taskRunner: TaskRunner,
|
||||
transformer: ResourceTransformer,
|
||||
@@ -141,7 +141,7 @@ export class PuppetDBEntityProvider implements EntityProvider {
|
||||
id: taskId,
|
||||
fn: async () => {
|
||||
const logger = this.logger.child({
|
||||
class: PuppetDBEntityProvider.prototype.constructor.name,
|
||||
class: PuppetDbEntityProvider.prototype.constructor.name,
|
||||
taskId,
|
||||
taskInstanceId: uuid.v4(),
|
||||
});
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { readProviderConfigs } from './PuppetDBEntityProviderConfig';
|
||||
import { readProviderConfigs } from './PuppetDbEntityProviderConfig';
|
||||
import { Duration } from 'luxon';
|
||||
|
||||
describe('readProviderConfigs', () => {
|
||||
+4
-4
@@ -22,11 +22,11 @@ import { Config } from '@backstage/config';
|
||||
import { DEFAULT_PROVIDER_ID } from './constants';
|
||||
|
||||
/**
|
||||
* Configuration of {@link PuppetDBEntityProvider}.
|
||||
* Configuration of {@link PuppetDbEntityProvider}.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type PuppetDBEntityProviderConfig = {
|
||||
export type PuppetDbEntityProviderConfig = {
|
||||
/**
|
||||
* ID of the provider.
|
||||
*/
|
||||
@@ -54,7 +54,7 @@ export type PuppetDBEntityProviderConfig = {
|
||||
*/
|
||||
export function readProviderConfigs(
|
||||
config: Config,
|
||||
): PuppetDBEntityProviderConfig[] {
|
||||
): PuppetDbEntityProviderConfig[] {
|
||||
const providersConfig = config.getOptionalConfig(
|
||||
'catalog.providers.puppetdb',
|
||||
);
|
||||
@@ -82,7 +82,7 @@ export function readProviderConfigs(
|
||||
function readProviderConfig(
|
||||
id: string,
|
||||
config: Config,
|
||||
): PuppetDBEntityProviderConfig {
|
||||
): PuppetDbEntityProviderConfig {
|
||||
const host = config.getString('host').replace(/\/+$/, '');
|
||||
const query = config.getOptionalString('query');
|
||||
|
||||
@@ -14,6 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export { PuppetDBEntityProvider } from './PuppetDBEntityProvider';
|
||||
export type { PuppetDBEntityProviderConfig } from './PuppetDBEntityProviderConfig';
|
||||
export { PuppetDbEntityProvider } from './PuppetDbEntityProvider';
|
||||
export type { PuppetDbEntityProviderConfig } from './PuppetDbEntityProviderConfig';
|
||||
export { DEFAULT_PROVIDER_ID, DEFAULT_OWNER } from './constants';
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
import { readPuppetNodes } from './read';
|
||||
import {
|
||||
DEFAULT_PROVIDER_ID,
|
||||
PuppetDBEntityProviderConfig,
|
||||
PuppetDbEntityProviderConfig,
|
||||
} from '../providers';
|
||||
import { DEFAULT_NAMESPACE } from '@backstage/catalog-model';
|
||||
import fetch from 'node-fetch';
|
||||
@@ -37,7 +37,7 @@ describe('readPuppetNodes', () => {
|
||||
const mockFetch = fetch as unknown as jest.Mocked<any>;
|
||||
|
||||
describe('where no query is specified', () => {
|
||||
const config: PuppetDBEntityProviderConfig = {
|
||||
const config: PuppetDbEntityProviderConfig = {
|
||||
host: 'https://puppetdb',
|
||||
id: DEFAULT_PROVIDER_ID,
|
||||
};
|
||||
@@ -186,7 +186,7 @@ describe('readPuppetNodes', () => {
|
||||
});
|
||||
|
||||
describe('where query is specified', () => {
|
||||
const config: PuppetDBEntityProviderConfig = {
|
||||
const config: PuppetDbEntityProviderConfig = {
|
||||
host: 'https://puppetdb',
|
||||
id: DEFAULT_PROVIDER_ID,
|
||||
query: '["=", "certname", "node1"]',
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { PuppetDBEntityProviderConfig } from '../providers';
|
||||
import { PuppetDbEntityProviderConfig } from '../providers';
|
||||
import { PuppetNode, ResourceTransformer } from './types';
|
||||
import { ResourceEntity } from '@backstage/catalog-model/';
|
||||
import { defaultResourceTransformer } from './transformers';
|
||||
@@ -29,7 +29,7 @@ import { Logger } from 'winston';
|
||||
* @param opts - Additional options.
|
||||
*/
|
||||
export async function readPuppetNodes(
|
||||
config: PuppetDBEntityProviderConfig,
|
||||
config: PuppetDbEntityProviderConfig,
|
||||
opts?: {
|
||||
transformer?: ResourceTransformer;
|
||||
logger?: Logger;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { PuppetDBEntityProviderConfig } from '../providers';
|
||||
import { PuppetDbEntityProviderConfig } from '../providers';
|
||||
import { PuppetNode } from './types';
|
||||
import { defaultResourceTransformer } from './transformers';
|
||||
import { DEFAULT_NAMESPACE } from '@backstage/catalog-model';
|
||||
@@ -23,7 +23,7 @@ import { ANNOTATION_PUPPET_CERTNAME } from './constants';
|
||||
|
||||
describe('defaultResourceTransformer', () => {
|
||||
it('should transform a puppet node to a resource entity', async () => {
|
||||
const config: PuppetDBEntityProviderConfig = {
|
||||
const config: PuppetDbEntityProviderConfig = {
|
||||
host: '',
|
||||
id: '',
|
||||
};
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
import { ResourceEntity } from '@backstage/catalog-model';
|
||||
import { JsonValue } from '@backstage/types';
|
||||
import { PuppetDBEntityProviderConfig } from '../providers/PuppetDBEntityProviderConfig';
|
||||
import { PuppetDbEntityProviderConfig } from '../providers/PuppetDbEntityProviderConfig';
|
||||
|
||||
/**
|
||||
* Customize the ingested Resource entity.
|
||||
@@ -30,7 +30,7 @@ import { PuppetDBEntityProviderConfig } from '../providers/PuppetDBEntityProvide
|
||||
*/
|
||||
export type ResourceTransformer = (
|
||||
node: PuppetNode,
|
||||
config: PuppetDBEntityProviderConfig,
|
||||
config: PuppetDbEntityProviderConfig,
|
||||
) => Promise<ResourceEntity | undefined>;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user