]> git.nbdom.net Git - nb.git/commitdiff
bin/ovh-api
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Sat, 4 Feb 2017 20:59:06 +0000 (20:59 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Sat, 4 Feb 2017 20:59:06 +0000 (20:59 +0000)
bin/ovh-api

index a5a6492cef15172349acf4b220d6343aec41a80f..2d1850ac1520338d65def99e7f8f3840491a5686 100755 (executable)
@@ -1,9 +1,9 @@
 #!/usr/bin/env perl
 use strict;
 use warnings;
-use OvhApi;
 use URI::Escape qw(uri_escape);
 use JSON;
+use OvhApi;
 #################################################################################
 #
 # VERSION
@@ -34,19 +34,23 @@ my %Opt = (
 get_options(\%Opt);
 # Auth
 if ($_ = $Opt{activate}) {
-# NB 14.12.16   my $Answer = $Api->requestCredentials(accessRules => [ { method => 'ALL', path => '/*' }]);
-# NB 14.12.16 
-# NB 14.12.16   if ($Answer) {
-# NB 14.12.16     my ($consumerKey, $validationUrl) = @{ $Answer->content}{qw{ consumerKey validationUrl }};
-# NB 14.12.16     # $consumerKey contains the newly created  Consumer Key
-# NB 14.12.16     # $validationUrl contains a link to OVH website in order to login an OVH account and link it to the credential
-# NB 14.12.16   }
-  #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": "ALL", "path": "/*" } ] }'|;
+  my $Api = OvhApi->new(type => OvhApi::OVH_API_EU, applicationKey => $));
+  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|;
-  #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": "/*" },{ "method": "PUT", "path": "/*" },{ "method": "POST", "path": "/*" },{ "method": "DELETE", "path": "/*" } ] }'|.'|jq .';
-  #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;
 }
 $main::_DATA_ = '';