add basic auth support

fixes #8
pull/11/head
Mike Heijmans 2016-05-18 09:47:23 -07:00
parent 1b0e8b40a8
commit 792081212d
No known key found for this signature in database
GPG Key ID: AD75EF5BA031CA8B
2 changed files with 20 additions and 0 deletions

View File

@ -17,6 +17,15 @@ docker run -d -p 80:80 parabuzzle/craneoperator:latest
## How do I configure it?
Available Environment Variables:
* **REGISTRY_HOST** - the registry host to browse (default: `localhost`)
* **REGISTRY_PORT** - the port of the registry host (default: `5000`)
* **REGISTRY_PROTO** - the protocol to use (ie: `http` or `https`) (default: `https`)
* **REGISTRY_SSL_VERIFY** - should the certificate be verified if using SSL (default: `true`)
* **USERNAME** - setting this will activate BASIC AUTH and require this username
* **PASSWORD** - optional password for BASIC AUTH (you must set the `USERNAME` for this to work)
```
docker run -d \
-p 80:80 \
@ -24,6 +33,9 @@ docker run -d \
-e REGISTRY_PORT=443 \
-e REGISTRY_PROTO=https \
-e REGISTRY_SSL_VERIFY=false \
-e USERNAME=admin \
-e PASSWORD=s3cr3t \
parabuzzle/craneoperator:latest
```
![screenshots/Crane_Operator.jpg](screenshots/Crane_Operator.jpg)

View File

@ -41,6 +41,14 @@ class CraneOp < Sinatra::Base
ENV['REGISTRY_SSL_VERIFY'] || 'true'
end
## Authentication ##
if ENV['USERNAME']
use Rack::Auth::Basic, "Please Authenticate to View" do |username, password|
username == ENV['USERNAME'] and password == ( ENV['PASSWORD'] || '' )
end
end
## Helpers ##
def to_bool(str)