'method' => 'GET',
);
get_options(\%Opt);
-# Auth
-if ($_ = $Opt{activate}) {
- my @keys = /:/ ? split(':',$_) : ($_,'');
- my $Api = OvhApi->new(type => OvhApi::OVH_API_EU, applicationKey => $keys[0], applicationSecret => $keys[1]);
- my $Answer = $Api->requestCredentials(accessRules => [ {
- 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 => '/*',
- }]);
-
- if ($Answer) {
- #my ($consumerKey, $validationUrl) = @{ $Answer->content}{qw{ consumerKey validationUrl }};
- 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
- }
- exit;
- 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|;
- exit 0;
-}
+# 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 => '/*',
+ method => 'GET', path => '/*',
+ method => 'POST', path => '/*',
+ method => 'PUT', path => '/*',
+ 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 }
$main::_DATA_ = '';
my $config = "$ENV{HOME}/.$NAME";
my @KEY = ();
-if (@ARGV and $ARGV[0] =~ /^(\w+):(\w+):(\w+)$/) {
+if (@ARGV and $ARGV[0] =~ /^(\w+):(\w+)(?::(\w+))?$/) {
@KEY = split(":",$ARGV[0]);
shift @ARGV;
@KEY or help();
help() unless @ARGV;
-my $o = OvhApi->new(type => OvhApi::OVH_API_EU, applicationKey => $KEY[0], applicationSecret => $KEY[1], consumerKey => $KEY[2]);
+my $Api = OvhApi->new(type => OvhApi::OVH_API_EU, applicationKey => $KEY[0], applicationSecret => $KEY[1], consumerKey => $KEY[2]);
+# Auth
+if (@KEY < 3) {
+ my $Answer = $Api->requestCredentials(accessRules => [ {
+ method => 'ALL', path => '/*',
+ }]);
+
+ if ($Answer) {
+ my ($consumerKey, $validationUrl) = @{ $Answer->content}{qw{ consumerKey validationUrl }};
+ 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
+ }
+ exit
+}
+
+# Query
my $URL = shift @ARGV or help();
my $BODY = @ARGV ? shift(@ARGV) : {};
#use Data::Dumper; die Dumper(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 = $o->rawCall(path=>$URL,method=>$Opt{method},body=>$BODY);
+my $response = $Api->rawCall(path=>$URL,method=>$Opt{method},body=>$BODY);
if ($response->isFailure()) {
die "$NAME: ERR: ".$response->error()."\n";
$main::DEBUG = $DEBUG = $_[0]{'debug'} if defined $_[0]{'debug'};
}
+# option[activate=s] [KEY] Activate a key (first bit before ":" or KEY[0])
__DATA__
=head1 NAME
-$NAME - Script to query ovh
+$NAME - Script to query ovh's api
=head1 SYNOPSIS
-Quick usage:
-
- $NAME k1:k2:k3 /PATH
- $NAME -activate JSHFDlkhaKJHGSF...
- $NAME /PATH
- Eg:
- /domain/zone/DOM/export
- /dedicated/server
- /ip
+ 1. Get your consumerKey:
+ $NAME applicationKey:applicationSecret
+ 2. Store your complete key
+ echo 'applicationKey:applicationSecret:consumerKey' > ~/.ovh-api && chmod 600 ~/.ovh-api
+ 3. Activate your key
+ Ex: https://eu.api.ovh.com/auth/?credentialToken=fXOwsn9y2qYHiIclcxChmAAYQLZLEPQEENAPz2EeAYDWj9W0CY9yVQR35bLi2540
+ 4. Use the api
+ $NAME applicationKey:applicationSecret:consumerKey /PATH
+ $NAME /PATH
=head1 OPTIONS
- option[activate=s] [KEY] Activate a key (first bit before ":" or KEY[0])
option[method|m=s] Method (default: GET)
option[verbose|v+] Verbose mode: increase the verbosity level.
option[debug+] Debug mode: increase the verbosity level.
=head1 DESCRIPTION
- $NAME k1:k2:k3 /domain
- $NAME /domain
- $NAME -activate MNBaskfjh
+From https://api.ovh.com/console:
- {
- "validationUrl": "https://eu.api.ovh.com/auth/?credentialToken=KJHDSFLAF...",
- "consumerKey": "KJHDSF...",
- "state": "pendingValidation"
- }
+ /domain/zone/<DOMAIN>/export
+ /dedicated/server
+ /dedicated/server/<SERVER>
=head1 REQUIRES
-Getopt::Std, Pod::Usage, OvhApi, URI::Escape, JSON
+ Getopt::Std, Pod::Usage, OvhApi, URI::Escape, JSON
+ apt-get install -y libjson-perl libwww-perl
=head1 COPYRIGHT AND LICENSE
-Copyright (C) 2016 Nicolas Boisselier
-
-See <http://www.gnu.org/licenses/>.
+ Copyright (C) 2016 Nicolas Boisselier
+ See <http://www.gnu.org/licenses/>.
=head1 AUTHOR
-Nicolas Boisselier nicolas.boisselier@gmail.com
+Nicolas Boisselier <nicolas.boisselier@gmail.com>
=cut