Skip to content

Commit

Permalink
Schema validation - new sample
Browse files Browse the repository at this point in the history
  • Loading branch information
andreyaksenov committed Sep 12, 2024
1 parent ac1177b commit 01cbe38
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
groups:
group001:
replicasets:
replicaset001:
instances:
instance001:
roles: [ http_api ]
roles_cfg:
http_api:
listen_address:
host: '127.0.0.1'
port: 8080
scheme: 'http'
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
-- http_api.lua --
local log = require('log').new("http_api")
local schema = require('experimental.config.utils.schema')

local listen_address_schema = schema.new('listen_address', schema.record({
listen_address = schema.record({
scheme = schema.enum({ 'http', 'https' }),
host = schema.scalar({ type = 'string' }),
port = schema.scalar({ type = 'integer' })
})
}))

local function validate(cfg)
listen_address_schema:validate(cfg)
end

local function apply(cfg)
local scheme = listen_address_schema:get(cfg, 'listen_address.scheme')
local host = listen_address_schema:get(cfg, 'listen_address.host')
local port = listen_address_schema:get(cfg, 'listen_address.port')
log.info("HTTP API endpoint: %s://%s:%d", scheme, host, port)
end

local function stop()
log.info("The 'http_api' role is stopped")
end

return {
validate = validate,
apply = apply,
stop = stop,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
instance001:

0 comments on commit 01cbe38

Please sign in to comment.