@roadiehq/catalog-backend-module-okta
Version:
A set of Backstage catalog providers for Okta
77 lines (73 loc) • 2.73 kB
JavaScript
;
var OktaEntityProvider = require('./OktaEntityProvider.cjs.js');
require('lodash');
var userNamingStrategyFactory = require('./userNamingStrategies/userNamingStrategyFactory.cjs.js');
var userEntityFromOktaUser = require('./userEntityFromOktaUser.cjs.js');
var accountConfig = require('./accountConfig.cjs.js');
var errors = require('@backstage/errors');
class OktaUserEntityProvider extends OktaEntityProvider.OktaEntityProvider {
namingStrategy;
userEntityFromOktaUser;
userFilter;
orgUrl;
customAttributesToAnnotationAllowlist;
static fromConfig(config, options) {
const accountConfig$1 = accountConfig.getAccountConfig(config);
return new OktaUserEntityProvider(accountConfig$1, options);
}
constructor(accountConfig, options) {
super(accountConfig, options);
this.namingStrategy = userNamingStrategyFactory.userNamingStrategyFactory(options.namingStrategy);
this.userEntityFromOktaUser = options.userTransformer || userEntityFromOktaUser.userEntityFromOktaUser;
this.userFilter = accountConfig.userFilter;
this.orgUrl = accountConfig.orgUrl;
this.customAttributesToAnnotationAllowlist = options.customAttributesToAnnotationAllowlist || [];
}
getProviderName() {
return `okta-user-${this.orgUrl}`;
}
async run() {
if (!this.connection) {
throw new Error("Not initialized");
}
this.logger.info(`Providing user resources from okta: ${this.orgUrl}`);
const userResources = [];
const client = this.getClient(this.orgUrl, ["okta.users.read"]);
const defaultAnnotations = await this.buildDefaultAnnotations();
const allUsers = await client.listUsers({ search: this.userFilter });
await allUsers.each((user) => {
const profileAnnotations = this.getCustomAnnotations(
user,
this.customAttributesToAnnotationAllowlist
);
const annotations = {
...defaultAnnotations,
...profileAnnotations
};
try {
const userEntity = this.userEntityFromOktaUser(
user,
this.namingStrategy,
{ annotations }
);
userResources.push(userEntity);
} catch (e) {
this.logger.warn(
`Failed to add user: ${errors.isError(e) ? e.message : "unknown error"}`
);
}
});
await this.connection.applyMutation({
type: "full",
entities: userResources.map((entity) => ({
entity,
locationKey: this.getProviderName()
}))
});
this.logger.info(
`Finished providing ${userResources.length} user resources from okta: ${this.orgUrl}`
);
}
}
exports.OktaUserEntityProvider = OktaUserEntityProvider;
//# sourceMappingURL=OktaUserEntityProvider.cjs.js.map