@cocreate/acme 1.2.0 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [1.2.2](https://github.com/CoCreate-app/CoCreate-acme/compare/v1.2.1...v1.2.2) (2024-01-08)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * ssl syncing ([65b226a](https://github.com/CoCreate-app/CoCreate-acme/commit/65b226a16487f3b8b6862092f6b3e83d8f119f51))
7
+
8
+ ## [1.2.1](https://github.com/CoCreate-app/CoCreate-acme/compare/v1.2.0...v1.2.1) (2024-01-08)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * handling hostPosition ([fa105b1](https://github.com/CoCreate-app/CoCreate-acme/commit/fa105b1a35927380cd88549d7675eebd2d80a163))
14
+
1
15
  # [1.2.0](https://github.com/CoCreate-app/CoCreate-acme/compare/v1.1.3...v1.2.0) (2024-01-08)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/acme",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "An intergration with ACME and CoCreateJS.",
5
5
  "keywords": [
6
6
  "acme",
package/src/index.js CHANGED
@@ -169,6 +169,8 @@ class CoCreateAcme {
169
169
  expires = expires.notAfter;
170
170
  this.setCertificate(host, expires, organization_id, hostKeyPath, cert, key)
171
171
 
172
+ console.log(`saving host: ${host} at postion: ${hostPosition}`)
173
+
172
174
  this.crud.send({
173
175
  method: 'object.update',
174
176
  host,
@@ -192,6 +194,7 @@ class CoCreateAcme {
192
194
 
193
195
  async getCertificate(host, organization_id) {
194
196
  const hostKeyPath = keyPath + host + '/';
197
+ let hostPosition
195
198
 
196
199
  if (!organization_id) {
197
200
  let org = await this.crud.getHost(host)
@@ -207,7 +210,6 @@ class CoCreateAcme {
207
210
  return false
208
211
 
209
212
  if (organization.host) {
210
- let hostPosition
211
213
  for (let i = 0; i < organization.host.length; i++) {
212
214
  if (organization.host[i].name === host) {
213
215
  hostPosition = i
@@ -223,7 +225,7 @@ class CoCreateAcme {
223
225
  }
224
226
  }
225
227
 
226
- if (hostPosition >= 0)
228
+ if (!hostPosition && hostPosition !== 0)
227
229
  return false
228
230
  }
229
231
 
@@ -241,11 +243,62 @@ class CoCreateAcme {
241
243
 
242
244
  const hostKeyPath = keyPath + host + '/';
243
245
  if (fs.existsSync(hostKeyPath + 'fullchain.pem')) {
244
- let expires = fs.readFileSync(hostKeyPath + 'fullchain.pem', 'utf8');
245
- expires = await forge.readCertificateInfo(expires);
246
+ let cert = fs.readFileSync(hostKeyPath + 'fullchain.pem', 'utf8');
247
+ let expires = await forge.readCertificateInfo(cert);
246
248
  expires = expires.notAfter;
247
249
  if (this.isValid(expires)) {
248
250
  this.setCertificate(host, expires, organization_id)
251
+
252
+ // TODO: remove after certs are synced
253
+ let key = fs.readFileSync(hostKeyPath + 'private-key.pem', 'utf8');
254
+ let hostPosition, org
255
+
256
+ if (!organization_id) {
257
+ let org = await this.crud.getHost(host)
258
+ if (org.error)
259
+ // console.log('Organization could not be found');
260
+ return false
261
+ else
262
+ organization_id = org._id
263
+ }
264
+
265
+ let organization = await this.crud.getOrganization(organization_id, false);
266
+ if (organization.error)
267
+ return false
268
+
269
+ if (organization.host) {
270
+ for (let i = 0; i < organization.host.length; i++) {
271
+ if (organization.host[i].name === host) {
272
+ hostPosition = i
273
+ console.log(`Found host: ${host} at postion: ${hostPosition}`)
274
+
275
+ if (organization.host[i].cert && organization.host[i].key) {
276
+ let expires = await forge.readCertificateInfo(organization.host[i].cert);
277
+ expires = expires.notAfter;
278
+ if (this.isValid(expires)) {
279
+ this.setCertificate(host, expires, organization_id, hostKeyPath, organization.host[i].cert, organization.host[i].key)
280
+ return true
281
+ }
282
+ }
283
+ break
284
+ }
285
+ }
286
+
287
+ if (!hostPosition && hostPosition !== 0)
288
+ return false
289
+ }
290
+
291
+ this.crud.send({
292
+ method: 'object.update',
293
+ host,
294
+ array: 'organizations',
295
+ object: {
296
+ _id: organization_id,
297
+ [`host[${hostPosition}]`]: { name: host, cert, key, expires },
298
+ },
299
+ organization_id
300
+ });
301
+
249
302
  return true
250
303
  }
251
304
  }