From 8b524d3fd0c9c0bf4a3b8b35af70d160719f0652 Mon Sep 17 00:00:00 2001 From: April King Date: Thu, 17 Mar 2016 09:28:55 -0500 Subject: [PATCH] Finish writing docker instructions, tweak some env variables --- README.md | 28 ++++++++++++++++++++++++++++ docker-compose.yml | 2 +- httpobs/conf/__init__.py | 8 +++++--- httpobs/scripts/httpobs | 17 ++++++----------- 4 files changed, 40 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 5f1b924..dc62366 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml index bc0f3b8..23b09b9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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: diff --git a/httpobs/conf/__init__.py b/httpobs/conf/__init__.py index c190b78..0cdac36 100644 --- a/httpobs/conf/__init__.py +++ b/httpobs/conf/__init__.py @@ -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__)) diff --git a/httpobs/scripts/httpobs b/httpobs/scripts/httpobs index 061b992..86940a8 100755 --- a/httpobs/scripts/httpobs +++ b/httpobs/scripts/httpobs @@ -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