@jfvilas/kind-plexus
Version:
Kind extensions of Backstage
556 lines (544 loc) • 13.8 kB
JavaScript
;
var backendPluginApi = require('@backstage/backend-plugin-api');
var alpha = require('@backstage/plugin-catalog-node/alpha');
var pluginCatalogNode = require('@backstage/plugin-catalog-node');
var catalogModel = require('@backstage/catalog-model');
var $schema$2 = "http://json-schema.org/draft-07/schema";
var $id$2 = "CobolEntityV1beta1";
var description$2 = ".....";
var examples$2 = [
{
apiVersion: "plexus.es/v1beta1",
kind: "Cobol",
metadata: {
name: "LoremService",
description: "Creates Lorems like a pro."
},
spec: {
name: "vendedor1",
owner: "user:julio"
}
}
];
var allOf$2 = [
{
$ref: "Entity"
},
{
type: "object",
required: [
"spec"
],
properties: {
apiVersion: {
"enum": [
"plexus.es/v1beta1"
]
},
kind: {
"enum": [
"Cobol"
]
},
spec: {
type: "object",
required: [
"name"
],
properties: {
name: {
type: "string",
description: "nombre del modulo",
examples: [
"JAFV001",
"JAFVR001"
],
minLength: 1
},
environment: {
type: "string",
"enum": [
"batch",
"cics"
],
description: "Entorno de ejecucion",
minLength: 1
},
owner: {
type: "string",
description: "An entity reference to the owner of the component.",
examples: [
"user:john.johnson"
],
minLength: 1
}
}
}
}
}
];
var cobolEntityV1beta1Schema = {
$schema: $schema$2,
$id: $id$2,
description: description$2,
examples: examples$2,
allOf: allOf$2
};
class CobolEntitiesProcessor {
// You often end up wanting to support multiple versions of your kind as you
// iterate on the definition, so we keep each version inside this array as a
// convenient pattern.
validators = [
// This is where we use the JSONSchema that we export from our isomorphic
// package
catalogModel.entityKindSchemaValidator(cobolEntityV1beta1Schema)
];
// Return processor name
getProcessorName() {
return "CobolEntitiesProcessor";
}
// validateEntityKind is responsible for signaling to the catalog processing
// engine that this entity is valid and should therefore be submitted for
// further processing.
async validateEntityKind(entity) {
for (const validator of this.validators) {
if (validator(entity)) {
return true;
}
}
return false;
}
async postProcessEntity(entity, _location, emit) {
if (entity.apiVersion === "plexus.es/v1beta1" && entity.kind === "Cobol") {
const cobolEntity = entity;
if (cobolEntity.spec.owner) {
var ownername = cobolEntity.spec.owner;
var ownertype = "User";
var i = ownername.indexOf(":");
if (i > 0) {
ownertype = ownername.substring(0, 1).toUpperCase() + ownername.substring(1, i);
ownername = ownername.substring(i + 1);
}
var ownerRel = {
source: {
kind: "Cobol",
namespace: "default",
name: cobolEntity.metadata.name
},
type: "ownedBy",
target: {
kind: ownertype,
namespace: "default",
name: ownername
}
};
emit(pluginCatalogNode.processingResult.relation(ownerRel));
var ownerRelRev = {
source: {
kind: ownertype,
namespace: "default",
name: ownername
},
type: "ownerOf",
target: {
kind: "Cobol",
namespace: "default",
name: cobolEntity.metadata.name
}
};
emit(pluginCatalogNode.processingResult.relation(ownerRelRev));
}
}
return entity;
}
}
const catalogModuleCobolEntitiesProcessor = backendPluginApi.createBackendModule({
pluginId: "catalog",
// <-- el pluginId no se puede inventar, indica a que componente core enganchamos el plugin
moduleId: "cobol",
// <-- este sí lo podemos inventar
register(env) {
env.registerInit({
deps: {
catalog: alpha.catalogProcessingExtensionPoint
},
async init({ catalog }) {
catalog.addProcessor(new CobolEntitiesProcessor());
}
});
}
});
var $schema$1 = "http://json-schema.org/draft-07/schema";
var $id$1 = "VendorEntityV1beta1";
var description$1 = ".....";
var examples$1 = [
{
apiVersion: "plexus.es/v1beta1",
kind: "Vendor",
metadata: {
name: "LoremService",
description: "Creates Lorems like a pro."
},
spec: {
name: "vendedor1",
owner: "user:julio"
}
}
];
var allOf$1 = [
{
$ref: "Entity"
},
{
type: "object",
required: [
"spec"
],
properties: {
apiVersion: {
"enum": [
"plexus.es/v1beta1"
]
},
kind: {
"enum": [
"Vendor"
]
},
spec: {
type: "object",
required: [
"name"
],
properties: {
name: {
type: "string",
description: "nombre del vendedor.",
examples: [
"microsoft",
"ibm"
],
minLength: 1
},
contact: {
type: "string",
description: "Email de contacto del vendor.",
examples: [
"sales@ibm.com",
"info@micorsoft.com"
],
minLength: 1
},
owner: {
type: "string",
description: "An entity reference to the owner of the component.",
examples: [
"user:john.johnson"
],
minLength: 1
},
builds: {
type: "array",
description: "An array of entity references to the components that are build by the vendor.",
items: {
type: "string",
minLength: 1
}
}
}
}
}
}
];
var vendorEntityV1beta1Schema = {
$schema: $schema$1,
$id: $id$1,
description: description$1,
examples: examples$1,
allOf: allOf$1
};
class VendorEntitiesProcessor {
// You often end up wanting to support multiple versions of your kind as you
// iterate on the definition, so we keep each version inside this array as a
// convenient pattern.
validators = [
// This is where we use the JSONSchema that we export from our isomorphic
// package
catalogModel.entityKindSchemaValidator(vendorEntityV1beta1Schema)
];
// Return processor name
getProcessorName() {
return "VendorEntitiesProcessor";
}
// validateEntityKind is responsible for signaling to the catalog processing
// engine that this entity is valid and should therefore be submitted for
// further processing.
async validateEntityKind(entity) {
for (const validator of this.validators) {
if (validator(entity)) {
return true;
}
}
return false;
}
async postProcessEntity(entity, _location, emit) {
if (entity.apiVersion === "plexus.es/v1beta1" && entity.kind === "Vendor") {
const vendorEntity = entity;
for (var a of vendorEntity.spec.builds) {
let kind = "Component";
let namespace = "default";
if (a.includes(":")) {
let i2 = a.indexOf(":");
kind = a.substring(0, i2);
a = a.substring(i2 + 1);
}
if (a.includes("/")) {
let i2 = a.indexOf("/");
namespace = a.substring(0, i2);
a = a.substring(i2 + 1);
}
let name = a;
let buildRel = {
source: {
kind: "Vendor",
namespace: "default",
name: vendorEntity.metadata.name
},
type: "builds",
target: {
kind,
namespace,
name
}
};
emit(pluginCatalogNode.processingResult.relation(buildRel));
}
if (vendorEntity.spec.owner) {
var ownername = vendorEntity.spec.owner;
var ownertype = "User";
var i = ownername.indexOf(":");
if (i > 0) {
ownertype = ownername.substring(0, 1).toUpperCase() + ownername.substring(1, i);
ownername = ownername.substring(i + 1);
}
var ownerRel = {
source: {
kind: "Vendor",
namespace: "default",
name: vendorEntity.metadata.name
},
type: "ownedBy",
target: {
kind: ownertype,
namespace: "default",
name: ownername
}
};
emit(pluginCatalogNode.processingResult.relation(ownerRel));
var ownerRelRev = {
source: {
kind: ownertype,
namespace: "default",
name: ownername
},
type: "ownerOf",
target: {
kind: "Vendor",
namespace: "default",
name: vendorEntity.metadata.name
}
};
emit(pluginCatalogNode.processingResult.relation(ownerRelRev));
}
}
return entity;
}
}
const catalogModuleVendorEntitiesProcessor = backendPluginApi.createBackendModule({
pluginId: "catalog",
// <-- el pluginId no se puede inventar, indica a que componente core enganchamos el plugin
moduleId: "vendor",
// <-- este sí lo podemos inventar
register(env) {
env.registerInit({
deps: {
catalog: alpha.catalogProcessingExtensionPoint
},
async init({ catalog }) {
catalog.addProcessor(new VendorEntitiesProcessor());
}
});
}
});
var $schema = "http://json-schema.org/draft-07/schema";
var $id = "MfModuleEntityV1beta1";
var description = ".....";
var examples = [
{
apiVersion: "plexus.es/v1beta1",
kind: "MfModule",
metadata: {
name: "LoremService",
description: "Creates Lorems like a pro."
},
spec: {
language: "pli",
languageenvironment: false,
owner: "user:julio"
}
}
];
var allOf = [
{
$ref: "Entity"
},
{
type: "object",
required: [
"spec"
],
properties: {
apiVersion: {
"enum": [
"plexus.es/v1beta1"
]
},
kind: {
"enum": [
"MfModule"
]
},
spec: {
type: "object",
properties: {
environment: {
type: "string",
"enum": [
"batch",
"cics"
],
description: "Entorno de ejecucion",
minLength: 1
},
language: {
type: "string",
"enum": [
"pli",
"rpg",
"cobol"
],
description: "Entorno de ejecucion",
minLength: 1
},
languageenvironment: {
type: "boolean",
description: "Usa o no LE"
},
owner: {
type: "string",
description: "An entity reference to the owner of the component.",
examples: [
"user:john.johnson"
],
minLength: 1
}
}
}
}
}
];
var mfModuleEntityV1beta1Schema = {
$schema: $schema,
$id: $id,
description: description,
examples: examples,
allOf: allOf
};
class MfModuleEntitiesProcessor {
// You often end up wanting to support multiple versions of your kind as you
// iterate on the definition, so we keep each version inside this array as a
// convenient pattern.
validators = [
// This is where we use the JSONSchema that we export from our isomorphic
// package
catalogModel.entityKindSchemaValidator(mfModuleEntityV1beta1Schema)
];
// Return processor name
getProcessorName() {
return "MfModuleEntitiesProcessor";
}
// validateEntityKind is responsible for signaling to the catalog processing
// engine that this entity is valid and should therefore be submitted for
// further processing.
async validateEntityKind(entity) {
for (const validator of this.validators) {
if (validator(entity)) {
return true;
}
}
return false;
}
async postProcessEntity(entity, _location, emit) {
if (entity.apiVersion === "plexus.es/v1beta1" && entity.kind.toLowerCase() === "mfmodule") {
const mfModuleEntity = entity;
if (mfModuleEntity.spec.owner) {
var ownername = mfModuleEntity.spec.owner;
var ownertype = "User";
var i = ownername.indexOf(":");
if (i > 0) {
ownertype = ownername.substring(0, 1).toUpperCase() + ownername.substring(1, i);
ownername = ownername.substring(i + 1);
}
var ownerRel = {
source: {
kind: "MfModule",
namespace: "default",
name: mfModuleEntity.metadata.name
},
type: "ownedBy",
target: {
kind: ownertype,
namespace: "default",
name: ownername
}
};
emit(pluginCatalogNode.processingResult.relation(ownerRel));
var ownerRelReverse = {
source: {
kind: ownertype,
namespace: "default",
name: ownername
},
type: "ownerOf",
target: {
kind: "MfModule",
namespace: "default",
name: mfModuleEntity.metadata.name
}
};
emit(pluginCatalogNode.processingResult.relation(ownerRelReverse));
}
}
return entity;
}
}
const catalogModuleMfModuleEntitiesProcessor = backendPluginApi.createBackendModule({
pluginId: "catalog",
// <-- el pluginId no se puede inventar, indica a que componente core enganchamos el plugin
moduleId: "mfmodule",
// <-- este sí lo podemos inventar
register(env) {
env.registerInit({
deps: {
catalog: alpha.catalogProcessingExtensionPoint
},
async init({ catalog }) {
catalog.addProcessor(new MfModuleEntitiesProcessor());
}
});
}
});
exports.catalogModuleCobolEntitiesProcessor = catalogModuleCobolEntitiesProcessor;
exports.catalogModuleMfModuleEntitiesProcessor = catalogModuleMfModuleEntitiesProcessor;
exports.catalogModuleVendorEntitiesProcessor = catalogModuleVendorEntitiesProcessor;
//# sourceMappingURL=index.cjs.js.map