From 12e59b03afd0591e4775cf4262c22af752924691 Mon Sep 17 00:00:00 2001 From: Bekir Pehlivan Date: Mon, 17 Jul 2023 15:02:12 +0300 Subject: [PATCH 1/5] Powershell session, mux'dan gin'e gecildi --- conf/config.yml | 1 - config.yml | 1 + go.mod | 46 +++-- go.sum | 123 ++++++++---- hyperv/memory.go | 16 ++ hyperv/network.go | 16 ++ hyperv/processor.go | 25 +++ hyperv/resp.go | 19 ++ hyperv/structs.go | 100 ++++++++++ hyperv/vhd.go | 18 ++ hyperv/vm.go | 19 ++ main.go | 197 ++++++++++---------- rest/rest.go | 29 +++ rest/server.go | 48 ----- rest/wmi.go | 142 -------------- utilities/commandline.go | 21 +++ conf/params.go => utilities/configparser.go | 107 +++++------ wmi/memory.go | 16 -- wmi/processor.go | 17 -- wmi/util.go | 18 -- wmi/vhd.go | 7 - wmi/vm.go | 20 -- 22 files changed, 536 insertions(+), 470 deletions(-) delete mode 100644 conf/config.yml create mode 100755 config.yml create mode 100644 hyperv/memory.go create mode 100644 hyperv/network.go create mode 100644 hyperv/processor.go create mode 100644 hyperv/resp.go create mode 100644 hyperv/structs.go create mode 100644 hyperv/vhd.go create mode 100644 hyperv/vm.go create mode 100644 rest/rest.go delete mode 100644 rest/server.go delete mode 100644 rest/wmi.go create mode 100644 utilities/commandline.go rename conf/params.go => utilities/configparser.go (69%) delete mode 100644 wmi/memory.go delete mode 100644 wmi/processor.go delete mode 100644 wmi/util.go delete mode 100644 wmi/vhd.go delete mode 100644 wmi/vm.go diff --git a/conf/config.yml b/conf/config.yml deleted file mode 100644 index 890780d..0000000 --- a/conf/config.yml +++ /dev/null @@ -1 +0,0 @@ -port: 8080 #Web port diff --git a/config.yml b/config.yml new file mode 100755 index 0000000..522a5b2 --- /dev/null +++ b/config.yml @@ -0,0 +1 @@ +port: 8080 \ No newline at end of file diff --git a/go.mod b/go.mod index d7df187..ca5f4d7 100644 --- a/go.mod +++ b/go.mod @@ -1,30 +1,48 @@ module wmi-rest -go 1.18 +go 1.20 require ( - github.com/StackExchange/wmi v1.2.1 - github.com/gorilla/mux v1.8.0 + github.com/bhendo/go-powershell v0.0.0-20190719160123-219e7fb4e41e + github.com/gin-gonic/gin v1.9.1 github.com/kardianos/service v1.2.2 - github.com/spf13/viper v1.14.0 + github.com/spf13/viper v1.16.0 ) require ( + github.com/bytedance/sonic v1.9.1 // indirect + github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect - github.com/go-ole/go-ole v1.2.6 // indirect + github.com/gabriel-vasile/mimetype v1.4.2 // indirect + github.com/gin-contrib/sse v0.1.0 // indirect + github.com/go-playground/locales v0.14.1 // indirect + github.com/go-playground/universal-translator v0.18.1 // indirect + github.com/go-playground/validator/v10 v10.14.0 // indirect + github.com/goccy/go-json v0.10.2 // indirect github.com/hashicorp/hcl v1.0.0 // indirect - github.com/magiconair/properties v1.8.6 // indirect + github.com/json-iterator/go v1.1.12 // indirect + github.com/juju/errors v1.0.0 // indirect + github.com/klauspost/cpuid/v2 v2.2.4 // indirect + github.com/leodido/go-urn v1.2.4 // indirect + github.com/magiconair/properties v1.8.7 // indirect + github.com/mattn/go-isatty v0.0.19 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect - github.com/pelletier/go-toml v1.9.5 // indirect - github.com/pelletier/go-toml/v2 v2.0.5 // indirect - github.com/spf13/afero v1.9.2 // indirect - github.com/spf13/cast v1.5.0 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/pelletier/go-toml/v2 v2.0.8 // indirect + github.com/spf13/afero v1.9.5 // indirect + github.com/spf13/cast v1.5.1 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect - github.com/subosito/gotenv v1.4.1 // indirect - golang.org/x/sys v0.0.0-20220908164124-27713097b956 // indirect - golang.org/x/text v0.4.0 // indirect + github.com/subosito/gotenv v1.4.2 // indirect + github.com/twitchyliquid64/golang-asm v0.15.1 // indirect + github.com/ugorji/go/codec v1.2.11 // indirect + golang.org/x/arch v0.3.0 // indirect + golang.org/x/crypto v0.9.0 // indirect + golang.org/x/net v0.10.0 // indirect + golang.org/x/sys v0.8.0 // indirect + golang.org/x/text v0.9.0 // indirect + google.golang.org/protobuf v1.30.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect - gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 59a873c..8ee0920 100644 --- a/go.sum +++ b/go.sum @@ -38,9 +38,15 @@ cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3f dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA= -github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8= +github.com/bhendo/go-powershell v0.0.0-20190719160123-219e7fb4e41e h1:KCjb01YiNoRaJ5c+SbnPLWjVzU9vqRYHg3e5JcN50nM= +github.com/bhendo/go-powershell v0.0.0-20190719160123-219e7fb4e41e/go.mod h1:f7vw6ObmmNcyFQLhZX9eUGBJGpnwTJFDvVjqZxIxHWY= +github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= +github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s= +github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= +github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams= +github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= @@ -57,15 +63,27 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po= github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= -github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE= +github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= +github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= +github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= +github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= +github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= +github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= +github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= -github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= -github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= -github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= +github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= +github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= +github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= +github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= +github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= +github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js= +github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= +github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= +github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -91,6 +109,7 @@ github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvq github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= @@ -102,7 +121,9 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= @@ -121,61 +142,82 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g= -github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= -github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= +github.com/juju/errors v1.0.0 h1:yiq7kjCLll1BiaRuNY53MGI0+EQ3rF6GB+wvboZDefM= +github.com/juju/errors v1.0.0/go.mod h1:B5x9thDqx0wIMH3+aLIMP9HjItInYWObRovoCFM5Qe8= github.com/kardianos/service v1.2.2 h1:ZvePhAHfvo0A7Mftk/tEzqEZ7Q4lgnR8sGz4xu1YX60= github.com/kardianos/service v1.2.2/go.mod h1:CIMRFEJVL+0DS1a3Nx06NaMn4Dz63Ng6O7dl0qH0zVM= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk= +github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= -github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo= -github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= +github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= +github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= +github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= +github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= +github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= +github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= -github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8= -github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= -github.com/pelletier/go-toml/v2 v2.0.5 h1:ipoSadvV8oGUjnUbMub59IDPPwfxF694nG/jwbMiyQg= -github.com/pelletier/go-toml/v2 v2.0.5/go.mod h1:OMHamSCAODeSsVrwwvcJOaoN0LIUIaFVNZzmWyNfXas= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= +github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= -github.com/spf13/afero v1.9.2 h1:j49Hj62F0n+DaZ1dDCvhABaPNSGNkt32oRFxI33IEMw= -github.com/spf13/afero v1.9.2/go.mod h1:iUV7ddyEEZPO5gA3zD4fJt6iStLlL+Lg4m2cihcDf8Y= -github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w= -github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/spf13/afero v1.9.5 h1:stMpOSZFs//0Lv29HduCmli3GUfpFoF3Y1Q/aXj/wVM= +github.com/spf13/afero v1.9.5/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ= +github.com/spf13/cast v1.5.1 h1:R+kOtfhWQE6TVQzY+4D7wJLBgkdVasCEFxSUBYBYIlA= +github.com/spf13/cast v1.5.1/go.mod h1:b9PdjNptOpzXr7Rq1q9gJML/2cdGQAo69NKzQ10KN48= github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk= github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/spf13/viper v1.14.0 h1:Rg7d3Lo706X9tHsJMUjdiwMpHB7W8WnSVOssIY+JElU= -github.com/spf13/viper v1.14.0/go.mod h1:WT//axPky3FdvXHzGw33dNdXXXfFQqmEalje+egj8As= +github.com/spf13/viper v1.16.0 h1:rGGH0XDZhdUOryiDWjmIvUSWpbNqisK8Wk0Vyefw8hc= +github.com/spf13/viper v1.16.0/go.mod h1:yg78JgCJcbrQOvV9YLXgkLaZqUidkY9K+Dd1FofRzQg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= -github.com/subosito/gotenv v1.4.1 h1:jyEFiXpy21Wm81FBN71l9VoMMV8H8jG+qIK3GCpY6Qs= -github.com/subosito/gotenv v1.4.1/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= +github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8= +github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= +github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= +github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= +github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= +github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -186,13 +228,18 @@ go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= +golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k= +golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= -golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= +golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -257,6 +304,9 @@ golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -285,7 +335,6 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -310,10 +359,14 @@ golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220908164124-27713097b956 h1:XeJjHH1KiLpKGb6lvMiksZ9l0fVUh+AmGcm0nOMEBOY= +golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -321,8 +374,10 @@ golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3 golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg= -golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -465,15 +520,16 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2 google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= +google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= @@ -485,5 +541,6 @@ honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= +rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/hyperv/memory.go b/hyperv/memory.go new file mode 100644 index 0000000..6f40b6b --- /dev/null +++ b/hyperv/memory.go @@ -0,0 +1,16 @@ +package hyperv + +import ( + "wmi-rest/utilities" + + "github.com/gin-gonic/gin" +) + +func Memory(c *gin.Context) { + input := c.Param("machid") + output, err := utilities.CommandLine(`Get-VM -Id ` + input + ` | Get-VMMemory | ConvertTo-Json`) + if err != nil { + c.JSON(500, gin.H{"error": err.Error()}) + } + c.Data(200, "application/json", []byte(output)) +} diff --git a/hyperv/network.go b/hyperv/network.go new file mode 100644 index 0000000..6bc9603 --- /dev/null +++ b/hyperv/network.go @@ -0,0 +1,16 @@ +package hyperv + +import ( + "wmi-rest/utilities" + + "github.com/gin-gonic/gin" +) + +func Network(c *gin.Context) { + input := c.Param("machid") + output, err := utilities.CommandLine(`Get-VM -Id ` + input + ` | Get-VMNetworkAdapter | ConvertTo-Json`) + if err != nil { + c.JSON(500, gin.H{"error": err.Error()}) + } + c.Data(200, "application/json", []byte(output)) +} diff --git a/hyperv/processor.go b/hyperv/processor.go new file mode 100644 index 0000000..8c81371 --- /dev/null +++ b/hyperv/processor.go @@ -0,0 +1,25 @@ +package hyperv + +import ( + "net/http" + "wmi-rest/utilities" + + "github.com/gin-gonic/gin" +) + +func Processor(c *gin.Context) { + input := c.Param("machid") + + if input == "" { + c.Data(returnResponse("No VM ID specified", http.StatusBadRequest, "failure", "error")) + return + } + + output, err := utilities.CommandLine(`Get-VM -Id ` + input + ` | Get-VMProcessor | ConvertTo-Json`) + if err != nil { + c.Data(returnResponse(err.Error(), http.StatusInternalServerError, "failure", "error")) + return + } + + c.Data(returnResponse(output, http.StatusOK, "success", "Processor info is displayed in data field.")) +} diff --git a/hyperv/resp.go b/hyperv/resp.go new file mode 100644 index 0000000..be25ac9 --- /dev/null +++ b/hyperv/resp.go @@ -0,0 +1,19 @@ +package hyperv + +import "encoding/json" + +type response struct { + Result string `json:"result"` + Message string `json:"message"` + Data interface{} `json:"data"` +} + +func returnResponse(respData interface{}, status int, result, message string) (code int, contentType string, data []byte) { + resp := response{ + Result: result, + Message: message, + Data: respData, + } + jsonResp, _ := json.MarshalIndent(resp, "", " ") + return status, "application/json", jsonResp +} diff --git a/hyperv/structs.go b/hyperv/structs.go new file mode 100644 index 0000000..4244bcf --- /dev/null +++ b/hyperv/structs.go @@ -0,0 +1,100 @@ +package hyperv + +import "time" + +type Msvm_ComputerSystem struct { + ElementName string + InstallDate time.Time + Name string + ProcessID int32 +} + +type VHDData struct { + ComputerName string `json:"ComputerName"` + Path string `json:"Path"` + VhdFormat int64 `json:"VhdFormat"` + VhdType int64 `json:"VhdType"` + FileSize int64 `json:"FileSize"` + Size int64 `json:"Size"` + MinimumSize interface{} `json:"MinimumSize"` + LogicalSectorSize int64 `json:"LogicalSectorSize"` + PhysicalSectorSize int64 `json:"PhysicalSectorSize"` + BlockSize int64 `json:"BlockSize"` + ParentPath string `json:"ParentPath"` + DiskIdentifier string `json:"DiskIdentifier"` + FragmentationPercentage int64 `json:"FragmentationPercentage"` + Alignment int64 `json:"Alignment"` + Attached bool `json:"Attached"` + DiskNumber interface{} `json:"DiskNumber"` + IsPMEMCompatible bool `json:"IsPMEMCompatible"` + AddressAbstractionType int64 `json:"AddressAbstractionType"` + Number interface{} `json:"Number"` +} + +type MemoryData struct { + ResourcePoolName string `json:"ResourcePoolName"` + Buffer int64 `json:"Buffer"` + DynamicMemoryEnabled bool `json:"DynamicMemoryEnabled"` + Maximum int64 `json:"Maximum"` + MaximumPerNUMANode int64 `json:"MaximumPerNumaNode"` + Minimum int64 `json:"Minimum"` + Priority int64 `json:"Priority"` + Startup int64 `json:"Startup"` + HugePagesEnabled bool `json:"HugePagesEnabled"` + MemoryEncryptionPolicy int64 `json:"MemoryEncryptionPolicy"` + MemoryEncryptionEnabled interface{} `json:"MemoryEncryptionEnabled"` + Name string `json:"Name"` + ID string `json:"Id"` + VMID string `json:"VMId"` + VMName string `json:"VMName"` + VMSnapshotID string `json:"VMSnapshotId"` + VMSnapshotName string `json:"VMSnapshotName"` + CIMSession CIMSession `json:"CimSession"` + ComputerName string `json:"ComputerName"` + IsDeleted bool `json:"IsDeleted"` + VMCheckpointID string `json:"VMCheckpointId"` + VMCheckpointName string `json:"VMCheckpointName"` +} + +type CIMSession struct { + ComputerName interface{} `json:"ComputerName"` + InstanceID string `json:"InstanceId"` +} + +type ProcessorData struct { + ResourcePoolName string `json:"ResourcePoolName"` + Count int64 `json:"Count"` + CompatibilityForMigrationEnabled bool `json:"CompatibilityForMigrationEnabled"` + CompatibilityForMigrationMode int64 `json:"CompatibilityForMigrationMode"` + CompatibilityForOlderOperatingSystemsEnabled bool `json:"CompatibilityForOlderOperatingSystemsEnabled"` + HwThreadCountPerCore int64 `json:"HwThreadCountPerCore"` + ExposeVirtualizationExtensions bool `json:"ExposeVirtualizationExtensions"` + EnablePerfmonPmu bool `json:"EnablePerfmonPmu"` + EnablePerfmonLbr bool `json:"EnablePerfmonLbr"` + EnablePerfmonPebs bool `json:"EnablePerfmonPebs"` + EnablePerfmonIpt bool `json:"EnablePerfmonIpt"` + EnableLegacyAPICMode bool `json:"EnableLegacyApicMode"` + APICMode int64 `json:"ApicMode"` + AllowACountMCount bool `json:"AllowACountMCount"` + CPUBrandString string `json:"CpuBrandString"` + PerfCPUFreqCapMhz int64 `json:"PerfCpuFreqCapMhz"` + Maximum int64 `json:"Maximum"` + Reserve int64 `json:"Reserve"` + RelativeWeight int64 `json:"RelativeWeight"` + MaximumCountPerNUMANode int64 `json:"MaximumCountPerNumaNode"` + MaximumCountPerNUMASocket int64 `json:"MaximumCountPerNumaSocket"` + EnableHostResourceProtection bool `json:"EnableHostResourceProtection"` + OperationalStatus []interface{} `json:"OperationalStatus"` + StatusDescription []interface{} `json:"StatusDescription"` + Name string `json:"Name"` + ID string `json:"Id"` + VMID string `json:"VMId"` + VMName string `json:"VMName"` + VMSnapshotID string `json:"VMSnapshotId"` + VMSnapshotName string `json:"VMSnapshotName"` + CIMSession CIMSession `json:"CimSession"` + ComputerName string `json:"ComputerName"` + IsDeleted bool `json:"IsDeleted"` + VMCheckpointID string `json:"VMCheckpointId"` + VMCheckpointName string `json:"VMCheckpointName"` +} diff --git a/hyperv/vhd.go b/hyperv/vhd.go new file mode 100644 index 0000000..8956b30 --- /dev/null +++ b/hyperv/vhd.go @@ -0,0 +1,18 @@ +package hyperv + +import ( + "wmi-rest/utilities" + + "github.com/gin-gonic/gin" +) + +func VHD(c *gin.Context) { + input := c.Param("machid") + output, err := utilities.CommandLine(`Get-VHD -Id ` + input + ` | ConvertTo-Json`) + + if err != nil { + c.JSON(500, gin.H{"error": err.Error()}) + } + + c.Data(200, "application/json", output) +} diff --git a/hyperv/vm.go b/hyperv/vm.go new file mode 100644 index 0000000..5a9ea08 --- /dev/null +++ b/hyperv/vm.go @@ -0,0 +1,19 @@ +package hyperv + +import ( + "net/http" + "wmi-rest/utilities" + + "github.com/gin-gonic/gin" +) + +func VMS(c *gin.Context) { + cmdline := `Get-WmiObject -namespace 'root\virtualization\v2' -class Msvm_ComputerSystem -Filter 'Caption="Virtual Machine"' | Select-Object -Property ElementName, InstallDate, Name, ProcessID | ConvertTo-Json` + output, err := utilities.CommandLine(cmdline) + + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + } + + c.Data(http.StatusOK, "application/json", output) +} diff --git a/main.go b/main.go index 38d7a14..0c1b627 100644 --- a/main.go +++ b/main.go @@ -1,98 +1,99 @@ -//go:build windows - -package main - -import ( - "flag" - "log" - "os" - "wmi-rest/conf" - "wmi-rest/rest" - - "github.com/kardianos/service" -) - -var logger service.Logger - -type program struct { - exit chan struct{} -} - -func (p *program) Start(s service.Service) error { - if service.Interactive() { - logger.Info("Running in interactive terminal.") - } else { - logger.Info("Running as service.") - } - p.exit = make(chan struct{}) - - go p.run() - - return nil -} - -func (p *program) run() { - c := conf.NewParams() - s := rest.NewServer(c.Port) - s.Run() -} - -func (p *program) Stop(s service.Service) error { - if service.Interactive() { - os.Exit(0) - } else { - logger.Info("Stopping service...") - close(p.exit) - } - return nil -} - -func main() { - svcFlag := flag.String("service", "", "Control the system service.") - flag.Parse() - - options := make(service.KeyValue) - options["Restart"] = "on-success" - options["SuccessExitStatus"] = "1 2 8 SIGKILL" - svcConfig := &service.Config{ - Name: "wmi-rest", - DisplayName: "WMI REST", - Description: "Simple REST service for some WMI features", - Option: options, - } - - prg := &program{} - s, err := service.New(prg, svcConfig) - if err != nil { - log.Fatal(err) - } - errs := make(chan error, 5) - logger, err = s.Logger(errs) - if err != nil { - log.Fatal(err) - } - - go func() { - for { - err := <-errs - if err != nil { - log.Print(err) - } - } - }() - - if len(*svcFlag) != 0 { - err := service.Control(s, *svcFlag) - if err != nil { - log.Printf("Valid actions: %q\n", service.ControlAction) - log.Fatal(err) - } - return - } - err = s.Run() - if err != nil { - logger.Error(err) - } - - select {} -} +package main + +import ( + "flag" + "log" + "os" + + // "log" + // "os" + + "wmi-rest/rest" + "wmi-rest/utilities" + + "github.com/kardianos/service" +) + +var logger service.Logger + +type program struct { + exit chan struct{} +} + +func (p *program) Start(s service.Service) error { + if service.Interactive() { + logger.Info("Running in interactive terminal.") + } else { + logger.Info("Running as service.") + } + p.exit = make(chan struct{}) + + go p.run() + + return nil +} + +func (p *program) run() { + c := utilities.ParseConfig() + rest.StartServer(c.Port, "1.2.0") +} + +func (p *program) Stop(s service.Service) error { + if service.Interactive() { + os.Exit(0) + } else { + logger.Info("Stopping service...") + close(p.exit) + } + return nil +} + +func main() { + svcFlag := flag.String("service", "", "Control the system service.") + flag.Parse() + + options := make(service.KeyValue) + options["Restart"] = "on-success" + options["SuccessExitStatus"] = "1 2 8 SIGKILL" + svcConfig := &service.Config{ + Name: "wmi-rest", + DisplayName: "WMI REST", + Description: "Simple REST service for some WMI features", + Option: options, + } + + prg := &program{} + s, err := service.New(prg, svcConfig) + if err != nil { + log.Fatal(err) + } + errs := make(chan error, 5) + logger, err = s.Logger(errs) + if err != nil { + log.Fatal(err) + } + + go func() { + for { + err := <-errs + if err != nil { + log.Print(err) + } + } + }() + + if len(*svcFlag) != 0 { + err := service.Control(s, *svcFlag) + if err != nil { + log.Printf("Valid actions: %q\n", service.ControlAction) + log.Fatal(err) + } + return + } + err = s.Run() + if err != nil { + logger.Error(err) + } + + select {} +} diff --git a/rest/rest.go b/rest/rest.go new file mode 100644 index 0000000..cec03fe --- /dev/null +++ b/rest/rest.go @@ -0,0 +1,29 @@ +package rest + +import ( + "net/http" + "strconv" + "wmi-rest/hyperv" + + "github.com/gin-gonic/gin" +) + +func StartServer(port int, version string) { + //gin.SetMode(gin.ReleaseMode) + //r := gin.New() + r := gin.Default() + r.GET("/vms", hyperv.VMS) + r.GET("/vms/:machid/memory", hyperv.Memory) + r.GET("/vms/:machid/network", hyperv.Network) + r.GET("/vms/:machid/processor", hyperv.Processor) + r.GET("/vms/:machid/vhd", hyperv.VHD) + + r.GET("/version", func(ctx *gin.Context) { + ctx.JSON(http.StatusOK, gin.H{ + "Result": "success", + "Message": "uygulama sürümü", + "Data": version, + }) + }) + r.Run(":" + strconv.Itoa(port)) +} diff --git a/rest/server.go b/rest/server.go deleted file mode 100644 index 764f349..0000000 --- a/rest/server.go +++ /dev/null @@ -1,48 +0,0 @@ -//go:build windows - -package rest - -import ( - "encoding/json" - "log" - "net/http" - "strconv" - "github.com/gorilla/mux" -) - -type Server struct { - port int -} - -func NewServer(port int) *Server { - return &Server{port: port} -} - -type response struct { - Result string `json:"result"` - Message string `json:"message"` - Data interface{} `json:"data"` -} - -func (s *Server) Run() { - r := mux.NewRouter() - - r.HandleFunc("/vms", vms) - r.HandleFunc("/vms/{name}/memory", memory) - r.HandleFunc("/vms/{name}/processor", processor) - r.HandleFunc("/vms/{name}/vhd", vhd) - r.HandleFunc("/version", version) - - err := http.ListenAndServe(":"+strconv.Itoa(s.port), r) - if err != nil { - log.Fatalln(err) - } -} - -func httpError(w http.ResponseWriter, err error, code int, resp response) { - w.WriteHeader(code) - resp.Result = "error" - resp.Message = err.Error() - jsonResp, _ := json.MarshalIndent(resp, "", " ") - _, _ = w.Write(jsonResp) -} diff --git a/rest/wmi.go b/rest/wmi.go deleted file mode 100644 index e746a14..0000000 --- a/rest/wmi.go +++ /dev/null @@ -1,142 +0,0 @@ -//go:build windows - -package rest - -import ( - "encoding/json" - "errors" - "net/http" - "wmi-rest/wmi" - "github.com/gorilla/mux" -) - -func vms(w http.ResponseWriter, req *http.Request) { - w.Header().Set("Content-Type", "application/json") - - var resp response - - data, err := wmi.VMs() - if err != nil { - httpError(w, err, http.StatusInternalServerError, resp) - return - } - - if len(data) == 0 { - httpError(w, errors.New("no VM found"), http.StatusNotFound, resp) - return - } - - resp.Result = "success" - resp.Message = "VMs are listed in data field." - resp.Data = data - - jsonResp, _ := json.MarshalIndent(resp, "", " ") - _, _ = w.Write(jsonResp) -} - - -func memory(w http.ResponseWriter, req *http.Request) { - w.Header().Set("Content-Type", "application/json") - - var resp response - - vars := mux.Vars(req) - name, ok := vars["name"] - if !ok { - httpError(w, errors.New("Name is missing in parameters"), http.StatusBadRequest, resp) - return - } - - data, err := wmi.Memory(name) - if err != nil { - httpError(w, err, http.StatusInternalServerError, resp) - return - } - - if len(data) == 0 { - httpError(w, errors.New("No memory info found"), http.StatusNotFound, resp) - return - } - - resp.Result = "success" - resp.Message = "Memory info is displayed in data field." - resp.Data = data - - jsonResp, _ := json.MarshalIndent(resp, "", " ") - _, _ = w.Write(jsonResp) -} - -func processor(w http.ResponseWriter, req *http.Request) { - w.Header().Set("Content-Type", "application/json") - - var resp response - - vars := mux.Vars(req) - name, ok := vars["name"] - if !ok { - httpError(w, errors.New("name is missing in parameters"), http.StatusBadRequest, resp) - return - } - - data, err := wmi.Processor(name) - if err != nil { - httpError(w, err, http.StatusInternalServerError, resp) - return - } - - if len(data) == 0 { - httpError(w, errors.New("No processor info found"), http.StatusNotFound, resp) - return - } - - resp.Result = "success" - resp.Message = "Processor info is displayed in data field." - resp.Data = data - - jsonResp, _ := json.MarshalIndent(resp, "", " ") - _, _ = w.Write(jsonResp) -} - -func vhd(w http.ResponseWriter, req *http.Request) { - w.Header().Set("Content-Type", "application/json") - - var resp response - - vars := mux.Vars(req) - name, ok := vars["name"] - if !ok { - httpError(w, errors.New("name is missing in parameters"), http.StatusBadRequest, resp) - return - } - - data, err := wmi.Vhd(name) - if err != nil { - httpError(w, err, http.StatusInternalServerError, resp) - return - } - - if len(data) == 0 { - httpError(w, errors.New("No image info found"), http.StatusNotFound, resp) - return - } - - resp.Result = "success" - resp.Message = "Image info is displayed in data field." - resp.Data = json.RawMessage(data) - - jsonResp, _ := json.MarshalIndent(resp, "", " ") - _, _ = w.Write(jsonResp) -} - -func version(w http.ResponseWriter, req *http.Request) { - w.Header().Set("Content-Type", "application/json") - - var resp response - - resp.Result = "success" - resp.Message = "Version is displayed in data field." - resp.Data = "0.4.1" - - jsonResp, _ := json.MarshalIndent(resp, "", " ") - _, _ = w.Write(jsonResp) -} diff --git a/utilities/commandline.go b/utilities/commandline.go new file mode 100644 index 0000000..87f6cb3 --- /dev/null +++ b/utilities/commandline.go @@ -0,0 +1,21 @@ +package utilities + +import ( + "github.com/bhendo/go-powershell" + "github.com/bhendo/go-powershell/backend" +) + +func initPwsh() powershell.Shell { + pwsh, err := powershell.New(&backend.Local{}) + if err != nil { + panic(err) + } + return pwsh +} + +var pwsh powershell.Shell = initPwsh() + +func CommandLine(ps string) ([]byte, error) { + output, _, err := pwsh.Execute(ps) + return []byte(output), err +} diff --git a/conf/params.go b/utilities/configparser.go similarity index 69% rename from conf/params.go rename to utilities/configparser.go index 747bab8..0c01df1 100644 --- a/conf/params.go +++ b/utilities/configparser.go @@ -1,56 +1,51 @@ -//go:build windows - -package conf - -import ( - "flag" - "log" - "os" - "path/filepath" - - "github.com/spf13/viper" -) - -type Params struct { - Port int -} - -func NewParams() (p *Params) { - ex, err := os.Executable() - if err != nil { - log.Fatalf("Error getting executable path, %s", err) - } - executablePath := filepath.Dir(ex) - - filePath := flag.String("config", executablePath+"\\config.yml", "Path of the configuration file in YAML format") - - if _, err := os.Stat(*filePath); os.IsNotExist(err) { - f, err := os.Create(*filePath) - if err != nil { - log.Fatalf("Error creating config file, %s", err) - } - defer f.Close() - - _, err = f.WriteString("port: 8080") - if err != nil { - log.Fatalf("Error writing config file, %s", err) - } - - log.Println("Default config file created in: " + *filePath) - } - - flag.Parse() - viper.SetConfigFile(*filePath) - viper.SetConfigType("yaml") - - if err := viper.ReadInConfig(); err != nil { - log.Fatalf("Error reading config file, %s", err) - } - - err = viper.Unmarshal(&p) - if err != nil { - log.Fatalf("Unable to decode into struct, %v\n", err) - } - - return -} +package utilities + +import ( + "flag" + "log" + "os" + "path/filepath" + + "github.com/spf13/viper" +) + +type Parameters struct { + Port int +} + +func ParseConfig() (p *Parameters) { + path, err := os.Executable() + if err != nil { + log.Fatalf("Error getting executable path, %s", err) + } + executablePath := filepath.Dir(path) + filePath := flag.String("config", executablePath+"\\config.yml", "Path of the configuration file in YAML format") + + if _, err := os.Stat(*filePath); os.IsNotExist(err) { + file, err := os.Create(*filePath) + if err != nil { + log.Fatalf("Error creating config file, %s", err) + } + defer file.Close() + + _, err = file.WriteString("port: 8080") + if err != nil { + log.Fatalf("Error writing config file, %s", err) + } + log.Println("Default config file created in: " + *filePath) + } + + flag.Parse() + viper.SetConfigFile(*filePath) + viper.SetConfigType("yaml") + + if err := viper.ReadInConfig(); err != nil { + log.Fatalf("Error reading config file, %s", err) + } + + if err := viper.Unmarshal(&p); err != nil { + log.Fatalf("Unable to decode into struct, %v\n", err) + } + + return +} diff --git a/wmi/memory.go b/wmi/memory.go deleted file mode 100644 index a8141e7..0000000 --- a/wmi/memory.go +++ /dev/null @@ -1,16 +0,0 @@ -package wmi - -import ( - "github.com/StackExchange/wmi" -) - -type Msvm_MemorySettingData struct { - Reservation int64 -} - -func Memory(vmName string) ([]Msvm_MemorySettingData, error) { - var dst []Msvm_MemorySettingData - q := "ASSOCIATORS OF {Msvm_VirtualSystemSettingData.InstanceID='Microsoft:"+vmName+"'} WHERE ResultClass = Msvm_MemorySettingData" - err := wmi.QueryNamespace(q, &dst, `root\virtualization\v2`) - return dst, err -} diff --git a/wmi/processor.go b/wmi/processor.go deleted file mode 100644 index d86143a..0000000 --- a/wmi/processor.go +++ /dev/null @@ -1,17 +0,0 @@ -package wmi - -import ( - "github.com/StackExchange/wmi" -) - -type Msvm_SummaryInformation struct { - NumberOfProcessors int16 - GuestOperatingSystem string -} - -func Processor(vmName string) ([]Msvm_SummaryInformation, error) { - var dst []Msvm_SummaryInformation - q := wmi.CreateQuery(&dst, "WHERE Name = '" + vmName + "'") - err := wmi.QueryNamespace(q, &dst, `root\virtualization\v2`) - return dst, err -} diff --git a/wmi/util.go b/wmi/util.go deleted file mode 100644 index 0809338..0000000 --- a/wmi/util.go +++ /dev/null @@ -1,18 +0,0 @@ -package wmi - -import ( - "os/exec" -) - -// execPS executes the given PowerShell command and returns its output as a byte slice. -// -// Parameters: -// ps - The PowerShell command to execute. -// -// Returns: -// The output of the PowerShell command as a byte slice. -// Any errors encountered during execution are returned as an error. -func execPS(ps string) ([]byte, error) { - cmd := exec.Command("powershell", "-NoProfile", "-NonInteractive", "-Command", ps) - return cmd.Output() -} diff --git a/wmi/vhd.go b/wmi/vhd.go deleted file mode 100644 index 0c17476..0000000 --- a/wmi/vhd.go +++ /dev/null @@ -1,7 +0,0 @@ -package wmi - -func Vhd(VMId string) ([]byte, error) { - ps := `Get-VHD -Id ` + VMId + ` | ConvertTo-Json` - output, err := execPS(ps) - return output, err -} diff --git a/wmi/vm.go b/wmi/vm.go deleted file mode 100644 index f8b2550..0000000 --- a/wmi/vm.go +++ /dev/null @@ -1,20 +0,0 @@ -package wmi - -import ( - "github.com/StackExchange/wmi" - "time" -) - -type MSVM_ComputerSystem struct { - ElementName string - InstallDate time.Time - Name string - ProcessID int32 -} - -func VMs() ([]MSVM_ComputerSystem, error) { - var dst []MSVM_ComputerSystem - q := wmi.CreateQuery(&dst, "WHERE Caption='Virtual Machine'") - err := wmi.QueryNamespace(q, &dst, `root\virtualization\v2`) - return dst, err -} From e4be25f92c06d5ba75178a96a68dd4c960a8c1da Mon Sep 17 00:00:00 2001 From: Emin Date: Mon, 17 Jul 2023 15:08:26 +0300 Subject: [PATCH 2/5] =?UTF-8?q?gitignore=20d=C3=BCzeltildi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 ++-- config.yml | 0 main.go | 3 --- rest/rest.go | 2 -- 4 files changed, 2 insertions(+), 7 deletions(-) mode change 100755 => 100644 config.yml diff --git a/.gitignore b/.gitignore index fba83b6..2e6feb0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ .idea/ -conf/config.yml +config.yml -*.exe \ No newline at end of file +*.exe diff --git a/config.yml b/config.yml old mode 100755 new mode 100644 diff --git a/main.go b/main.go index 0c1b627..51ae50b 100644 --- a/main.go +++ b/main.go @@ -5,9 +5,6 @@ import ( "log" "os" - // "log" - // "os" - "wmi-rest/rest" "wmi-rest/utilities" diff --git a/rest/rest.go b/rest/rest.go index cec03fe..29e49cb 100644 --- a/rest/rest.go +++ b/rest/rest.go @@ -9,8 +9,6 @@ import ( ) func StartServer(port int, version string) { - //gin.SetMode(gin.ReleaseMode) - //r := gin.New() r := gin.Default() r.GET("/vms", hyperv.VMS) r.GET("/vms/:machid/memory", hyperv.Memory) From 1b0df17857a4bc29d0e2b18947d8d25d34d708c9 Mon Sep 17 00:00:00 2001 From: Emin Date: Mon, 17 Jul 2023 16:39:00 +0300 Subject: [PATCH 3/5] =?UTF-8?q?REST=20apisi=20yeni=20de=C4=9Fi=C5=9Fiklikl?= =?UTF-8?q?ere=20uyumlu=20hale=20getirildi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hyperv/memory.go | 12 ++++++++++-- hyperv/network.go | 12 ++++++++++-- hyperv/resp.go | 8 +++++++- hyperv/vhd.go | 18 +++++++++++++++--- hyperv/vm.go | 10 ++++++++-- main.go | 3 +++ rest/rest.go | 2 ++ 7 files changed, 55 insertions(+), 10 deletions(-) diff --git a/hyperv/memory.go b/hyperv/memory.go index 6f40b6b..39de741 100644 --- a/hyperv/memory.go +++ b/hyperv/memory.go @@ -1,6 +1,7 @@ package hyperv import ( + "net/http" "wmi-rest/utilities" "github.com/gin-gonic/gin" @@ -8,9 +9,16 @@ import ( func Memory(c *gin.Context) { input := c.Param("machid") + + if input == "" { + c.Data(returnResponse("No VM ID specified", http.StatusBadRequest, "failure", "error")) + return + } + output, err := utilities.CommandLine(`Get-VM -Id ` + input + ` | Get-VMMemory | ConvertTo-Json`) if err != nil { - c.JSON(500, gin.H{"error": err.Error()}) + c.Data(returnResponse(err.Error(), http.StatusInternalServerError, "failure", "error")) + return } - c.Data(200, "application/json", []byte(output)) + c.Data(returnResponse(output, http.StatusOK, "success", "Memory info is displayed in data field")) } diff --git a/hyperv/network.go b/hyperv/network.go index 6bc9603..1220d08 100644 --- a/hyperv/network.go +++ b/hyperv/network.go @@ -1,6 +1,7 @@ package hyperv import ( + "net/http" "wmi-rest/utilities" "github.com/gin-gonic/gin" @@ -8,9 +9,16 @@ import ( func Network(c *gin.Context) { input := c.Param("machid") + + if input == "" { + c.Data(returnResponse("No VM ID specified", http.StatusBadRequest, "failure", "error")) + return + } + output, err := utilities.CommandLine(`Get-VM -Id ` + input + ` | Get-VMNetworkAdapter | ConvertTo-Json`) if err != nil { - c.JSON(500, gin.H{"error": err.Error()}) + c.Data(returnResponse(err.Error(), http.StatusInternalServerError, "failure", "error")) + return } - c.Data(200, "application/json", []byte(output)) + c.Data(returnResponse(output, http.StatusOK, "success", "Network info is displayed in data field")) } diff --git a/hyperv/resp.go b/hyperv/resp.go index be25ac9..b30eced 100644 --- a/hyperv/resp.go +++ b/hyperv/resp.go @@ -9,11 +9,17 @@ type response struct { } func returnResponse(respData interface{}, status int, result, message string) (code int, contentType string, data []byte) { + + value, ok := respData.(string) + if ok { + respData, _ = json.Marshal(value) + } resp := response{ Result: result, Message: message, - Data: respData, + Data: json.RawMessage(respData.([]byte)), } jsonResp, _ := json.MarshalIndent(resp, "", " ") + println(status, "application/json", jsonResp) return status, "application/json", jsonResp } diff --git a/hyperv/vhd.go b/hyperv/vhd.go index 8956b30..b8a02d0 100644 --- a/hyperv/vhd.go +++ b/hyperv/vhd.go @@ -1,6 +1,7 @@ package hyperv import ( + "net/http" "wmi-rest/utilities" "github.com/gin-gonic/gin" @@ -8,11 +9,22 @@ import ( func VHD(c *gin.Context) { input := c.Param("machid") - output, err := utilities.CommandLine(`Get-VHD -Id ` + input + ` | ConvertTo-Json`) + if input == "" { + c.Data(returnResponse("No VM ID specified", http.StatusBadRequest, "failure", "error")) + return + } + + output, err := utilities.CommandLine(`Get-VHD -Id ` + input + ` | ConvertTo-Json`) if err != nil { - c.JSON(500, gin.H{"error": err.Error()}) + c.Data(returnResponse(err.Error(), http.StatusInternalServerError, "failure", "error")) + return + } + + if len(output) < 1 { + c.Data(returnResponse("No Disk found.", http.StatusInternalServerError, "failure", "error")) + return } - c.Data(200, "application/json", output) + c.Data(returnResponse(output, http.StatusOK, "success", "VHD info is displayed in data field")) } diff --git a/hyperv/vm.go b/hyperv/vm.go index 5a9ea08..c825b96 100644 --- a/hyperv/vm.go +++ b/hyperv/vm.go @@ -12,8 +12,14 @@ func VMS(c *gin.Context) { output, err := utilities.CommandLine(cmdline) if err != nil { - c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + c.Data(returnResponse(err.Error(), http.StatusInternalServerError, "failure", "error")) + return } - c.Data(http.StatusOK, "application/json", output) + if len(output) == 0 { + c.Data(returnResponse("No VM found.", http.StatusInternalServerError, "failure", "error")) + return + } + + c.Data(returnResponse(output, http.StatusOK, "success", "VMs displayed in data field")) } diff --git a/main.go b/main.go index 51ae50b..0c1b627 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,9 @@ import ( "log" "os" + // "log" + // "os" + "wmi-rest/rest" "wmi-rest/utilities" diff --git a/rest/rest.go b/rest/rest.go index 29e49cb..cec03fe 100644 --- a/rest/rest.go +++ b/rest/rest.go @@ -9,6 +9,8 @@ import ( ) func StartServer(port int, version string) { + //gin.SetMode(gin.ReleaseMode) + //r := gin.New() r := gin.Default() r.GET("/vms", hyperv.VMS) r.GET("/vms/:machid/memory", hyperv.Memory) From 7a7556632b571801118f3c65ef44ab9f3f26a3f7 Mon Sep 17 00:00:00 2001 From: Emin Date: Mon, 17 Jul 2023 16:52:46 +0300 Subject: [PATCH 4/5] =?UTF-8?q?Powershell=20init=20maine=20ta=C5=9F=C4=B1n?= =?UTF-8?q?d=C4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hyperv/resp.go | 1 - main.go | 2 ++ utilities/commandline.go | 10 +++++----- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/hyperv/resp.go b/hyperv/resp.go index b30eced..366d0b6 100644 --- a/hyperv/resp.go +++ b/hyperv/resp.go @@ -20,6 +20,5 @@ func returnResponse(respData interface{}, status int, result, message string) (c Data: json.RawMessage(respData.([]byte)), } jsonResp, _ := json.MarshalIndent(resp, "", " ") - println(status, "application/json", jsonResp) return status, "application/json", jsonResp } diff --git a/main.go b/main.go index 0c1b627..5fee399 100644 --- a/main.go +++ b/main.go @@ -52,6 +52,8 @@ func main() { svcFlag := flag.String("service", "", "Control the system service.") flag.Parse() + utilities.InitPwsh() + options := make(service.KeyValue) options["Restart"] = "on-success" options["SuccessExitStatus"] = "1 2 8 SIGKILL" diff --git a/utilities/commandline.go b/utilities/commandline.go index 87f6cb3..f4c0a3d 100644 --- a/utilities/commandline.go +++ b/utilities/commandline.go @@ -5,16 +5,16 @@ import ( "github.com/bhendo/go-powershell/backend" ) -func initPwsh() powershell.Shell { - pwsh, err := powershell.New(&backend.Local{}) +var pwsh powershell.Shell + +func InitPwsh() { + var err error + pwsh, err = powershell.New(&backend.Local{}) if err != nil { panic(err) } - return pwsh } -var pwsh powershell.Shell = initPwsh() - func CommandLine(ps string) ([]byte, error) { output, _, err := pwsh.Execute(ps) return []byte(output), err From 3a5de4ee3a4a405c3722c3a059902a843aac1e9a Mon Sep 17 00:00:00 2001 From: Emin Date: Tue, 18 Jul 2023 11:16:47 +0300 Subject: [PATCH 5/5] =?UTF-8?q?status=20kodlar=C4=B1=20statusOK=20olarak?= =?UTF-8?q?=20de=C4=9Fi=C5=9Ftirildi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hyperv/resp.go | 6 +-- hyperv/structs.go | 100 ---------------------------------------------- hyperv/vhd.go | 2 +- hyperv/vm.go | 2 +- main.go | 3 -- rest/rest.go | 2 +- 6 files changed, 5 insertions(+), 110 deletions(-) delete mode 100644 hyperv/structs.go diff --git a/hyperv/resp.go b/hyperv/resp.go index 366d0b6..81578f2 100644 --- a/hyperv/resp.go +++ b/hyperv/resp.go @@ -8,10 +8,8 @@ type response struct { Data interface{} `json:"data"` } -func returnResponse(respData interface{}, status int, result, message string) (code int, contentType string, data []byte) { - - value, ok := respData.(string) - if ok { +func returnResponse(respData interface{}, status int, result, message string) (int, string, []byte) { + if value, ok := respData.(string); ok { respData, _ = json.Marshal(value) } resp := response{ diff --git a/hyperv/structs.go b/hyperv/structs.go deleted file mode 100644 index 4244bcf..0000000 --- a/hyperv/structs.go +++ /dev/null @@ -1,100 +0,0 @@ -package hyperv - -import "time" - -type Msvm_ComputerSystem struct { - ElementName string - InstallDate time.Time - Name string - ProcessID int32 -} - -type VHDData struct { - ComputerName string `json:"ComputerName"` - Path string `json:"Path"` - VhdFormat int64 `json:"VhdFormat"` - VhdType int64 `json:"VhdType"` - FileSize int64 `json:"FileSize"` - Size int64 `json:"Size"` - MinimumSize interface{} `json:"MinimumSize"` - LogicalSectorSize int64 `json:"LogicalSectorSize"` - PhysicalSectorSize int64 `json:"PhysicalSectorSize"` - BlockSize int64 `json:"BlockSize"` - ParentPath string `json:"ParentPath"` - DiskIdentifier string `json:"DiskIdentifier"` - FragmentationPercentage int64 `json:"FragmentationPercentage"` - Alignment int64 `json:"Alignment"` - Attached bool `json:"Attached"` - DiskNumber interface{} `json:"DiskNumber"` - IsPMEMCompatible bool `json:"IsPMEMCompatible"` - AddressAbstractionType int64 `json:"AddressAbstractionType"` - Number interface{} `json:"Number"` -} - -type MemoryData struct { - ResourcePoolName string `json:"ResourcePoolName"` - Buffer int64 `json:"Buffer"` - DynamicMemoryEnabled bool `json:"DynamicMemoryEnabled"` - Maximum int64 `json:"Maximum"` - MaximumPerNUMANode int64 `json:"MaximumPerNumaNode"` - Minimum int64 `json:"Minimum"` - Priority int64 `json:"Priority"` - Startup int64 `json:"Startup"` - HugePagesEnabled bool `json:"HugePagesEnabled"` - MemoryEncryptionPolicy int64 `json:"MemoryEncryptionPolicy"` - MemoryEncryptionEnabled interface{} `json:"MemoryEncryptionEnabled"` - Name string `json:"Name"` - ID string `json:"Id"` - VMID string `json:"VMId"` - VMName string `json:"VMName"` - VMSnapshotID string `json:"VMSnapshotId"` - VMSnapshotName string `json:"VMSnapshotName"` - CIMSession CIMSession `json:"CimSession"` - ComputerName string `json:"ComputerName"` - IsDeleted bool `json:"IsDeleted"` - VMCheckpointID string `json:"VMCheckpointId"` - VMCheckpointName string `json:"VMCheckpointName"` -} - -type CIMSession struct { - ComputerName interface{} `json:"ComputerName"` - InstanceID string `json:"InstanceId"` -} - -type ProcessorData struct { - ResourcePoolName string `json:"ResourcePoolName"` - Count int64 `json:"Count"` - CompatibilityForMigrationEnabled bool `json:"CompatibilityForMigrationEnabled"` - CompatibilityForMigrationMode int64 `json:"CompatibilityForMigrationMode"` - CompatibilityForOlderOperatingSystemsEnabled bool `json:"CompatibilityForOlderOperatingSystemsEnabled"` - HwThreadCountPerCore int64 `json:"HwThreadCountPerCore"` - ExposeVirtualizationExtensions bool `json:"ExposeVirtualizationExtensions"` - EnablePerfmonPmu bool `json:"EnablePerfmonPmu"` - EnablePerfmonLbr bool `json:"EnablePerfmonLbr"` - EnablePerfmonPebs bool `json:"EnablePerfmonPebs"` - EnablePerfmonIpt bool `json:"EnablePerfmonIpt"` - EnableLegacyAPICMode bool `json:"EnableLegacyApicMode"` - APICMode int64 `json:"ApicMode"` - AllowACountMCount bool `json:"AllowACountMCount"` - CPUBrandString string `json:"CpuBrandString"` - PerfCPUFreqCapMhz int64 `json:"PerfCpuFreqCapMhz"` - Maximum int64 `json:"Maximum"` - Reserve int64 `json:"Reserve"` - RelativeWeight int64 `json:"RelativeWeight"` - MaximumCountPerNUMANode int64 `json:"MaximumCountPerNumaNode"` - MaximumCountPerNUMASocket int64 `json:"MaximumCountPerNumaSocket"` - EnableHostResourceProtection bool `json:"EnableHostResourceProtection"` - OperationalStatus []interface{} `json:"OperationalStatus"` - StatusDescription []interface{} `json:"StatusDescription"` - Name string `json:"Name"` - ID string `json:"Id"` - VMID string `json:"VMId"` - VMName string `json:"VMName"` - VMSnapshotID string `json:"VMSnapshotId"` - VMSnapshotName string `json:"VMSnapshotName"` - CIMSession CIMSession `json:"CimSession"` - ComputerName string `json:"ComputerName"` - IsDeleted bool `json:"IsDeleted"` - VMCheckpointID string `json:"VMCheckpointId"` - VMCheckpointName string `json:"VMCheckpointName"` -} diff --git a/hyperv/vhd.go b/hyperv/vhd.go index b8a02d0..372da3a 100644 --- a/hyperv/vhd.go +++ b/hyperv/vhd.go @@ -22,7 +22,7 @@ func VHD(c *gin.Context) { } if len(output) < 1 { - c.Data(returnResponse("No Disk found.", http.StatusInternalServerError, "failure", "error")) + c.Data(returnResponse("No Disk found.", http.StatusOK, "failure", "error")) return } diff --git a/hyperv/vm.go b/hyperv/vm.go index c825b96..b7ff02d 100644 --- a/hyperv/vm.go +++ b/hyperv/vm.go @@ -17,7 +17,7 @@ func VMS(c *gin.Context) { } if len(output) == 0 { - c.Data(returnResponse("No VM found.", http.StatusInternalServerError, "failure", "error")) + c.Data(returnResponse("No VM found.", http.StatusOK, "failure", "error")) return } diff --git a/main.go b/main.go index 5fee399..3ab64aa 100644 --- a/main.go +++ b/main.go @@ -5,9 +5,6 @@ import ( "log" "os" - // "log" - // "os" - "wmi-rest/rest" "wmi-rest/utilities" diff --git a/rest/rest.go b/rest/rest.go index cec03fe..a1aab84 100644 --- a/rest/rest.go +++ b/rest/rest.go @@ -21,7 +21,7 @@ func StartServer(port int, version string) { r.GET("/version", func(ctx *gin.Context) { ctx.JSON(http.StatusOK, gin.H{ "Result": "success", - "Message": "uygulama sürümü", + "Message": "Application version", "Data": version, }) })