diff --git a/makefile b/makefile index 80825eb..255168a 100644 --- a/makefile +++ b/makefile @@ -3,88 +3,9 @@ all: build-server Q ?= @ OPTS ?= --progress -NAME ?= John -EMAIL ?= john@example.com - -# For requests where authentication is required. -LOGIN ?= -ifeq ($(LOGIN),) -LOGIN_OPT = -else -LOGIN_OPT = -l $(LOGIN) -endif - -SOURCE_FILES = $(wildcard src/*.cr src/*/*.cr src/*/*/*.cr) - -################## -### SETUP COMMANDS -################## - -PASSWORD_FILE ?= /tmp/PASSWORD -setup: - @[ -f $(PASSWORD_FILE) ] || echo -n "coucou" > $(PASSWORD_FILE) - -DATA_DIRECTORY ?= /tmp/DATA-AUTHD -run-authd: - ./bin/authd -R -E --storage $(DATA_DIRECTORY) - -test-authd: setup - ./bin/authd -k $(PASSWORD_FILE) -R -E --storage $(DATA_DIRECTORY) - -# First user always is the admin. -add-first-user: - ./bin/authc bootstrap $(NAME) $(EMAIL) - - -#################### -### REQUEST EXAMPLES -#################### - -ACTIVATION_KEY ?= put-your-key-here -add-user:; $(Q)./bin/authc user add $(NAME) $(EMAIL) $(LOGIN_OPT) -register:; $(Q)./bin/authc user register $(NAME) $(EMAIL) -validate:; $(Q)./bin/authc user validate $(NAME) $(ACTIVATION_KEY) -get-user:; $(Q)./bin/authc user get $(NAME) $(LOGIN_OPT) - -SERVICE ?= 'auth' -RESOURCE ?= '*' -UID ?= 1000 -PERMISSION ?= Read -permission-check:; ./bin/authc permission check $(UID) $(SERVICE) $(RESOURCE) $(LOGIN_OPT) -permission-set:; ./bin/authc permission set $(UID) $(SERVICE) $(RESOURCE) $(PERMISSION) $(LOGIN_OPT) - - -################### -### DEVELOPER TOOLS -################### - -bin/authd: $(SOURCE_FILES); $(Q)shards build authd $(OPTS) -bin/authc: $(SOURCE_FILES); $(Q)shards build authc $(OPTS) -build-server: bin/authd -build-client: bin/authc -build: build-server build-client - -doc: - crystal docs - -HTTPD_ACCESS_LOGS ?= /tmp/access-authd-docs.log -HTTPD_ADDR ?= 127.0.0.1 -HTTPD_PORT ?= 9000 -DIR ?= docs -serve-doc: - darkhttpd $(DIR) --addr $(HTTPD_ADDR) --port $(HTTPD_PORT) --log $(HTTPD_ACCESS_LOGS) - -print-messages:; cat src/requests/*.cr | ./bin/get-messages.awk -print-message-numbers:; make -s print-messages | grep -E "^[0-9]" | sort -n -print-messages-no-comments:; make -s print-messages | grep -vE '^[[:blank:]]+#' -print-response-messages:; cat src/responses/*.cr | ./bin/get-messages.awk -print-response-message-numbers:; make -s print-response-messages | grep -E "^[0-9]" | sort -n -print-response-messages-no-comments:; make -s print-response-messages | grep -vE '^[[:blank:]]+#' - -wipe-db: - rm -r $(DATA_DIRECTORY) - -release: - make build-server OPTS="--progress --release" - --include migration.mk +include mk/build.mk +include mk/install.mk +include mk/setup.mk +include mk/commands.mk +-include mk/migration.mk +-include mk/dev.mk diff --git a/mk/build.mk b/mk/build.mk new file mode 100644 index 0000000..524aeb0 --- /dev/null +++ b/mk/build.mk @@ -0,0 +1,10 @@ +SOURCE_FILES = $(wildcard src/*.cr src/*/*.cr src/*/*/*.cr) +CRFLAGS ?= --progress + +bin/authd: $(SOURCE_FILES); $(Q)shards build authd $(CRFLAGS) +bin/authc: $(SOURCE_FILES); $(Q)shards build authc $(CRFLAGS) +build-server: bin/authd +build-client: bin/authc +build: build-server build-client + +release:; make build-server CRFLAGS="--progress --release" diff --git a/mk/commands.mk b/mk/commands.mk new file mode 100644 index 0000000..7fe57ce --- /dev/null +++ b/mk/commands.mk @@ -0,0 +1,25 @@ +# REQUEST EXAMPLES + +NAME ?= John +EMAIL ?= john@example.com + +# For requests where authentication is required. +LOGIN ?= +ifeq ($(LOGIN),) +LOGIN_OPT = +else +LOGIN_OPT = -l $(LOGIN) +endif + +ACTIVATION_KEY ?= put-your-key-here +add-user:; $(Q)$(LOC)authc user add $(NAME) $(EMAIL) $(LOGIN_OPT) +register:; $(Q)$(LOC)authc user register $(NAME) $(EMAIL) +validate:; $(Q)$(LOC)authc user validate $(NAME) $(ACTIVATION_KEY) +get-user:; $(Q)$(LOC)authc user get $(NAME) $(LOGIN_OPT) + +SERVICE ?= 'auth' +RESOURCE ?= '*' +UID ?= 1000 +PERMISSION ?= Read +permission-check:; $(LOC)authc permission check $(UID) $(SERVICE) $(RESOURCE) $(LOGIN_OPT) +permission-set:; $(LOC)authc permission set $(UID) $(SERVICE) $(RESOURCE) $(PERMISSION) $(LOGIN_OPT) diff --git a/mk/dev.mk b/mk/dev.mk new file mode 100644 index 0000000..2c92dfe --- /dev/null +++ b/mk/dev.mk @@ -0,0 +1,15 @@ +# DEVELOPER TOOLS + +print-messages:; cat src/requests/*.cr | ./bin/get-messages.awk +print-message-numbers:; make -s print-messages | grep -E "^[0-9]" | sort -n +print-messages-no-comments:; make -s print-messages | grep -vE '^[[:blank:]]+#' +print-response-messages:; cat src/responses/*.cr | ./bin/get-messages.awk +print-response-message-numbers:; make -s print-response-messages | grep -E "^[0-9]" | sort -n +print-response-messages-no-comments:; make -s print-response-messages | grep -vE '^[[:blank:]]+#' + +HTTPD_ACCESS_LOGS ?= /tmp/access-authd-docs.log +HTTPD_ADDR ?= 127.0.0.1 +HTTPD_PORT ?= 9000 +DIR ?= docs +serve-doc: + darkhttpd $(DIR) --addr $(HTTPD_ADDR) --port $(HTTPD_PORT) --log $(HTTPD_ACCESS_LOGS) diff --git a/mk/install.mk b/mk/install.mk new file mode 100644 index 0000000..b2dc688 --- /dev/null +++ b/mk/install.mk @@ -0,0 +1,20 @@ +# DESTDIR envvar is a way to install the application in a different root (for building packages for example). +PREFIX ?= $(DESTDIR)/usr/local/ +BINDIR ?= $(PREFIX)/bin +SHAREDIR ?= $(PREFIX)/share +DOCDIR ?= $(SHAREDIR)/doc/authd +MANDIR ?= $(SHAREDIR)/man + +install-authd: build-server ; install -D -m 555 ./bin/authd $(BINDIR)/authd +install-authc: build-client ; install -D -m 555 ./bin/authc $(BINDIR)/authc +install-binaries: install-authd install-authc + +install-man-authd:; install -D -m 444 ./man/authd.1 $(MANDIR)/authd.1 +install-man-authc:; install -D -m 444 ./man/authc.1 $(MANDIR)/authc.1 +install-man: install-man-authd install-man-authc + +doc:; crystal docs +install-dev-doc: doc ; install -D docs/ $(DOCDIR) + +# By default, dev documentation isn't installed. +install: install-binaries install-man #install-dev-doc diff --git a/migration.mk b/mk/migration.mk similarity index 100% rename from migration.mk rename to mk/migration.mk diff --git a/mk/setup.mk b/mk/setup.mk new file mode 100644 index 0000000..1bbd2eb --- /dev/null +++ b/mk/setup.mk @@ -0,0 +1,11 @@ +PASSWORD_FILE ?= /tmp/PASSWORD +DATA_DIRECTORY ?= /tmp/DATA-AUTHD + +run-authd:; setup; $(Q)$(LOC)authd -k $(PASSWORD_FILE) -R -E --storage $(DATA_DIRECTORY) + +# First user always is the admin. +add-first-user:; $(Q)$(LOC)authc bootstrap $(NAME) $(EMAIL) + +setup:; @[ -f $(PASSWORD_FILE) ] || echo -n "coucou" > $(PASSWORD_FILE) + +wipe-db:; rm -r $(DATA_DIRECTORY)