#! /usr/bin/env perl
# vim: set filetype=perl ts=4 sw=4 sts=4 et:
use common::sense;

use File::Basename;
use lib dirname(__FILE__) . '/../../../lib/perl';
use OVH::Result;
use OVH::Bastion;
use OVH::Bastion::Plugin qw( :DEFAULT help );

my $remainingOptions = OVH::Bastion::Plugin::begin(
    argv    => \@ARGV,
    header  => "remove the TOTP configuration of an account (MFA)",
    options => {
        "account=s" => \my $account,
    },
    helptext => <<'EOF'
Remove the TOTP configuration of an account

Usage: --osh SCRIPT_NAME --account ACCOUNT

  --account ACCOUNT  Specify which account you want to remove the TOTP configuration of

Note that if doesn't remove the TOTP requirement, if set (see ``accountModify`` for this).
EOF
);

my $fnret;

if (not $account) {
    help();
    osh_exit 'ERR_MISSING_PARAMETER', "Expected an --account argument";
}

$fnret = OVH::Bastion::is_bastion_account_valid_and_existing(account => $account);
$fnret or osh_exit $fnret;
$account = $fnret->value->{'account'};

my @command = qw{ sudo -n -u root -- /usr/bin/env perl -T };
push @command, $OVH::Bastion::BASEPATH . '/bin/helper/osh-accountMFAResetTOTP';
push @command, "--account", $account;

osh_exit(OVH::Bastion::helper(cmd => \@command));
