Skip to content

Instantly share code, notes, and snippets.

#!/bin/sh -e
test -z $1 && exit 1
name=$1
cpus=$(( $(sysctl -n hw.ncpu) / 2))
mems=$(( $(sysctl -n hw.memsize) / 1024 ** 2 / 2))
#iso=debian-testing-amd64-netinst.iso
iso=debian-8.2.0-amd64-netinst.iso
#preseed="testing-preseed.txt"
preseed="jessie-preseed.txt"
INSTALLED_APPS = (
(snip)
'django_auth_custom_example', # <--
)
MIDDLEWARE_CLASSES = (
(snip)
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django_auth_custom_example.middleware.CustomAuthMiddleware', # <--
(snip)
# -*- coding: utf-8 -*-
from rest_framework.authentication import BaseAuthentication
from rest_framework import exceptions, HTTP_HEADER_ENCODING
from django_auth_custom_example.models import CustomAuthToken
def get_authorization_header(request):
auth = request.META.get('HTTP_X_AUTH_TOKEN', b'')
if isinstance(auth, type('')):
auth = auth.encode(HTTP_HEADER_ENCODING)
# -*- coding: utf-8 -*-
import sys
from django.db import models
from django.contrib.auth.models import User
class CustomAuthToken(models.Model):
TOKEN_TYPE_CHOICES = (
('user', 'user'),
# -*- coding: utf-8 -*-
from datetime import datetime
from django.conf import settings
from django.contrib.auth.models import User
from django.utils.timezone import utc
from custom_authlib import client # client library for custom authentication
from django_auth_custom_example.models import CustomAuthToken
class CustomAuthBackend(object):
# -*- coding: utf-8 -*-
from django.contrib.auth import authenticate, login
from django.http import HttpResponseRedirect
from django.conf import settings
class CustomAuthMiddleware(object):
def process_request(self, request):
_token = None
This file has been truncated, but you can view the full file.
define("travis/adapters/application", ["exports", "ember-data", "travis/config/environment"], function(e, t, a) {
"use strict";
var r;
r = t["default"].ActiveModelAdapter.extend({
host: a["default"].apiEndpoint,
coalesceFindRequests: !0,
ajaxOptions: function(e, t, a) {
var r, n, i;
return n = this._super(e, t, a), n.headers || (n.headers = {}), n.headers.accept = "application/json; version=2", (i = Travis.sessionStorage.getItem("travis.token")) && ((r = n.headers).Authorization || (r.Authorization = "token " + i)), n
},
@mkouhei
mkouhei / pyvenv-temporary.sh
Last active August 29, 2015 14:21
Create venv using pyvenv temporarily, because virtualenv of Sid is blocken at 20150522
#!/bin/sh -e
# You must install curl, python2, python3, python3-pyvenv in advance.
if [ -z $1 ]; then
echo 'input pyvenv directory' && read targetdir
else
targetdir=$1
fi
@mkouhei
mkouhei / backup2swift.json
Created May 5, 2015 22:30
backup2swift linkdraw data
{
"nodes": [
{
"color": "",
"r": "6",
"link": "",
"name": "backup2swift"
},
{
"color": "#5F9EA0",
#!/bin/sh -e
unset LANG
key=""
ctime="+0"
test -z $1 && ctime="-365"
test -z $2 && key="total"
check_python() {
printf "%-12s:" "Python"