Finish writing docker instructions, tweak some env variables

This commit is contained in:
April King 2016-03-17 09:28:55 -05:00
Родитель 1a2682339b
Коммит 8b524d3fd0
4 изменённых файлов: 40 добавлений и 15 удалений

Просмотреть файл

@ -61,6 +61,34 @@ optional arguments:
-x, --hidden don't list scan in the recent scan results
```
## Contributing
### Prerequisites
* Python 3
* Git
### Running a local scanner with Docker
* Install [Docker Toolbox](https://www.docker.com/products/docker-toolbox) and [VirtualBox](https://www.virtualbox.org/wiki/Downloads)
```
# Install the HTTP Observatory client and requests library
$ git clone https://github.com/mozilla/http-observatory.git
$ cd http-observatory
$ pip3 install .
$ pip3 install --upgrade requests
# Create docker machine
$ docker-machine create --driver virtualbox --virtualbox-disk-size "40000" http-observatory
# Save the URL to the eventual frontend in your .profile, .bash_profile, or whatever
$ echo export HTTPOBS_FRONTEND_API_URL=http://$(docker-machine ip http-observatory):57001/api/v1 >> ~/.profile
$ . ~/.profile
# Start up the docker instance and install all the pieces
$ eval $(docker-machine env http-observatory)
$ docker-compose up -d
```
## Authors
* April King

Просмотреть файл

@ -9,7 +9,7 @@ services:
env_file:
- httpobs/conf/.env
environment:
- HTTPOBS_BACKEND_URL=http://backend:57002/api/v1
- HTTPOBS_BACKEND_API_URL=http://backend:57002/api/v1
- HTTPOBS_DATABASE_PASS=httpobsapipassword
- HTTPOBS_ENVIRONMENT=frontend
links:

Просмотреть файл

@ -37,9 +37,11 @@ else:
print('Invalid environment. Exiting.')
sys.exit(1)
# Set the FRONTEND and BACKEND URLs
FRONTEND_API_URL = environ.get('HTTPOBS_FRONTEND_URL', 'http://localhost:57001/api/v1')
BACKEND_API_URL = environ.get('HTTPOBS_BACKEND_URL', 'http://localhost:57002/api/v1')
# Set the frontend and backend URLs
FRONTEND_API_URL = environ.get('HTTPOBS_FRONTEND_API_URL',
'https://http.observatory.services.mozilla.com/api/v1')
BACKEND_API_URL = environ.get('HTTPOBS_BACKEND_API_URL',
'https://observatory-scanner.services.mozilla.com:57002/api/v1')
# Set some database provider specific parameters
__dirname = os.path.abspath(os.path.dirname(__file__))

Просмотреть файл

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
from __future__ import print_function
from operator import itemgetter
@ -7,16 +7,11 @@ from sys import exit
import argparse
import datetime
import json
import os
import requests
import sys
import time
if 'HTTPOBS_DEV' in os.environ: # TODO: use httpobs.conf
HTTP_OBS_URL = 'http://http-observatory.services.mozilla.com:57001/api/v1'
else:
HTTP_OBS_URL = 'https://http-observatory.services.mozilla.com/api/v1'
from httpobs.conf import FRONTEND_API_URL
def analyze(host):
@ -31,7 +26,7 @@ def analyze(host):
try:
# First, make a POST to the Observatory to start the scan
scan = requests.post(HTTP_OBS_URL + '/analyze?host={host}'.format(host=host), data=data).json()
scan = requests.post(FRONTEND_API_URL + '/analyze?host={host}'.format(host=host), data=data).json()
# Notify the user if the user if they attempted a rescan too soon
if args.rescan and scan.get('error') == 'rescan-attempt-too-soon':
@ -40,7 +35,7 @@ def analyze(host):
# Keep polling the HTTP Observatory for the scan to finish
if scan.get('state') != 'FINISHED':
scan = poll(HTTP_OBS_URL + '/analyze?host={host}'.format(host=host),
scan = poll(FRONTEND_API_URL + '/analyze?host={host}'.format(host=host),
key='state',
values=['FINISHED'],
method='GET')
@ -49,11 +44,11 @@ def analyze(host):
except SystemExit:
raise
except:
print('\nUnable to get result from the HTTP Observatory.')
print('\nCannot connect to HTTP Observatory at: {url}.'.format(url=FRONTEND_API_URL))
exit(1)
# Get the test results
tests = poll(HTTP_OBS_URL + '/getScanResults?scan={scan}'.format(scan=scan['scan_id']),
tests = poll(FRONTEND_API_URL + '/getScanResults?scan={scan}'.format(scan=scan['scan_id']),
key='x-frame-options')
# Print out a notification on stderr that it's a cached result