检索闪亮服务器配置的数据

时间:2020-05-20 20:56:24

标签: r shiny shiny-server

/etc/shiny-server/shiny-server.conf中,我有一个SSL configuration,看起来像:

server {
  # ...
  ssl /etc/path/to/ssl-key.pem /etc/path/to/ssl.cert;
  # ...
}

现在,从运行Shiny Server的服务器上的R REPL中,我很好奇是否有一种方法可以通过任何类型的shiny-server.conf# server.R library(shiny) shinyServer(function(input, output, session){ # ... ? }) 检索配置数据半)官方API。

类似的东西:

"ssl": ["/etc/path/to/ssl-key.pem", "/etc/path/to/ssl.cert"]

这将产生以下效果:

import scrapy
from scrapy.crawler import CrawlerProcess

class myspider(scrapy.Spider):
    name = 'my_spider'

    name_loc = '//div[@id="divListView"]//h4/a/text()'
    price_loc = 'div.price > span::text'
    def start_requests(self):
        yield scrapy.Request('url=https://www.czone.com.pk/mouse-pakistan-ppt.95.aspx', callback=self.parse)

    def parse(self, reponse):
        page1_prices = response.css(myspider.price_loc).extract()
        page1_names = response.xpath(myspider.name_loc).extract()
        for price, name in zip(page1_prices, page1_names):
            mice_names.append(name)
            mice_prices.append(price)
        links = response.css('a.PageNumber::attr(href)').extract()
        for link in links:
            yield response.follow(url=link, callback=self.parse_pages)

    def parse_pages(self, response):
        page_prices = response.css(myspider.price_loc).extract()
        page_names = response.xpath(myspider.name_loc).extract()
        for price, name in zip(page_prices, page_names):
            mice_names.append(name)
            mice_prices.append(price)
mice_names = []
mice_prices = []

process = CrawlerProcess()
process.crawl(myspider)
process.start()
print(mice_names)
print(mice_prices)

1 个答案:

答案 0 :(得分:1)

老实说,我认为您无法访问该页面,因为允许应用程序(因此是“常规用户”)查看配置项可能会带来安全风险。 (例如,其中可能包含SAML / LDAP / ...配置的机密。)

现在我不知道这个答案能解决这个问题,它可能使您能够找到需要的东西。

注意:我故意过滤掉session中的几种类型的对象,因为我发现它们要么崩溃了(它们是复杂的复合对象,也许是谁知道它们中的内容),要么它们是显然只是无关紧要的。如果您想对被过滤掉的内部结构有更多的了解,可以将其saveRDS存入文件并从服务器中检索出来。

library(shiny)

ui <- bootstrapPage(
  h3("Parsed query string"),
  verbatimTextOutput("queryText"),
  h3("URL components"),
  verbatimTextOutput("sessionText"),
  h3("EnvVars"),
  verbatimTextOutput("envvarText")
)

server <- function(input, output, session) {
  # Parse the GET query string
  output$queryText <- renderText({
    query <- parseQueryString(session$clientData$url_search)
    # Return a string with key-value pairs
    paste(names(query), query, sep = "=", collapse=", ")
  })
  # Return the components of the URL in a string:
  output$sessionText <- renderText({
    cls <- sapply(session, function(a) class(a)[1])
    nms <- names(cls[ cls %in% c("list", "character", "numeric", "integer", "NULL", "logical", "environment") ])
    nms <- setdiff(nms, ".__enclos_env__")
    paste(
      capture.output(
        str(
          sapply(nms,
                 function(sessnm) {
                   if (inherits(session[[sessnm]], c("environment", "reactivevalues"))) {
                     sapply(names(session[[sessnm]]), function(nm) session[[sessnm]][[nm]], simplify = FALSE)
                   } else if (inherits(session[[sessnm]], c("character", "numeric", "integer"))) {
                     session[[sessnm]]
                   } else class(session[[sessnm]])
                 }, simplify = FALSE),
          nchar.max = 1e5,
          vec.len = 1e5
        )
      ),
      collapse = "\n"
    )
  })
  # Dump the environment variables
  output$envvarText <- renderText({
    paste(
      capture.output(
        str(as.list(Sys.getenv()))
      ),
      collapse = "\n"
    )
  })
}

shinyApp(ui, server)

这呈现了这样的内容(一些隐私被屏蔽了,并且通常很模糊,因为根据您的特定服务器,您的结果可能有所不同。

enter image description here

这是在Ubuntu 16.04上托管的RStudio Connect v1.8.2上。通过SAML进行身份验证;其他身份验证方法的字段可能略有不同(或多或少)。

相关问题