token-handler + build only when necessary
parent
6e1a7ead08
commit
0c817e1f96
11
Makefile
11
Makefile
|
@ -13,6 +13,8 @@ endif
|
|||
|
||||
Q ?= @
|
||||
|
||||
SHOULD_UPDATE = ./bin/should-update
|
||||
|
||||
####################
|
||||
### REQUEST EXAMPLES
|
||||
####################
|
||||
|
@ -69,12 +71,15 @@ run-dnsmanagerd:
|
|||
$(Q)$(LD_P) ./bin/dnsmanagerd -v $(VERBOSITY) -r $(DBDIR)
|
||||
|
||||
build-server:
|
||||
$(Q)shards build dnsmanagerd
|
||||
$(Q)-$(SHOULD_UPDATE) bin/dnsmanagerd && shards build dnsmanagerd
|
||||
|
||||
build-client:
|
||||
$(Q)shards build dnsmanager-client
|
||||
$(Q)-$(SHOULD_UPDATE) bin/dnsmanager-client && shards build dnsmanager-client
|
||||
|
||||
build: build-server build-client
|
||||
build-token-handler:
|
||||
$(Q)-$(SHOULD_UPDATE) bin/token-handler && shards build token-handler
|
||||
|
||||
build: build-server build-client build-token-handler
|
||||
|
||||
print-messages:
|
||||
cat src/requests/*.cr | ./bin/get-messages.awk
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Should we run the build?
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
exec >& 2
|
||||
echo "Usage: $0 <exe>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exe=$1
|
||||
|
||||
# If the binary hasn't already be compiled.
|
||||
[ -f "${exe}" ] || exit 0
|
||||
|
||||
v=`find src/ -type f -newer "${exe}" | wc -l`
|
||||
test "${v}" != "0"
|
|
@ -30,5 +30,7 @@ targets:
|
|||
main: tools/write-zone-file.cr
|
||||
write-template-zone-file:
|
||||
main: tools/write-template-zone-file.cr
|
||||
token-handler:
|
||||
main: tools/token-handler.cr
|
||||
|
||||
license: ISC
|
||||
|
|
|
@ -1,23 +1,24 @@
|
|||
require "ipc"
|
||||
require "http/server"
|
||||
|
||||
port = ARGV[0].to_i rescue 8080
|
||||
addr = ARGV[1] rescue "127.0.0.1"
|
||||
|
||||
server = HTTP::Server.new do |context|
|
||||
request = context.request
|
||||
# TODO: connect to `dnsmanagerd`.
|
||||
|
||||
server = HTTP::Server.new do |context|
|
||||
pp! context.request.remote_address
|
||||
|
||||
case request.path
|
||||
case context.request.path
|
||||
when /^\/token-update\/(?<token>[a-z-]+)/
|
||||
token = $~["token"]
|
||||
if token.nil?
|
||||
context.response.status_code = 404
|
||||
context.response.content_type = "text/html"
|
||||
context.response.print "invalid token"
|
||||
else
|
||||
context.response.content_type = "text/html"
|
||||
context.response.print "coucou, token: #{token}"
|
||||
# TODO: send update to `dnsmanagerd`.
|
||||
end
|
||||
else
|
||||
context.response.status_code = 404
|
||||
|
|
Loading…
Reference in New Issue