From d016e089180c74c3954a6294137efda560de1cb5 Mon Sep 17 00:00:00 2001 From: Mischa ter Smitten Date: Wed, 1 Feb 2017 10:29:52 +0100 Subject: [PATCH 01/15] Remove unused dependencies (#103) Using unattended-upgrades --- .infra/group_vars/all/_frey.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.infra/group_vars/all/_frey.yml b/.infra/group_vars/all/_frey.yml index fb94b97..2556281 100644 --- a/.infra/group_vars/all/_frey.yml +++ b/.infra/group_vars/all/_frey.yml @@ -8,7 +8,7 @@ apt_upgrade: false apt_dpkg_configure: true apt_install_state: present apt_clean: true -apt_autoremove: true +apt_autoremove: false # ansistrano roles ansistrano_shared_paths: @@ -29,3 +29,6 @@ hostname: "{{ fqdn.split('.')[0] }}" nodejs_yarn: false nodejs_npm_global_packages: - name: yarn + +# unattended-upgrades +unattended_remove_unused_dependencies: true From 63014c78ccd73c00394b6ce01edf502ab6409a5a Mon Sep 17 00:00:00 2001 From: Mischa ter Smitten Date: Wed, 1 Feb 2017 10:46:36 +0100 Subject: [PATCH 02/15] Cleanup Frey file (#104) --- .infra/Freyfile.hcl | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/.infra/Freyfile.hcl b/.infra/Freyfile.hcl index e71eba9..91221cb 100644 --- a/.infra/Freyfile.hcl +++ b/.infra/Freyfile.hcl @@ -111,7 +111,22 @@ install { name = "Install tusd" roles { role = "{{{init.paths.roles_dir}}}/apt/1.4.0" - apt_install = ["apg", "build-essential", "curl", "git-core", "htop", "iotop", "libpcre3", "logtail", "mlocate", "mtr", "psmisc", "telnet", "vim", "wget"] + apt_install = [ + "apg", + "build-essential", + "curl", + "git-core", + "htop", + "iotop", + "libpcre3", + "logtail", + "mlocate", + "mtr", + "psmisc", + "telnet", + "vim", + "wget" + ] } roles { role = "{{{init.paths.roles_dir}}}/unattended-upgrades/1.3.1" @@ -167,7 +182,6 @@ setup { } roles { role = "{{{init.paths.roles_dir}}}/fqdn/1.2.1" - fqdn = "{{lookup('env', 'FREY_DOMAIN')}}" } tasks { file = "path=/mnt/tusd-data state=directory owner=www-data group=ubuntu mode=ug+rwX,o= recurse=yes" From e9255c63b90abc773116a68a6d9142a77ce0206b Mon Sep 17 00:00:00 2001 From: Marius Date: Mon, 6 Feb 2017 15:10:43 +0100 Subject: [PATCH 03/15] Make minor improvements to memorylocker internals --- memorylocker/memorylocker.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/memorylocker/memorylocker.go b/memorylocker/memorylocker.go index aa0664d..280ee9f 100644 --- a/memorylocker/memorylocker.go +++ b/memorylocker/memorylocker.go @@ -20,8 +20,8 @@ import ( // cheap mechanism. Locks will only exist as long as this object is kept in // reference and will be erased if the program exits. type MemoryLocker struct { - locks map[string]bool - mutex *sync.Mutex + locks map[string]struct{} + mutex sync.Mutex } // NewMemoryLocker creates a new in-memory locker. The DataStore parameter @@ -34,8 +34,7 @@ func NewMemoryLocker(_ tusd.DataStore) *MemoryLocker { // New creates a new in-memory locker. func New() *MemoryLocker { return &MemoryLocker{ - locks: make(map[string]bool), - mutex: new(sync.Mutex), + locks: make(map[string]struct{}), } } @@ -54,7 +53,7 @@ func (locker *MemoryLocker) LockUpload(id string) error { return tusd.ErrFileLocked } - locker.locks[id] = true + locker.locks[id] = struct{}{} return nil } @@ -62,11 +61,11 @@ func (locker *MemoryLocker) LockUpload(id string) error { // UnlockUpload releases a lock. If no such lock exists, no error will be returned. func (locker *MemoryLocker) UnlockUpload(id string) error { locker.mutex.Lock() - defer locker.mutex.Unlock() // Deleting a non-existing key does not end in unexpected errors or panic // since this operation results in a no-op delete(locker.locks, id) + locker.mutex.Unlock() return nil } From 3dd28fa02871b95b19f8a0e17c714da729ad8612 Mon Sep 17 00:00:00 2001 From: Marius Date: Mon, 6 Feb 2017 15:32:37 +0100 Subject: [PATCH 04/15] Exclude certain blacklisted ciphers from Nginx --- .infra/files/nginx.conf | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.infra/files/nginx.conf b/.infra/files/nginx.conf index 89a4ad5..b67c8a9 100644 --- a/.infra/files/nginx.conf +++ b/.infra/files/nginx.conf @@ -13,6 +13,17 @@ server { # of common primes ssl_dhparam /etc/nginx/dhparams.pem; + # Restrict supported ciphers to prevent certain browsers from refusing to + # connect because we are offering blacklisted ciphers. This configuration has + # been generated by Mozilla's SSL Configuration Generator on the + # intermediate profile and can be accessed at: + # https://mozilla.github.io/server-side-tls/ssl-config-generator/?server=nginx-1.10.1&openssl=1.0.1e&hsts=no&profile=intermediate + # More information about blacklisted ciphers can be found at: + # http://security.stackexchange.com/questions/126775/understanding-blacklisted-ciphers-for-http2 + ssl_protocols TLSv1 TLSv1.1 TLSv1.2; + ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS'; + ssl_prefer_server_ciphers on; + # Enable OCSP stapling which allows clients to verify that our certificate # is not revoked without contacting the Certificate Authority by appending a # CA-signed promise, that it's still valid, to the TLS handshake response. From 30cd41836d9d52789ff695961bf7fa9cf2652d77 Mon Sep 17 00:00:00 2001 From: Mischa ter Smitten Date: Thu, 16 Feb 2017 09:51:48 +0100 Subject: [PATCH 05/15] Improved .gitignore for Frey using Docker (#109) --- .gitignore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 636514e..967dfb9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,7 @@ tusd/data cover.out data/ -.infra/env.sh -.infra/env.*.sh +.infra/env.* .infra/ssh/tusd.pem .infra/Frey-residu* .infra/ssh/frey-tusd.pem From f8c2c4401ed60f3519addbf6c247ddb386fa9b54 Mon Sep 17 00:00:00 2001 From: Mischa ter Smitten Date: Thu, 16 Feb 2017 12:53:09 +0100 Subject: [PATCH 06/15] Fix incorrect install_npm_user (#110) --- .infra/group_vars/all/_frey.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.infra/group_vars/all/_frey.yml b/.infra/group_vars/all/_frey.yml index 2556281..0e52e5c 100644 --- a/.infra/group_vars/all/_frey.yml +++ b/.infra/group_vars/all/_frey.yml @@ -27,6 +27,7 @@ hostname: "{{ fqdn.split('.')[0] }}" # nodejs nodejs_yarn: false +nodejs_install_npm_user: "{{ ansible_user | default(lookup('env', 'USER')) }}" nodejs_npm_global_packages: - name: yarn From 918240fe32d32f9074b521f2ed268c48d77de9bd Mon Sep 17 00:00:00 2001 From: Mischa ter Smitten Date: Thu, 16 Feb 2017 13:44:24 +0100 Subject: [PATCH 07/15] Fix incorrect install npm user (#111) * Fix incorrect install_npm_user * Fix incorrect install_npm_user --- .infra/group_vars/all/_frey.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.infra/group_vars/all/_frey.yml b/.infra/group_vars/all/_frey.yml index 0e52e5c..7dabfe9 100644 --- a/.infra/group_vars/all/_frey.yml +++ b/.infra/group_vars/all/_frey.yml @@ -27,7 +27,7 @@ hostname: "{{ fqdn.split('.')[0] }}" # nodejs nodejs_yarn: false -nodejs_install_npm_user: "{{ ansible_user | default(lookup('env', 'USER')) }}" +nodejs_install_npm_user: root nodejs_npm_global_packages: - name: yarn From f1d2d1c60f25a02a32ec367b697e97b60d82eb5a Mon Sep 17 00:00:00 2001 From: Kevin van Zonneveld Date: Fri, 17 Feb 2017 10:56:08 +0100 Subject: [PATCH 08/15] Upgrade Frey to v0.3.30 /cc @tersmitten (#112) --- .infra/group_vars/all/_frey.yml | 35 ------------ .infra/package.json | 2 +- .infra/yarn.lock | 94 ++++++++++++++++++++++++++++----- 3 files changed, 81 insertions(+), 50 deletions(-) delete mode 100644 .infra/group_vars/all/_frey.yml diff --git a/.infra/group_vars/all/_frey.yml b/.infra/group_vars/all/_frey.yml deleted file mode 100644 index 7dabfe9..0000000 --- a/.infra/group_vars/all/_frey.yml +++ /dev/null @@ -1,35 +0,0 @@ -# Frey specific overrides, DO NOT EDIT THIS FILE ---- -# apt role -apt_manage_sources_list: true -apt_src_enable: false -apt_update_cache_valid_time: 86400 -apt_upgrade: false -apt_dpkg_configure: true -apt_install_state: present -apt_clean: true -apt_autoremove: false - -# ansistrano roles -ansistrano_shared_paths: - - logs -ansistrano_keep_releases: 10 -ansistrano_npm: no -ansistrano_owner: www-data -ansistrano_group: www-data -ansistrano_allow_anonymous_stats: no - -ansistrano_remove_rolled_back: no - -# fqdn -fqdn: "{{ lookup('env', 'FREY_DOMAIN') }}" -hostname: "{{ fqdn.split('.')[0] }}" - -# nodejs -nodejs_yarn: false -nodejs_install_npm_user: root -nodejs_npm_global_packages: - - name: yarn - -# unattended-upgrades -unattended_remove_unused_dependencies: true diff --git a/.infra/package.json b/.infra/package.json index 8c0d75f..94aff06 100644 --- a/.infra/package.json +++ b/.infra/package.json @@ -3,7 +3,7 @@ "version": "0.0.1", "description": "This folder is charge of launching master.tus.io via [Frey](https://github.com/kvz/frey). You could re-use bits of this, but you could also run tusd any other way you want. It's not a requirement for running a tusd server.", "dependencies": { - "frey": "0.3.28" + "frey": "0.3.30" }, "devDependencies": {}, "scripts": { diff --git a/.infra/yarn.lock b/.infra/yarn.lock index 5fe0837..a9ba4e0 100644 --- a/.infra/yarn.lock +++ b/.infra/yarn.lock @@ -6,7 +6,7 @@ abbrev@1: version "1.0.9" resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.0.9.tgz#91b4792588a7738c25f35dd6f63752a2f8776135" -ansi-escapes@^1.1.0: +ansi-escapes@^1.0.0, ansi-escapes@^1.1.0: version "1.4.0" resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-1.4.0.tgz#d3a8a83b319aa67793662b13e761c7911422306e" @@ -124,12 +124,23 @@ chalk@1.1.3, chalk@^1.0.0, chalk@^1.1.1: strip-ansi "^3.0.0" supports-color "^2.0.0" -cli-cursor@^1.0.1: +cli-cursor@^1.0.1, cli-cursor@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-1.0.2.tgz#64da3f7d56a54412e59794bd62dc35295e8f2987" dependencies: restore-cursor "^1.0.1" +cli-spinners@0.1.2: + version "0.1.2" + resolved "https://registry.yarnpkg.com/cli-spinners/-/cli-spinners-0.1.2.tgz#bb764d88e185fb9e1e6a2a1f19772318f605e31c" + +cli-truncate@0.2.1: + version "0.2.1" + resolved "https://registry.yarnpkg.com/cli-truncate/-/cli-truncate-0.2.1.tgz#9f15cfbb0705005369216c626ac7d05ab90dd574" + dependencies: + slice-ansi "0.0.4" + string-width "^1.0.1" + cli-width@^2.0.0: version "2.1.0" resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-2.1.0.tgz#b234ca209b29ef66fc518d9b98d5847b00edf00a" @@ -162,7 +173,7 @@ concat-map@0.0.1: version "0.0.1" resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" -concat-stream@: +concat-stream@, concat-stream@^1.4.7: version "1.6.0" resolved "https://registry.yarnpkg.com/concat-stream/-/concat-stream-1.6.0.tgz#0aac662fd52be78964d5532f694784e70110acf7" dependencies: @@ -287,7 +298,7 @@ fakefile@0.0.8: dependencies: fs-extra "0.26.5" -figures@^1.3.5: +figures@1.7.0, figures@^1.3.5: version "1.7.0" resolved "https://registry.yarnpkg.com/figures/-/figures-1.7.0.tgz#cbe1e3affcf1cd44b80cadfed28dc793a9701d2e" dependencies: @@ -328,9 +339,9 @@ flat@2.0.0: dependencies: is-buffer "~1.1.2" -frey@0.3.28: - version "0.3.28" - resolved "https://registry.yarnpkg.com/frey/-/frey-0.3.28.tgz#d18c641d82faee834c18a7925388497e494d6888" +frey@0.3.30: + version "0.3.30" + resolved "https://registry.yarnpkg.com/frey/-/frey-0.3.30.tgz#b3175045edd57780f058acd6d673dec8bfbd5905" dependencies: async "1.5.2" babel-polyfill "6.13.0" @@ -351,12 +362,13 @@ frey@0.3.28: os-homedir "1.0.1" rc "1.1.6" replace "0.3.0" + scrolex "0.0.24" semver "5.1.0" strip-indent "1.0.1" toml "2.3.0" tomlify-j0.4 "1.0.1" update-notifier "0.6.3" - uuid "^3.0.0" + uuid "3.0.0" yargs "4.3.2" fs-extra@0.26.5: @@ -695,6 +707,10 @@ lodash.assign@^4.0.3, lodash.assign@^4.0.6: version "4.2.0" resolved "https://registry.yarnpkg.com/lodash.assign/-/lodash.assign-4.2.0.tgz#0d99f3ccd7a6d261d19bdaeb9245005d285808e7" +lodash@4.17.4: + version "4.17.4" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" + lodash@4.6.1, lodash@^4.3.0: version "4.6.1" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.6.1.tgz#df00c1164ad236b183cfc3887a5e8d38cc63cbbc" @@ -707,6 +723,19 @@ lodash@~2.4.1: version "2.4.2" resolved "https://registry.yarnpkg.com/lodash/-/lodash-2.4.2.tgz#fadd834b9683073da179b3eae6d9c0d15053f73e" +log-symbols@1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-1.0.2.tgz#376ff7b58ea3086a0f09facc74617eca501e1a18" + dependencies: + chalk "^1.0.0" + +log-update@1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/log-update/-/log-update-1.0.2.tgz#19929f64c4093d2d2e7075a1dad8af59c296b8d1" + dependencies: + ansi-escapes "^1.0.0" + cli-cursor "^1.0.2" + lowercase-keys@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/lowercase-keys/-/lowercase-keys-1.0.0.tgz#4e3366b39e7f5457e35f1324bdf6f88d0bfc7306" @@ -811,7 +840,11 @@ os-locale@^1.4.0: dependencies: lcid "^1.0.0" -os-tmpdir@^1.0.0: +os-shim@^0.1.2: + version "0.1.3" + resolved "https://registry.yarnpkg.com/os-shim/-/os-shim-0.1.3.tgz#6b62c3791cf7909ea35ed46e17658bb417cb3917" + +os-tmpdir@1.0.2, os-tmpdir@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274" @@ -1006,6 +1039,24 @@ rx-lite@^3.1.2: version "3.1.2" resolved "https://registry.yarnpkg.com/rx-lite/-/rx-lite-3.1.2.tgz#19ce502ca572665f3b647b10939f97fd1615f102" +scrolex@0.0.24: + version "0.0.24" + resolved "https://registry.yarnpkg.com/scrolex/-/scrolex-0.0.24.tgz#07747bcf00a6770fae1514198466fa3d32515335" + dependencies: + chalk "1.1.3" + cli-spinners "0.1.2" + cli-truncate "0.2.1" + depurar "0.3.0" + figures "1.7.0" + lodash "4.17.4" + log-symbols "1.0.2" + log-update "1.0.2" + os-tmpdir "1.0.2" + slice-ansi "0.0.4" + spawn-sync "1.0.15" + strip-ansi "3.0.1" + uuid "3.0.1" + semver-diff@^2.0.0: version "2.1.0" resolved "https://registry.yarnpkg.com/semver-diff/-/semver-diff-2.1.0.tgz#4bbb8437c8d37e4b0cf1a68fd726ec6d645d6d36" @@ -1020,10 +1071,21 @@ sigmund@~1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/sigmund/-/sigmund-1.0.1.tgz#3ff21f198cad2175f9f3b781853fd94d0d19b590" +slice-ansi@0.0.4: + version "0.0.4" + resolved "https://registry.yarnpkg.com/slice-ansi/-/slice-ansi-0.0.4.tgz#edbf8903f66f7ce2f8eafd6ceed65e264c831b35" + slide@^1.1.5: version "1.1.6" resolved "https://registry.yarnpkg.com/slide/-/slide-1.1.6.tgz#56eb027d65b4d2dce6cb2e2d32c4d4afc9e1d707" +spawn-sync@1.0.15: + version "1.0.15" + resolved "https://registry.yarnpkg.com/spawn-sync/-/spawn-sync-1.0.15.tgz#b00799557eb7fb0c8376c29d44e8a1ea67e57476" + dependencies: + concat-stream "^1.4.7" + os-shim "^0.1.2" + spdx-correct@~1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/spdx-correct/-/spdx-correct-1.0.2.tgz#4b3073d933ff51f3912f03ac5519498a4150db40" @@ -1054,7 +1116,7 @@ string_decoder@~0.10.x: version "0.10.31" resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94" -strip-ansi@^3.0.0, strip-ansi@^3.0.1: +strip-ansi@3.0.1, strip-ansi@^3.0.0, strip-ansi@^3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-3.0.1.tgz#6a385fb8853d952d5ff05d0e8aaf94278dc63dcf" dependencies: @@ -1149,14 +1211,18 @@ util-deprecate@~1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" +uuid@3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.0.0.tgz#6728fc0459c450d796a99c31837569bdf672d728" + +uuid@3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.0.1.tgz#6544bba2dfda8c1cf17e629a3a305e2bb1fee6c1" + uuid@^2.0.1: version "2.0.3" resolved "https://registry.yarnpkg.com/uuid/-/uuid-2.0.3.tgz#67e2e863797215530dff318e5bf9dcebfd47b21a" -uuid@^3.0.0: - version "3.0.1" - resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.0.1.tgz#6544bba2dfda8c1cf17e629a3a305e2bb1fee6c1" - validate-npm-package-license@^3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/validate-npm-package-license/-/validate-npm-package-license-3.0.1.tgz#2804babe712ad3379459acfbe24746ab2c303fbc" From 1f176099c7586d7b2efcc5838f382c2362ab4d03 Mon Sep 17 00:00:00 2001 From: Kevin van Zonneveld Date: Fri, 17 Feb 2017 14:48:54 +0100 Subject: [PATCH 09/15] Upgrade Frey to v0.3.31 /cc @tersmitten (#113) --- .infra/package.json | 2 +- .infra/yarn.lock | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/.infra/package.json b/.infra/package.json index 94aff06..ab15db8 100644 --- a/.infra/package.json +++ b/.infra/package.json @@ -3,7 +3,7 @@ "version": "0.0.1", "description": "This folder is charge of launching master.tus.io via [Frey](https://github.com/kvz/frey). You could re-use bits of this, but you could also run tusd any other way you want. It's not a requirement for running a tusd server.", "dependencies": { - "frey": "0.3.30" + "frey": "0.3.31" }, "devDependencies": {}, "scripts": { diff --git a/.infra/yarn.lock b/.infra/yarn.lock index a9ba4e0..95a60e9 100644 --- a/.infra/yarn.lock +++ b/.infra/yarn.lock @@ -339,9 +339,9 @@ flat@2.0.0: dependencies: is-buffer "~1.1.2" -frey@0.3.30: - version "0.3.30" - resolved "https://registry.yarnpkg.com/frey/-/frey-0.3.30.tgz#b3175045edd57780f058acd6d673dec8bfbd5905" +frey@0.3.31: + version "0.3.31" + resolved "https://registry.yarnpkg.com/frey/-/frey-0.3.31.tgz#258aad2248af2c6c73e2854ba140ea189db7f624" dependencies: async "1.5.2" babel-polyfill "6.13.0" @@ -362,7 +362,7 @@ frey@0.3.30: os-homedir "1.0.1" rc "1.1.6" replace "0.3.0" - scrolex "0.0.24" + scrolex "0.0.26" semver "5.1.0" strip-indent "1.0.1" toml "2.3.0" @@ -637,6 +637,10 @@ is-stream@^1.0.0: version "1.1.0" resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44" +is-travis@1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/is-travis/-/is-travis-1.0.0.tgz#89d40ed56d9b8f8c36dfbe5811ba7e5e14944df9" + is-utf8@^0.2.0: version "0.2.1" resolved "https://registry.yarnpkg.com/is-utf8/-/is-utf8-0.2.1.tgz#4b0da1442104d1b336340e80797e865cf39f7d72" @@ -1039,15 +1043,16 @@ rx-lite@^3.1.2: version "3.1.2" resolved "https://registry.yarnpkg.com/rx-lite/-/rx-lite-3.1.2.tgz#19ce502ca572665f3b647b10939f97fd1615f102" -scrolex@0.0.24: - version "0.0.24" - resolved "https://registry.yarnpkg.com/scrolex/-/scrolex-0.0.24.tgz#07747bcf00a6770fae1514198466fa3d32515335" +scrolex@0.0.26: + version "0.0.26" + resolved "https://registry.yarnpkg.com/scrolex/-/scrolex-0.0.26.tgz#6076fb13bf8f5953225567dc08700ab695accb1c" dependencies: chalk "1.1.3" cli-spinners "0.1.2" cli-truncate "0.2.1" depurar "0.3.0" figures "1.7.0" + is-travis "1.0.0" lodash "4.17.4" log-symbols "1.0.2" log-update "1.0.2" From ca95bf275ab246ec4b2fa4e01c36ddc504d0515c Mon Sep 17 00:00:00 2001 From: Marius Date: Mon, 20 Feb 2017 17:14:58 +0100 Subject: [PATCH 10/15] Exclude too detailed information from timeout error --- unrouted_handler.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/unrouted_handler.go b/unrouted_handler.go index 7886ef2..02e4ca1 100644 --- a/unrouted_handler.go +++ b/unrouted_handler.go @@ -5,6 +5,7 @@ import ( "errors" "io" "log" + "net" "net/http" "os" "regexp" @@ -603,6 +604,14 @@ func (handler *UnroutedHandler) sendError(w http.ResponseWriter, r *http.Request err = ErrNotFound } + // Errors for read timeouts contain too much information which is not + // necessary for us and makes grouping for the metrics harder. The error + // message looks like: read tcp 127.0.0.1:1080->127.0.0.1:53673: i/o timeout + // Therefore, we use a common error message for all of them. + if netErr, ok := err.(net.Error); ok && netErr.Timeout() { + err = errors.New("read tcp: i/o timeout") + } + status := 500 if statusErr, ok := err.(HTTPError); ok { status = statusErr.StatusCode() From 68b6b206889038b13736430b0eae1424ac52a96d Mon Sep 17 00:00:00 2001 From: Marius Date: Tue, 21 Feb 2017 23:00:51 +0100 Subject: [PATCH 11/15] Add test for NotifiyUploadProgress --- patch_test.go | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/patch_test.go b/patch_test.go index d84b518..4848285 100644 --- a/patch_test.go +++ b/patch_test.go @@ -1,11 +1,13 @@ package tusd_test import ( + "io" "io/ioutil" "net/http" "os" "strings" "testing" + "time" "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" @@ -289,4 +291,68 @@ func TestPatch(t *testing.T) { Code: http.StatusNoContent, }).Run(handler, t) }) + + SubTest(t, "NotifyUploadProgress", func(t *testing.T, store *MockFullDataStore) { + gomock.InOrder( + store.EXPECT().GetInfo("yes").Return(FileInfo{ + ID: "yes", + Offset: 0, + Size: 100, + }, nil), + store.EXPECT().WriteChunk("yes", int64(0), NewReaderMatcher("first second third")).Return(int64(18), nil), + ) + + handler, _ := NewHandler(Config{ + DataStore: store, + NotifyUploadProgress: true, + }) + + c := make(chan FileInfo, 10) + handler.UploadProgress = c + + reader, writer := io.Pipe() + + go func() { + writer.Write([]byte("first ")) + <-time.After(time.Second) + writer.Write([]byte("second ")) + writer.Write([]byte("third")) + writer.Close() + }() + + (&httpTest{ + Method: "PATCH", + URL: "yes", + ReqHeader: map[string]string{ + "Tus-Resumable": "1.0.0", + "Content-Type": "application/offset+octet-stream", + "Upload-Offset": "0", + }, + ReqBody: reader, + Code: http.StatusNoContent, + ResHeader: map[string]string{ + "Upload-Offset": "18", + }, + }).Run(handler, t) + + // Wait a short time after the request has been handled before closing the + // channel because another goroutine may still write to the channel. + <-time.After(10 * time.Millisecond) + close(handler.UploadProgress) + + a := assert.New(t) + + info := <-c + a.Equal("yes", info.ID) + a.Equal(int64(100), info.Size) + a.Equal(int64(6), info.Offset) + + info = <-c + a.Equal("yes", info.ID) + a.Equal(int64(100), info.Size) + a.Equal(int64(18), info.Offset) + + _, more := <-c + a.False(more) + }) } From 73b273d4bdaa911401e65cf53311d6ed522102e8 Mon Sep 17 00:00:00 2001 From: Marius Date: Tue, 21 Feb 2017 23:17:07 +0100 Subject: [PATCH 12/15] Add documentation for NotifyUploadProgress --- config.go | 4 +++- unrouted_handler.go | 14 +++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/config.go b/config.go index f2517a2..94b4f7e 100644 --- a/config.go +++ b/config.go @@ -31,7 +31,9 @@ type Config struct { // NotifyTerminatedUploads indicates whether sending notifications about // terminated uploads using the TerminatedUploads channel should be enabled. NotifyTerminatedUploads bool - NotifyUploadProgress bool + // NotifyUploadProgress indicates whether sending notifications about + // the upload progress using the UploadProgress channel should be enabled. + NotifyUploadProgress bool // Logger is the logger to use internally, mostly for printing requests. Logger *log.Logger // Respect the X-Forwarded-Host, X-Forwarded-Proto and Forwarded headers diff --git a/unrouted_handler.go b/unrouted_handler.go index 02e4ca1..73425e8 100644 --- a/unrouted_handler.go +++ b/unrouted_handler.go @@ -85,7 +85,15 @@ type UnroutedHandler struct { // happen if the NotifyTerminatedUploads field is set to true in the Config // structure. TerminatedUploads chan FileInfo - UploadProgress chan FileInfo + // UploadProgress is used to send notifications about the progress of the + // currently running uploads. For each open PATCH request, every second + // a FileInfo instance will be send over this channel with the Offset field + // being set to the number of bytes which have been transfered to the server. + // Please be aware that this number may be higher than the number of bytes + // which have been stored by the data store! Sending to this channel will only + // happen if the NotifyUploadProgress field is set to true in the Config + // structure. + UploadProgress chan FileInfo // Metrics provides numbers of the usage for this handler. Metrics Metrics } @@ -663,6 +671,10 @@ func (w *progressWriter) Write(b []byte) (int, error) { return len(b), nil } +// sendProgressMessage will send a notification over the UploadProgress channel +// every second, indicating how much data has been transfered to the server. +// It will stop sending these instances once the returned channel has been +// closed. The returned reader should be used to read the request body. func (handler *UnroutedHandler) sendProgressMessages(info FileInfo, reader io.Reader) (io.Reader, chan<- struct{}) { progress := &progressWriter{ Offset: info.Offset, From 9a3667b8ab3aae4fcf0b9186bb3627a1ad0c645d Mon Sep 17 00:00:00 2001 From: Marius Date: Tue, 21 Feb 2017 23:24:28 +0100 Subject: [PATCH 13/15] Add documentation about post-receive event --- docs/hooks.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/hooks.md b/docs/hooks.md index 973e27a..55d6101 100644 --- a/docs/hooks.md +++ b/docs/hooks.md @@ -69,3 +69,7 @@ This event will be triggered after an upload is fully finished, meaning that all ### post-terminate This event will be triggered after an upload has been terminated, meaning that the upload has been totally stopped and all associating chunks have been fully removed from the storage. Therefore, one is not able to retrieve the upload's content anymore and one may wish to notify further applications that this upload will never be resumed nor finished. + +### post-receive + +This event will be triggered for every running upload to indicate its current progress. It will occur for each open PATCH request, every second. The offset property will be set to the number of bytes which have been transfered to the server, at the time in total. Please be aware that this number may be higher than the number of bytes which have been stored by the data store! From 9ad88c04240fe0cefdc76757a8ef484bb0ebb2f9 Mon Sep 17 00:00:00 2001 From: Marius Date: Tue, 21 Feb 2017 23:27:23 +0100 Subject: [PATCH 14/15] Include Go 1.8 release into tested versions --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 329eda8..68c7d70 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ go: - 1.5 - 1.6 - 1.7 -- 1.8beta2 +- 1.8 sudo: required cache: apt: true @@ -33,11 +33,11 @@ deploy: skip_cleanup: true on: tags: true - go: 1.7 + go: 1.8 repo: tus/tusd - provider: script script: .scripts/deploy_current.sh on: branch: master - go: 1.7 + go: 1.8 repo: tus/tusd From 45a9278c74e60682f54a1046aeae3d6e973c63cb Mon Sep 17 00:00:00 2001 From: Marius Date: Tue, 21 Feb 2017 23:33:59 +0100 Subject: [PATCH 15/15] Include channel testing in goroutine fore NotifyUploadProgress test --- patch_test.go | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/patch_test.go b/patch_test.go index 4848285..3ccb430 100644 --- a/patch_test.go +++ b/patch_test.go @@ -307,17 +307,34 @@ func TestPatch(t *testing.T) { NotifyUploadProgress: true, }) - c := make(chan FileInfo, 10) + c := make(chan FileInfo) handler.UploadProgress = c reader, writer := io.Pipe() + a := assert.New(t) go func() { writer.Write([]byte("first ")) - <-time.After(time.Second) + + info := <-c + a.Equal("yes", info.ID) + a.Equal(int64(100), info.Size) + a.Equal(int64(6), info.Offset) + writer.Write([]byte("second ")) writer.Write([]byte("third")) + + info = <-c + a.Equal("yes", info.ID) + a.Equal(int64(100), info.Size) + a.Equal(int64(18), info.Offset) + writer.Close() + + info = <-c + a.Equal("yes", info.ID) + a.Equal(int64(100), info.Size) + a.Equal(int64(18), info.Offset) }() (&httpTest{ @@ -340,18 +357,6 @@ func TestPatch(t *testing.T) { <-time.After(10 * time.Millisecond) close(handler.UploadProgress) - a := assert.New(t) - - info := <-c - a.Equal("yes", info.ID) - a.Equal(int64(100), info.Size) - a.Equal(int64(6), info.Offset) - - info = <-c - a.Equal("yes", info.ID) - a.Equal(int64(100), info.Size) - a.Equal(int64(18), info.Offset) - _, more := <-c a.False(more) })