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.4 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';
import { accountIdDropdown } from '../common/account-dropdown';

export const changeCredentialsInVault = createAction({
  auth: cyberarkAuth,
  name: 'change_credentials_in_vault',
  classification: 'WRITE',
  displayName: 'Change Credentials in the Vault',
  description:
    'Sets account credentials and changes them in the Vault. This will not affect credentials on the target device.',
  audience: 'both',
  aiMetadata: {
    description: 'Sets a new credential value for a stored CyberArk account (by account ID) and updates it in the Vault only — it does NOT change the credential on the target device, so the Vault may end up out of sync with the managed system. Use when you need to record a known credential in the Vault. Not idempotent: each call writes a new Vault password version.',
    idempotent: false,
  },
  props: {
    accountId: accountIdDropdown,
    newCredentials: Property.ShortText({
      displayName: 'New Credentials',
      description:
        'The new account credentials that will be allocated to the account in the Vault. Leading and trailing white spaces will be automatically removed.',
      required: true,
    }),
  },
  async run(context) {
    const authData = await getAuthToken(context.auth);

    try {
      const response = await httpClient.sendRequest({
        method: HttpMethod.POST,
        url: `${authData.serverUrl}/PasswordVault/API/Accounts/${context.propsValue.accountId}/Password/Update/`,
        headers: {
          'Content-Type': 'application/json',
          Authorization: authData.token,
        },
        body: {
          NewCredentials: context.propsValue.newCredentials,
        },
      });

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