All files / src/commands/tcp-redirs tcp-redirs.remove.command.js

82.35% Statements 28/34
100% Branches 1/1
0% Functions 0/1
82.35% Lines 28/34

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x             193x 193x  
import { removeTcpRedir } from '@clevercloud/client/esm/api/v2/application.js';
import { z } from 'zod';
import { defineArgument } from '../../lib/define-argument.js';
import { defineCommand } from '../../lib/define-command.js';
import { Logger } from '../../logger.js';
import * as Application from '../../models/application.js';
import { sendToApi } from '../../models/send-to-api.js';
import { aliasOption, appIdOrNameOption } from '../global.options.js';
import { namespaceOption } from './tcp-redirs.options.js';
 
export const tcpRedirsRemoveCommand = defineCommand({
  description: 'Remove a TCP redirection from the application',
  since: '2.3.0',
  options: {
    namespace: namespaceOption,
    alias: aliasOption,
    app: appIdOrNameOption,
  },
  args: [
    defineArgument({
      schema: z.coerce.number().int().min(1025, 65535),
      description: 'port identifying the TCP redirection',
      placeholder: 'port',
    }),
  ],
  async handler(options, port) {
    const { alias, app: appIdOrName, namespace } = options;
    const { ownerId, appId } = await Application.resolveId(appIdOrName, alias);

    await removeTcpRedir({ id: ownerId, appId, sourcePort: port, namespace }).then(sendToApi);

    Logger.println('Successfully removed tcp redirection.');
  },
});