add auth and backup apis

parent 737e177e
package Auth;
use strict;
use warnings;
use lib "..";
use Request;
use JSON;
sub Info {
my ($succ, $req) = Request::api_request("v1/auth/info", "GET", 1, "");
if ($succ) {
my %data = %{decode_json($req)};
print("Account: $data{name} ($data{email})\n");
print("Permissions: " . join(", ", @{$data{acls}}) . "\n");
}
}
1;
package Backup;
use strict;
use warnings;
use lib "..";
use Request;
use JSON;
sub List {
my ($succ, $req) = Request::api_request("v1/backup/list", "GET", 1, "");
if ($succ) {
if ($req eq "[]") {
print("No backups were found on this account.\n");
return;
}
my %data = %{decode_json($req)};
print "Current backups:\n";
foreach my $backup (keys %data) {
my $size_normal = "";
if ($data{$backup}{size} > 1073741824) { $size_normal = $data{$backup}{size}/1073741824 . "GiB"; }
elsif ($data{$backup}{size} > 1048576) { $size_normal = $data{$backup}{size}/1048576 . "MiB"; }
elsif ($data{$backup}{size} > 1024) { $size_normal = $data{$backup}{size}/1024 . "KiB"; }
else { $size_normal = $data{$backup}{size} . "B"; }
print("Backup: $data{$backup}{BACKUPID} ($data{$backup}{description})\n");
print("Created: $data{$backup}{date_created}\n");
print("Size: $size_normal\n");
print("Status: $data{$backup}{status}\n\n");
}
}
}
1;
......@@ -9,6 +9,7 @@ use File::Basename;
use API::Account;
use API::App;
use API::Auth;
use API::Backup;
our $API_KEY;
......@@ -40,17 +41,20 @@ You can set an api key by exporting API_KEY=<key> as an environment variable.
--account-info * - Show account information and balance.
--app-list - Show a list of available applications.
--auth-info * - Show information on the supplied api key.
--backup-list * - Display a list of available backups.
EOF
}
my $arg_account_info;
my $arg_app_list;
my $arg_auth_info;
my $arg_backup_list;
my $arg_help;
GetOptions( "account-info" => \$arg_account_info,
"app-list" => \$arg_app_list,
"auth-info" => \$arg_auth_info,
"backup-list" => \$arg_backup_list,
"help" => \$arg_help )
or die("Error in command line arguments.\n");
......@@ -64,6 +68,8 @@ if ($arg_account_info) {
App::List();
} elsif ($arg_auth_info) {
Auth::Info();
} elsif ($arg_backup_list) {
Backup::List();
} elsif ($arg_help) {
help();
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment