Просмотр исходного кода

Add in check for S3 credentials

James Allen 12 лет назад
Родитель
Сommit
0d531d2641
3 измененных файлов с 49 добавлено и 6 удалено
  1. 44 3
      Gruntfile.coffee
  2. 1 1
      README.md
  3. 4 2
      package.json

+ 44 - 3
Gruntfile.coffee

@@ -4,6 +4,8 @@ exec = require("child_process").exec
 rimraf = require "rimraf"
 rimraf = require "rimraf"
 Path = require "path"
 Path = require "path"
 semver = require "semver"
 semver = require "semver"
+settings = require "settings-sharelatex"
+knox = require "knox"
 
 
 SERVICES = [{
 SERVICES = [{
 	name: "web"
 	name: "web"
@@ -89,7 +91,9 @@ module.exports = (grunt) ->
 		Helpers.checkRedis @async()
 		Helpers.checkRedis @async()
 	grunt.registerTask "check:latexmk", "Check that latexmk is installed", () ->
 	grunt.registerTask "check:latexmk", "Check that latexmk is installed", () ->
 		Helpers.checkLatexmk @async()
 		Helpers.checkLatexmk @async()
-	grunt.registerTask "check", "Check that you have the required dependencies installed", ["check:redis", "check:latexmk"]
+	grunt.registerTask "check:s3", "Check that Amazon S3 credentials are configured", () ->
+		Helpers.checkS3 @async()
+	grunt.registerTask "check", "Check that you have the required dependencies installed", ["check:redis", "check:latexmk", "check:s3"]
 
 
 	Helpers =
 	Helpers =
 		installService: (repo_src, dir, callback = (error) ->) ->
 		installService: (repo_src, dir, callback = (error) ->) ->
@@ -141,7 +145,7 @@ module.exports = (grunt) ->
 			exec "redis-cli info", (error, stdout, stderr) ->
 			exec "redis-cli info", (error, stdout, stderr) ->
 				if error? and error.message.match("Could not connect")
 				if error? and error.message.match("Could not connect")
 					grunt.log.error "FAIL. Redis is not running"
 					grunt.log.error "FAIL. Redis is not running"
-					return
+					return callback(error)
 				else if error?
 				else if error?
 					return callback(error)
 					return callback(error)
 				else
 				else
@@ -149,6 +153,7 @@ module.exports = (grunt) ->
 					if !m?
 					if !m?
 						grunt.log.error "FAIL."
 						grunt.log.error "FAIL."
 						grunt.log.error "Unknown redis version"
 						grunt.log.error "Unknown redis version"
+						error = new Error("Unknown redis version")
 					else
 					else
 						version = m[1]
 						version = m[1]
 						if semver.gt(version, "2.6.0")
 						if semver.gt(version, "2.6.0")
@@ -157,7 +162,8 @@ module.exports = (grunt) ->
 						else
 						else
 							grunt.log.error "FAIL."
 							grunt.log.error "FAIL."
 							grunt.log.error "Redis version is too old (#{version}). Must be 2.6.0 or greater."
 							grunt.log.error "Redis version is too old (#{version}). Must be 2.6.0 or greater."
-				callback()
+							error = new Error("Redis version is too old (#{version}). Must be 2.6.0 or greater.")
+				callback(error)
 
 
 		checkLatexmk: (callback = (error) ->) ->
 		checkLatexmk: (callback = (error) ->) ->
 			grunt.log.write "Checking latexmk is installed... "
 			grunt.log.write "Checking latexmk is installed... "
@@ -170,6 +176,7 @@ module.exports = (grunt) ->
 					latexmk comes with TexLive 2013, and must be a version from 2013 or later.
 					latexmk comes with TexLive 2013, and must be a version from 2013 or later.
 					This is a not a fatal error, but compiling will not work without latexmk
 					This is a not a fatal error, but compiling will not work without latexmk
 					"""
 					"""
+					return callback(error)
 				else if error?
 				else if error?
 					return callback(error)
 					return callback(error)
 				else
 				else
@@ -177,6 +184,7 @@ module.exports = (grunt) ->
 					if !m?
 					if !m?
 						grunt.log.error "FAIL."
 						grunt.log.error "FAIL."
 						grunt.log.error "Unknown latexmk version"
 						grunt.log.error "Unknown latexmk version"
+						error = new Error("Unknown latexmk version")
 					else
 					else
 						version = m[1]
 						version = m[1]
 						if semver.gte(version + ".0", "4.39.0")
 						if semver.gte(version + ".0", "4.39.0")
@@ -188,6 +196,39 @@ module.exports = (grunt) ->
 							latexmk version is too old (#{version}). Must be 4.39 or greater.
 							latexmk version is too old (#{version}). Must be 4.39 or greater.
 							This is a not a fatal error, but compiling will not work without latexmk
 							This is a not a fatal error, but compiling will not work without latexmk
 							"""
 							"""
+							error = new Error("latexmk is too old")
+				callback(error)
+
+		checkS3: (callback = (error) ->) ->
+			grunt.log.write "Checking S3 credentials... "
+			try
+				client = knox.createClient({
+					key: settings.s3.key
+					secret: settings.s3.secret
+					bucket: settings.s3.buckets.user_files
+				})
+			catch e
+				grunt.log.error "FAIL."
+				grunt.log.errorlns """
+				Please configure you Amazon S3 credentials in config/settings.development.coffee
+
+				Amazon S3 (Simple Storage Service) is a cloud storage service provided by
+				Amazon. ShareLaTeX uses S3 for storing binary files like images. You can 
+				sign up for an account and find out more at:
+
+				    http://aws.amazon.com/s3/
+                  
+				"""
+				return callback()
+
+			client.getFile "does-not-exist", (error, response) ->
+				unless response? and response.statusCode == 404
+					grunt.log.error "FAIL."
+					grunt.log.errorlns """
+					Could not connect to Amazon S3. Please check your credentials.
+					"""
+				else
+					grunt.log.write "OK."
 				callback()
 				callback()
 
 
 
 

+ 1 - 1
README.md

@@ -26,7 +26,7 @@ Next install all the node modules and ShareLaTeX services:
 Now check that your system is set up correctly to run ShareLaTeX (checks that you have
 Now check that your system is set up correctly to run ShareLaTeX (checks that you have
 the required dependencies installed.) Watch out for any failures.
 the required dependencies installed.) Watch out for any failures.
 
 
-	$ grunt check
+	$ grunt check --force
 
 
 When that has finished, run ShareLaTeX with
 When that has finished, run ShareLaTeX with
 
 

+ 4 - 2
package.json

@@ -2,7 +2,8 @@
   "name": "sharelatex",
   "name": "sharelatex",
   "description": "An online collaborative LaTeX editor",
   "description": "An online collaborative LaTeX editor",
   "dependencies": {
   "dependencies": {
-    "rimraf": "~2.2.6"
+    "rimraf": "~2.2.6",
+    "settings-sharelatex": "git+https://github.com/sharelatex/settings-sharelatex.git"
   },
   },
   "devDependencies": {
   "devDependencies": {
     "grunt": "~0.4.2",
     "grunt": "~0.4.2",
@@ -11,6 +12,7 @@
     "grunt-execute": "~0.1.5",
     "grunt-execute": "~0.1.5",
     "grunt-available-tasks": "~0.4.1",
     "grunt-available-tasks": "~0.4.1",
     "grunt-concurrent": "~0.4.3",
     "grunt-concurrent": "~0.4.3",
-    "semver": "~2.2.1"
+    "semver": "~2.2.1",
+    "knox": "~0.8.9"
   }
   }
 }
 }