Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

2.6 KB
Raw Blame
import { createAction, Property } from '@activepieces/pieces-framework';
import { cyberarkAuth } from '../auth';
import { httpClient, HttpMethod } from '@activepieces/pieces-common';
import { getAuthToken } from '../common/auth-helper';

export const changeCredentialsBulk = createAction({
  auth: cyberarkAuth,
  name: 'change_credentials_bulk',
  classification: 'WRITE',
  displayName: 'Change Credentials Immediately in Bulk',
  description:
    'Marks multiple accounts for an immediate credentials change by the CPM to a new random value',
  audience: 'both',
  aiMetadata: {
    description: 'Marks a list of CyberArk accounts (by account ID) for an immediate CPM credential change to a new random value on both the Vault and the target device, optionally rotating every account in the same account group. Use to force a rotation across many accounts at once. Not idempotent: each call triggers another rotation to a fresh random secret.',
    idempotent: false,
  },
  props: {
    accountIds: Property.Array({
      displayName: 'Account IDs',
      description: 'List of unique account IDs to change credentials for',
      required: true,
    }),
    changeEntireGroup: Property.Checkbox({
      displayName: 'Change Entire Group',
      description:
        'Whether the CPM changes the credentials for all accounts in the same account group. Only applies to accounts that belong to an account group.',
      required: false,
      defaultValue: false,
    }),
  },
  async run(context) {
    const authData = await getAuthToken(context.auth);

    const changeEntireGroup = context.propsValue.changeEntireGroup ?? false;
    const bulkItems = (context.propsValue.accountIds as string[]).map(
      (accountId) => ({
        accountId,
        ChangeEntireGroup: changeEntireGroup,
      })
    );

    try {
      const response = await httpClient.sendRequest({
        method: HttpMethod.POST,
        url: `${authData.serverUrl}/PasswordVault/API/Accounts/Change/Bulk`,
        headers: {
          'Content-Type': 'application/json',
          Authorization: authData.token,
        },
        body: {
          bulkItems,
        },
      });

      if (response.status === 200) {
        return {
          success: true,
          details: response.body,
        };
      } else {
        return {
          success: false,
          error: `Failed to change credentials in bulk. Status: ${response.status}`,
          details: response.body,
        };
      }
    } catch (error) {
      return {
        success: false,
        error: 'Failed to change credentials in bulk',
        details: error instanceof Error ? error.message : String(error),
      };
    }
  },
});