Files
threshold-ui/ui/admin/tests/e2e/helpers/boundary-cli/host-catalogs.mjs
T
Michael Li 007f5d8b46 refact(e2e): Split up boundary-cli helper methods (#2430)
* refact(e2e): Split up boundary-cli helper methods

* CR: Use ESM import

* CR: Move authenticated state to a non-shared file

* CR: Use mjs

* CR: Modify playwright config to .mjs
2024-08-19 16:00:16 -04:00

60 lines
1.7 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { execSync } from 'node:child_process';
import { nanoid } from 'nanoid';
/**
* Creates a new static host catalog
* @param {string} projectId ID of the project under which the host catalog will be created.
* @returns {Promise<string>} new host catalog's ID
*/
export async function createStaticHostCatalogCli(projectId) {
const hostCatalogName = 'static-host-catalog-' + nanoid();
let hostCatalog;
try {
hostCatalog = JSON.parse(
execSync(
`boundary host-catalogs create static \
-scope-id ${projectId} \
-name ${hostCatalogName} \
-format json`,
),
).item;
} catch (e) {
console.log(`${e.stderr}`);
}
return hostCatalog.id;
}
/**
* Creates a new dynamic AWS host catalog
* @param {string} projectId ID of the project under which the host catalog will be created.
* @param {string} region Name of the AWS region that the host catalog will be created for.
* @returns {Promise<string>} new host catalog's ID
*/
export async function createDynamicAwsHostCatalogCli(projectId, region) {
const hostCatalogName = 'dynamic-aws-host-catalog-' + nanoid();
let hostCatalog;
try {
hostCatalog = JSON.parse(
execSync(
`boundary host-catalogs create plugin \
-name ${hostCatalogName} \
-scope-id ${projectId} \
-plugin-name aws \
-attr disable_credential_rotation=true \
-attr region=${region} \
-secret access_key_id=env://E2E_AWS_ACCESS_KEY_ID \
-secret secret_access_key=env://E2E_AWS_SECRET_ACCESS_KEY \
-format json`,
),
).item;
} catch (e) {
console.log(`${e.stderr}`);
}
return hostCatalog.id;
}