Skip to content

Commit

Permalink
Merge pull request #6 from oetiker/master
Browse files Browse the repository at this point in the history
* support for formatting numbers with metric prefix
  • Loading branch information
oetiker authored Apr 23, 2019
2 parents 172c3f9 + 8e82faa commit 57572ba
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 50 deletions.
10 changes: 8 additions & 2 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
0.0.0 2018-04-12 Tobias Oetiker (tobi@oetiker.ch)
0.4.0 2019-04-23 17:15:11 +0200 Tobias Oetiker <tobi@oetiker.ch>

- new mandatory configuration option ad_uri to configure the address
of an active directory server.

0.3.2 2019-04-03 16:13:38 +0200 Tobias Oetiker <tobi@oetiker.ch>

- added support for formatting number with metric prefix

- started project
8 changes: 7 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ README COPYRIGHT: VERSION
dist-hook:
$(PERL) -i -p -e 's/#VERSION#/$(PACKAGE_VERSION)/g;s/#YEAR#/$(YEAR)/g;s/#DATE#/$(DATE)/g;' $(distdir)/public/index.html $(distdir)/public/script/$(QX_CLASS).js
$(PERL) -i -p -e 's/\$$VERSION\s*=\s*".+?";/\$$VERSION = "$(PACKAGE_VERSION)";/;' $(distdir)/lib/$(MJ_CLASS).pm

echo `cat VERSION` `date +"%Y-%m-%d %H:%M:%S %z"` `git config user.name` '<'`git config user.email`'>' >> CHANGES.new
echo >> CHANGES.new
echo ' -' >> CHANGES.new
echo >> CHANGES.new
cat CHANGES >> CHANGES.new && mv CHANGES.new CHANGES
$$EDITOR CHANGES
cat CHANGES > $(distdir)/CHANGES

