From: Nicolas Boisselier Date: Sat, 4 Feb 2017 21:53:21 +0000 (+0000) Subject: bin/ovh-api X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=fde638598d48bf561c5ecb0ed83fde57a54f3ca3;p=nb.git bin/ovh-api --- diff --git a/bin/ovh-api b/bin/ovh-api index d22a39f9..9fc067ee 100755 --- a/bin/ovh-api +++ b/bin/ovh-api @@ -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//export /dedicated/server /dedicated/server/