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

index d22a39f92d7562b58971f86594ee314a839cf5d5..9fc067ee358e88bc851b006d265c016e9da288d2 100755 (executable)
@@ -66,7 +66,25 @@ if (@ARGV and $ARGV[0] =~ /^(\w+):(\w+)(?::(\w+))?$/) {
 my $Api = OvhApi->new(type => OvhApi::OVH_API_EU, applicationKey => $KEY[0], applicationSecret => $KEY[1], consumerKey => $KEY[2]);
 
 # Auth
-if (@KEY < 3) {
+auth() if @KEY < 3;
+
+# Query
+query();
+
+
+#################################################################################
+#
+# END
+#
+#################################################################################
+exit 0;
+
+#################################################################################
+#
+# Functions
+#
+#################################################################################
+sub auth {
   my $Answer = $Api->requestCredentials(accessRules => [ {
     method => 'ALL', path => '/*',
   }]);
@@ -76,14 +94,14 @@ if (@KEY < 3) {
     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 "New go to $validationUrl\n";
+    print "Go to $validationUrl\n";
     print "Your consumerKey is $consumerKey\n";
     print "Create ~/.ovh.api with permission 600 with\n".join(':',@KEY)."\n";
   }
   exit
 }
 
-# Query
+sub query {
 help() unless @ARGV;
 my $URL = shift @ARGV or help();
 my $BODY = @ARGV ? shift(@ARGV) : {};
@@ -104,19 +122,8 @@ exit unless defined $content;
 $content = JSON::encode_json($content) if $content and ref($content) ne '';
 #use Data::Dumper; die Dumper($content);
 print "$content\n";
+}
 
-#################################################################################
-#
-# END
-#
-#################################################################################
-exit 0;
-
-#################################################################################
-#
-# Functions
-#
-#################################################################################
 sub help {
 #------------------------------------------------------------------------------
 # Print help and exit
@@ -229,6 +236,7 @@ $NAME - Script to query ovh's api
 
 From https://api.ovh.com/console:
 
+       /ips
   /domain/zone/<DOMAIN>/export
   /dedicated/server
   /dedicated/server/<SERVER>