test:
$(PERL) "-MExtUtils::Command::MM" "-e" "test_harness(0, 'lib','thirdparty/lib/perl5')" t/*.t
Expand Down
7 changes: 7 additions & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,13 @@ README COPYRIGHT: VERSION
dist-hook:
$(PERL) -i -p -e 's/#VERSION#/$(PACKAGE_VERSION)/g;s/#YEAR#/$(YEAR)/g;s/#DATE#/$(DATE)/g;' $(distdir)/public/index.html $(distdir)/public/script/$(QX_CLASS).js
$(PERL) -i -p -e 's/\$$VERSION\s*=\s*".+?";/\$$VERSION = "$(PACKAGE_VERSION)";/;' $(distdir)/lib/$(MJ_CLASS).pm
echo `cat VERSION` `date +"%Y-%m-%d %H:%M:%S %z"` `git config user.name` '<'`git config user.email`'>' >> CHANGES.new
echo >> CHANGES.new
echo ' -' >> CHANGES.new
echo >> CHANGES.new
cat CHANGES >> CHANGES.new && mv CHANGES.new CHANGES
$$EDITOR CHANGES
cat CHANGES > $(distdir)/CHANGES

test:
$(PERL) "-MExtUtils::Command::MM" "-e" "test_harness(0, 'lib','thirdparty/lib/perl5')" t/*.t
Expand Down
3 changes: 2 additions & 1 deletion PERL_MODULES
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Mojolicious~8
CallBackery@0.14.2
CallBackery@0.16.0
Mojo::SQLite
Mojo::IOLoop::ReadWriteFork
Mojolicious::Plugin::SPNEGO
Role::Tiny
PPI
JSON::Validator
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.1
0.4.0
20 changes: 10 additions & 10 deletions configure
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.69 for bdass 0.3.1.
# Generated by GNU Autoconf 2.69 for bdass 0.4.0.
#
# Report bugs to <tobi@oetiker.ch>.
#
Expand Down Expand Up @@ -580,8 +580,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='bdass'
PACKAGE_TARNAME='bdass'
PACKAGE_VERSION='0.3.1'
PACKAGE_STRING='bdass 0.3.1'
PACKAGE_VERSION='0.4.0'
PACKAGE_STRING='bdass 0.4.0'
PACKAGE_BUGREPORT='tobi@oetiker.ch'
PACKAGE_URL=''

Expand Down Expand Up @@ -1236,7 +1236,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
\`configure' configures bdass 0.3.1 to adapt to many kinds of systems.
\`configure' configures bdass 0.4.0 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
Expand Down Expand Up @@ -1303,7 +1303,7 @@ fi

if test -n "$ac_init_help"; then
case $ac_init_help in
short | recursive ) echo "Configuration of bdass 0.3.1:";;
short | recursive ) echo "Configuration of bdass 0.4.0:";;
esac
cat <<\_ACEOF
Expand Down Expand Up @@ -1396,7 +1396,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
bdass configure 0.3.1
bdass configure 0.4.0
generated by GNU Autoconf 2.69
Copyright (C) 2012 Free Software Foundation, Inc.
Expand All @@ -1413,7 +1413,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by bdass $as_me 0.3.1, which was
It was created by bdass $as_me 0.4.0, which was
generated by GNU Autoconf 2.69. Invocation command line was
$ $0 $@
Expand Down Expand Up @@ -2287,7 +2287,7 @@ fi
# Define the identity of the package.
PACKAGE='bdass'
VERSION='0.3.1'
VERSION='0.4.0'
cat >>confdefs.h <<_ACEOF
Expand Down Expand Up @@ -3535,7 +3535,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by bdass $as_me 0.3.1, which was
This file was extended by bdass $as_me 0.4.0, which was
generated by GNU Autoconf 2.69. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
Expand Down Expand Up @@ -3588,7 +3588,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
bdass config.status 0.3.1
bdass config.status 0.4.0
configured by $0, generated by GNU Autoconf 2.69,
with options \\"\$ac_cs_config\\"
Expand Down
1 change: 1 addition & 0 deletions etc/bdass.cfg.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ cfg_db = /tmp/bdass.db
sesame_user = adfadsfasdf4ee3r
# perl -MDigest::SHA -e 'print Digest::SHA::hmac_sha1_hex("access"),"\n"'
sesame_pass = 393afhkjhffjj
ad_uri = ldap://my-ad-Server

*** FRONTEND ***
logo = ../resource/bdass/logo.png
Expand Down
7 changes: 6 additions & 1 deletion lib/Bdass.pm
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ has userObject => sub {
};

sub startup ($app) {
$app->plugin('SPNEGO',ad_server => $app->config->cfgHash->{BACKEND}{ad_uri});
$app->config->cfgHash; # read and validate config
unshift @{$app->commands->namespaces}, __PACKAGE__.'::Command';
$app->SUPER::startup(@_);
Expand Down Expand Up @@ -129,4 +130,8 @@ CREATE TABLE IF NOT EXISTS history (
history_ts TIMESTAMP NOT NULL DEFAULT (strftime('%s', 'now')),
history_js INTEGER NOT NULL REFERENCES js(js_id),
history_note TEXT
);
);
-- 2 up
ALTER TABLE cbuser ADD cbuser_groups TEXT default '{}';
15 changes: 10 additions & 5 deletions lib/Bdass/GuiPlugin/Job.pm
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@ has tableCfg => sub ($self) {
},
{
label => trm('Size'),
type => 'text',
type => 'num',
format => {
unitPrefix => 'metric',
maximumFractionDigits => 2,
postfix => 'Byte',
locale => 'en'
},
width => '2*',
key => 'job_size',
sortable => true,
Expand Down Expand Up @@ -103,7 +109,8 @@ has tableCfg => sub ($self) {
},
{
label => trm('Created'),
type => 'string',
type => 'date',
format => 'yyyy-MM-dd HH:mm:ss Z',
width => '3*',
key => 'job_ts_created',
sortable => true,
Expand Down Expand Up @@ -228,9 +235,7 @@ sub getTableData ($self,$args,@opts) {
],
['job.*','js_name','cbuser_login'],$userFilter,\%SORT
)->hashes->each(sub ($el,$id) {
$el->{job_ts_created}
= strftime('%Y-%m-%d %H:%M:%S',localtime($el->{job_ts_created}));
$el->{job_size} = sprintf("%.1e",$el->{job_size});
$el->{job_ts_created} = $el->{job_ts_created}*1000;
})->to_array;
return $data;
}
Expand Down
3 changes: 3 additions & 0 deletions lib/Bdass/Model/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ has grammar => sub {
my $gr = $self->SUPER::grammar;
push @{$gr->{_sections}},'CONNECTION';
push @{$gr->{_mandatory}},'CONNECTION';
push @{$gr->{BACKEND}{_vars}},'ad_uri';
push @{$gr->{BACKEND}{_mandatory}},'ad_uri';
$gr->{BACKEND}{ad_uri} = { _doc => 'AD URI - ldap://ad1.company.com'};
$gr->{CONNECTION} = {
_vars => [],
_sections => ['/\S+/'],
Expand Down
68 changes: 67 additions & 1 deletion lib/Bdass/Model/User.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,73 @@ Bdass::Model::User - Bdass specific user

use Mojo::Base 'CallBackery::User';
use CallBackery::Exception qw(mkerror);
use Mojo::Util qw(b64_encode sha1_sum);
use Mojo::Util qw(b64_encode sha1_sum dumper);
use Mojo::JSON qw(encode_json decode_json);

has userId => sub {
shift->userInfo->{cbuser_id};
};

sub provisionOrUpdateUser {
my $self = shift;
my $user = shift;
my $groups = shift;
my $userInfo = $self->db->fetchRow('cbuser',{login=>$user->{samaccountname}});

my $data = {
login => $user->{samaccountname},
given => $user->{givenname},
family => $user->{sn},
groups => encode_json($groups),
};

if (not $userInfo){
$data->{note} = 'auto provisioned '.localtime(time);
}
else {
$data->{id} = $userInfo->{cbuser_id};
}

$self->db->updateOrInsertData('cbuser',{
map { $_ => $data->{$_} } qw(login family given groups note)
},$data->{id} ? { id => int($data->{id}) } : ());
}

has userInfo => sub {
my $self = shift;
my $userId = $self->cookieConf->{u};
if (not $userId) {
$self->controller->ntlm_auth({
auth_success_cb => sub {
my $c = shift;
my $user = shift;
my $ldap = shift; # bound Net::LDAP::SPNEGO connection
my $groups = $ldap->get_ad_groups($user->{samaccountname});
$self->log->debug(dumper $groups);
$userId = $self->provisionOrUpdateUser($user,$groups);
return 1; # 1 is you are happy with the outcome
}
}) or return undef;
}
# prevent recursion by already setting the userId
$self->userId($userId);

my $info = $self->db->fetchRow('cbuser',{id=>$self->userId});
$info->{sessionCookie} = $self->makeSessionCookie();
delete $info->{cbuser_groups};
return $info;
};

has loginName => sub {
shift->userInfo->{email} // '*UNKNOWN*';
};

# this decides if the user can login
has isUserAuthenticated => sub {
my $self = shift;

$self->userId ? 1 : 0;
};


1;
15 changes: 6 additions & 9 deletions thirdparty/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2018 Tobias Oetiker
# Copyright (C) 2017 Tobias Oetiker

AUTOMAKE_OPTIONS = foreign

Expand All @@ -11,15 +11,15 @@ EXTRA_DIST = $(THIRDPARTY_DIST) $(wildcard bin/cpanm)
all-local: touch

touch: CPAN/touch ../config.status ../PERL_MODULES
$(AM_V_GEN)cat ../PERL_MODULES | PERL_CPANM_HOME=$(THIRDPARTY_DIR) xargs $(PERL) $(THIRDPARTY_DIR)/bin/cpanm -q --notest --local-lib-contained $(THIRDPARTY_DIR) --mirror file://$(THIRDPARTY_DIR)/CPAN --mirror-only
$(AM_V_GEN)cat ../PERL_MODULES | grep -v '#' | PERL_CPANM_HOME=$(THIRDPARTY_DIR) xargs $(PERL) $(THIRDPARTY_DIR)/bin/cpanm -q --notest --local-lib-contained $(THIRDPARTY_DIR) --mirror file://$(THIRDPARTY_DIR)/CPAN --mirror-only
$(AM_V_GEN)touch touch

CPAN/touch: ../PERL_MODULES
echo "POPULATING OUR LOCAL micro CPAN"
$(AM_V_GEN)$(URL_CAT) https://cpanmin.us | PERL_CPANM_HOME=$(THIRDPARTY_DIR) $(PERL) - -q --notest --local-lib $(THIRDPARTY_DIR) --save-dists $(THIRDPARTY_DIR)/CPAN --force App::cpanminus
$(AM_V_GEN)PERL5LIB=$(THIRDPARTY_DIR)/Ore/lib/perl5 PERL_CPANM_HOME=$(THIRDPARTY_DIR)/Ore $(THIRDPARTY_DIR)/bin/cpanm -q --notest --local-lib $(THIRDPARTY_DIR)/Ore File::Which OrePAN
$(AM_V_GEN)cat ../PERL_MODULES | PERL_CPANM_HOME=$(THIRDPARTY_DIR) xargs $(PERL) $(THIRDPARTY_DIR)/bin/cpanm -q --self-contained --notest --local-lib-contained $(THIRDPARTY_DIR) --save-dists $(THIRDPARTY_DIR)/CPAN
$(AM_V_GEN)PERL5LIB=$(THIRDPARTY_DIR)/Ore/lib/perl5 $(THIRDPARTY_DIR)/Ore/bin/orepan_index.pl --repository $(THIRDPARTY_DIR)/CPAN
$(AM_V_GEN)PERL_CPANM_HOME=$(THIRDPARTY_DIR)/Ore $(THIRDPARTY_DIR)/bin/cpanm -q --notest --local-lib $(THIRDPARTY_DIR)/Ore File::Which OrePAN
$(AM_V_GEN)cat ../PERL_MODULES | grep -v '#' | PERL_CPANM_HOME=$(THIRDPARTY_DIR) xargs $(PERL) $(THIRDPARTY_DIR)/bin/cpanm -q --self-contained --notest --local-lib-contained $(THIRDPARTY_DIR) --save-dists $(THIRDPARTY_DIR)/CPAN
- $(AM_V_GEN)PERL5LIB=$(THIRDPARTY_DIR)/Ore/lib/perl5 $(THIRDPARTY_DIR)/Ore/bin/orepan_index.pl --repository $(THIRDPARTY_DIR)/CPAN 2>&1 | egrep -v 'INFO.*Ore|uninitialized|Useless'
# Ore fails to extract the version form DBI
$(AM_V_GEN)gunzip -c CPAN/modules/02packages.details.txt.gz | perl -pe 's{^(DBI\s+)undef(\s+\S+/DBI-)(\d+\.\d+)(\.tar)}{$$1$$3$$2$$3$$4}' | gzip | cat > x.gz && mv x.gz CPAN/modules/02packages.details.txt.gz
$(AM_V_GEN)touch CPAN/touch
Expand All @@ -28,7 +28,4 @@ clean-local:
ls -1 | grep -v Makefile | grep -v bin | grep -v CPAN | xargs rm -rf

distclean-local:
ls -1 | grep -v Makefile | xargs rm -rf

install-exec-hook:
[ ! -d lib/perl5 ] || mkdir -p $(DESTDIR)$(libdir) && cp -fr lib/perl5/* $(DESTDIR)$(libdir)
ls -1 | grep -v Makefile | xargs rm -rf
34 changes: 15 additions & 19 deletions thirdparty/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

@SET_MAKE@

# Copyright (C) 2018 Tobias Oetiker
# Copyright (C) 2017 Tobias Oetiker
VPATH = @srcdir@
am__is_gnu_make = { \
if test -z '$(MAKELEVEL)'; then \
Expand Down Expand Up @@ -340,8 +340,7 @@ install-dvi: install-dvi-am
install-dvi-am:

install-exec-am:
@$(NORMAL_INSTALL)
$(MAKE) $(AM_MAKEFLAGS) install-exec-hook

install-html: install-html-am

install-html-am:
Expand Down Expand Up @@ -380,35 +379,35 @@ ps-am:

uninstall-am:

.MAKE: install-am install-exec-am install-strip
.MAKE: install-am install-strip

.PHONY: all all-am all-local check check-am clean clean-generic \
clean-local cscopelist-am ctags-am distclean distclean-generic \
distclean-local distdir dvi dvi-am html html-am info info-am \
install install-am install-data install-data-am install-dvi \
install-dvi-am install-exec install-exec-am install-exec-hook \
install-html install-html-am install-info install-info-am \
install-man install-pdf install-pdf-am install-ps \
install-ps-am install-strip installcheck installcheck-am \
installdirs maintainer-clean maintainer-clean-generic \
mostlyclean mostlyclean-generic pdf pdf-am ps ps-am tags-am \
uninstall uninstall-am
install-dvi-am install-exec install-exec-am install-html \
install-html-am install-info install-info-am install-man \
install-pdf install-pdf-am install-ps install-ps-am \
install-strip installcheck installcheck-am installdirs \
maintainer-clean maintainer-clean-generic mostlyclean \
mostlyclean-generic pdf pdf-am ps ps-am tags-am uninstall \
uninstall-am

.PRECIOUS: Makefile


all-local: touch

touch: CPAN/touch ../config.status ../PERL_MODULES
$(AM_V_GEN)cat ../PERL_MODULES | PERL_CPANM_HOME=$(THIRDPARTY_DIR) xargs $(PERL) $(THIRDPARTY_DIR)/bin/cpanm -q --notest --local-lib-contained $(THIRDPARTY_DIR) --mirror file://$(THIRDPARTY_DIR)/CPAN --mirror-only
$(AM_V_GEN)cat ../PERL_MODULES | grep -v '#' | PERL_CPANM_HOME=$(THIRDPARTY_DIR) xargs $(PERL) $(THIRDPARTY_DIR)/bin/cpanm -q --notest --local-lib-contained $(THIRDPARTY_DIR) --mirror file://$(THIRDPARTY_DIR)/CPAN --mirror-only
$(AM_V_GEN)touch touch

CPAN/touch: ../PERL_MODULES
echo "POPULATING OUR LOCAL micro CPAN"
$(AM_V_GEN)$(URL_CAT) https://cpanmin.us | PERL_CPANM_HOME=$(THIRDPARTY_DIR) $(PERL) - -q --notest --local-lib $(THIRDPARTY_DIR) --save-dists $(THIRDPARTY_DIR)/CPAN --force App::cpanminus
$(AM_V_GEN)PERL5LIB=$(THIRDPARTY_DIR)/Ore/lib/perl5 PERL_CPANM_HOME=$(THIRDPARTY_DIR)/Ore $(THIRDPARTY_DIR)/bin/cpanm -q --notest --local-lib $(THIRDPARTY_DIR)/Ore File::Which OrePAN
$(AM_V_GEN)cat ../PERL_MODULES | PERL_CPANM_HOME=$(THIRDPARTY_DIR) xargs $(PERL) $(THIRDPARTY_DIR)/bin/cpanm -q --self-contained --notest --local-lib-contained $(THIRDPARTY_DIR) --save-dists $(THIRDPARTY_DIR)/CPAN
$(AM_V_GEN)PERL5LIB=$(THIRDPARTY_DIR)/Ore/lib/perl5 $(THIRDPARTY_DIR)/Ore/bin/orepan_index.pl --repository $(THIRDPARTY_DIR)/CPAN
$(AM_V_GEN)PERL_CPANM_HOME=$(THIRDPARTY_DIR)/Ore $(THIRDPARTY_DIR)/bin/cpanm -q --notest --local-lib $(THIRDPARTY_DIR)/Ore File::Which OrePAN
$(AM_V_GEN)cat ../PERL_MODULES | grep -v '#' | PERL_CPANM_HOME=$(THIRDPARTY_DIR) xargs $(PERL) $(THIRDPARTY_DIR)/bin/cpanm -q --self-contained --notest --local-lib-contained $(THIRDPARTY_DIR) --save-dists $(THIRDPARTY_DIR)/CPAN
- $(AM_V_GEN)PERL5LIB=$(THIRDPARTY_DIR)/Ore/lib/perl5 $(THIRDPARTY_DIR)/Ore/bin/orepan_index.pl --repository $(THIRDPARTY_DIR)/CPAN 2>&1 | egrep -v 'INFO.*Ore|uninitialized|Useless'
# Ore fails to extract the version form DBI
$(AM_V_GEN)gunzip -c CPAN/modules/02packages.details.txt.gz | perl -pe 's{^(DBI\s+)undef(\s+\S+/DBI-)(\d+\.\d+)(\.tar)}{$$1$$3$$2$$3$$4}' | gzip | cat > x.gz && mv x.gz CPAN/modules/02packages.details.txt.gz
$(AM_V_GEN)touch CPAN/touch
Expand All @@ -417,10 +416,7 @@ clean-local:
ls -1 | grep -v Makefile | grep -v bin | grep -v CPAN | xargs rm -rf

distclean-local:
ls -1 | grep -v Makefile | xargs rm -rf

install-exec-hook:
[ ! -d lib/perl5 ] || mkdir -p $(DESTDIR)$(libdir) && cp -fr lib/perl5/* $(DESTDIR)$(libdir)
ls -1 | grep -v Makefile | xargs rm -rf

# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
Expand Down

0 comments on commit 57572ba

Please sign in to comment.