简介

为了让你的设施接入Shifu。咱们用Go编写了一个简略的HTTP到 PowerShell 的中间件,供开发者应用。

设计

这个HTTP到PowerShell的中间件是这样设计的:

  • 中间件在主机上裸露了一个HTTP接口
  • 该HTTP接口用于转发来自内部的申请到 Windows 主机
  • 中间件将代理后果和执行状态返回给请求者

性能

将HTTP申请体代理到PowerShell shell并执行

承受HTTP申请体中的所有内容,并在规定超时工夫内执行。

构建中间件

操作

386

GOOS=windows GOARCH=386 go build -a -o http2powershell.exe cmd/httpstub/powershellstub/powershellstub.go

amd64

GOOS=windows GOARCH=amd64 go build -a -o http2powershell.exe cmd/httpstub/powershellstub/powershellstub.go

应用办法

该可执行文件须要配置以下环境变量:

  • EDGEDEVICE_DRIVER_HTTP_PORT (可选)

    • 驱动程序容器的HTTP服务器端口,默认为11112
  • EDGEDEVICE_DRIVER_EXEC_TIMEOUT_SECOND (可选)

    • 执行指令的超时工夫,能够通过在命令后面加上timeout <seconds>来实现。

对于Windows主机的操作:

如果要运行中间件,请双击http2powershell.exe,默认状况下,中间件会在0.0.0.0上监听11112端口。

对于Shifu的操作:

应用/examples/simple-powershell-stub中提供的样本部署文件。

shifu的根目录下公布:

kubectl apply -f driver_util/http-to-powershell-stub/examples/Simple-powershell-stub

代理命令

应用curlWindows主机公布申请:

root@nginx:/# curl "edgedevice-powershell/issue_cmd?flags_no_parameter=ls,C:"    Directory: C:\Mode                 LastWriteTime         Length Name                                                   ----                 -------------         ------ ----                                                   d-----          6/5/2021   8:10 PM                PerfLogs                                               d-r---          6/9/2022   2:48 PM                Program Files                                          d-r---         4/29/2022   8:02 PM                Program Files (x86)                                    d-r---         4/16/2022   1:46 AM                Users                                                  d-----          6/9/2022   2:48 PM                Windows                                                d-----         4/17/2022   5:23 PM                xampp                                                     root@nginx:/# curl "edgedevice-powershell/issue_cmd?flags_no_parameter=ping,8.8.8.8"Pinging 8.8.8.8 with 32 bytes of data:Reply from 8.8.8.8: bytes=32 time=64ms TTL=114Reply from 8.8.8.8: bytes=32 time=56ms TTL=114Reply from 8.8.8.8: bytes=32 time=57ms TTL=114Reply from 8.8.8.8: bytes=32 time=59ms TTL=114Ping statistics for 8.8.8.8:    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),Approximate round trip times in milli-seconds:    Minimum = 56ms, Maximum = 64ms, Average = 59ms

示例

当应用curl向一个给定的URL公布申请时,命令如下:

curl "example.com/issue_cmd?flags_no_parameter=ping,8.8.8.8

而后申请将从HTTP的中间件传到Windows主机的PowerShell

> powershell.exe ping 8.8.8.8

请留神,默认的定时EDGEDEVICE_DRIVER_EXEC_TIMEOUT_SECOND能够被URL中的timeout标记所笼罩,例如:

  • 如果没有timeout标记(命令超时,输入不残缺):
root@nginx:/# curl "example.com/issue_cmd?flags_no_parameter=ping,-n,6,8.8.8.8"   Pinging 8.8.8.8 with 32 bytes of data:Reply from 8.8.8.8: bytes=32 time=58ms TTL=114Reply from 8.8.8.8: bytes=32 time=51ms TTL=114Reply from 8.8.8.8: bytes=32 time=59ms TTL=114Reply from 8.8.8.8: bytes=32 time=45ms TTL=114Reply from 8.8.8.8: bytes=32 time=59ms TTL=114
  • 应用timeout标记(输入残缺):
root@nginx:/# curl "example.com/issue_cmd?timeout=10&flags_no_parameter=ping,-n,6,8.8.8.8" Pinging 8.8.8.8 with 32 bytes of data:Reply from 8.8.8.8: bytes=32 time=60ms TTL=114Reply from 8.8.8.8: bytes=32 time=60ms TTL=114Reply from 8.8.8.8: bytes=32 time=59ms TTL=114Reply from 8.8.8.8: bytes=32 time=59ms TTL=114Reply from 8.8.8.8: bytes=32 time=59ms TTL=114Reply from 8.8.8.8: bytes=32 time=60ms TTL=114Ping statistics for 8.8.8.8:    Packets: Sent = 6, Received = 6, Lost = 0 (0% loss),Approximate round trip times in milli-seconds:    Minimum = 59ms, Maximum = 60ms, Average = 59ms

咱们还增加了一个参数stub_toleration来解决deviceShifu和中间件之间的提早问题。默认状况下,它被设置为1秒,你能够用以下办法笼罩这个工夫:

root@nginx:/# curl "example.com/issue_cmd?timeout=10&flags_no_parameter=ping,-n,6,8.8.8.8&stub_toleration=0"