Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| be1a5eacd9 | |||
| 182b98d74a | |||
| b918668949 | |||
| 64145abf0c | |||
| d283db97a0 | |||
| c386bfa413 |
@ -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/"
|
||||
|
||||
22
shard.lock
22
shard.lock
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user