Skip to content

Commit

Permalink
Support for etcd3
Browse files Browse the repository at this point in the history
  • Loading branch information
ceecko committed Apr 5, 2021
1 parent 0c18202 commit 4b54c40
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 54 deletions.
59 changes: 7 additions & 52 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
const path = require('path');

const myDefaults = {
// etcd object which provides .get(), .set() and .del() methods such as "node-etcd" module
// etcd3 object
etcdObj: null,
// etcd path prefix where challenges are stored
etcdPathPrefix: '/le-challenge-etcd/',
etcdPathPrefix: 'le-challenge-etcd/',
};

module.exports = cfg => {
Expand All @@ -16,55 +14,12 @@ module.exports = cfg => {

return {
init: async () => {},

get: opts => {
return new Promise((resolve, reject) => {
options.etcdObj.get(
path.posix.join(options.etcdPathPrefix, opts.challenge.token),
(err, data) => {
if(err) {
reject(err)
return
}

resolve({keyAuthorization: data.node.value})
}
)
})
get: async opts => {
const value = await options.etcdObj.get(`${options.etcdPathPrefix}${opts.challenge.token}`)
return {keyAuthorization: value}
},

set: opts => {
return new Promise((resolve, reject) => {
options.etcdObj.set(
path.posix.join(options.etcdPathPrefix, opts.challenge.token),
opts.challenge.keyAuthorization,
err => {
if(err) {
reject(err)
return
}

resolve()
}
)
})
},

remove: opts => {
return new Promise((resolve, reject) => {
options.etcdObj.del(
path.posix.join(options.etcdPathPrefix, opts.challenge.token),
err => {
if(err) {
reject(err)
return
}

resolve()
}
)
})
}
set: opts => options.etcdObj.put(`${options.etcdPathPrefix}${opts.challenge.token}`).value(opts.challenge.keyAuthorization),
remove: opts => options.etcdObj.delete().key(`${options.etcdPathPrefix}${opts.challenge.token}`),
}
}

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "le-challenge-etcd",
"version": "2.0.0",
"description": "An etcd-based strategy for greenlock v4 for reading, setting and removing ACME challenges",
"version": "3.0.0",
"description": "An etcd3-based strategy for greenlock v4 for reading, setting and removing ACME challenges",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand All @@ -16,6 +16,7 @@
"cluster",
"ephemeral",
"etcd",
"etcd3",
"http",
"http-01",
"le",
Expand Down

0 comments on commit 4b54c40

Please sign in to comment.