mirror of
https://github.com/ovh/the-bastion.git
synced 2025-01-10 17:30:51 +08:00
2a51a78b54
* Move to ubuntu-20.04 runner * Remove check in dockers tests
67 lines
1.9 KiB
Perl
Executable file
67 lines
1.9 KiB
Perl
Executable file
#! /usr/bin/env perl
|
|
# vim: set filetype=perl ts=4 sw=4 sts=4 et:
|
|
use common::sense;
|
|
use Term::ANSIColor;
|
|
|
|
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 => "delete an existing bastion account",
|
|
options => {
|
|
'realm=s' => \my $wantedRealm,
|
|
},
|
|
helptext => <<'EOF',
|
|
Delete a bastion realm
|
|
|
|
Usage: --osh SCRIPT_NAME --realm REALM
|
|
|
|
--realm REALM Name of the realm to delete
|
|
EOF
|
|
);
|
|
|
|
#
|
|
# code
|
|
#
|
|
my $fnret;
|
|
|
|
#
|
|
# params check
|
|
#
|
|
if (!$wantedRealm) {
|
|
help();
|
|
osh_exit 'ERR_MISSING_PARAMETER', "Missing 'realm' parameter";
|
|
}
|
|
|
|
my $pristineRealm = $wantedRealm;
|
|
$wantedRealm = "realm_$wantedRealm";
|
|
$fnret = OVH::Bastion::is_bastion_account_valid_and_existing(account => $wantedRealm, accountType => "realm");
|
|
$fnret or osh_exit $fnret;
|
|
$wantedRealm = $fnret->value->{'account'}; # untaint
|
|
|
|
osh_info "!!!! WARNING !!!! WARNING !!!! WARNING !!!! WARNING !!!! WARNING !!!!";
|
|
osh_info "!!!! WARNING !!!! WARNING !!!! WARNING !!!! WARNING !!!! WARNING !!!!";
|
|
osh_info "!!!! WARNING !!!! WARNING !!!! WARNING !!!! WARNING !!!! WARNING !!!!";
|
|
osh_info " ";
|
|
|
|
osh_info "You are about to DELETE a bastion realm, to be sure you're not drunk, type the following sentence:";
|
|
osh_info " ";
|
|
osh_info ' "Yes, do as I say and delete <insert_here_the_realm_name>, kthxbye" ';
|
|
osh_info " ";
|
|
my $sentence = <STDIN>;
|
|
chomp $sentence;
|
|
|
|
if ($sentence ne "Yes, do as I say and delete $pristineRealm, kthxbye") {
|
|
osh_exit 'ERR_OPERATOR_IS_DRUNK', "You're drunk, apparently, aborted.";
|
|
}
|
|
osh_info "OK, proceeding...";
|
|
|
|
my @command = qw{ sudo -n -u root -- /usr/bin/env perl -T };
|
|
push @command, $OVH::Bastion::BASEPATH . '/bin/helper/osh-accountDelete';
|
|
push @command, '--type', 'realm', '--account', $wantedRealm;
|
|
|
|
osh_exit OVH::Bastion::helper(cmd => \@command);
|