From 7615ec25ab8f9777e09b2c1c6e0259c43a93d4b3 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Thu, 24 Nov 2016 21:15:43 +0000 Subject: [PATCH] ovh-api seems broken --- bin/ovh-api | 62 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/bin/ovh-api b/bin/ovh-api index 93d6b723..b4c3ff0b 100755 --- a/bin/ovh-api +++ b/bin/ovh-api @@ -32,8 +32,16 @@ my %Opt = ( 'method' => 'GET', ); get_options(\%Opt); -help() unless @ARGV; $main::_DATA_ = undef; +# Auth +if ($_ = $Opt{activate}) { + exec qq|curl -s -XPOST -H"X-Ovh-Application: $_" -H "Content-type: application/json" https://eu.api.ovh.com/1.0/auth/credential -d '{"accessRules": [ { "method": "GET", "path": "/*" } ] }'|.'|jq .'; + #print qq|curl -XPOST -H"X-Ovh-Application: $_" -H "Content-type: application/json" https://eu.api.ovh.com/1.0/auth/credential -d '{"accessRules": [ { "method": "GET", "path": "/*" } ], "redirection":"https://www.mywebsite.com/" }'\n|; + #exec("curl","-XPOST",'-H',"X-Ovh-Application: $_",'-H','Content-type: application/json','https://eu.api.ovh.com/1.0/auth/credential','-d',qq|'{"accessRules": [ { "method": "GET", "path": "/*" } ],"redirection":"https://www.mywebsite.com/" }'|); + exit 0; +} +help() unless @ARGV; + ################################################################################# # @@ -42,19 +50,27 @@ $main::_DATA_ = undef; ################################################################################# #use Data::Dumper; my $config = "$ENV{HOME}/.$NAME"; -my @KEY = split(":",-e $config ? chomp($_=`cat "$config"`)&&$_ : shift @ARGV); -my $URL = @ARGV == 1 ? shift @ARGV : join('/',map{uri_escape($_)} @ARGV); +my @KEY = (); + +if (@ARGV and $ARGV[0] =~ /^(\w+):(\w+):(\w+)$/) { + @KEY = split(":",$ARGV[0]); + shift @ARGV; + +} elsif ($ENV{$NAME.'_KEY'}) { + @KEY = split(':',$ENV{$NAME.'_KEY'}); +} elsif (-e $config) { + open(CONFIG,"$config") or die "$NAME: can't read $config"; + @KEY = split(":",chomp($_=join('',)) && $_); + close CONFIG; -# Auth -if (@KEY==1) { - #print qq|curl -XPOST -H"X-Ovh-Application: $KEY[0]" -H "Content-type: application/json" https://eu.api.ovh.com/1.0/auth/credential -d '{"accessRules": [ { "method": "GET", "path": "/*" } ], "redirection":"https://www.mywebsite.com/" }'\n|; - exec qq|curl -s -XPOST -H"X-Ovh-Application: $KEY[0]" -H "Content-type: application/json" https://eu.api.ovh.com/1.0/auth/credential -d '{"accessRules": [ { "method": "GET", "path": "/*" } ] }'|.'|jq .'; - #exec("curl","-XPOST",'-H',"X-Ovh-Application: $KEY[0]",'-H','Content-type: application/json','https://eu.api.ovh.com/1.0/auth/credential','-d',qq|'{"accessRules": [ { "method": "GET", "path": "/*" } ],"redirection":"https://www.mywebsite.com/" }'|); - exit 0; } +@KEY or help(); +die map{"$_\n"} @KEY; my $o = OvhApi->new(type => OvhApi::OVH_API_EU, applicationKey => $KEY[0], applicationSecret => $KEY[1], consumerKey => $KEY[2]); +my $URL = shift @ARGV or help(); +#my $URL = @ARGV == 1 ? shift @ARGV : join('/',map{uri_escape($_)} @ARGV); my $response = $o->get(path=>$URL,method=>$Opt{method}); if (!$response) { @@ -162,15 +178,15 @@ $NAME - Script to query ovh =head1 SYNOPSIS -Quick usage: $NAME k1:k2:k3 URL or $NAME k1 to activate a first account - -=head1 DESCRIPTION +Quick usage: -https://api.ovh.com/g934.first_step_with_api -https://api.ovh.com/console/#/domain + $NAME k1:k2:k3 /PATH + $NAME /PATH + $NAME -activate JSHFDlkhaKJHGSF... =head1 OPTIONS + option[activate=s] [KEY] Activate a key (first bit before ":" or KEY[0]) option[method|m] Method (default: GET) option[verbose|v+] Verbose mode: increase the verbosity level. option[debug+] Debug mode: increase the verbosity level. @@ -180,9 +196,17 @@ https://api.ovh.com/console/#/domain =cut -=head1 EXAMPLES +=head1 DESCRIPTION $NAME k1:k2:k3 /domain +$NAME /domain +$NAME -activate MNBaskfjh + + { + "validationUrl": "https://eu.api.ovh.com/auth/?credentialToken=KJHDSFLAF...", + "consumerKey": "KJHDSF...", + "state": "pendingValidation" + } =head1 REQUIRES @@ -192,16 +216,8 @@ Getopt::Std, Pod::Usage Copyright (C) 2016 Nicolas Boisselier -This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - See . -=head1 SEE ALSO - -OvhApi - =head1 AUTHOR Nicolas Boisselier nicolas.boisselier@gmail.com -- 2.47.3