-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c97c28
commit 3647d9c
Showing
12 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
...ode_snippets/snippets/config/instances.enabled/application_validate_cfg_array/config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
groups: | ||
group001: | ||
replicasets: | ||
replicaset001: | ||
instances: | ||
instance001: | ||
roles: [ http-api ] | ||
roles_cfg: | ||
http-api: | ||
- host: '127.0.0.1' | ||
port: 8080 | ||
scheme: 'http' | ||
- host: '127.0.0.1' | ||
port: 8443 | ||
scheme: 'https' |
34 changes: 34 additions & 0 deletions
34
...de_snippets/snippets/config/instances.enabled/application_validate_cfg_array/http-api.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
-- 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.array({ | ||
items = 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) | ||
for _, uri in pairs(cfg) do | ||
local scheme = uri.scheme | ||
local host = uri.host | ||
local port = uri.port | ||
log.info("HTTP API endpoint: %s://%s:%d", scheme, host, port) | ||
end | ||
end | ||
|
||
local function stop() | ||
log.info("The 'http_api' role is stopped") | ||
end | ||
|
||
return { | ||
validate = validate, | ||
apply = apply, | ||
stop = stop, | ||
} |
1 change: 1 addition & 0 deletions
1
...e_snippets/snippets/config/instances.enabled/application_validate_cfg_array/instances.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
instance001: |
15 changes: 15 additions & 0 deletions
15
doc/code_snippets/snippets/config/instances.enabled/application_validate_cfg_map/config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
groups: | ||
group001: | ||
replicasets: | ||
replicaset001: | ||
instances: | ||
instance001: | ||
roles: [ http_api ] | ||
roles_cfg: | ||
http_api: | ||
host: '127.0.0.1' | ||
port: 8080 | ||
scheme: 'http' | ||
query_params: | ||
skip: 0 | ||
limit: 10 |
39 changes: 39 additions & 0 deletions
39
...code_snippets/snippets/config/instances.enabled/application_validate_cfg_map/http_api.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
-- http_api.lua -- | ||
log = require('log').new("http_api") | ||
schema = require('experimental.config.utils.schema') | ||
|
||
listen_address_schema = schema.new('listen_address', schema.record({ | ||
scheme = schema.enum({ 'http', 'https' }), | ||
host = schema.scalar({ type = 'string' }), | ||
port = schema.scalar({ type = 'integer' }), | ||
query_params = schema.map({ key = schema.scalar({ type = 'string' }), | ||
value = schema.scalar({ type = 'integer' }) }) | ||
})) | ||
|
||
local function validate(cfg) | ||
listen_address_schema:validate(cfg) | ||
end | ||
|
||
local function apply(cfg) | ||
test_cfg = cfg | ||
local scheme = listen_address_schema:get(cfg, 'scheme') | ||
local host = listen_address_schema:get(cfg, 'host') | ||
local port = listen_address_schema:get(cfg, 'port') | ||
local query_params = listen_address_schema:get(cfg, 'query_params') | ||
local query_string = '' | ||
for name, value in pairs(query_params) do | ||
query_string = query_string .. name .. '=' .. value .. '&' | ||
end | ||
local query_string_without_amp = string.gsub(query_string, "&$", "") | ||
log.info("HTTP API endpoint: %s://%s:%d?%s", scheme, host, port, query_string_without_amp) | ||
end | ||
|
||
local function stop() | ||
log.info("The 'http_api' role is stopped") | ||
end | ||
|
||
return { | ||
validate = validate, | ||
apply = apply, | ||
stop = stop, | ||
} |
1 change: 1 addition & 0 deletions
1
...ode_snippets/snippets/config/instances.enabled/application_validate_cfg_map/instances.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
instance001: |
12 changes: 12 additions & 0 deletions
12
...de_snippets/snippets/config/instances.enabled/application_validate_cfg_record/config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
groups: | ||
group001: | ||
replicasets: | ||
replicaset001: | ||
instances: | ||
instance001: | ||
roles: [ http_api ] | ||
roles_cfg: | ||
http_api: | ||
host: '127.0.0.1' | ||
port: 8080 | ||
scheme: 'http' |
30 changes: 30 additions & 0 deletions
30
...e_snippets/snippets/config/instances.enabled/application_validate_cfg_record/http_api.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
-- 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({ | ||
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, 'scheme') | ||
local host = listen_address_schema:get(cfg, 'host') | ||
local port = listen_address_schema:get(cfg, '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, | ||
} |
1 change: 1 addition & 0 deletions
1
..._snippets/snippets/config/instances.enabled/application_validate_cfg_record/instances.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
instance001: |
9 changes: 9 additions & 0 deletions
9
...de_snippets/snippets/config/instances.enabled/application_validate_cfg_scalar/config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
groups: | ||
group001: | ||
replicasets: | ||
replicaset001: | ||
instances: | ||
instance001: | ||
roles: [ http_api ] | ||
roles_cfg: | ||
http_api: 'http://127.0.0.1:8080' |
24 changes: 24 additions & 0 deletions
24
...e_snippets/snippets/config/instances.enabled/application_validate_cfg_scalar/http_api.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
-- http_api.lua -- | ||
local log = require('log').new("http_api") | ||
local schema = require('experimental.config.utils.schema') | ||
|
||
local http_api_schema = schema.new('http_api', schema.scalar({ type = 'string' })) | ||
|
||
local function validate(cfg) | ||
http_api_schema:validate(cfg) | ||
end | ||
|
||
local function apply(cfg) | ||
local http_api_cfg = http_api_schema:get(cfg) | ||
log.info("HTTP API endpoint: %s", http_api_cfg) | ||
end | ||
|
||
local function stop() | ||
log.info("The 'http_api' role is stopped") | ||
end | ||
|
||
return { | ||
validate = validate, | ||
apply = apply, | ||
stop = stop, | ||
} |
1 change: 1 addition & 0 deletions
1
..._snippets/snippets/config/instances.enabled/application_validate_cfg_scalar/instances.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
instance001: |