mirror of
https://github.com/metrico/qryn.git
synced 2025-03-14 10:07:18 +00:00
Basic auth for cLoki (#9)
* Added ClickHouse Auth * Basic auth for cLoki too
This commit is contained in:
@ -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
|
||||
|
14
cloki.js
14
cloki.js
@ -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()
|
||||
|
@ -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"
|
||||
|
Reference in New Issue
Block a user