Dynamic addition of sites? #82

Open
opened 2022-05-18 14:13:03 +00:00 by Ghost · 1 comment

I want to set up the server in such a way that users can add sites and get certificates on their own.

I see that sites are only added in the config. Is there any possibility to do something like this?

app.use('/add-site', () => {
  const domains = ['foo.com', 'www.foo.com']
  greenlockExpress.add(domains)
})

And store, for example, a config file in s3 buckets? Now I managed to store only certificates. The configuration file is still in the same place as the application.

I want to set up the server in such a way that users can add sites and get certificates on their own. I see that sites are only added in the config. Is there any possibility to do something like this? ``` app.use('/add-site', () => { const domains = ['foo.com', 'www.foo.com'] greenlockExpress.add(domains) }) ``` And store, for example, a config file in s3 buckets? Now I managed to store only certificates. The configuration file is still in the same place as the application.
Author

Used by dynamodb to store the configuration. Include this file in the greenlock configuration. I took this code from the repository (unfortunately I don’t remember which one), but there was an implementation on mongodb, I changed it to dynamodb.

To add a new site, you simply add information about it to dynamodb.

This code passes all tests.

const Domain = require('../models/domain')

const manager = {}

module.exports = {
  create: (opts = {}) => {
    let config = {}

    config = {
      ...opts,
    }

    manager.set = async (opts) => {
      try {
        let site

        const id = opts.subject
        const { Item } = await Domain.get(id)

        site = {
          ...opts,
        }

        if (Item) {
          site = {
            ...Item,
            ...site,
          }
        }

        return Domain.put({ subject: id, ...site })
      } catch (e) {
        console.log('manager set error: ', e.message)
        throw e
      }
    }

    manager.get = async (opts) => {
      try {
        const { servername, wildname } = opts
        const id = servername || wildname

        return Domain.get(id)
      } catch (e) {
        console.log('manager get error: ', e.message)
        throw e
      }
    }

    manager.defaults = async (opts) => {
      config = {
        ...config,
        ...opts,
      }

      return config
    }

    manager.find = async (opts) => {
      const res = await Domain.scan()

      const allConfigs = res.Items

      const { subject, servernames } = opts
      if (!subject && !servernames) {
        return allConfigs
      }

      if (subject) {
        const configsBySubject = allConfigs.filter((config) => config.subject === subject)

        if (configsBySubject.length) {
          return configsBySubject
        }
      }
      if (servernames && servernames.length) {
        const configsByServernames = allConfigs.filter((config) => (
          servernames.includes(config.subject) ||
          servernames.find((servername) => config.altnames?.includes(servername))
        ))

        if (configsByServernames.length) {
          return configsByServernames
        }
      }
      return []
    }

    return manager
  },
  _manager: manager,
}

Used by dynamodb to store the configuration. Include this file in the greenlock configuration. I took this code from the repository (unfortunately I don’t remember which one), but there was an implementation on mongodb, I changed it to dynamodb. To add a new site, you simply add information about it to dynamodb. This code passes all tests. ``` const Domain = require('../models/domain') const manager = {} module.exports = { create: (opts = {}) => { let config = {} config = { ...opts, } manager.set = async (opts) => { try { let site const id = opts.subject const { Item } = await Domain.get(id) site = { ...opts, } if (Item) { site = { ...Item, ...site, } } return Domain.put({ subject: id, ...site }) } catch (e) { console.log('manager set error: ', e.message) throw e } } manager.get = async (opts) => { try { const { servername, wildname } = opts const id = servername || wildname return Domain.get(id) } catch (e) { console.log('manager get error: ', e.message) throw e } } manager.defaults = async (opts) => { config = { ...config, ...opts, } return config } manager.find = async (opts) => { const res = await Domain.scan() const allConfigs = res.Items const { subject, servernames } = opts if (!subject && !servernames) { return allConfigs } if (subject) { const configsBySubject = allConfigs.filter((config) => config.subject === subject) if (configsBySubject.length) { return configsBySubject } } if (servernames && servernames.length) { const configsByServernames = allConfigs.filter((config) => ( servernames.includes(config.subject) || servernames.find((servername) => config.altnames?.includes(servername)) )) if (configsByServernames.length) { return configsByServernames } } return [] } return manager }, _manager: manager, } ```
Sign in to join this conversation.
No Label
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: root/greenlock-express.js#82
No description provided.