| 
									
										
										
										
											2016-08-05 03:54:57 -04:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var fs = require('fs'); | 
					
						
							|  |  |  | var path = require('path'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-05 04:10:33 -04:00
										 |  |  | var defaults = { | 
					
						
							| 
									
										
										
										
											2016-08-09 12:57:41 -04:00
										 |  |  |   webrootPath: [ '~', 'letsencrypt', 'var', 'lib' ].join(path.sep) | 
					
						
							| 
									
										
										
										
											2016-08-05 04:10:33 -04:00
										 |  |  | , debug: false | 
					
						
							| 
									
										
										
										
											2016-08-05 03:54:57 -04:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 12:57:41 -04:00
										 |  |  | var Challenge = module.exports; | 
					
						
							| 
									
										
										
										
											2016-08-05 04:10:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 12:57:41 -04:00
										 |  |  | Challenge.create = function (options) { | 
					
						
							| 
									
										
										
										
											2016-08-05 04:10:33 -04:00
										 |  |  |   var results = {}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 12:57:41 -04:00
										 |  |  |   Object.keys(Challenge).forEach(function (key) { | 
					
						
							|  |  |  |     results[key] = Challenge[key]; | 
					
						
							| 
									
										
										
										
											2016-08-05 04:10:33 -04:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2016-08-09 12:57:41 -04:00
										 |  |  |   results.create = undefined; | 
					
						
							| 
									
										
										
										
											2016-08-05 04:10:33 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   Object.keys(defaults).forEach(function (key) { | 
					
						
							|  |  |  |     if (!(key in options)) { | 
					
						
							|  |  |  |       options[key] = defaults[key]; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2016-08-09 12:57:41 -04:00
										 |  |  |   results._options = options; | 
					
						
							| 
									
										
										
										
											2016-08-05 04:10:33 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   results.getOptions = function () { | 
					
						
							|  |  |  |     return results._options; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return results; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 13:05:36 -04:00
										 |  |  | //
 | 
					
						
							|  |  |  | // NOTE: the "args" here in `set()` are NOT accessible to `get()` and `remove()`
 | 
					
						
							|  |  |  | // They are provided so that you can store them in an implementation-specific way
 | 
					
						
							|  |  |  | // if you need access to them.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | Challenge.set = function (args, domain, challengePath, keyAuthorization, done) { | 
					
						
							| 
									
										
										
										
											2016-08-05 03:54:57 -04:00
										 |  |  |   var mkdirp = require('mkdirp'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 13:05:36 -04:00
										 |  |  |   mkdirp(args.webrootPath, function (err) { | 
					
						
							| 
									
										
										
										
											2016-08-05 03:54:57 -04:00
										 |  |  |     if (err) { | 
					
						
							|  |  |  |       done(err); | 
					
						
							|  |  |  |       return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 13:05:36 -04:00
										 |  |  |     fs.writeFile(path.join(args.webrootPath, challengePath), keyAuthorization, 'utf8', function (err) { | 
					
						
							| 
									
										
										
										
											2016-08-05 03:54:57 -04:00
										 |  |  |       done(err); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 13:05:36 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // NOTE: the "defaults" here are still merged and templated, just like "args" would be,
 | 
					
						
							|  |  |  | // but if you specifically need "args" you must retrieve them from some storage mechanism
 | 
					
						
							|  |  |  | // based on domain and key
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2016-08-09 12:57:41 -04:00
										 |  |  | Challenge.get = function (defaults, domain, key, done) { | 
					
						
							|  |  |  |   fs.readFile(path.join(defaults.webrootPath, key), 'utf8', done); | 
					
						
							| 
									
										
										
										
											2016-08-05 03:54:57 -04:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 12:57:41 -04:00
										 |  |  | Challenge.remove = function (defaults, domain, key, done) { | 
					
						
							|  |  |  |   fs.unlink(path.join(defaults.webrootPath, key), done); | 
					
						
							| 
									
										
										
										
											2016-08-05 03:54:57 -04:00
										 |  |  | }; |