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

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

export const disableUser = createAction({
  auth: cyberarkAuth,
  name: 'disable_user',
  classification: 'DESTRUCTIVE',
  displayName: 'Disable User',
  description: 'Disables a specific user in the Vault',
  audience: 'both',
  aiMetadata: {
    description: 'Disables a Vault user identified by user ID so they can no longer authenticate, without deleting the account. Use to temporarily revoke access. Idempotent: disabling an already-disabled user leaves it disabled.',
    idempotent: true,
  },
  props: {
    userId: userIdDropdown
  },
  async run(context) {
    const authData = await getAuthToken(context.auth);

    try {
      const response = await httpClient.sendRequest({
        method: HttpMethod.POST,
        url: `${authData.serverUrl}/PasswordVault/API/Users/${context.propsValue.userId}/disable/`,
        headers: {
          'Content-Type': 'application/json',
          Authorization: authData.token
        }
      });

      if (response.status === 200 || response.status === 204) {
        return {
          success: true,
          message: `User ${context.propsValue.userId} disabled successfully`
        };
      } else {
        return {
          success: false,
          error: `Failed to disable user. Status: ${response.status}`,
          details: response.body
        };
      }
    } catch (error) {
      return {
        success: false,
        error: 'Failed to disable user',
        details: error instanceof Error ? error.message : String(error)
      };
    }
  }
});