Basic auth for cLoki (#9)

* Added ClickHouse Auth

* Basic auth for cLoki too
This commit is contained in:
lansio
2019-05-30 23:03:12 +03:00
committed by Lorenzo Mangani
parent 854c9760cf
commit 7a73bbcbd6
3 changed files with 18 additions and 1 deletions

View File

@ -4,6 +4,8 @@ FROM node:8
# BUILD FORCE
ENV BUILD 703024
ENV PORT 3100
ENV CLOKI_LOGIN "logger"
ENV CLOKI_PASSWORD "password"
COPY . /app
WORKDIR /app

View File

@ -49,6 +49,16 @@ fastify.register(require('fastify-url-data'), (err) => {
if (err) throw err
})
fastify.register(require('fastify-basic-auth'), { validate })
function validate (username, password, req, reply, done) {
if (username === process.env.CLOKI_LOGIN && password === process.env.CLOKI_PASSWORD) {
done()
} else {
done(new Error('Unauthorized!: Wrong username/password.'))
}
}
fastify.addContentTypeParser('application/x-protobuf', function (req, done) {
var data = ''
req.on('data', chunk => { data += chunk })
@ -57,6 +67,10 @@ fastify.addContentTypeParser('application/x-protobuf', function (req, done) {
})
})
fastify.after(() => {
fastify.addHook('preHandler', fastify.basicAuth)
})
/*
fastify.addContentTypeParser('*', function (req, done) {
done()

View File

@ -25,7 +25,8 @@
"jsonic": "^0.3.1",
"protocol-buffers": "^4.1.0",
"record-cache": "^1.1.0",
"short-hash": "^1.0.0"
"short-hash": "^1.0.0",
"fastify-basic-auth": "^0.4.0"
},
"directories": {
"lib": "lib"