Skip to content

Commit

Permalink
Merge pull request #157 from subutai-io/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
dilshat authored Nov 21, 2017
2 parents 9a9eb53 + b88be0a commit 1ecdec9
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 6 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
# gorjun
Gorjun is a golang replacement for Kurjun project.
# Gorjun
Gorjun is a golang replacement for Kurjun project. Kurjun is Subutai's CDN software.

## Vagrant

Use vagrant to create a multi-machine development and testing environment in an internal network. The master vm builds, configures and runs Gorjun. The cdn\[1-n] nodes are NGINX CDN cache nodes.

> vagrant up
> vagrant ssh master
> ping cdn1.local
> ping cdn2.local
63 changes: 63 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
BOX_IMAGE = "debian/stretch64"
NODE_COUNT = 2
MASTER_RAM = 768
MASTER_CPU = 2
CDN_RAM = 384
CDN_CPU = 1

Vagrant.configure("2") do |config|
config.vm.define "master" do |subconfig|
subconfig.vm.box = BOX_IMAGE
subconfig.vm.hostname = "master"

subconfig.vm.network "private_network", ip: "10.55.2.10",
virtualbox__intnet: true

subconfig.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
v.memory = MASTER_RAM
v.cpus = MASTER_CPU
end

subconfig.vm.provision "shell", inline: <<-SHELL
echo "Installing golang, building Gorjun, and running ..."
apt-get install -y curl git
curl -O https://storage.googleapis.com/golang/go1.8.4.linux-amd64.tar.gz
tar -zxvf ./go1.8.4.linux-amd64.tar.gz
chown -R root:root ./go
mv go /usr/local
rm -rf ./go1.8.4.linux-amd64.tar.gz
echo 'export GOPATH=$HOME/work' >> ~vagrant/.profile
echo 'export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin' >> ~vagrant/.profile
su - vagrant -c 'mkdir /home/vagrant/work'
su - vagrant -c 'go get github.com/subutai-io/gorjun'
echo 'TODO: still need to configure and start up gorjun'
echo 'TODO: lets also load some stuff into it to test'
SHELL
end

(1..NODE_COUNT).each do |i|
config.vm.define "cdn#{i}" do |subconfig|
subconfig.vm.box = BOX_IMAGE
subconfig.vm.hostname = "cdn#{i}"
subconfig.vm.network "private_network", ip: "10.55.2.#{i + 10}",
virtualbox__intnet: true

subconfig.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
v.memory = CDN_RAM
v.cpus = CDN_CPU
end

subconfig.vm.provision "shell", inline: <<-SHELL
echo "Installing NGINX cdn node ..."
apt-get install -y nginx
echo 'TODO: still need to configure nginx and cache'
SHELL
end
end

config.vm.provision "shell", inline: <<-SHELL
apt-get install -y avahi-daemon libnss-mdns net-tools
SHELL
end
8 changes: 4 additions & 4 deletions upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ type share struct {

//Handler function works with income upload requests, makes sanity checks, etc
func Handler(w http.ResponseWriter, r *http.Request) (md5sum, sha256sum, owner string) {
r.ParseMultipartForm(32 << 20)
if len(r.MultipartForm.Value["token"]) == 0 || len(db.CheckToken(r.MultipartForm.Value["token"][0])) == 0 {
token := r.Header.Get("token")
owner = strings.ToLower(db.CheckToken(token))
if len(token) == 0 || len(owner) == 0 {
w.WriteHeader(http.StatusUnauthorized)
w.Write([]byte("Not authorized"))
log.Warn(r.RemoteAddr + " - rejecting unauthorized upload request")
return
}

owner = strings.ToLower(db.CheckToken(r.MultipartForm.Value["token"][0]))
r.ParseMultipartForm(32 << 20)

file, header, err := r.FormFile("file")
if log.Check(log.WarnLevel, "Failed to parse POST form", err) {
Expand Down

0 comments on commit 1ecdec9

Please sign in to comment.