Skip to content

Commit

Permalink
Merge branch 'release-0.1.0-1'
Browse files Browse the repository at this point in the history
  • Loading branch information
gregcorbett committed Jun 2, 2016
2 parents 32c8c4e + 4cf5fa0 commit 516b217
Show file tree
Hide file tree
Showing 32 changed files with 2,808 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.pyc
*.log
static/
33 changes: 33 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
language: python
python:
- "2.6"
- "2.7"
- "3.4"
matrix:
allow_failures:
- python: "2.7"
- python: "3.4"
fast_finish: true

# use the mysql service
services:
- mysql

# Route build to container-based infrastructure
sudo: false
# Cache the dependencies installed by pip
cache: pip

# Install defaults to "pip install -r requirements.txt"

# Commands that prepare things for the test
before_script:
# create an empty mysql database
- mysql -u root -e "create database apel_rest"
- mysql -u root apel_rest < schemas/cloud.sql
- export PYTHONPATH=$PYTHONPATH:`pwd -P`

# Command to run tests
script: coverage run --source='.' manage.py test

after_success: coveralls
52 changes: 51 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,51 @@
# rest
# REST

[![Build Status](https://travis-ci.org/apel/rest.svg?branch=dev)](https://travis-ci.org/apel/rest)
[![Coverage Status](https://coveralls.io/repos/github/apel/rest/badge.svg?branch=dev)](https://coveralls.io/github/apel/rest?branch=dev)

Experimental REST API for APEL

## Using the docker image

1. install docker and httpd (httpd is needed on the host machine for `/usr/sbin/apachectl`, do NOT start httpd)

2. pull in the latest image: `docker pull gregcorbett/rest`

3. Run the docker with `docker run -d -p 80:80 -p 443:443 gregcorbett/rest /usr/sbin/apachectl -D FOREGROUND`

4. Navigate a web browser to "https://\<hostname\>/index/"

## Setup from source

1. Install python, pip, mysql, apache, apache modules and IGTF trust bundle
```
yum install python-pip python-devel httpd httpd-devel mysql mysql-server mysql-devel gcc mod_ssl mod_wsgi ca-policy-egi-core
```

2. Upgrade pip and setuptools
```
pip install pip --upgrade
pip install setuptools --upgrade
```

3. Install requirements.txt

4. Clone the repo to `/var/www/html`

5. Run `mysql -u root -e "create database apel_rest"` and `mysql -u root apel_rest < schemas/cloud.sql` to set up database

6. Create a new, self signed, certificate
```
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/httpd/ssl/apache.key -out /etc/httpd/ssl/apache.crt
```
7. Copy `conf/httpd.conf` to `/etc/httpd/conf/httpd.conf`

8. Copy `conf/ssl.connf` to `/etc/httpd/conf.d/ssl.conf`

9. Copy `conf/apel_rest_api.conf to `/etc/httpd/conf.d/apel_rest_api.conf`

10. Run `python manage.py collectstatic`

11. Start Apache with `service httpd start`

12. Navigate a web browser to "https://\<hostname\>/index/"
13 changes: 13 additions & 0 deletions apel_rest/PlainTextParser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from rest_framework.parsers import BaseParser

class PlainTextParser(BaseParser):
"""
Plain text parser.
"""
media_type = 'text/plain'

def parse(self, stream, media_type=None, parser_context=None):
"""
Simply return a string representing the body of the request.
"""
return stream.read()
1 change: 1 addition & 0 deletions apel_rest/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = '0, 1, 0'
167 changes: 167 additions & 0 deletions apel_rest/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
"""
Django settings for apel_rest project.
For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '6^&2c@p@nld52qs4nfp1%99plh&*69&@@9%no3sgq6v+ci&g73'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

TEMPLATE_DEBUG = False

ALLOWED_HOSTS = ['*']


# Application definition

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
)

MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.RemoteUserMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

# AUTHENTICATION_BACKENDS = (
# 'django.contrib.auth.backends.RemoteUserBackend',
# )

ROOT_URLCONF = 'apel_rest.urls'

WSGI_APPLICATION = 'apel_rest.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}

# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/

STATIC_ROOT = '/var/www/html/static'
STATIC_URL = '/static/'

# debugging stuff
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s]: %(message)s",
'datefmt': "%d/%b/%Y %H:%M:%S"
},
'simple': {
'format': '%(levelname)s: %(message)s'
},
},
'handlers': {
# 'file': {
# 'class': 'logging.FileHandler',
# 'filename': './apel_rest.log',
# 'formatter': 'verbose'
# },
'console': {
'class': 'logging.StreamHandler',
'formatter': 'simple'
},
},
'loggers': {
'django': {
'handlers': ['console'],
'propagate': True,
'level': 'INFO',
},
'api': {
'handlers': ['console'],
'level': 'INFO',
#'level': 'DEBUG',
},
}
}

# XML stuff
REST_FRAMEWORK = {
'DEFAULT_PARSER_CLASSES': (
'apel_rest.PlainTextParser.PlainTextParser',
),
# this would add HTML buttons for pagination, but only in 3.3
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
# 'DEFAULT_RENDERER_CLASSES': (
# 'rest_framework_xml.renderers.XMLRenderer',
# ),
}

# Defines where the REST API will store
# incoming messages for later processing
QPATH = '/var/spool/apel/cloud'

# Defines the database settings
# used by the REST API
CLOUD_DB_CONF = '/etc/apel/clouddb.cfg'

# Defines the maximum results per page
# returned from the REST API
RESULTS_PER_PAGE = 100

# Defines what field to return
# in the REST API
RETURN_HEADERS = ["VOGroup",
"SiteName",
"UpdateTime",
"WallDuration",
"EarliestStartTime",
"LatestStartTime",
"Day",
"Month",
"Year"]

# this should hide the GET?format button
# this doesnt do anything, probably because of using older Django
URL_FORMAT_OVERRIDE = None
16 changes: 16 additions & 0 deletions apel_rest/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from django.conf.urls import patterns, include, url

from django.contrib import admin
from api.views.CloudRecordSummaryView import CloudRecordSummaryView
from api.views.CloudRecordView import CloudRecordView
admin.autodiscover()

urlpatterns = patterns('',
# Examples:
# url(r'^$', 'apel_rest.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),

url(r'^admin/', include(admin.site.urls)),
url(r'^api/v1/cloud/record$', CloudRecordView.as_view()),
url(r'^api/v1/cloud/record/summary$', CloudRecordSummaryView.as_view())
)
14 changes: 14 additions & 0 deletions apel_rest/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
WSGI config for apel_rest project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/
"""

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "apel_rest.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
2 changes: 2 additions & 0 deletions api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__version__ = '0, 1, 0'

3 changes: 3 additions & 0 deletions api/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
3 changes: 3 additions & 0 deletions api/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
Empty file added api/tests/__init__.py
Empty file.
Loading

0 comments on commit 516b217

Please sign in to comment.