Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
69d32cb
Redis connection
pzduniak Dec 9, 2014
79a7b5b
changing port
pzduniak Dec 10, 2014
f4ee3f0
Continuing the implementation
pzduniak Dec 10, 2014
2d3c9ab
Added vagrant for easier testing
pzduniak Dec 10, 2014
369509c
Fixed some small issues that made tests impossible
pzduniak Dec 10, 2014
c159a6f
Cache code
pzduniak Dec 11, 2014
d08fd27
Added redis to the travis tests
pzduniak Dec 11, 2014
50885df
Added a CircleCI build script
pzduniak Dec 11, 2014
f262dfc
Fixing typo in circle.yml
pzduniak Dec 11, 2014
abefed5
Trying to get services running
pzduniak Dec 11, 2014
a9d229a
atom pls
pzduniak Dec 11, 2014
446793c
circleci pls
pzduniak Dec 11, 2014
0ab5ba3
Custom test command
pzduniak Dec 11, 2014
4f234e9
Merge pull request #17 from lavab/feature/cache
pzduniak Dec 13, 2014
1133c78
Key votes storage benchmark
pzduniak Dec 14, 2014
0a1040f
models.Key change
pzduniak Dec 14, 2014
44d0b68
Fixing before merge; changed GET /keys to work with new logic
pzduniak Dec 14, 2014
853276e
Merge pull request #18 from lavab/feature/account-improvements
pzduniak Dec 15, 2014
0747039
YubiCloud support added-ish
pzduniak Dec 15, 2014
abf00e7
Merge pull request #19 from lavab/feature/yubikey
pzduniak Dec 15, 2014
518045d
Added support for multiple Yubikeys
pzduniak Dec 17, 2014
0596b00
queue basis
pzduniak Dec 19, 2014
7886e26
Merge branch 'develop' into feature/emails
pzduniak Dec 19, 2014
943d36d
A large chunk of base emails code
pzduniak Dec 21, 2014
91106bd
websockets
pzduniak Dec 21, 2014
76c1a2d
SockJS support
pzduniak Dec 26, 2014
4a55c84
Added message type to data sent back to WS client
pzduniak Dec 27, 2014
d8d0ece
Fixed tests and changed status badges in README.md
pzduniak Dec 27, 2014
5ea87c3
Fixing configuration for automatic tests
pzduniak Dec 27, 2014
ff64a72
GET /emails
pzduniak Dec 28, 2014
b93f083
Removed PUT /emails/:id, implemented DELETE /emails/:id and GET /emai…
pzduniak Dec 28, 2014
c2fff71
setup.go, the 700-line wonder
pzduniak Dec 28, 2014
9406d94
Weak password test
pzduniak Dec 28, 2014
0953b23
Added email tests
pzduniak Dec 28, 2014
09e2938
Merge pull request #20 from lavab/feature/emails
pzduniak Dec 28, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
*~
*.exe
_vagrant/.vagrant
.config.conf
11 changes: 0 additions & 11 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ version=v0

## Build status:

