token-handler + build only when necessary
parent
6e1a7ead08
commit
0c817e1f96
11
Makefile
11
Makefile
|
@ -13,6 +13,8 @@ endif
|
||||||
|
|
||||||
Q ?= @
|
Q ?= @
|
||||||
|
|
||||||
|
SHOULD_UPDATE = ./bin/should-update
|
||||||
|
|
||||||
####################
|
####################
|
||||||
### REQUEST EXAMPLES
|
### REQUEST EXAMPLES
|
||||||
####################
|
####################
|
||||||
|
@ -69,12 +71,15 @@ run-dnsmanagerd:
|
||||||
$(Q)$(LD_P) ./bin/dnsmanagerd -v $(VERBOSITY) -r $(DBDIR)
|
$(Q)$(LD_P) ./bin/dnsmanagerd -v $(VERBOSITY) -r $(DBDIR)
|
||||||
|
|
||||||
build-server:
|
build-server:
|
||||||
$(Q)shards build dnsmanagerd
|
$(Q)-$(SHOULD_UPDATE) bin/dnsmanagerd && shards build dnsmanagerd
|
||||||
|
|
||||||
build-client:
|
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:
|
print-messages:
|
||||||
cat src/requests/*.cr | ./bin/get-messages.awk
|
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
|
main: tools/write-zone-file.cr
|
||||||
write-template-zone-file:
|
write-template-zone-file:
|
||||||
main: tools/write-template-zone-file.cr
|
main: tools/write-template-zone-file.cr
|
||||||
|
token-handler:
|
||||||
|
main: tools/token-handler.cr
|
||||||
|
|
||||||
license: ISC
|
license: ISC
|
||||||
|
|
|
@ -1,23 +1,24 @@
|
||||||
|
require "ipc"
|
||||||
require "http/server"
|
require "http/server"
|
||||||
|
|
||||||
port = ARGV[0].to_i rescue 8080
|
port = ARGV[0].to_i rescue 8080
|
||||||
addr = ARGV[1] rescue "127.0.0.1"
|
addr = ARGV[1] rescue "127.0.0.1"
|
||||||
|
|
||||||
server = HTTP::Server.new do |context|
|
# TODO: connect to `dnsmanagerd`.
|
||||||
request = context.request
|
|
||||||
|
|
||||||
|
server = HTTP::Server.new do |context|
|
||||||
pp! context.request.remote_address
|
pp! context.request.remote_address
|
||||||
|
|
||||||
case request.path
|
case context.request.path
|
||||||
when /^\/token-update\/(?<token>[a-z-]+)/
|
when /^\/token-update\/(?<token>[a-z-]+)/
|
||||||
token = $~["token"]
|
token = $~["token"]
|
||||||
if token.nil?
|
if token.nil?
|
||||||
context.response.status_code = 404
|
context.response.status_code = 404
|
||||||
context.response.content_type = "text/html"
|
|
||||||
context.response.print "invalid token"
|
context.response.print "invalid token"
|
||||||
else
|
else
|
||||||
context.response.content_type = "text/html"
|
context.response.content_type = "text/html"
|
||||||
context.response.print "coucou, token: #{token}"
|
context.response.print "coucou, token: #{token}"
|
||||||
|
# TODO: send update to `dnsmanagerd`.
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
context.response.status_code = 404
|
context.response.status_code = 404
|
||||||
|
|
Loading…
Reference in New Issue