#!/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 $usage = $store->usage({ login => $login });
my $user  = $store->user_get($login);

if ( $usage > $user->{quota} ) {
	warn "ERROR: $login $usage > quota $user->{quota}";
	exit 1;
} else {
	warn "OK: $login $usage < quota $user->{quota}";
	exit 0;
}
