#!/usr/bin/perl -T
use warnings;
use strict;

use Data::Dump qw(dump);

use lib '/srv/cloudstore/lib';
use CloudStore::Couchbase;

my $store = CloudStore::Couchbase->new;

my $login = $ENV{RSYNC_MODULE_NAME} || die "no RSYNC_MODULE_NAME";

my $user  = $store->user_get($login);

my $ok = $user->{usage} <= $user->{quota};

warn $store->status( $login => sprintf 'usage: %s %d %s %d'
	, ( $ok ? 'OK' : 'ERROR' )
	, $user->{usage}
	, ( $ok ? '<=' : '>' )
	, $user->{quota}
),$/;

my $exit = $ok ? 0 : 1;
warn "# exit $exit";
exit $exit;
