Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { frodo } from '@rockcarver/frodo-lib';

import { configManagerExportTelemetry } from '../../../configManagerOps/FrConfigTelemetry';
import { getTokens } from '../../../ops/AuthenticateOps';
import { verboseMessage } from '../../../utils/Console';
import { FrodoCommand } from '../../FrodoCommand';

const { CLOUD_DEPLOYMENT_TYPE_KEY } = frodo.utils.constants;

const deploymentTypes = [CLOUD_DEPLOYMENT_TYPE_KEY];

export default function setup() {
const program = new FrodoCommand(
'frodo config-manager pull telemetry',
[],
deploymentTypes
);
program
.description('Export telemetry exporters.')
.option(
'-c, --category <category>',
'Telemetry category to export (e.g. otlp, splunk).'
)
.option('-n, --name <name>', 'Name of a single exporter to export.')
.action(async (host, realm, user, password, options, command) => {
command.handleDefaultArgsAndOpts(
host,
realm,
user,
password,
options,
command
);
const getTokensIsSuccessful = await getTokens(
false,
true,
deploymentTypes
);
if (!getTokensIsSuccessful) process.exit(1);
verboseMessage('Exporting telemetry configuration.');
const outcome = await configManagerExportTelemetry(
options.category,
options.name
);
if (!outcome) process.exitCode = 1;
});
return program;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import SecretMappings from './config-manager-pull-secret-mappings';
import Secrets from './config-manager-pull-secrets';
import ServiceObjects from './config-manager-pull-service-objects';
import Services from './config-manager-pull-services';
import Telemetry from './config-manager-pull-telemetry';
import Terms from './config-manager-pull-terms-and-conditions';
import Test from './config-manager-pull-test';
import Themes from './config-manager-pull-themes';
Expand Down Expand Up @@ -76,6 +77,7 @@ export default function setup() {
program.addCommand(ServiceObjects().name('service-objects'));
program.addCommand(Services().name('services'));
program.addCommand(Themes().name('themes'));
program.addCommand(Telemetry().name('telemetry'));
program.addCommand(Terms().name('terms-and-conditions'));
program.addCommand(Test().name('test'));
program.addCommand(UiConfig().name('ui-config'));
Expand Down
47 changes: 47 additions & 0 deletions src/configManagerOps/FrConfigTelemetryOps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { frodo } from '@rockcarver/frodo-lib';
import { TelemetryExporterCategory } from '@rockcarver/frodo-lib/types/api/cloud/TelemetryApi';

import { printError } from '../utils/Console';

const { saveJsonToFile, getFilePath } = frodo.utils;
const { exportTelemetry } = frodo.cloud.telemetry;

/**
* Exports telemetry configuration in config manager format
* @param {TelemetryExporterCategory} category optional parameter to export telemetry by category.
* @param {string} name optional parameter to export telemetry config by name.
* @returns { Promise<boolean> } returns true if telemetry was successfully exported
*/
export async function configManagerExportTelemetry(
category?: TelemetryExporterCategory,
name?: string
): Promise<boolean> {
try {
const exporters = await exportTelemetry(name, category);

for (const [cat, providers] of Object.entries(exporters.telemetry)) {
for (const provider of providers) {
const exportProvider = provider as any;
if (exportProvider.headers) {
const placeholders: Record<string, string> = {};
Object.keys(exportProvider.headers).forEach((headerName) => {
placeholders[headerName] =
`\${TELEMETRY_HEADER_${cat}_${provider.id}_${headerName}}`
.replaceAll('-', '_')
.toUpperCase();
});
exportProvider.headers = placeholders;
}
saveJsonToFile(
exportProvider,
getFilePath(`telemetry/${cat}/${provider.id}.json`, true),
false
);
}
}
return true;
} catch (e) {
printError(e);
}
return false;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`CLI help interface for 'config-manager pull telemetry' should be expected english 1`] = `
"Usage: frodo config-manager pull telemetry [options] [host] [realm] [username] [password]

[Experimental] Export telemetry exporters.

Arguments:
host AM base URL, e.g.: https://cdk.iam.example.com/am.
To use a connection profile, just specify a unique
substring or alias.
realm Realm. Specify realm as '/' for the root realm or
'realm' or '/parent/child' otherwise. (default:
"alpha" for Identity Cloud tenants, "/" otherwise.)
username Username to login with. Must be an admin user with
appropriate rights to manage authentication
journeys/trees.
password Password.

Deployment: Cloud-only

Options:
-c, --category <category> Telemetry category to export (e.g. otlp, splunk).
-n, --name <name> Name of a single exporter to export.
-h, --help Help
-hh, --help-more Help with all options.
-hhh, --help-all Help with all options, environment variables, and
usage examples.
"
`;
10 changes: 10 additions & 0 deletions test/client_cli/en/config-manager-pull-telemetry.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import cp from 'child_process';
import { promisify } from 'util';

const exec = promisify(cp.exec);
const CMD = 'frodo config-manager pull telemetry --help';
const { stdout } = await exec(CMD);

test("CLI help interface for 'config-manager pull telemetry' should be expected english", async () => {
expect(stdout).toMatchSnapshot();
});
100 changes: 100 additions & 0 deletions test/e2e/__snapshots__/config-manager-pull-telemetry.e2e.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`frodo config-manager pull telemetry "frodo config-manager pull telemetry --category splunk": should export only splunk exporters 1`] = `0`;

exports[`frodo config-manager pull telemetry "frodo config-manager pull telemetry --category splunk": should export only splunk exporters 2`] = `""`;

exports[`frodo config-manager pull telemetry "frodo config-manager pull telemetry --category splunk": should export only splunk exporters: telemetryTestDir2/telemetry/splunk/frodo-test-splunk-1.json 1`] = `
{
"endpoint": "https://example.com:8088'",
"id": "frodo-test-splunk-1",
"index": "test",
"sources": [
"am-access",
],
"token": "",
}
`;

exports[`frodo config-manager pull telemetry "frodo config-manager pull telemetry -c otlp -n test-otlp": should export a single named exporter 1`] = `0`;

exports[`frodo config-manager pull telemetry "frodo config-manager pull telemetry -c otlp -n test-otlp": should export a single named exporter 2`] = `""`;

exports[`frodo config-manager pull telemetry "frodo config-manager pull telemetry -c otlp -n test-otlp": should export a single named exporter: telemetryTestDir3/telemetry/otlp/test-otlp.json 1`] = `
{
"encoding": "JSON",
"endpoint": "https://example-siem.com:4317",
"headers": {
"api-key": "\${TELEMETRY_HEADER_OTLP_TEST_OTLP_API_KEY}",
"api-secret": "\${TELEMETRY_HEADER_OTLP_TEST_OTLP_API_SECRET}",
},
"id": "test-otlp",
"sources": [
"am-activity",
"idm-activity",
],
"type": "HTTP",
}
`;

exports[`frodo config-manager pull telemetry "frodo config-manager pull telemetry -c otlp": should export only the otlp exporter 1`] = `0`;

exports[`frodo config-manager pull telemetry "frodo config-manager pull telemetry -c otlp": should export only the otlp exporter 2`] = `""`;

exports[`frodo config-manager pull telemetry "frodo config-manager pull telemetry -c otlp": should export only the otlp exporter: telemetryTestDir5/telemetry/otlp/test-otlp.json 1`] = `
{
"encoding": "JSON",
"endpoint": "https://example-siem.com:4317",
"headers": {
"api-key": "\${TELEMETRY_HEADER_OTLP_TEST_OTLP_API_KEY}",
"api-secret": "\${TELEMETRY_HEADER_OTLP_TEST_OTLP_API_SECRET}",
},
"id": "test-otlp",
"sources": [
"am-activity",
"idm-activity",
],
"type": "HTTP",
}
`;

exports[`frodo config-manager pull telemetry "frodo config-manager pull telemetry -n test-otlp": should export a single named exporter 1`] = `0`;

exports[`frodo config-manager pull telemetry "frodo config-manager pull telemetry -n test-otlp": should export a single named exporter 2`] = `""`;

exports[`frodo config-manager pull telemetry "frodo config-manager pull telemetry -n test-otlp": should export a single named exporter: telemetryTestDir4/telemetry/otlp/test-otlp.json 1`] = `
{
"encoding": "JSON",
"endpoint": "https://example-siem.com:4317",
"headers": {
"api-key": "\${TELEMETRY_HEADER_OTLP_TEST_OTLP_API_KEY}",
"api-secret": "\${TELEMETRY_HEADER_OTLP_TEST_OTLP_API_SECRET}",
},
"id": "test-otlp",
"sources": [
"am-activity",
"idm-activity",
],
"type": "HTTP",
}
`;

exports[`frodo config-manager pull telemetry "frodo config-manager pull telemetry": should export telemetry in fr-config-manager style" 1`] = `0`;

exports[`frodo config-manager pull telemetry "frodo config-manager pull telemetry": should export telemetry in fr-config-manager style" 2`] = `""`;

exports[`frodo config-manager pull telemetry "frodo config-manager pull telemetry": should export telemetry in fr-config-manager style": telemetryTestDir/telemetry/otlp/datadog.json 1`] = `
{
"encoding": "PROTO",
"endpoint": "https://otlp.us5.datadoghq.com/v1/logs",
"headers": {
"dd-api-key": "\${TELEMETRY_HEADER_OTLP_DATADOG_DD_API_KEY}",
},
"id": "datadog",
"sources": [
"am-activity",
"idm-activity",
],
"type": "HTTP",
}
`;
97 changes: 97 additions & 0 deletions test/e2e/config-manager-pull-telemetry.e2e.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/**
* Follow this process to write e2e tests for the CLI project:
*
* 1. Test if all the necessary mocks for your tests already exist.
* In mock mode, run the command you want to test with the same arguments
* and parameters exactly as you want to test it, for example:
*
* $ FRODO_MOCK=1 frodo conn save https://openam-frodo-dev.forgeblocks.com/am volker.scheuber@forgerock.com Sup3rS3cr3t!
*
* If your command completes without errors and with the expected results,
* all the required mocks already exist and you are good to write your
* test and skip to step #4.
*
* If, however, your command fails and you see errors like the one below,
* you know you need to record the mock responses first:
*
* [Polly] [adapter:node-http] Recording for the following request is not found and `recordIfMissing` is `false`.
*
* 2. Record mock responses for your exact command.
* In mock record mode, run the command you want to test with the same arguments
* and parameters exactly as you want to test it, for example:
*
* $ FRODO_MOCK=record frodo conn save https://openam-frodo-dev.forgeblocks.com/am volker.scheuber@forgerock.com Sup3rS3cr3t!
*
* Wait until you see all the Polly instances (mock recording adapters) have
* shutdown before you try to run step #1 again.
* Messages like these indicate mock recording adapters shutting down:
*
* Polly instance 'conn/4' stopping in 3s...
* Polly instance 'conn/4' stopping in 2s...
* Polly instance 'conn/save/3' stopping in 3s...
* Polly instance 'conn/4' stopping in 1s...
* Polly instance 'conn/save/3' stopping in 2s...
* Polly instance 'conn/4' stopped.
* Polly instance 'conn/save/3' stopping in 1s...
* Polly instance 'conn/save/3' stopped.
*
* 3. Validate your freshly recorded mock responses are complete and working.
* Re-run the exact command you want to test in mock mode (see step #1).
*
* 4. Write your test.
* Make sure to use the exact command including number of arguments and params.
*
* 5. Commit both your test and your new recordings to the repository.
* Your tests are likely going to reside outside the frodo-lib project but
* the recordings must be committed to the frodo-lib project.
*/

/*
FRODO_MOCK=record FRODO_NO_CACHE=1 FRODO_HOST=https://openam-frodo-dev.forgeblocks.com/am frodo config-manager pull telemetry -D telemetryTestDir
FRODO_MOCK=record FRODO_NO_CACHE=1 FRODO_HOST=https://openam-frodo-dev.forgeblocks.com/am frodo config-manager pull telemetry --category splunk -D telemetryTestDir2
FRODO_MOCK=record FRODO_NO_CACHE=1 FRODO_HOST=https://openam-frodo-dev.forgeblocks.com/am frodo config-manager pull telemetry -c otlp -n test-otlp -D telemetryTestDir3
FRODO_MOCK=record FRODO_NO_CACHE=1 FRODO_HOST=https://openam-frodo-dev.forgeblocks.com/am frodo config-manager pull telemetry -n test-otlp -D telemetryTestDir4
FRODO_MOCK=record FRODO_NO_CACHE=1 FRODO_HOST=https://openam-frodo-dev.forgeblocks.com/am frodo config-manager pull telemetry -c otlp -D telemetryTestDir5
*/


import { getEnv, testExport } from './utils/TestUtils';
import { connection as c } from './utils/TestConfig';

process.env['FRODO_MOCK'] = '1';
process.env['FRODO_CONNECTION_PROFILES_PATH'] =
'./test/e2e/env/Connections.json';
const env = getEnv(c);

describe('frodo config-manager pull telemetry', () => {
test('"frodo config-manager pull telemetry": should export telemetry in fr-config-manager style"', async () => {
const dirName = 'telemetryTestDir';
const CMD = `frodo config-manager pull telemetry -D ${dirName}`;
await testExport(CMD, env, undefined, undefined, dirName, false);
});

test('"frodo config-manager pull telemetry --category splunk": should export only splunk exporters', async () => {
const dirName = 'telemetryTestDir2';
const CMD = `frodo config-manager pull telemetry --category splunk -D ${dirName}`;
await testExport(CMD, env, undefined, undefined, dirName, false);
});

test('"frodo config-manager pull telemetry -c otlp -n test-otlp": should export a single named exporter', async () => {
const dirName = 'telemetryTestDir3';
const CMD = `frodo config-manager pull telemetry -c otlp -n test-otlp -D ${dirName}`;
await testExport(CMD, env, undefined, undefined, dirName, false);
});

test('"frodo config-manager pull telemetry -n test-otlp": should export a single named exporter', async () => {
const dirName = 'telemetryTestDir4';
const CMD = `frodo config-manager pull telemetry -n test-otlp -D ${dirName}`;
await testExport(CMD, env, undefined, undefined, dirName, false);
});

test('"frodo config-manager pull telemetry -c otlp": should export only the otlp exporter', async () => {
const dirName = 'telemetryTestDir5';
const CMD = `frodo config-manager pull telemetry -c otlp -D ${dirName}`;
await testExport(CMD, env, undefined, undefined, dirName, false);
});

});
Loading