-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathentrypoint.R
More file actions
48 lines (42 loc) · 799 Bytes
/
entrypoint.R
File metadata and controls
48 lines (42 loc) · 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
box::use(
plumber[
pr,
pr_run,
pr_set_api_spec
],
here[
here
]
)
add_auth <- function(
api,
paths = NULL
) {
api[["components"]] <- list(
securitySchemes = list(
ApiKeyAuth = list(
type = "apiKey",
`in` = "header",
name = "X-API-KEY",
description = "Add API Key here"
)
)
)
if (is.null(paths)) paths <- names(api$paths)
for (path in paths) {
nn <- names(api$paths[[path]])
for (p in intersect(nn, c("get", "head", "post", "put", "delete"))) {
api$paths[[path]][[p]] <- c(
api$paths[[path]][[p]],
list(security = list(list(ApiKeyAuth = vector())))
)
}
}
api
}
pr("plumber.R") |>
pr_set_api_spec(add_auth) |>
pr_run(
port = 8008,
host = "0.0.0.0"
)