- `master` - [![Build Status](https://magnum.travis-ci.com/lavab/api.svg?token=kJbppXeTxzqpCVvt4t5X&branch=master)](https://magnum.travis-ci.com/lavab/api)
- `develop` - [![Build Status](https://magnum.travis-ci.com/lavab/api.svg?token=kJbppXeTxzqpCVvt4t5X&branch=develop)](https://magnum.travis-ci.com/lavab/api)
- `master` - [![Circle CI](https://circleci.com/gh/lavab/api/tree/master.svg?style=svg&circle-token=4a52d619a03d0249906195d6447ceb60a475c0c5)](https://circleci.com/gh/lavab/api/tree/master)
- `develop` - [![Circle CI](https://circleci.com/gh/lavab/api/tree/develop.svg?style=svg&circle-token=4a52d619a03d0249906195d6447ceb60a475c0c5)](https://circleci.com/gh/lavab/api/tree/develop)
115 changes: 115 additions & 0 deletions _research/vote_storage/benchmark_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package vote_storage_test

import (
"math/rand"
"testing"

"github.com/dancannon/gorethink"
"github.com/dchest/uniuri"
)

var (
session *gorethink.Session
key2find string
table2search string
)

func init() {
var err error
session, err = gorethink.Connect(gorethink.ConnectOpts{
Address: "127.0.0.1:28015",
})
if err != nil {
panic(err)
}

key2find = uniuri.New()

// Create a new table
gorethink.Db("test").TableDrop("benchmark_keys_list").Run(session)
gorethink.Db("test").TableCreate("benchmark_keys_list").Run(session)

var klist []*KeysList

// Populate with sample data
for n := 0; n < 300; n++ {
keys := rndStringSlice(999)
keys = randomlyInsert(keys, key2find)

y := uniuri.New()
if n == 153 {
table2search = y
}

klist = append(klist, &KeysList{
ID: y,
Voted: keys,
})
}

gorethink.Db("test").Table("benchmark_keys_list").Insert(klist).Run(session)
}

func rndStringSlice(count int) []string {
var r []string
for i := 0; i < count; i++ {
r = append(r, uniuri.New())
}
return r
}

func randomlyInsert(s []string, x string) []string {
i := rand.Intn(len(s) - 1)

s = append(s[:i], append([]string{x}, s[i:]...)...)

return s
}

type KeysList struct {
ID string `gorethink:"id"`
Voted []string `gorethink:"voted"`
}

func BenchmarkContains(b *testing.B) {
for n := 0; n < b.N; n++ {
contains, err := gorethink.Db("test").Table("benchmark_keys_list").Get(table2search).Field("voted").Contains(key2find).Run(session)
if err != nil {
b.Log(err)
b.Fail()
}

var res bool
err = contains.One(&res)
if err != nil {
b.Log(err)
b.Fail()
}
if !res {
b.Log("invalid response")
b.Fail()
}
}
}

func BenchmarkAppend(b *testing.B) {
for n := 0; n < b.N; n++ {
_, err := gorethink.Db("test").Table("benchmark_keys_list").Get(table2search).Field("voted").Append(uniuri.New()).Run(session)
if err != nil {
b.Log(err)
b.Fail()
}
}
}

func BenchmarkDelete(b *testing.B) {
for n := 0; n < b.N; n++ {
_, err := gorethink.Db("test").Table("benchmark_keys_list").Get(table2search).Field("voted").DeleteAt(
gorethink.Expr(gorethink.Db("test").Table("benchmark_keys_list").Get(table2search).Field("voted").IndexesOf(key2find).AtIndex(0)),
).Run(session)
if err != nil {
b.Log(err)
b.Fail()
}
}
}
40 changes: 40 additions & 0 deletions _research/ws_client/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>lavab client</title>
</head>
<body>
<select id="method">
<option>GET</option>
<option>POST</option>
<option>PUT</option>
<option>DELETE</option>
</select>

<input type="text" id="path" /><br>
<textarea id="body"></textarea><br>
<button id="send">Query</button>

<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="//cdn.jsdelivr.net/sockjs/0.3.4/sockjs.min.js"></script>
<script type="text/javascript">
$(function() {
var sock = new SockJS("http://127.0.0.1:5000/ws");

$("#send").click(function() {
sock.send(JSON.stringify({
id: "random id",
method: $("#method").val(),
path: $("#path").val(),
body: $("#body").val(),
}));
});

sock.onmessage = function(e) {
console.log(JSON.parse(e.data));
};
});
</script>
</body>
</html>
58 changes: 58 additions & 0 deletions _vagrant/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

#config.vm.define "redisthink" do |rethinkdb|
#rethinkdb.vm.box = "ubuntu/trusty64"

# rethinkdb
#rethinkdb.vm.network "forwarded_port", guest: 8080, host: 8080
#rethinkdb.vm.network "forwarded_port", guest: 28015, host: 28015
#rethinkdb.vm.network "forwarded_port", guest: 29015, host: 29015

# redis
#rethinkdb.vm.network "forwarded_port", guest: 6379, host: 6379

#rethinkdb.vm.provider "virtualbox" do |v|
#v.memory = 2048
#v.cpus = 4
#end

# load ansible playbook
#rethinkdb.vm.provision "shell", path: "deploy.sh"
#end

config.vm.define "docker" do |docker|
docker.vm.box = "ubuntu/trusty64"

docker.vm.network "forwarded_port", guest: 4222, host: 4222
docker.vm.network "forwarded_port", guest: 8333, host: 8333
docker.vm.network "forwarded_port", guest: 6379, host: 6379
docker.vm.network "forwarded_port", guest: 8080, host: 8080
docker.vm.network "forwarded_port", guest: 28015, host: 28015
docker.vm.network "forwarded_port", guest: 29015, host: 29015

docker.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
v.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
end

docker.vm.provision "docker" do |d|
d.pull_images "apcera/gnatsd"
d.run "apcera/gnatsd",
args: "--name gnatsd -p 4222:4222 -p 8333:8333"

d.pull_images "dockerfile/rethinkdb"
d.run "dockerfile/rethinkdb",
args: "--name rethinkdb -p 8080:8080 -p 28015:28015 -p 29015:29015"

d.pull_images "dockerfile/redis"
d.run "dockerfile/redis",
args: "--name redis -p 6379:6379"
end
end
end
14 changes: 14 additions & 0 deletions _vagrant/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

export DEBIAN_FRONTEND=noninteractive

apt-get update -qq
apt-get install -y python2.7 python-pip

pip install ansible

mkdir /etc/ansible
echo "localhost" > /etc/ansible/hosts

cd /vagrant
ansible-playbook -vvvv playbook.yml
46 changes: 46 additions & 0 deletions _vagrant/playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
- hosts: 127.0.0.1
connection: local
sudo: true
tasks:
# install rethinkdb
- name: add rethinkdb sources
shell: . /etc/lsb-release && echo "deb http://download.rethinkdb.com/apt $DISTRIB_CODENAME main" | tee /etc/apt/sources.list.d/rethinkdb.list
- name: add rethinkdb key
shell: wget -qO- http://download.rethinkdb.com/apt/pubkey.gpg | apt-key add -
- name: update apt cache
apt: update_cache=yes
- name: install rethinkdb
apt: pkg=rethinkdb state=present
# configure rethinkdb
- name: ensure group is present
group: name=rethinkdb state=present
- name: ensure user is present
user: name=rethinkdb state=present
- name: copy master config file
copy: src=./rethinkdb.conf dest=/etc/rethinkdb/instances.d/rethinkdb.conf owner=rethinkdb group=rethinkdb mode=664
- name: start rethinkdb
service: name=rethinkdb state=restarted
# install redis
- name: prepare a directory
shell: mkdir /tmp/redis-stable
- name: download redis
get_url: url=http://download.redis.io/redis-stable.tar.gz dest=/tmp/redis-stable.tar.gz
- name: unpack redis
unarchive: src=/tmp/redis-stable.tar.gz dest=/tmp/redis-stable copy=no
- name: make redis
shell: 'cd /tmp/redis-stable/redis-stable && make && make install'
- name: ensure group is present
group: name=redis state=present
- name: ensure user is present
user: name=redis state=present
- name: prepare config and storage directories for redis
shell: mkdir /etc/redis; mkdir /var/redis; sudo mkdir /var/redis/6379
- name: prepare the config and an init script for redis
shell: sudo cp /tmp/redis-stable/redis-stable/utils/redis_init_script /etc/init.d/redis_6379
- name: upload the config to the vm
copy: src=./redis.conf dest=/etc/redis/6379.conf owner=redis group=redis mode=664
- name: put the prepared config on the server
shell: sudo update-rc.d redis_6379 defaults
- name: start redis_6379
service: name=redis_6379 state=restarted
Loading