From 444d363fac085c5e79bb5ddae5800d4be144f5ee Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Sat, 4 Feb 2017 21:40:01 +0000 Subject: [PATCH] bin/ovh-api --- bin/ovh-api | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/bin/ovh-api b/bin/ovh-api index e170c42a..91dc0a63 100755 --- a/bin/ovh-api +++ b/bin/ovh-api @@ -33,24 +33,6 @@ my %Opt = ( ); get_options(\%Opt); # NB 04.02.17 # Auth -# NB 04.02.17 if ($_ = $Opt{activate}) { -# NB 04.02.17 my @keys = /:/ ? split(':',$_) : ($_,''); -# NB 04.02.17 my $Api = OvhApi->new(type => OvhApi::OVH_API_EU, applicationKey => $keys[0], applicationSecret => $keys[1]); -# NB 04.02.17 my $Answer = $Api->requestCredentials(accessRules => [ { -# NB 04.02.17 method => 'ALL', path => '/*', -# NB 04.02.17 method => 'GET', path => '/*', -# NB 04.02.17 method => 'POST', path => '/*', -# NB 04.02.17 method => 'PUT', path => '/*', -# NB 04.02.17 method => 'DELETE', path => '/*', -# NB 04.02.17 }]); -# NB 04.02.17 -# NB 04.02.17 if ($Answer) { -# NB 04.02.17 #my ($consumerKey, $validationUrl) = @{ $Answer->content}{qw{ consumerKey validationUrl }}; -# NB 04.02.17 print map {"$_\n"} @{ $Answer->content}{qw{ consumerKey validationUrl }}; -# NB 04.02.17 # $consumerKey contains the newly created Consumer Key -# NB 04.02.17 # $validationUrl contains a link to OVH website in order to login an OVH account and link it to the credential -# NB 04.02.17 } -# NB 04.02.17 exit; # NB 04.02.17 exec qq|curl -s -XPOST -H"X-Ovh-Application: $_" -H "Content-type: application/json" --data '{"accessRules":[{"method":"GET","path":"/*"},{"method":"POST","path":"/*"},{"method":"PUT","path":"/*"},{"method":"DELETE","path":"/*"}]}' https://api.ovh.com/1.0/auth/credential|; # NB 04.02.17 exit 0; # NB 04.02.17 } @@ -92,13 +74,11 @@ if (@KEY < 3) { die "Error" unless $Answer; if ($Answer) { my ($consumerKey, $validationUrl) = @{ $Answer->content}{qw{ consumerKey validationUrl }}; + # $validationUrl contains a link to OVH website in order to login an OVH account and link it to the credential push @KEY, $consumerKey; print "Your consumerKey is $consumerKey\n"; print "You need to validate in your browser at $validationUrl\n"; - print "Create ~/.ovh.api with this content ".join(':',@KEY)."\n"; - #print map {"$_\n"} @{ $Answer->content}{qw{ consumerKey validationUrl }}; - # $consumerKey contains the newly created Consumer Key - # $validationUrl contains a link to OVH website in order to login an OVH account and link it to the credential + print "Create ~/.ovh.api with permission 600 with\n".join(':',@KEY)."\n"; } exit } @@ -107,20 +87,12 @@ if (@KEY < 3) { help() unless @ARGV; my $URL = shift @ARGV or help(); my $BODY = @ARGV ? shift(@ARGV) : {}; -#use Data::Dumper; die Dumper(JSON::encode_json($BODY)); -# NB 14.12.16 use LWP::Simple; -# NB 14.12.16 if ($URL eq '/help') { -# NB 14.12.16 die LWP::Simple::get('https://eu.api.ovh.com/console/'); -# NB 14.12.16 } -#my $URL = @ARGV == 1 ? shift @ARGV : join('/',map{uri_escape($_)} @ARGV); if ( -e $BODY ) { $BODY = JSON::decode_json(`cat $BODY`); } elsif (ref($BODY) eq '') { $BODY = JSON::encode_json($BODY); } -#$BODY = -e $BODY ? JSON::decode_json(`cat $BODY`) : JSON::encode_json($BODY);# if $BODY; -#use Data::Dumper; die Dumper($BODY); my $response = $Api->rawCall(path=>$URL,method=>$Opt{method},body=>$BODY); if ($response->isFailure()) { -- 2.47.3