6 Commits

Author SHA1 Message Date
be1a5eacd9 No tenemos tests 2024-08-29 17:45:21 -03:00
182b98d74a v0.2.0 2024-08-29 17:44:59 -03:00
b918668949 Soportar distintas redes 2024-08-29 17:44:21 -03:00
64145abf0c Logs 2024-08-29 17:44:10 -03:00
d283db97a0 Crear los directorios si no existen 2024-08-29 17:42:08 -03:00
c386bfa413 Usar Crystal 1.6 2024-08-29 17:33:31 -03:00
4 changed files with 36 additions and 24 deletions

View File

@ -1,5 +1,4 @@
stages:
- "test"
- "build"
- "upload"
- "release"
@ -7,17 +6,11 @@ variables:
RELEASE_DIRECTORY: "rap-inbox-${CI_COMMIT_TAG}-linux-amd64"
RELEASE_TARBALL: "${RELEASE_DIRECTORY}.tar.gz"
PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/rap-inbox/${CI_COMMIT_TAG}/${RELEASE_TARBALL}"
test:
stage: "test"
image: "crystallang/crystal:latest-alpine"
script:
- "shards install"
- "crystal spec"
build:
rules:
- if: "$CI_COMMIT_TAG"
stage: "build"
image: "crystallang/crystal:latest-alpine"
image: "crystallang/crystal:1.6-alpine"
cache:
paths:
- "lib/"

View File

@ -1,18 +1,18 @@
version: 1.0
version: 2.0
shards:
backtracer:
git: https://github.com/sija/backtracer.cr.git
version: 1.2.2
exception_page:
github: crystal-loot/exception_page
version: 0.1.4
git: https://github.com/crystal-loot/exception_page.git
version: 0.3.1
kemal:
github: kemalcr/kemal
commit: a8c0f09b858162bd13c96663febef5527b322a32
kilt:
github: jeromegn/kilt
version: 0.4.0
git: https://github.com/kemalcr/kemal.git
version: 1.3.0+git.commit.ae7cda829162ea27668b3fc79cd1868026e25098
radix:
github: luislavena/radix
version: 0.3.9
git: https://github.com/luislavena/radix.git
version: 0.4.1

View File

@ -1,5 +1,5 @@
name: rap-inbox
version: 0.1.1
version: 0.2.0
authors:
- rené montes <renemontes@partidopirata.com.ar>
@ -15,4 +15,4 @@ license: MIT
dependencies:
kemal:
github: kemalcr/kemal
branch: master
tag: v1.3.0

View File

@ -1,28 +1,47 @@
require "kemal"
require "file_utils"
# No queremos filtrar las llaves!
serve_static false
# Acepta llaves de tinc por post a menos que ya existan
post "/:host" do |env|
post "/:network/:host" do |env|
HTTP::FormData.parse(env.request) do |u|
network = env.params.url["network"]
host = env.params.url["host"]
# Sólo letras, números y guiones bajos
unless host =~ /\A[a-z0-9_]+\z/i
Log.info { "#{host} no sigue el formato de nombre de nodo, ignorando" }
halt env, status_code: 403, response: "Forbidden"
end
path = File.join [Kemal.config.public_folder, "hosts", host]
unless network =~ /\A[a-z0-9]+\z/i
Log.info { "#{network} no sigue el formato de nombre de red, ignorando" }
halt env, status_code: 403, response: "Forbidden"
end
path = File.join [Kemal.config.public_folder, "networks", network, "hosts", host]
# No aceptar llaves que ya existan
halt env, status_code: 403, response: "Forbidden" if File.exists? path
if File.exists? path
Log.info { "#{path} ya existe, ignorando" }
halt env, status_code: 403, response: "Forbidden"
end
# Crea el directorio si no existe
FileUtils.mkdir_p File.dirname(path)
# Copiar el archivo al destino
File.open path, "w" do |f|
IO.copy u.body, f
end
Log.info { "#{host} creado en #{network}" }
# Responder con 201
halt env, status_code: 201, response: "Created"
end