2

I've been trying to use the greenlock.js module for Node to try and obtain ssl certificates for a domain registered in cloudflare.

I have seen some examples on greenlock-express, however, I would like to use this module without needing to use express.

The issue is that I obtain the following error when creating the greenlock object:

internal/validators.js:120
    throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
    at validateString (internal/validators.js:120:11)
    at Object.resolve (path.js:980:7)
    at Object.Init._init (/git_reps/greenlock_test/node_modules/@root/greenlock/lib/init.js:128:14)
    at Object.greenlock._create (/git_reps/greenlock_test/node_modules/@root/greenlock/greenlock.js:58:22)
    at Object.G.create (/git_reps/greenlock_test/node_modules/@root/greenlock/greenlock.js:482:15)
    at Object.<anonymous> (/git_reps/greenlock_test/greenlock-test.js:13:27)
    at Module._compile (internal/modules/cjs/loader.js:1138:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
    at Module.load (internal/modules/cjs/loader.js:986:32)
    at Function.Module._load (internal/modules/cjs/loader.js:879:14) {
  code: 'ERR_INVALID_ARG_TYPE'
}

My code is as follows, I have not even implemented any other function yet because it breaks here:

  1 'use strict'
  2 
  3 const pkg = require ('./package.json');
  4 const Greenlock = require('greenlock');
  5 const acmeDnsCloudflare = require('acme-dns-01-cloudflare');
  6 
  7 const cloudflareDns01 = new acmeDnsCloudflare({
  8         token: 'dummyToken',
  9         verifyPropagation: true,
 10         verbose: true
 11 });


 13 let greenlock = Greenlock.create({
 14         configDir: './greenlock.d/config.json',
 15         packageAgent: pkg.name + '/' + pkg.version,
 16         maintainerEmail: 'maintaner@example.com',
 17         staging: true,
 18         notify: function(event, details){
 19                 if('error'=== event){
 20                         console.error(details);
 21                 }
 22         }
 23 });


1 Answers1

1

I don't know wich version you're using, using current 4.0.5 the challenge module has to be defined as a string and is instanciate internally by GreenLock

"use strict";

var config_ovh = require('./my_modules/config_ovh');
var pkg = require("./package.json");
var Greenlock = require("@root/greenlock");

var greenlock = Greenlock.create({
    packageRoot: __dirname,
    configDir: "./greenlock.d/",
    packageAgent: pkg.name + "/" + pkg.version,
    maintainerEmail: "me@domain.fr",
    staging: true,
    notify: function (event, details) {
        if ("error" === event) {
            console.error('greenlock notify :' + event, details);
        }
    },
});

greenlock.manager
    .defaults({
        agreeToTerms: true,
        subscriberEmail: "me@domain.fr",
        store: {
            module: "greenlock-store-fs",
            basePath: "./certs",
        },
        challenges: {
            "dns-01": {
                module: "acme-dns-01-ovh",
                appKey: config_ovh.appKey,
                appSecret: config_ovh.appSecret,
                consumerKey: config_ovh.consumerKey,
                region: "ovh-eu",
                propagationDelay: 5000,
            },
        },
    })
    .then(function (fullConfig) {
        //...
    });

var altnames = [
    "sub1.domain.fr",
    "sub2.domain.fr",
];

greenlock
    .add({
        subject: altnames[0],
        altnames: altnames,
    })
    .then(function () {
        // saved config to db (or file system)
        console.log('greenlock then', arguments);
    });

This code successfully generates the certificates (acme-dns-01-ovh being my own implementation for the OVH DNS challenge), but the process terminates and I currently don't see how the auto-renewal works...

Damien
  • 11
  • 1