mirror of
https://github.com/openziti/ziti.git
synced 2026-10-13 23:59:53 +00:00
@@ -0,0 +1,116 @@
|
||||
name: build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- release-*
|
||||
pull_request:
|
||||
|
||||
env:
|
||||
GOX_OUTPUT: "release/{{.Arch}}/{{.OS}}/{{.Dir}}"
|
||||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||
gh_ci_key: ${{ secrets.GH_CI_KEY }}
|
||||
|
||||
jobs:
|
||||
mac-os-build:
|
||||
name: Build Mac OS binaries
|
||||
runs-on: macos-10.15
|
||||
steps:
|
||||
- name: Git Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Install Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: '^1.15.0'
|
||||
|
||||
- name: Install Ziti CI
|
||||
uses: netfoundry/ziti-ci@v1
|
||||
|
||||
- name: Build and Test
|
||||
run: |
|
||||
pip install --upgrade pip
|
||||
pip install awscli
|
||||
go get github.com/mitchellh/gox
|
||||
$(go env GOPATH)/bin/ziti-ci generate-build-info common/version/info_generated.go version
|
||||
CGO_ENABLED=true $(go env GOPATH)/bin/gox -os=darwin -arch=amd64 -output=$GOX_OUTPUT ./...
|
||||
aws s3 sync --no-progress release/ s3://ziti-cmd-build-tmp/${{ github.run_id }}
|
||||
|
||||
windows-build:
|
||||
name: Build Windows binaries
|
||||
runs-on: windows-2019
|
||||
steps:
|
||||
- name: Git Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Install Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: '^1.15.0'
|
||||
|
||||
- name: Install Ziti CI
|
||||
uses: netfoundry/ziti-ci@v1
|
||||
|
||||
- name: Build and Test
|
||||
shell: bash
|
||||
run: |
|
||||
choco install python --version 3.6.8
|
||||
python -m pip install --upgrade pip
|
||||
pip install awscli
|
||||
go get github.com/mitchellh/gox
|
||||
$(go env GOPATH)/bin/ziti-ci generate-build-info common/version/info_generated.go version
|
||||
CGO_ENABLED=true $(go env GOPATH)/bin/gox -os=windows -arch=amd64 -output=$GOX_OUTPUT ./...
|
||||
aws s3 sync --no-progress release/ s3://ziti-cmd-build-tmp/${{ github.run_id }}
|
||||
|
||||
tag-and-publish:
|
||||
name: Build Linux Binaries, Tag and Publish
|
||||
runs-on: ubuntu-18.04
|
||||
needs: [ mac-os-build, windows-build ]
|
||||
steps:
|
||||
- name: Git Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Install Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: '^1.15.0'
|
||||
|
||||
- name: Install Ziti CI
|
||||
uses: netfoundry/ziti-ci@v1
|
||||
|
||||
- name: Build and Test
|
||||
env:
|
||||
JFROG_API_KEY: ${{ secrets.JFROG_API_KEY }}
|
||||
jenkins_user: ${{ secrets.JENKINS_USER }}
|
||||
jenkins_user_token: ${{ secrets.JENKINS_USER_TOKEN }}
|
||||
jenkins_job_token: ${{ secrets.JENKINS_JOB_TOKEN }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
sudo apt-get -yq install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf
|
||||
pip install --upgrade --user pip
|
||||
pip install awscli
|
||||
$(go env GOPATH)/bin/ziti-ci configure-git
|
||||
$(go env GOPATH)/bin/ziti-ci generate-build-info common/version/info_generated.go version
|
||||
go get github.com/mitchellh/gox
|
||||
CGO_ENABLED=true $(go env GOPATH)/bin/gox -os=linux -arch=amd64 -output=$GOX_OUTPUT ./...
|
||||
CC=arm-linux-gnueabihf-gcc CGO_ENABLED=true gox -cgo -os=linux -arch=arm -output=$GOX_OUTPUT ./...
|
||||
aws s3 sync --no-progress s3://ziti-cmd-build-tmp/${{ github.run_id }} release/
|
||||
aws s3 rm --recursive s3://ziti-cmd-build-tmp/${{ github.run_id }}
|
||||
$(go env GOPATH)/bin/ziti-ci publish-to-artifactory
|
||||
$(go env GOPATH)/bin/ziti-ci trigger-jenkins-smoke-build
|
||||
|
||||
- name: Publish
|
||||
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/head/release-')
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
$(go env GOPATH)/bin/ziti-ci tag -v -f version
|
||||
$(go env GOPATH)/bin/ziti-ci publish-to-github
|
||||
-77
@@ -1,77 +0,0 @@
|
||||
version: "~> 1.0"
|
||||
|
||||
import:
|
||||
- source: netfoundry/ziti-ci:go-defaults.yml@v1
|
||||
- source: netfoundry/ziti-ci:ziti-ci.yml@v1
|
||||
|
||||
env:
|
||||
global:
|
||||
- GOX_OUTPUT="release/{{.Arch}}/{{.OS}}/{{.Dir}}"
|
||||
|
||||
stages:
|
||||
- name: "Build and Test"
|
||||
- name: "Tag and Publish"
|
||||
|
||||
jobs:
|
||||
include:
|
||||
- stage: "Build and Test"
|
||||
os: linux
|
||||
arch: arm64
|
||||
dist: bionic
|
||||
env: GOX_OS=linux
|
||||
script:
|
||||
- set -e
|
||||
- sudo dpkg --add-architecture armhf
|
||||
- sudo apt-get update -yq
|
||||
- |-
|
||||
sudo apt-get -yq install \
|
||||
crossbuild-essential-armhf \
|
||||
libc6:armhf
|
||||
- pip install --upgrade --user pip
|
||||
- pip install --user awscli
|
||||
- go get github.com/mitchellh/gox
|
||||
- ziti-ci generate-build-info common/version/info_generated.go version
|
||||
- CC=arm-linux-gnueabihf-gcc CGO_ENABLED=true gox -cgo -os="$GOX_OS" -arch=arm -output=$GOX_OUTPUT ./...
|
||||
- aws s3 sync release/ s3://ziti-cmd-build-tmp/$TRAVIS_BUILD_ID
|
||||
|
||||
- stage: "Build and Test"
|
||||
os: mac
|
||||
env: GOX_OS=darwin
|
||||
script:
|
||||
- set -e
|
||||
- pip install --upgrade pip
|
||||
- pip install awscli
|
||||
- go get github.com/mitchellh/gox
|
||||
- ziti-ci generate-build-info common/version/info_generated.go version
|
||||
- CGO_ENABLED=true gox -os="$GOX_OS" -arch=$TRAVIS_CPU_ARCH -output=$GOX_OUTPUT ./...
|
||||
- aws s3 sync release/ s3://ziti-cmd-build-tmp/$TRAVIS_BUILD_ID
|
||||
|
||||
- stage: "Build and Test"
|
||||
os: windows
|
||||
env: GOX_OS=windows PATH=/c/Python36:/c/Python36/Scripts:$PATH
|
||||
script:
|
||||
- set -e
|
||||
- choco install python --version 3.6.8
|
||||
- python -m pip install --upgrade pip
|
||||
- pip install awscli
|
||||
- go get github.com/mitchellh/gox
|
||||
- ziti-ci generate-build-info common/version/info_generated.go version
|
||||
- CGO_ENABLED=true gox -os="$GOX_OS" -arch=$TRAVIS_CPU_ARCH -output=$GOX_OUTPUT ./...
|
||||
- aws s3 sync release/ s3://ziti-cmd-build-tmp/$TRAVIS_BUILD_ID
|
||||
|
||||
- stage: "Tag and Publish"
|
||||
os: linux
|
||||
arch: amd64
|
||||
script:
|
||||
- set -e
|
||||
- pip install --upgrade --user pip
|
||||
- pip install awscli
|
||||
- ziti-ci configure-git
|
||||
- ziti-ci generate-build-info common/version/info_generated.go version
|
||||
- go get github.com/mitchellh/gox
|
||||
- CGO_ENABLED=true gox -os="linux" -arch=$TRAVIS_CPU_ARCH -output=$GOX_OUTPUT ./...
|
||||
- ziti-ci tag --only-for-branch master -v -f "$VERSION_FILE"
|
||||
- aws s3 sync s3://ziti-cmd-build-tmp/$TRAVIS_BUILD_ID release/
|
||||
- aws s3 rm --recursive s3://ziti-cmd-build-tmp/$TRAVIS_BUILD_ID
|
||||
- ziti-ci publish-to-artifactory
|
||||
- ziti-ci trigger-jenkins-smoke-build
|
||||
@@ -1,3 +1,17 @@
|
||||
# Release 0.17.5
|
||||
|
||||
## What's New
|
||||
* Builds have been moved from travis.org to Github Actions
|
||||
* IDs generated for entities in the Edge no longer use underscores and instead use periods to avoid issues when used as a common name in CSRs
|
||||
* [edge#424](https://github.com/openziti/edge/issues/424) Authenticated, non-admin, clients can query service terminators
|
||||
* [sdk-golang#112](https://github.com/openziti/sdk-golang/issues/112) Process checks for Windows are case-insensitive
|
||||
* The CLI agent now runs over unix sockets and is enabled by default. See doc/ops-agent.md for details in the ziti repository.
|
||||
* [ziti#245](https://github.com/openziti/ziti/issues/245) Make timeout used by CLI's internal REST client configurable via cmd line arg
|
||||
|
||||
All `ziti edge controller` subcommands now support the `--timeout=n` flag which controls the internal REST-client timeout used when communicating with the Controller. The timeout resolution is in seconds. If this flag is not specified, the default is `5`. Prior to this release, the the REST-client timeout was always `2`. You now have the opportunity to increase the timeout if necessary (e.g. if large amounts of data are being queried).
|
||||
|
||||
All `ziti edge controller` subcommands now support the `--verbose` flag which will cause internal REST-client to emit debugging information concerning HTTP headers, status, raw json response data, and more. You now have the opportunity to see much more information, which could be valuable during trouble-shooting.
|
||||
|
||||
# Release 0.17.4
|
||||
## Breaking Changes
|
||||
* Process posture checks now accept process posture responses with `signerFingerprints` instead of a single
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
# Runtime Operations Agent
|
||||
The ziti controller and ziti router can both be introspected at runtime using the ziti command line tool.
|
||||
|
||||
## Available Operations
|
||||
1. Get the stack traces of all go-routines the running process
|
||||
1. `ziti ps stack`
|
||||
1. Force garbage collection
|
||||
1. `ziti ps gc`
|
||||
1. View memory statistics
|
||||
1. `ziti ps memstats`
|
||||
1. Example:
|
||||
```
|
||||
$ ziti ps memstats
|
||||
alloc: 22.89MB (24005552 bytes)
|
||||
total-alloc: 1.49GB (1602895000 bytes)
|
||||
sys: 75.02MB (78660608 bytes)
|
||||
lookups: 0
|
||||
mallocs: 23141725
|
||||
frees: 22895477
|
||||
heap-alloc: 22.89MB (24005552 bytes)
|
||||
heap-sys: 63.00MB (66060288 bytes)
|
||||
heap-idle: 34.71MB (36397056 bytes)
|
||||
heap-in-use: 28.29MB (29663232 bytes)
|
||||
heap-released: 31.31MB (32833536 bytes)
|
||||
heap-objects: 246248
|
||||
stack-in-use: 1.00MB (1048576 bytes)
|
||||
stack-sys: 1.00MB (1048576 bytes)
|
||||
stack-mspan-inuse: 500.44KB (512448 bytes)
|
||||
stack-mspan-sys: 576.00KB (589824 bytes)
|
||||
stack-mcache-inuse: 20.34KB (20832 bytes)
|
||||
stack-mcache-sys: 32.00KB (32768 bytes)
|
||||
other-sys: 2.97MB (3109868 bytes)
|
||||
gc-sys: 5.70MB (5974840 bytes)
|
||||
next-gc: when heap-alloc >= 24.58MB (25776064 bytes)
|
||||
last-gc: 2020-11-30 16:35:46.766977147 -0500 EST
|
||||
gc-pause-total: 10.939682ms
|
||||
gc-pause: 228800
|
||||
num-gc: 140
|
||||
enable-gc: true
|
||||
debug-gc: false
|
||||
```
|
||||
1. Get the go version used to build the executable
|
||||
1. `ziti ps goversion`
|
||||
1. Gets snapshot of the heap
|
||||
1. `ziti ps pprof-heap`
|
||||
1. Run cpu profiling for 30 seconds and returns the results
|
||||
1. `ziti ps pprof-cpu`
|
||||
1. Get Go runtime statistics such as number of goroutines, GOMAXPROCS, and NumCPU
|
||||
1. `ziti ps stats`
|
||||
1. Example:
|
||||
```
|
||||
$ ziti ps stats
|
||||
goroutines: 50
|
||||
OS threads: 19
|
||||
GOMAXPROCS: 12
|
||||
num CPU: 12
|
||||
```
|
||||
1. Run tracing for 5 seconds and return the result
|
||||
1. `ziti ps trace`
|
||||
1. Set the GC target percentage
|
||||
1. `ziti ps setgc <percentage>`
|
||||
|
||||
## Disabling the Agent
|
||||
The agent is enabled by default. It can be disabled using `--cliagent false`.
|
||||
|
||||
## Configuring Agent
|
||||
By default, the agent will listen on a Unix socket at `/tmp/gops-agent.<pid>.sock`. You can change this to a custom unix socket or use a network socket instead.
|
||||
|
||||
Examples:
|
||||
1. `ziti-controller --cli-agent-addr unix:/tmp/my-special-agent-file.sock`
|
||||
2. `ziti-controller --cli-agent-addr tcp:127.0.0.1:10001`
|
||||
|
||||
The agent uses unix sockets to limit security risk. Only the user on the machine who started the application, or the root user should be able to access the socket.
|
||||
|
||||
## Selecting Agent
|
||||
When running `ziti ps`, the target agent may be specified in a few different ways.
|
||||
|
||||
1. If no target is provided it will scan in `/tmp` for valid sockets. If only one is found, that one will be used. If multiple are found and error will be reported along with the different running processes.
|
||||
1. The target can be listed by name. So if you have a ziti-controller and a ziti-router running, you can do `ziti ps goversion ziti-router` it will find the ziti-router and talk with that. If you have multiple ziti-routers running, this will fail.
|
||||
1. You can specify the application PID. Example: `ziti ps goversion 1224770`
|
||||
1. If you are using network sockets you can specify the address. Example: `ziti ps goversion tcp:my-host:10001`
|
||||
@@ -3,7 +3,9 @@ v: 3
|
||||
#trace:
|
||||
# path: ctrl.trace
|
||||
|
||||
#profile:
|
||||
profile:
|
||||
# cpu:
|
||||
# path: /home/plorenz/tmp/ctrl.cpu.pprof
|
||||
# memory:
|
||||
# path: ctrl.memprof
|
||||
|
||||
|
||||
@@ -88,3 +88,6 @@ listeners:
|
||||
#maxOutstandingConnects: 100
|
||||
# the number of milliseconds to wait before a hello synchronization fails and closes the connection (30ms to 60000ms, default: 1000ms)
|
||||
#connectTimeoutMs: 3000
|
||||
- binding: proxy
|
||||
address: tcp:0.0.0.0:7001
|
||||
service: loop
|
||||
|
||||
@@ -19,16 +19,15 @@ require (
|
||||
github.com/fatih/color v1.7.0
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
|
||||
github.com/golang/protobuf v1.4.3
|
||||
github.com/google/go-cmp v0.5.2
|
||||
github.com/google/go-cmp v0.5.4
|
||||
github.com/gorilla/mux v1.8.0
|
||||
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d
|
||||
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0
|
||||
github.com/keybase/go-ps v0.0.0-20190827175125-91aafc93ba19
|
||||
github.com/michaelquigley/pfxlog v0.0.0-20190813191113-2be43bd0dccc
|
||||
github.com/openziti/edge v0.17.18
|
||||
github.com/openziti/fabric v0.14.16
|
||||
github.com/openziti/foundation v0.14.16
|
||||
github.com/openziti/sdk-golang v0.14.10
|
||||
github.com/openziti/edge v0.17.24
|
||||
github.com/openziti/fabric v0.14.19
|
||||
github.com/openziti/foundation v0.14.23
|
||||
github.com/openziti/sdk-golang v0.15.0
|
||||
github.com/pborman/uuid v1.2.0
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0
|
||||
@@ -45,6 +44,6 @@ require (
|
||||
google.golang.org/grpc v1.27.0
|
||||
gopkg.in/AlecAivazis/survey.v1 v1.8.7
|
||||
gopkg.in/resty.v1 v1.12.0
|
||||
gopkg.in/yaml.v2 v2.3.0
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
rsc.io/goversion v1.2.0
|
||||
)
|
||||
|
||||
@@ -66,8 +66,8 @@ github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdn
|
||||
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
|
||||
github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g=
|
||||
github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s=
|
||||
github.com/cenkalti/backoff/v4 v4.0.2 h1:JIufpQLbh4DkbQoii76ItQIUFzevQSqOLZca4eamEDs=
|
||||
github.com/cenkalti/backoff/v4 v4.0.2/go.mod h1:eEew/i+1Q6OrCDZh3WiXYv3+nJwBASZ8Bog/87DQnVg=
|
||||
github.com/cenkalti/backoff/v4 v4.1.0 h1:c8LkOFQTzuO0WBM/ae5HdGQuZPfPxp7lqBRwQRm4fSc=
|
||||
github.com/cenkalti/backoff/v4 v4.1.0/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
|
||||
github.com/cheekybits/genny v1.0.0 h1:uGGa4nei+j20rOSeDeP5Of12XVm7TGUd4dJA9RDitfE=
|
||||
@@ -275,6 +275,8 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
|
||||
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
|
||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
|
||||
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
|
||||
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
|
||||
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
|
||||
@@ -357,8 +359,6 @@ github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1
|
||||
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
|
||||
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
|
||||
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 h1:iQTw/8FWTuc7uiaSepXwyf3o52HaUYcV+Tu66S3F5GA=
|
||||
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8=
|
||||
github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4=
|
||||
github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA=
|
||||
github.com/kataras/go-events v0.0.3-0.20201007151548-c411dc70c0a6 h1:XXnySN8wVet8S4UlcXHjh8Oa7618Eu7z92HxU5cIfhA=
|
||||
@@ -462,8 +462,8 @@ github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQz
|
||||
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||
github.com/mitchellh/mapstructure v1.3.2 h1:mRS76wmkOn3KkKAyXDu42V+6ebnXWIztFSYGN7GeoRg=
|
||||
github.com/mitchellh/mapstructure v1.3.2/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/mitchellh/mapstructure v1.3.3 h1:SzB1nHZ2Xi+17FP0zVQBHIZqvwRN9408fJO8h+eeNA8=
|
||||
github.com/mitchellh/mapstructure v1.3.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/mitchellh/mapstructure v1.4.0 h1:7ks8ZkOP5/ujthUsT07rNv+nkLXCQWKNHuwzOAesEks=
|
||||
github.com/mitchellh/mapstructure v1.4.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
|
||||
@@ -496,17 +496,15 @@ github.com/onsi/gomega v1.8.1/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoT
|
||||
github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE=
|
||||
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
||||
github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8=
|
||||
github.com/openziti/edge v0.17.18 h1:50qAK2cgxRmmQbXHXn+ZV17eaYd4X1jaWFm2MaqKwu0=
|
||||
github.com/openziti/edge v0.17.18/go.mod h1:4TwpD7s/uEwVjM5HK1PJTyPakR2WEVraQbVQF9u+4es=
|
||||
github.com/openziti/fabric v0.14.16 h1:l+5ZX4FoXHusYDq7bFRaqOFtLpIVuZ/lqYibTKEJwg0=
|
||||
github.com/openziti/fabric v0.14.16/go.mod h1:aNECd87kH0bKntsHwPHtjbYf/9bk3MnlzQj21maO6FQ=
|
||||
github.com/openziti/foundation v0.14.15 h1:9QqOqo82wzws8zf5bfqezrmRj9E7AU1hnZHz8wiI9JY=
|
||||
github.com/openziti/foundation v0.14.15/go.mod h1:z98OIbCyr2B57EtamNgvDVIoQXct+zVVxOif9KsOOaM=
|
||||
github.com/openziti/foundation v0.14.16 h1:37jQVIVc3ZB/5Eb6FNS5uH6jQauTEbMWeIgblZCCnyQ=
|
||||
github.com/openziti/foundation v0.14.16/go.mod h1:z98OIbCyr2B57EtamNgvDVIoQXct+zVVxOif9KsOOaM=
|
||||
github.com/openziti/sdk-golang v0.14.9/go.mod h1:oD18qkd+NQrT0oRuq6eckKcmvgCum8lmP3wV7R8yWBg=
|
||||
github.com/openziti/sdk-golang v0.14.10 h1:XzbCDkJy+bh2M2uY1QvudksB+W8eXwZtIyp/QuLaVCk=
|
||||
github.com/openziti/sdk-golang v0.14.10/go.mod h1:oD18qkd+NQrT0oRuq6eckKcmvgCum8lmP3wV7R8yWBg=
|
||||
github.com/openziti/edge v0.17.24 h1:kPiAcOYtff33CK6K7+85eER4jMZdypX7zaAXURrYt9Y=
|
||||
github.com/openziti/edge v0.17.24/go.mod h1:8c8DWabK6VWLJSytUye27IskxF/k+6N6NDuU5fS7d/Y=
|
||||
github.com/openziti/fabric v0.14.19 h1:X3VviSCDnikrE39Zw7GRaSH9wud0sEzrbGtPo3dt01I=
|
||||
github.com/openziti/fabric v0.14.19/go.mod h1:VaRRUgL40VSaqUf75YREZMG/m2xLjRcsJtxmKxzfMoQ=
|
||||
github.com/openziti/foundation v0.14.18/go.mod h1:z98OIbCyr2B57EtamNgvDVIoQXct+zVVxOif9KsOOaM=
|
||||
github.com/openziti/foundation v0.14.23 h1:SHzPG2v2XCLBaUvh71NFezobctTb+KBEStiWObcziL0=
|
||||
github.com/openziti/foundation v0.14.23/go.mod h1:jb1fNtW+s4I43Zo7etlCwoDkOglBhR6E0g6D6dp0Bu4=
|
||||
github.com/openziti/sdk-golang v0.15.0 h1:Vuerj0IkHluKB92Fxmiyw9KUahABcdH/0uBZy3yiAac=
|
||||
github.com/openziti/sdk-golang v0.15.0/go.mod h1:J2/UCmA3TXBiqTggu4QbceXP+kiqbfgHU7HbhAqnG2E=
|
||||
github.com/orcaman/concurrent-map v0.0.0-20190826125027-8c72a8bb44f6 h1:lNCW6THrCKBiJBpz8kbVGjC7MgdCGKwuvBgc7LoD6sw=
|
||||
github.com/orcaman/concurrent-map v0.0.0-20190826125027-8c72a8bb44f6/go.mod h1:Lu3tH6HLW3feq74c2GC+jIMS/K2CFcDWnWD9XkenwhI=
|
||||
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
|
||||
@@ -946,6 +944,8 @@ gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
|
||||
gopkg.in/yaml.v2 v2.3.0/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 h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
@@ -27,7 +27,8 @@ import (
|
||||
|
||||
func init() {
|
||||
root.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose logging")
|
||||
root.PersistentFlags().BoolVarP(&cliAgentEnabled, "cliagent", "a", false, "Enable CLI Agent (use in dev only)")
|
||||
root.PersistentFlags().BoolVarP(&cliAgentEnabled, "cliagent", "a", true, "Enable/disabled CLI Agent (enabled by default)")
|
||||
root.PersistentFlags().StringVar(&cliAgentAddr, "cli-agent-addr", "", "Specify where CLI Agent should list (ex: unix:/tmp/myfile.sock or tcp:127.0.0.1:10001)")
|
||||
root.PersistentFlags().StringVar(&logFormatter, "log-formatter", "", "Specify log formatter [json|pfxlog|text]")
|
||||
|
||||
edgeSubCmd.AddCommands(root, version.GetCmdBuildInfo())
|
||||
@@ -56,6 +57,7 @@ var root = &cobra.Command{
|
||||
}
|
||||
var verbose bool
|
||||
var cliAgentEnabled bool
|
||||
var cliAgentAddr string
|
||||
var logFormatter string
|
||||
|
||||
func Execute() {
|
||||
|
||||
@@ -18,10 +18,11 @@ package subcmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/michaelquigley/pfxlog"
|
||||
"github.com/openziti/edge/controller/server"
|
||||
"github.com/openziti/fabric/controller"
|
||||
"github.com/openziti/foundation/agent"
|
||||
"github.com/openziti/ziti/common/version"
|
||||
"github.com/openziti/ziti/ziti/agent"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -39,8 +40,8 @@ var runCmd = &cobra.Command{
|
||||
func run(cmd *cobra.Command, args []string) {
|
||||
if config, err := controller.LoadConfig(args[0]); err == nil {
|
||||
if cliAgentEnabled {
|
||||
if err := agent.Listen(agent.Options{}); err != nil {
|
||||
panic(err)
|
||||
if err := agent.Listen(agent.Options{Addr: cliAgentAddr}); err != nil {
|
||||
pfxlog.Logger().WithError(err).Error("unable to start CLI agent")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/michaelquigley/pfxlog"
|
||||
"github.com/openziti/fabric/router/xgress_transport"
|
||||
"github.com/openziti/foundation/agent"
|
||||
"github.com/openziti/foundation/identity/dotziti"
|
||||
"github.com/openziti/foundation/identity/identity"
|
||||
"github.com/openziti/foundation/transport"
|
||||
@@ -70,6 +71,10 @@ func newDialerCmd() *dialerCmd {
|
||||
func (cmd *dialerCmd) run(_ *cobra.Command, args []string) {
|
||||
log := pfxlog.Logger()
|
||||
|
||||
if err := agent.Listen(agent.Options{}); err != nil {
|
||||
pfxlog.Logger().WithError(err).Error("unable to start CLI agent")
|
||||
}
|
||||
|
||||
scenario, err := LoadScenario(args[0])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
||||
@@ -18,6 +18,7 @@ package loop3
|
||||
|
||||
import (
|
||||
"github.com/michaelquigley/pfxlog"
|
||||
"github.com/openziti/foundation/agent"
|
||||
"github.com/openziti/foundation/identity/dotziti"
|
||||
"github.com/openziti/foundation/identity/identity"
|
||||
"github.com/openziti/foundation/transport"
|
||||
@@ -60,6 +61,10 @@ func newListenerCmd() *listenerCmd {
|
||||
}
|
||||
|
||||
func (cmd *listenerCmd) run(_ *cobra.Command, _ []string) {
|
||||
if err := agent.Listen(agent.Options{}); err != nil {
|
||||
pfxlog.Logger().WithError(err).Error("unable to start CLI agent")
|
||||
}
|
||||
|
||||
if strings.HasPrefix(cmd.bindAddress, "edge") {
|
||||
cmd.listenEdge()
|
||||
} else {
|
||||
|
||||
@@ -31,7 +31,7 @@ func (r *Result) getSuccessBytes() []byte {
|
||||
|
||||
func (r *Result) Tx(p *protocol) error {
|
||||
dataLen := 1 + len(r.Message)
|
||||
if err := p.txHeader(dataLen); err != nil {
|
||||
if err := p.txHeader(p.peer, dataLen); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -129,16 +129,17 @@ func (block *Block) Tx(p *protocol) error {
|
||||
|
||||
dataLen := 1 /* block type */ + len(tsBytes) + 4 /* sequence bytes */ + len(block.Hash) + len(block.Data)
|
||||
|
||||
if err := p.txHeader(dataLen); err != nil {
|
||||
buf := &bytes.Buffer{}
|
||||
if err := p.txHeader(buf, dataLen); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := p.peer.Write([]byte{block.Type}); err != nil {
|
||||
if _, err := buf.Write([]byte{block.Type}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(tsBytes) > 0 {
|
||||
if _, err := p.peer.Write(tsBytes); err != nil {
|
||||
if _, err := buf.Write(tsBytes); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -146,15 +147,19 @@ func (block *Block) Tx(p *protocol) error {
|
||||
seqBytes := make([]byte, 4)
|
||||
binary.LittleEndian.PutUint32(seqBytes, block.Sequence)
|
||||
|
||||
if _, err := p.peer.Write(seqBytes); err != nil {
|
||||
if _, err := buf.Write(seqBytes); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := p.peer.Write(block.Hash); err != nil {
|
||||
if _, err := buf.Write(block.Hash); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := p.peer.Write(block.Data); err != nil {
|
||||
if _, err := buf.Write(block.Data); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := p.peer.Write(buf.Bytes()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -24,10 +24,12 @@ import (
|
||||
"fmt"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/michaelquigley/pfxlog"
|
||||
"github.com/openziti/foundation/util/info"
|
||||
"github.com/openziti/ziti/ziti-fabric-test/subcmd/loop3/pb"
|
||||
"github.com/pkg/errors"
|
||||
"io"
|
||||
"math/rand"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -39,6 +41,7 @@ type protocol struct {
|
||||
rxBlocks chan *Block
|
||||
txCount int32
|
||||
rxCount int32
|
||||
lastRx int64
|
||||
latencies chan *time.Time
|
||||
errors chan error
|
||||
}
|
||||
@@ -90,7 +93,7 @@ func (p *protocol) txer(done chan bool) {
|
||||
defer log.Debug("complete")
|
||||
|
||||
var latency *time.Time
|
||||
|
||||
var lastSend time.Time
|
||||
for p.txCount < p.test.TxRequests {
|
||||
select {
|
||||
case block := <-p.txGenerator.blocks:
|
||||
@@ -109,16 +112,24 @@ func (p *protocol) txer(done chan bool) {
|
||||
}
|
||||
}
|
||||
|
||||
if err := block.Tx(p); err == nil {
|
||||
p.txCount++
|
||||
if p.test.TxPacing > 0 {
|
||||
jitter := 0
|
||||
if p.test.TxMaxJitter > 0 {
|
||||
jitter = rand.Intn(int(p.test.TxMaxJitter))
|
||||
}
|
||||
time.Sleep(time.Duration(int(p.test.TxPacing)+jitter) * time.Millisecond)
|
||||
if p.test.TxPacing > 0 {
|
||||
jitter := 0
|
||||
if p.test.TxMaxJitter > 0 {
|
||||
jitter = rand.Intn(int(p.test.TxMaxJitter))
|
||||
}
|
||||
|
||||
nextSend := lastSend.Add(time.Duration(int(p.test.TxPacing)+jitter) * time.Millisecond)
|
||||
now := time.Now()
|
||||
if nextSend.After(now) {
|
||||
time.Sleep(nextSend.Sub(now))
|
||||
lastSend = nextSend
|
||||
} else {
|
||||
lastSend = now
|
||||
}
|
||||
}
|
||||
|
||||
if err := block.Tx(p); err == nil {
|
||||
atomic.AddInt32(&p.txCount, 1)
|
||||
} else {
|
||||
log.Errorf("error sending block (%s)", err)
|
||||
p.errors <- err
|
||||
@@ -156,8 +167,9 @@ func (p *protocol) rxer(done chan bool) {
|
||||
}
|
||||
}
|
||||
|
||||
atomic.AddInt32(&p.rxCount, 1)
|
||||
atomic.StoreInt64(&p.lastRx, info.NowInMilliseconds())
|
||||
p.rxBlocks <- block
|
||||
p.rxCount++
|
||||
}
|
||||
|
||||
close(p.rxBlocks)
|
||||
@@ -201,12 +213,15 @@ func (p *protocol) verifier() {
|
||||
}
|
||||
|
||||
case <-time.After(time.Duration(p.test.RxTimeout) * time.Millisecond):
|
||||
err := fmt.Errorf("rx timeout exceeded (%d ms.)", p.test.RxTimeout)
|
||||
p.errors <- err
|
||||
if closeErr := p.peer.Close(); closeErr != nil {
|
||||
log.Error(closeErr)
|
||||
}
|
||||
log.Error(err)
|
||||
timeSinceLastRx := info.NowInMilliseconds() - atomic.LoadInt64(&p.lastRx)
|
||||
errStr := fmt.Sprintf("rx timeout exceeded (%d ms.). Last rx: %v. tx count: %v, rx count: %v",
|
||||
p.test.RxTimeout, timeSinceLastRx, atomic.LoadInt32(&p.txCount), atomic.LoadInt32(&p.rxCount))
|
||||
// err := errors.New(errStr)
|
||||
log.Errorf(errStr)
|
||||
// p.errors <- err
|
||||
//if closeErr := p.peer.Close(); closeErr != nil {
|
||||
// log.Error(closeErr)
|
||||
//}
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -251,10 +266,10 @@ func (p *protocol) txPb(pb proto.Message) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = p.txMagicHeader(); err != nil {
|
||||
if err = p.txMagicHeader(p.peer); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := p.txLength(len(data)); err != nil {
|
||||
if err := p.txLength(p.peer, len(data)); err != nil {
|
||||
return err
|
||||
}
|
||||
n, err := p.peer.Write(data)
|
||||
@@ -297,8 +312,8 @@ func (p *protocol) rxPb(pb proto.Message) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *protocol) txMagicHeader() error {
|
||||
n, err := p.peer.Write(MagicHeader)
|
||||
func (p *protocol) txMagicHeader(w io.Writer) error {
|
||||
n, err := w.Write(MagicHeader)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -308,10 +323,10 @@ func (p *protocol) txMagicHeader() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *protocol) txLength(length int) error {
|
||||
func (p *protocol) txLength(w io.Writer, length int) error {
|
||||
out := make([]byte, 4)
|
||||
binary.LittleEndian.PutUint32(out, uint32(length))
|
||||
n, err := p.peer.Write(out)
|
||||
n, err := w.Write(out)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -321,12 +336,12 @@ func (p *protocol) txLength(length int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *protocol) txHeader(msgLen int) error {
|
||||
if err := p.txMagicHeader(); err != nil {
|
||||
func (p *protocol) txHeader(w io.Writer, msgLen int) error {
|
||||
if err := p.txMagicHeader(w); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := p.txLength(msgLen); err != nil {
|
||||
if err := p.txLength(w, msgLen); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -26,6 +26,8 @@ import (
|
||||
func init() {
|
||||
root.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose logging")
|
||||
root.PersistentFlags().StringVar(&logFormatter, "log-formatter", "", "Specify log formatter [json|pfxlog|text]")
|
||||
root.PersistentFlags().BoolVar(&cliAgentEnabled, "cli-agent", true, "Enable/disable CLI Agent (enabled by default)")
|
||||
root.PersistentFlags().StringVar(&cliAgentAddr, "cli-agent-addr", "", "Specify where CLI Agent should list (ex: unix:/tmp/myfile.sock or tcp:127.0.0.1:10001)")
|
||||
}
|
||||
|
||||
var root = &cobra.Command{
|
||||
@@ -52,6 +54,8 @@ var root = &cobra.Command{
|
||||
|
||||
var verbose bool
|
||||
var logFormatter string
|
||||
var cliAgentEnabled bool
|
||||
var cliAgentAddr string
|
||||
|
||||
func Execute() {
|
||||
if err := root.Execute(); err != nil {
|
||||
|
||||
@@ -17,10 +17,12 @@
|
||||
package subcmd
|
||||
|
||||
import (
|
||||
"github.com/michaelquigley/pfxlog"
|
||||
"github.com/openziti/edge/router/xgress_edge"
|
||||
"github.com/openziti/edge/router/xgress_edge_transport"
|
||||
"github.com/openziti/fabric/router"
|
||||
"github.com/openziti/fabric/router/xgress"
|
||||
"github.com/openziti/foundation/agent"
|
||||
"github.com/openziti/ziti/common/version"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -40,6 +42,12 @@ var runCmd = &cobra.Command{
|
||||
|
||||
func run(cmd *cobra.Command, args []string) {
|
||||
if config, err := router.LoadConfig(args[0]); err == nil {
|
||||
if cliAgentEnabled {
|
||||
if err := agent.Listen(agent.Options{Addr: cliAgentAddr}); err != nil {
|
||||
pfxlog.Logger().WithError(err).Error("unable to start CLI agent")
|
||||
}
|
||||
}
|
||||
|
||||
config.SetFlags(getFlags(cmd))
|
||||
|
||||
r := router.Create(config, version.GetCmdBuildInfo())
|
||||
|
||||
@@ -1,272 +0,0 @@
|
||||
/*
|
||||
Copyright NetFoundry, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
https://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Package agent provides hooks programs can register to retrieve
|
||||
// diagnostics data by using the Ziti CLI.
|
||||
package agent
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
gosignal "os/signal"
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
"runtime/pprof"
|
||||
"runtime/trace"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/openziti/ziti/ziti/signal"
|
||||
"github.com/openziti/ziti/ziti/util"
|
||||
"github.com/kardianos/osext"
|
||||
)
|
||||
|
||||
const defaultAddr = "127.0.0.1:0"
|
||||
|
||||
var (
|
||||
mu sync.Mutex
|
||||
portfile string
|
||||
listener net.Listener
|
||||
|
||||
units = []string{" bytes", "KB", "MB", "GB", "TB", "PB"}
|
||||
)
|
||||
|
||||
// Options allows configuring the started agent.
|
||||
type Options struct {
|
||||
// Addr is the host:port the agent will be listening at.
|
||||
// Optional.
|
||||
Addr string
|
||||
|
||||
// ConfigDir is the directory to store the configuration file,
|
||||
// PID of the gops process, filename, port as well as content.
|
||||
// Optional.
|
||||
ConfigDir string
|
||||
|
||||
// ShutdownCleanup automatically cleans up resources if the
|
||||
// running process receives an interrupt. Otherwise, users
|
||||
// can call Close before shutting down.
|
||||
// Optional.
|
||||
ShutdownCleanup bool
|
||||
}
|
||||
|
||||
// Listen starts the gops agent on a host process. Once agent started, users
|
||||
// can use the advanced gops features. The agent will listen to Interrupt
|
||||
// signals and exit the process, if you need to perform further work on the
|
||||
// Interrupt signal use the options parameter to configure the agent
|
||||
// accordingly.
|
||||
//
|
||||
// Note: The agent exposes an endpoint via a TCP connection that can be used by
|
||||
// any program on the system. Review your security requirements before starting
|
||||
// the agent.
|
||||
func Listen(opts Options) error {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
|
||||
if portfile != "" {
|
||||
return fmt.Errorf("gops: agent already listening at: %v", listener.Addr())
|
||||
}
|
||||
|
||||
// new
|
||||
gopsdir := opts.ConfigDir
|
||||
if gopsdir == "" {
|
||||
cfgDir, err := util.ConfigDir()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
gopsdir = cfgDir
|
||||
}
|
||||
|
||||
err := os.MkdirAll(gopsdir, os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if opts.ShutdownCleanup {
|
||||
gracefulShutdown()
|
||||
}
|
||||
|
||||
addr := opts.Addr
|
||||
if addr == "" {
|
||||
addr = defaultAddr
|
||||
}
|
||||
ln, err := net.Listen("tcp", addr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
listener = ln
|
||||
port := listener.Addr().(*net.TCPAddr).Port
|
||||
portfile = fmt.Sprintf("%s/%d", gopsdir, os.Getpid())
|
||||
err = ioutil.WriteFile(portfile, []byte(strconv.Itoa(port)), os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
go listen()
|
||||
return nil
|
||||
}
|
||||
|
||||
func listen() {
|
||||
buf := make([]byte, 1)
|
||||
for {
|
||||
fd, err := listener.Accept()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "gops: %v", err)
|
||||
if netErr, ok := err.(net.Error); ok && !netErr.Temporary() {
|
||||
break
|
||||
}
|
||||
continue
|
||||
}
|
||||
if _, err := fd.Read(buf); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "gops: %v", err)
|
||||
continue
|
||||
}
|
||||
if err := handle(fd, buf); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "gops: %v", err)
|
||||
continue
|
||||
}
|
||||
fd.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func gracefulShutdown() {
|
||||
c := make(chan os.Signal, 1)
|
||||
gosignal.Notify(c, os.Interrupt)
|
||||
go func() {
|
||||
// cleanup the socket on shutdown.
|
||||
<-c
|
||||
Close()
|
||||
os.Exit(1)
|
||||
}()
|
||||
}
|
||||
|
||||
// Close closes the agent, removing temporary files and closing the TCP listener.
|
||||
// If no agent is listening, Close does nothing.
|
||||
func Close() {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
|
||||
if portfile != "" {
|
||||
os.Remove(portfile)
|
||||
portfile = ""
|
||||
}
|
||||
if listener != nil {
|
||||
listener.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func formatBytes(val uint64) string {
|
||||
var i int
|
||||
var target uint64
|
||||
for i = range units {
|
||||
target = 1 << uint(10*(i+1))
|
||||
if val < target {
|
||||
break
|
||||
}
|
||||
}
|
||||
if i > 0 {
|
||||
return fmt.Sprintf("%0.2f%s (%d bytes)", float64(val)/(float64(target)/1024), units[i], val)
|
||||
}
|
||||
return fmt.Sprintf("%d bytes", val)
|
||||
}
|
||||
|
||||
func handle(conn io.ReadWriter, msg []byte) error {
|
||||
switch msg[0] {
|
||||
case signal.StackTrace:
|
||||
return pprof.Lookup("goroutine").WriteTo(conn, 2)
|
||||
case signal.GC:
|
||||
runtime.GC()
|
||||
_, err := conn.Write([]byte("ok"))
|
||||
return err
|
||||
case signal.MemStats:
|
||||
var s runtime.MemStats
|
||||
runtime.ReadMemStats(&s)
|
||||
fmt.Fprintf(conn, "alloc: %v\n", formatBytes(s.Alloc))
|
||||
fmt.Fprintf(conn, "total-alloc: %v\n", formatBytes(s.TotalAlloc))
|
||||
fmt.Fprintf(conn, "sys: %v\n", formatBytes(s.Sys))
|
||||
fmt.Fprintf(conn, "lookups: %v\n", s.Lookups)
|
||||
fmt.Fprintf(conn, "mallocs: %v\n", s.Mallocs)
|
||||
fmt.Fprintf(conn, "frees: %v\n", s.Frees)
|
||||
fmt.Fprintf(conn, "heap-alloc: %v\n", formatBytes(s.HeapAlloc))
|
||||
fmt.Fprintf(conn, "heap-sys: %v\n", formatBytes(s.HeapSys))
|
||||
fmt.Fprintf(conn, "heap-idle: %v\n", formatBytes(s.HeapIdle))
|
||||
fmt.Fprintf(conn, "heap-in-use: %v\n", formatBytes(s.HeapInuse))
|
||||
fmt.Fprintf(conn, "heap-released: %v\n", formatBytes(s.HeapReleased))
|
||||
fmt.Fprintf(conn, "heap-objects: %v\n", s.HeapObjects)
|
||||
fmt.Fprintf(conn, "stack-in-use: %v\n", formatBytes(s.StackInuse))
|
||||
fmt.Fprintf(conn, "stack-sys: %v\n", formatBytes(s.StackSys))
|
||||
fmt.Fprintf(conn, "stack-mspan-inuse: %v\n", formatBytes(s.MSpanInuse))
|
||||
fmt.Fprintf(conn, "stack-mspan-sys: %v\n", formatBytes(s.MSpanSys))
|
||||
fmt.Fprintf(conn, "stack-mcache-inuse: %v\n", formatBytes(s.MCacheInuse))
|
||||
fmt.Fprintf(conn, "stack-mcache-sys: %v\n", formatBytes(s.MCacheSys))
|
||||
fmt.Fprintf(conn, "other-sys: %v\n", formatBytes(s.OtherSys))
|
||||
fmt.Fprintf(conn, "gc-sys: %v\n", formatBytes(s.GCSys))
|
||||
fmt.Fprintf(conn, "next-gc: when heap-alloc >= %v\n", formatBytes(s.NextGC))
|
||||
lastGC := "-"
|
||||
if s.LastGC != 0 {
|
||||
lastGC = fmt.Sprint(time.Unix(0, int64(s.LastGC)))
|
||||
}
|
||||
fmt.Fprintf(conn, "last-gc: %v\n", lastGC)
|
||||
fmt.Fprintf(conn, "gc-pause-total: %v\n", time.Duration(s.PauseTotalNs))
|
||||
fmt.Fprintf(conn, "gc-pause: %v\n", s.PauseNs[(s.NumGC+255)%256])
|
||||
fmt.Fprintf(conn, "num-gc: %v\n", s.NumGC)
|
||||
fmt.Fprintf(conn, "enable-gc: %v\n", s.EnableGC)
|
||||
fmt.Fprintf(conn, "debug-gc: %v\n", s.DebugGC)
|
||||
case signal.Version:
|
||||
fmt.Fprintf(conn, "%v\n", runtime.Version())
|
||||
case signal.HeapProfile:
|
||||
pprof.WriteHeapProfile(conn)
|
||||
case signal.CPUProfile:
|
||||
if err := pprof.StartCPUProfile(conn); err != nil {
|
||||
return err
|
||||
}
|
||||
time.Sleep(30 * time.Second)
|
||||
pprof.StopCPUProfile()
|
||||
case signal.Stats:
|
||||
fmt.Fprintf(conn, "goroutines: %v\n", runtime.NumGoroutine())
|
||||
fmt.Fprintf(conn, "OS threads: %v\n", pprof.Lookup("threadcreate").Count())
|
||||
fmt.Fprintf(conn, "GOMAXPROCS: %v\n", runtime.GOMAXPROCS(0))
|
||||
fmt.Fprintf(conn, "num CPU: %v\n", runtime.NumCPU())
|
||||
case signal.BinaryDump:
|
||||
path, err := osext.Executable()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
_, err = bufio.NewReader(f).WriteTo(conn)
|
||||
return err
|
||||
case signal.Trace:
|
||||
trace.Start(conn)
|
||||
time.Sleep(5 * time.Second)
|
||||
trace.Stop()
|
||||
case signal.SetGCPercent:
|
||||
perc, err := binary.ReadVarint(bufio.NewReader(conn))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Fprintf(conn, "New GC percent set to %v. Previous value was %v.\n", perc, debug.SetGCPercent(int(perc)))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
Copyright NetFoundry, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
https://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Package agent provides hooks programs can register to retrieve
|
||||
// diagnostics data by using the Ziti CLI.
|
||||
package agent
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestListen(t *testing.T) {
|
||||
err := Listen(Options{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
Close()
|
||||
}
|
||||
|
||||
func TestAgentClose(t *testing.T) {
|
||||
err := Listen(Options{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
Close()
|
||||
_, err = os.Stat(portfile)
|
||||
if !os.IsNotExist(err) {
|
||||
t.Fatalf("portfile = %q doesn't exist; err = %v", portfile, err)
|
||||
}
|
||||
if portfile != "" {
|
||||
t.Fatalf("got = %q; want empty portfile", portfile)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUseCustomConfigDir(t *testing.T) {
|
||||
err := Listen(Options{
|
||||
ConfigDir: os.TempDir(),
|
||||
ShutdownCleanup: true,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
Close()
|
||||
}
|
||||
|
||||
func TestAgentListenMultipleClose(t *testing.T) {
|
||||
err := Listen(Options{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
Close()
|
||||
Close()
|
||||
Close()
|
||||
Close()
|
||||
}
|
||||
|
||||
func TestFormatBytes(t *testing.T) {
|
||||
tests := []struct {
|
||||
val uint64
|
||||
want string
|
||||
}{
|
||||
{1023, "1023 bytes"},
|
||||
{1024, "1.00KB (1024 bytes)"},
|
||||
{1024*1024 - 100, "1023.90KB (1048476 bytes)"},
|
||||
{1024 * 1024, "1.00MB (1048576 bytes)"},
|
||||
{1024 * 1025, "1.00MB (1049600 bytes)"},
|
||||
{1024 * 1024 * 1024, "1.00GB (1073741824 bytes)"},
|
||||
{1024*1024*1024 + 430*1024*1024, "1.42GB (1524629504 bytes)"},
|
||||
{1024 * 1024 * 1024 * 1024 * 1024, "1.00PB (1125899906842624 bytes)"},
|
||||
{1024 * 1024 * 1024 * 1024 * 1024 * 1024, "1024.00PB (1152921504606846976 bytes)"},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
result := formatBytes(tt.val)
|
||||
if result != tt.want {
|
||||
t.Errorf("formatBytes(%v) = %q; want %q", tt.val, result, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,10 +17,10 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory"
|
||||
"github.com/openziti/ziti/ziti/cmd/ziti/cmd/table"
|
||||
"github.com/openziti/ziti/ziti/cmd/ziti/internal/log"
|
||||
"fmt"
|
||||
"github.com/spf13/cobra"
|
||||
"io"
|
||||
"os"
|
||||
@@ -38,6 +38,7 @@ type CommonOptions struct {
|
||||
Verbose bool
|
||||
Staging bool
|
||||
ConfigIdentity string
|
||||
Timeout int
|
||||
}
|
||||
|
||||
type ServerFlags struct {
|
||||
@@ -72,6 +73,7 @@ func (options *CommonOptions) addCommonFlags(cmd *cobra.Command) {
|
||||
cmd.Flags().BoolVarP(&options.Verbose, "verbose", "", false, "Enable verbose logging")
|
||||
cmd.Flags().BoolVarP(&options.Staging, "staging", "", false, "Install/Upgrade components from the ziti-staging repo")
|
||||
cmd.Flags().StringVarP(&options.ConfigIdentity, "configIdentity", "i", "", "Which configIdentity to use")
|
||||
cmd.Flags().IntVarP(&options.Timeout, "timeout", "t", 5, "Timeout for REST operations (specified in seconds)")
|
||||
options.Cmd = cmd
|
||||
}
|
||||
|
||||
|
||||
@@ -33,4 +33,5 @@ type CommonOptions struct {
|
||||
Verbose bool
|
||||
Staging bool
|
||||
ConfigIdentity string
|
||||
Timeout int
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ var ZITI_COMPONENTS = []string{
|
||||
c.ZITI_FABRIC,
|
||||
c.ZITI_FABRIC_GW,
|
||||
c.ZITI_FABRIC_TEST,
|
||||
c.ZITI_PROXY,
|
||||
c.ZITI_PROX_C,
|
||||
c.ZITI_ROUTER,
|
||||
c.ZITI_TUNNEL,
|
||||
|
||||
@@ -23,8 +23,8 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func mapNameToID(entityType string, val string) (string, error) {
|
||||
list, _, err := filterEntitiesOfType(entityType, fmt.Sprintf("id=\"%s\"", val), false, nil)
|
||||
func mapNameToID(entityType string, val string, o commonOptions) (string, error) {
|
||||
list, _, err := filterEntitiesOfType(entityType, fmt.Sprintf("id=\"%s\"", val), false, nil, o.Timeout, o.Verbose)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -33,7 +33,7 @@ func mapNameToID(entityType string, val string) (string, error) {
|
||||
return val, nil
|
||||
}
|
||||
|
||||
list, _, err = filterEntitiesOfType(entityType, fmt.Sprintf("name=\"%s\"", val), false, nil)
|
||||
list, _, err = filterEntitiesOfType(entityType, fmt.Sprintf("name=\"%s\"", val), false, nil, o.Timeout, o.Verbose)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -54,8 +54,8 @@ func mapNameToID(entityType string, val string) (string, error) {
|
||||
return entityId, nil
|
||||
}
|
||||
|
||||
func mapIdToName(entityType string, val string) (string, error) {
|
||||
list, _, err := filterEntitiesOfType(entityType, fmt.Sprintf(`id="%s"`, val), false, nil)
|
||||
func mapIdToName(entityType string, val string, o commonOptions) (string, error) {
|
||||
list, _, err := filterEntitiesOfType(entityType, fmt.Sprintf(`id="%s"`, val), false, nil, o.Timeout, o.Verbose)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -69,7 +69,7 @@ func mapIdToName(entityType string, val string) (string, error) {
|
||||
return name, nil
|
||||
}
|
||||
|
||||
func mapNamesToIDs(entityType string, list ...string) ([]string, error) {
|
||||
func mapNamesToIDs(entityType string, o commonOptions, list ...string) ([]string, error) {
|
||||
var result []string
|
||||
for _, val := range list {
|
||||
if strings.HasPrefix(val, "id") {
|
||||
@@ -81,7 +81,7 @@ func mapNamesToIDs(entityType string, list ...string) ([]string, error) {
|
||||
name := strings.TrimPrefix(val, "name:")
|
||||
query = fmt.Sprintf(`name="%s"`, name)
|
||||
}
|
||||
list, _, err := filterEntitiesOfType(entityType, query, false, nil)
|
||||
list, _, err := filterEntitiesOfType(entityType, query, false, nil, o.Timeout, o.Verbose)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -103,10 +103,10 @@ func mapNamesToIDs(entityType string, list ...string) ([]string, error) {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func mapIdentityNameToID(nameOrId string) (string, error) {
|
||||
return mapNameToID("identities", nameOrId)
|
||||
func mapIdentityNameToID(nameOrId string, o commonOptions) (string, error) {
|
||||
return mapNameToID("identities", nameOrId, o)
|
||||
}
|
||||
|
||||
func mapCaNameToID(nameOrId string) (string, error) {
|
||||
return mapNameToID("cas", nameOrId)
|
||||
func mapCaNameToID(nameOrId string, o commonOptions) (string, error) {
|
||||
return mapNameToID("cas", nameOrId, o)
|
||||
}
|
||||
|
||||
@@ -56,5 +56,5 @@ func newCreateCmd(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Com
|
||||
|
||||
// createEntityOfType create an entity of the given type on the Ziti Edge Controller
|
||||
func createEntityOfType(entityType string, body string, options *commonOptions) (*gabs.Container, error) {
|
||||
return util.EdgeControllerCreate(entityType, body, options.Out, options.OutputJSONResponse)
|
||||
return util.EdgeControllerCreate(entityType, body, options.Out, options.OutputJSONResponse, options.Timeout, options.Verbose)
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/Jeffail/gabs"
|
||||
"github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
|
||||
"github.com/openziti/foundation/util/term"
|
||||
"github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -78,7 +78,7 @@ func runCreateIdentityPassword(idType string, options *createAuthenticatorUpdb)
|
||||
return errors.New("an identity must be specified")
|
||||
}
|
||||
|
||||
id, err := mapIdentityNameToID(options.idOrName)
|
||||
id, err := mapIdentityNameToID(options.idOrName, options.commonOptions)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -95,7 +95,7 @@ func runCreateConfig(o *createConfigOptions) error {
|
||||
return errors.Errorf("unable to parse data as json: %v", err)
|
||||
}
|
||||
|
||||
configTypeId, err := mapNameToID("config-types", o.Args[1])
|
||||
configTypeId, err := mapNameToID("config-types", o.Args[1], o.commonOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ func runCreateEdgeRouter(o *createEdgeRouterOptions) error {
|
||||
}
|
||||
|
||||
func getEdgeRouterJwt(o *createEdgeRouterOptions, id string) error {
|
||||
newRouter, err := DetailEntityOfType("edge-routers", id, o.OutputJSONResponse, o.Out)
|
||||
newRouter, err := DetailEntityOfType("edge-routers", id, o.OutputJSONResponse, o.Out, o.commonOptions.Timeout, o.commonOptions.Verbose)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -68,12 +68,12 @@ func newCreateEdgeRouterPolicyCmd(f cmdutil.Factory, out io.Writer, errOut io.Wr
|
||||
|
||||
// runCreateEdgeRouterPolicy create a new edgeRouterPolicy on the Ziti Edge Controller
|
||||
func runCreateEdgeRouterPolicy(o *createEdgeRouterPolicyOptions) error {
|
||||
edgeRouterRoles, err := convertNamesToIds(o.edgeRouterRoles, "edge-routers")
|
||||
edgeRouterRoles, err := convertNamesToIds(o.edgeRouterRoles, "edge-routers", o.commonOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
identityRoles, err := convertNamesToIds(o.identityRoles, "identities")
|
||||
identityRoles, err := convertNamesToIds(o.identityRoles, "identities", o.commonOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -114,16 +114,16 @@ func runCreateIdentity(idType string, o *createIdentityOptions) error {
|
||||
}
|
||||
|
||||
if o.jwtOutputFile != "" {
|
||||
if err := getIdentityJwt(o, id); err != nil {
|
||||
if err := getIdentityJwt(o, id, o.commonOptions.Timeout, o.commonOptions.Verbose); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func getIdentityJwt(o *createIdentityOptions, id string) error {
|
||||
func getIdentityJwt(o *createIdentityOptions, id string, timeout int, verbose bool) error {
|
||||
|
||||
newIdentity, err := DetailEntityOfType("identities", id, o.OutputJSONResponse, o.Out)
|
||||
newIdentity, err := DetailEntityOfType("identities", id, o.OutputJSONResponse, o.Out, timeout, verbose)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ func newCreateServiceCmd(f cmdutil.Factory, out io.Writer, errOut io.Writer) *co
|
||||
|
||||
// runCreateService implements the command to create a service
|
||||
func runCreateService(o *createServiceOptions) (err error) {
|
||||
configs, err := mapNamesToIDs("configs", o.configs...)
|
||||
configs, err := mapNamesToIDs("configs", o.commonOptions, o.configs...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -68,12 +68,12 @@ func newCreateServiceEdgeRouterPolicyCmd(f cmdutil.Factory, out io.Writer, errOu
|
||||
|
||||
// runCreateServiceEdgeRouterPolicy create a new edgeRouterPolicy on the Ziti Edge Controller
|
||||
func runCreateServiceEdgeRouterPolicy(o *createServiceEdgeRouterPolicyOptions) error {
|
||||
edgeRouterRoles, err := convertNamesToIds(o.edgeRouterRoles, "edge-routers")
|
||||
edgeRouterRoles, err := convertNamesToIds(o.edgeRouterRoles, "edge-routers", o.commonOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
serviceRoles, err := convertNamesToIds(o.serviceRoles, "services")
|
||||
serviceRoles, err := convertNamesToIds(o.serviceRoles, "services", o.commonOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -78,17 +78,17 @@ func runCreateServicePolicy(o *createServicePolicyOptions) error {
|
||||
return errors.Errorf("Invalid policy type '%v'. Valid values: [Bind, Dial]", policyType)
|
||||
}
|
||||
|
||||
serviceRoles, err := convertNamesToIds(o.serviceRoles, "services")
|
||||
serviceRoles, err := convertNamesToIds(o.serviceRoles, "services", o.commonOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
identityRoles, err := convertNamesToIds(o.identityRoles, "identities")
|
||||
identityRoles, err := convertNamesToIds(o.identityRoles, "identities", o.commonOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
postureCheckRoles, err := convertNamesToIds(o.postureCheckRoles, "postureChecks")
|
||||
postureCheckRoles, err := convertNamesToIds(o.postureCheckRoles, "postureChecks", o.commonOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -118,12 +118,12 @@ func runCreateServicePolicy(o *createServicePolicyOptions) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func convertNamesToIds(roles []string, entityType string) ([]string, error) {
|
||||
func convertNamesToIds(roles []string, entityType string, o commonOptions) ([]string, error) {
|
||||
var result []string
|
||||
for _, val := range roles {
|
||||
if strings.HasPrefix(val, "@") {
|
||||
idOrName := strings.TrimPrefix(val, "@")
|
||||
id, err := mapNameToID(entityType, idOrName)
|
||||
id, err := mapNameToID(entityType, idOrName, o)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -77,12 +77,12 @@ func newCreateTerminatorCmd(f cmdutil.Factory, out io.Writer, errOut io.Writer)
|
||||
// runCreateTerminator implements the command to create a Terminator
|
||||
func runCreateTerminator(o *createTerminatorOptions) (err error) {
|
||||
entityData := gabs.New()
|
||||
service, err := mapNameToID("services", o.Args[0])
|
||||
service, err := mapNameToID("services", o.Args[0], o.commonOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
router, err := mapNameToID("edge-routers", o.Args[1])
|
||||
router, err := mapNameToID("edge-routers", o.Args[1], o.commonOptions)
|
||||
if err != nil {
|
||||
router = o.Args[1] // might be a pure fabric router, id might not be UUID
|
||||
}
|
||||
|
||||
@@ -51,9 +51,9 @@ func runCheckIntegrityDb(o *dbCheckIntegrityOptions) error {
|
||||
var body *gabs.Container
|
||||
|
||||
if o.fix {
|
||||
body, err = util.EdgeControllerUpdate("database/fix-data-integrity", "", o.Out, http.MethodPost, o.OutputJSONRequest, o.OutputJSONResponse)
|
||||
body, err = util.EdgeControllerUpdate("database/fix-data-integrity", "", o.Out, http.MethodPost, o.OutputJSONRequest, o.OutputJSONResponse, o.commonOptions.Timeout, o.commonOptions.Verbose)
|
||||
} else {
|
||||
body, err = util.EdgeControllerList("database/check-data-integrity", nil, o.OutputJSONResponse, o.Out)
|
||||
body, err = util.EdgeControllerList("database/check-data-integrity", nil, o.OutputJSONResponse, o.Out, o.commonOptions.Timeout, o.commonOptions.Verbose)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
||||
@@ -58,6 +58,6 @@ func newDbSnapshotCmd(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra
|
||||
}
|
||||
|
||||
func runSnapshotDb(o *dbSnapshotOptions) error {
|
||||
_, err := util.EdgeControllerUpdate("database/snapshot", "", o.Out, http.MethodPost, false, false)
|
||||
_, err := util.EdgeControllerUpdate("database/snapshot", "", o.Out, http.MethodPost, false, false, o.commonOptions.Timeout, o.commonOptions.Verbose)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -98,13 +98,13 @@ func runDeleteEntityOfType(o *commonOptions, entityType string) error {
|
||||
var err error
|
||||
ids := []string{o.Args[0]}
|
||||
if entityType != "terminators" && entityType != "api-sessions" && entityType != "sessions" {
|
||||
ids, err = mapNamesToIDs(entityType, o.Args[0])
|
||||
ids, err = mapNamesToIDs(entityType, *o, o.Args[0])
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, id := range ids {
|
||||
_, err := util.EdgeControllerDelete(entityType, id, o.Out, o.OutputJSONResponse)
|
||||
_, err := util.EdgeControllerDelete(entityType, id, o.Out, o.OutputJSONResponse, o.Timeout, o.Verbose)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -120,5 +120,5 @@ func getPlural(entityType string) string {
|
||||
}
|
||||
|
||||
func deleteEntityOfType(entityType string, id string, options *commonOptions) (*gabs.Container, error) {
|
||||
return util.EdgeControllerDelete(entityType, id, options.Out, options.OutputJSONResponse)
|
||||
return util.EdgeControllerDelete(entityType, id, options.Out, options.OutputJSONResponse, options.Timeout, options.Verbose)
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ func newDeleteAuthenticatorUpdb(idType string, options *commonOptions) *cobra.Co
|
||||
|
||||
func runDeleteUpdb(idOrName string, options *deleteUpdbOptions) error {
|
||||
|
||||
id, err := mapIdentityNameToID(idOrName)
|
||||
id, err := mapIdentityNameToID(idOrName, options.commonOptions)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -22,8 +22,8 @@ import (
|
||||
"io"
|
||||
)
|
||||
|
||||
func DetailEntityOfType(entityType, entityId string, logJSON bool, out io.Writer) (*gabs.Container, error) {
|
||||
jsonParsed, err := util.EdgeControllerDetailEntity(entityType, entityId, logJSON, out)
|
||||
func DetailEntityOfType(entityType, entityId string, logJSON bool, out io.Writer, timeout int, verbose bool) (*gabs.Container, error) {
|
||||
jsonParsed, err := util.EdgeControllerDetailEntity(entityType, entityId, logJSON, out, timeout, verbose)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -307,18 +307,18 @@ func listEntitiesWithOptions(entityType string, options *commonOptions) ([]*gabs
|
||||
params.Add("filter", options.Args[0])
|
||||
}
|
||||
|
||||
return listEntitiesOfType(entityType, params, options.OutputJSONResponse, options.Out)
|
||||
return listEntitiesOfType(entityType, params, options.OutputJSONResponse, options.Out, options.Timeout, options.Verbose)
|
||||
}
|
||||
|
||||
func filterEntitiesOfType(entityType string, filter string, logJSON bool, out io.Writer) ([]*gabs.Container, *paging, error) {
|
||||
func filterEntitiesOfType(entityType string, filter string, logJSON bool, out io.Writer, timeout int, verbose bool) ([]*gabs.Container, *paging, error) {
|
||||
params := url.Values{}
|
||||
params.Add("filter", filter)
|
||||
return listEntitiesOfType(entityType, params, logJSON, out)
|
||||
return listEntitiesOfType(entityType, params, logJSON, out, timeout, verbose)
|
||||
}
|
||||
|
||||
// listEntitiesOfType queries the Ziti Controller for entities of the given type
|
||||
func listEntitiesOfType(entityType string, params url.Values, logJSON bool, out io.Writer) ([]*gabs.Container, *paging, error) {
|
||||
jsonParsed, err := util.EdgeControllerList(entityType, params, logJSON, out)
|
||||
func listEntitiesOfType(entityType string, params url.Values, logJSON bool, out io.Writer, timeout int, verbose bool) ([]*gabs.Container, *paging, error) {
|
||||
jsonParsed, err := util.EdgeControllerList(entityType, params, logJSON, out, timeout, verbose)
|
||||
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@@ -357,7 +357,7 @@ func getPaging(c *gabs.Container) *paging {
|
||||
|
||||
// listEntitiesOfType queries the Ziti Controller for entities of the given type
|
||||
func filterSubEntitiesOfType(entityType, subType, entityId, filter string, o *commonOptions) ([]*gabs.Container, *paging, error) {
|
||||
jsonParsed, err := util.EdgeControllerListSubEntities(entityType, subType, entityId, filter, o.OutputJSONResponse, o.Out)
|
||||
jsonParsed, err := util.EdgeControllerListSubEntities(entityType, subType, entityId, filter, o.OutputJSONResponse, o.Out, o.Timeout, o.Verbose)
|
||||
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@@ -381,7 +381,7 @@ func runListEdgeRouters(roleFilters []string, roleSemantic string, options *comm
|
||||
if roleSemantic != "" {
|
||||
params.Add("roleSemantic", roleSemantic)
|
||||
}
|
||||
children, paging, err := listEntitiesOfType("edge-routers", params, options.OutputJSONResponse, options.Out)
|
||||
children, paging, err := listEntitiesOfType("edge-routers", params, options.OutputJSONResponse, options.Out, options.Timeout, options.Verbose)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -424,12 +424,12 @@ func outputEdgeRouterPolicies(o *commonOptions, children []*gabs.Container, pagi
|
||||
id, _ := entity.Path("id").Data().(string)
|
||||
name, _ := entity.Path("name").Data().(string)
|
||||
|
||||
identityRoles, err := mapRoleIdsToNames(entity, "identityRoles", "identities")
|
||||
identityRoles, err := mapRoleIdsToNames(entity, "identityRoles", "identities", *o)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
edgeRouterRoles, err := mapRoleIdsToNames(entity, "edgeRouterRoles", "edge-routers")
|
||||
edgeRouterRoles, err := mapRoleIdsToNames(entity, "edgeRouterRoles", "edge-routers", *o)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -488,7 +488,7 @@ func runListServices(asIdentity string, configTypes []string, roleFilters []stri
|
||||
if len(configTypes) == 1 && strings.EqualFold("all", configTypes[0]) {
|
||||
params.Add("configTypes", "all")
|
||||
} else {
|
||||
if configTypes, err := mapNamesToIDs("config-types", configTypes...); err != nil {
|
||||
if configTypes, err := mapNamesToIDs("config-types", *options, configTypes...); err != nil {
|
||||
return err
|
||||
} else {
|
||||
for _, configType := range configTypes {
|
||||
@@ -502,7 +502,7 @@ func runListServices(asIdentity string, configTypes []string, roleFilters []stri
|
||||
if roleSemantic != "" {
|
||||
params.Add("roleSemantic", roleSemantic)
|
||||
}
|
||||
children, pagingInfo, err := listEntitiesOfType("services", params, options.OutputJSONResponse, options.Out)
|
||||
children, pagingInfo, err := listEntitiesOfType("services", params, options.OutputJSONResponse, options.Out, options.Timeout, options.Verbose)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -537,9 +537,9 @@ func outputServiceConfigs(o *commonOptions, children []*gabs.Container, pagingIn
|
||||
|
||||
for _, entity := range children {
|
||||
service, _ := entity.Path("service").Data().(string)
|
||||
serviceName, _ := mapIdToName("services", service)
|
||||
serviceName, _ := mapIdToName("services", service, *o)
|
||||
config, _ := entity.Path("config").Data().(string)
|
||||
configName, _ := mapIdToName("configs", config)
|
||||
configName, _ := mapIdToName("configs", config, *o)
|
||||
_, err := fmt.Fprintf(o.Out, "service: %v config: %v\n", serviceName, configName)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -565,11 +565,11 @@ func outputServiceEdgeRouterPolicies(o *commonOptions, children []*gabs.Containe
|
||||
for _, entity := range children {
|
||||
id, _ := entity.Path("id").Data().(string)
|
||||
name, _ := entity.Path("name").Data().(string)
|
||||
edgeRouterRoles, err := mapRoleIdsToNames(entity, "edgeRouterRoles", "edge-routers")
|
||||
edgeRouterRoles, err := mapRoleIdsToNames(entity, "edgeRouterRoles", "edge-routers", *o)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
serviceRoles, err := mapRoleIdsToNames(entity, "serviceRoles", "services")
|
||||
serviceRoles, err := mapRoleIdsToNames(entity, "serviceRoles", "services", *o)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -600,16 +600,16 @@ func outputServicePolicies(o *commonOptions, children []*gabs.Container, pagingI
|
||||
name, _ := entity.Path("name").Data().(string)
|
||||
policyType, _ := entity.Path("type").Data().(string)
|
||||
|
||||
identityRoles, err := mapRoleIdsToNames(entity, "identityRoles", "identities")
|
||||
identityRoles, err := mapRoleIdsToNames(entity, "identityRoles", "identities", *o)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
serviceRoles, err := mapRoleIdsToNames(entity, "serviceRoles", "services")
|
||||
serviceRoles, err := mapRoleIdsToNames(entity, "serviceRoles", "services", *o)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
postureCheckRoles, err := mapRoleIdsToNames(entity, "postureCheckRoles", "posture-checks")
|
||||
postureCheckRoles, err := mapRoleIdsToNames(entity, "postureCheckRoles", "posture-checks", *o)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -623,7 +623,7 @@ func outputServicePolicies(o *commonOptions, children []*gabs.Container, pagingI
|
||||
return nil
|
||||
}
|
||||
|
||||
func mapRoleIdsToNames(c *gabs.Container, path string, entityType string) ([]string, error) {
|
||||
func mapRoleIdsToNames(c *gabs.Container, path string, entityType string, o commonOptions) ([]string, error) {
|
||||
jsonValues := c.Path(path).Data()
|
||||
if jsonValues == nil {
|
||||
return nil, nil
|
||||
@@ -636,7 +636,7 @@ func mapRoleIdsToNames(c *gabs.Container, path string, entityType string) ([]str
|
||||
str := val.(string)
|
||||
if strings.HasPrefix(str, "@") {
|
||||
id := strings.TrimPrefix(str, "@")
|
||||
name, err := mapIdToName(entityType, id)
|
||||
name, err := mapIdToName(entityType, id, o)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -660,7 +660,7 @@ func runListIdentities(roleFilters []string, roleSemantic string, options *commo
|
||||
if roleSemantic != "" {
|
||||
params.Add("roleSemantic", roleSemantic)
|
||||
}
|
||||
children, pagingInfo, err := listEntitiesOfType("identities", params, options.OutputJSONResponse, options.Out)
|
||||
children, pagingInfo, err := listEntitiesOfType("identities", params, options.OutputJSONResponse, options.Out, options.Timeout, options.Verbose)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -819,7 +819,7 @@ func outputConfigs(o *commonOptions, children []*gabs.Container, pagingInfo *pag
|
||||
for _, entity := range children {
|
||||
id, _ := entity.Path("id").Data().(string)
|
||||
name, _ := entity.Path("name").Data().(string)
|
||||
configType, _ := entity.Path("type").Data().(string)
|
||||
configType, _ := entity.Path("configType.name").Data().(string)
|
||||
data, _ := entity.Path("data").Data().(map[string]interface{})
|
||||
formattedData, err := json.MarshalIndent(data, " ", " ")
|
||||
if err != nil {
|
||||
@@ -935,7 +935,7 @@ func runListRoleAttributes(entityType string, o *commonOptions) error {
|
||||
|
||||
func runListChilden(parentType, childType string, o *commonOptions, outputF outputFunction) error {
|
||||
idOrName := o.Args[0]
|
||||
parentId, err := mapNameToID(parentType, idOrName)
|
||||
parentId, err := mapNameToID(parentType, idOrName, *o)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ func (o *loginOptions) Run() error {
|
||||
|
||||
body := container.String()
|
||||
|
||||
jsonParsed, err := util.EdgeControllerLogin(host, o.Cert, body, o.Out, o.OutputJSONResponse)
|
||||
jsonParsed, err := util.EdgeControllerLogin(host, o.Cert, body, o.Out, o.OutputJSONResponse, o.commonOptions.Timeout, o.commonOptions.Verbose)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -110,12 +110,12 @@ func newPolicyAdvisorServicesCmd(f cmdutil.Factory, out io.Writer, errOut io.Wri
|
||||
// runIdentitiesPolicyAdvisor create a new policyAdvisor on the Ziti Edge Controller
|
||||
func runIdentitiesPolicyAdvisor(o *policyAdvisorOptions) error {
|
||||
if len(o.Args) > 0 {
|
||||
identityId, err := mapNameToID("identities", o.Args[0])
|
||||
identityId, err := mapNameToID("identities", o.Args[0], o.commonOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(o.Args) > 1 {
|
||||
serviceId, err := mapNameToID("services", o.Args[1])
|
||||
serviceId, err := mapNameToID("services", o.Args[1], o.commonOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -140,13 +140,13 @@ func runIdentitiesPolicyAdvisor(o *policyAdvisorOptions) error {
|
||||
// runServicesPolicyAdvisor create a new policyAdvisor on the Ziti Edge Controller
|
||||
func runServicesPolicyAdvisor(o *policyAdvisorOptions) error {
|
||||
if len(o.Args) > 0 {
|
||||
serviceId, err := mapNameToID("services", o.Args[0])
|
||||
serviceId, err := mapNameToID("services", o.Args[0], o.commonOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(o.Args) > 1 {
|
||||
identityId, err := mapNameToID("identities", o.Args[1])
|
||||
identityId, err := mapNameToID("identities", o.Args[1], o.commonOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -206,7 +206,7 @@ func runPolicyAdvisorForIdentities(o *policyAdvisorOptions) error {
|
||||
done := false
|
||||
for !done {
|
||||
filter := fmt.Sprintf(`true skip %v limit 2`, skip)
|
||||
children, _, err := filterEntitiesOfType("identities", filter, false, o.Out)
|
||||
children, _, err := filterEntitiesOfType("identities", filter, false, o.Out, o.commonOptions.Timeout, o.commonOptions.Verbose)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -236,7 +236,7 @@ func runPolicyAdvisorForServices(o *policyAdvisorOptions) error {
|
||||
done := false
|
||||
for !done {
|
||||
filter := fmt.Sprintf(`true skip %v limit 2`, skip)
|
||||
children, _, err := filterEntitiesOfType("services", filter, false, o.Out)
|
||||
children, _, err := filterEntitiesOfType("services", filter, false, o.Out, o.commonOptions.Timeout, o.commonOptions.Verbose)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -285,7 +285,7 @@ func runPolicyAdvisorForIdentity(identityId string, o *policyAdvisorOptions) err
|
||||
}
|
||||
|
||||
if skip == 0 {
|
||||
identityName, err := mapIdToName("identities", identityId)
|
||||
identityName, err := mapIdToName("identities", identityId, o.commonOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -320,7 +320,7 @@ func runPolicyAdvisorForService(serviceId string, o *policyAdvisorOptions) error
|
||||
}
|
||||
|
||||
if skip == 0 {
|
||||
serviceName, err := mapIdToName("services", serviceId)
|
||||
serviceName, err := mapIdToName("services", serviceId, o.commonOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -332,7 +332,7 @@ func runPolicyAdvisorForService(serviceId string, o *policyAdvisorOptions) error
|
||||
}
|
||||
|
||||
func runPolicyAdvisorForIdentityAndService(identityId, serviceId string, o *policyAdvisorOptions) error {
|
||||
result, err := util.EdgeControllerList("identities/"+identityId+"/policy-advice/"+serviceId, nil, o.OutputJSONResponse, o.Out)
|
||||
result, err := util.EdgeControllerList("identities/"+identityId+"/policy-advice/"+serviceId, nil, o.OutputJSONResponse, o.Out, o.commonOptions.Timeout, o.commonOptions.Verbose)
|
||||
if err != nil || o.OutputJSONResponse {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -45,6 +45,8 @@ type commonOptions struct {
|
||||
func (options *commonOptions) AddCommonFlags(cmd *cobra.Command) {
|
||||
cmd.Flags().BoolVarP(&options.OutputJSONResponse, "output-json", "j", false, "Output the full JSON response from the Ziti Edge Controller")
|
||||
cmd.Flags().BoolVar(&options.OutputJSONRequest, "output-request-json", false, "Output the full JSON request to the Ziti Edge Controller")
|
||||
cmd.Flags().IntVarP(&options.Timeout, "timeout", "", 5, "Timeout for REST operations (specified in seconds)")
|
||||
cmd.Flags().BoolVarP(&options.Verbose, "verbose", "", false, "Enable verbose logging")
|
||||
}
|
||||
|
||||
// newCmdEdgeController creates a command object for the "edge controller" command
|
||||
|
||||
@@ -72,9 +72,9 @@ func deleteEntityOfTypeWithBody(entityType string, body string, options *commonO
|
||||
|
||||
// updateEntityOfType updates an entity of the given type on the Ziti Edge Controller
|
||||
func updateEntityOfType(entityType string, body string, options *commonOptions, method string) (*gabs.Container, error) {
|
||||
return util.EdgeControllerUpdate(entityType, body, options.Out, method, options.OutputJSONRequest, options.OutputJSONResponse)
|
||||
return util.EdgeControllerUpdate(entityType, body, options.Out, method, options.OutputJSONRequest, options.OutputJSONResponse, options.Timeout, options.Verbose)
|
||||
}
|
||||
|
||||
func doRequest(entityType string, options *commonOptions, doRequest func(request *resty.Request, url string) (*resty.Response, error)) (*gabs.Container, error) {
|
||||
return util.EdgeControllerRequest(entityType, options.Out, options.OutputJSONResponse, doRequest)
|
||||
return util.EdgeControllerRequest(entityType, options.Out, options.OutputJSONResponse, options.Timeout, options.Verbose, doRequest)
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ func updateSelfPassword(current string, new string, options commonOptions) error
|
||||
setJSONValue(passwordData, current, "currentPassword")
|
||||
setJSONValue(passwordData, new, "password")
|
||||
|
||||
respEnvelope, err := util.EdgeControllerList("current-identity/authenticators", map[string][]string{"filter": {`method="updb"`}}, options.OutputJSONResponse, options.Out)
|
||||
respEnvelope, err := util.EdgeControllerList("current-identity/authenticators", map[string][]string{"filter": {`method="updb"`}}, options.OutputJSONResponse, options.Out, options.Timeout, options.Verbose)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -128,7 +128,7 @@ func updateSelfPassword(current string, new string, options commonOptions) error
|
||||
}
|
||||
|
||||
func setIdentityPassword(identity, password string, options commonOptions) error {
|
||||
id, err := mapIdentityNameToID(identity)
|
||||
id, err := mapIdentityNameToID(identity, options)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -108,7 +108,7 @@ func runUpdateCa(options updateCaOptions) error {
|
||||
return runVerifyCa(options)
|
||||
}
|
||||
|
||||
id, err := mapCaNameToID(options.nameOrId)
|
||||
id, err := mapCaNameToID(options.nameOrId, options.commonOptions)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -132,7 +132,7 @@ func runUpdateCa(options updateCaOptions) error {
|
||||
}
|
||||
|
||||
func runVerifyCa(options updateCaOptions) error {
|
||||
id, err := mapCaNameToID(options.nameOrId)
|
||||
id, err := mapCaNameToID(options.nameOrId, options.commonOptions)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -72,7 +72,7 @@ func newUpdateConfigCmd(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cob
|
||||
|
||||
// runUpdateConfig update a new config on the Ziti Edge Controller
|
||||
func runUpdateConfig(o *updateConfigOptions) error {
|
||||
id, err := mapNameToID("configs", o.Args[0])
|
||||
id, err := mapNameToID("configs", o.Args[0], o.commonOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ func newUpdateEdgeRouterCmd(f cmdutil.Factory, out io.Writer, errOut io.Writer)
|
||||
|
||||
// runUpdateEdgeRouter update a new edgeRouter on the Ziti Edge Controller
|
||||
func runUpdateEdgeRouter(o *updateEdgeRouterOptions) error {
|
||||
id, err := mapNameToID("edge-routers", o.Args[0])
|
||||
id, err := mapNameToID("edge-routers", o.Args[0], o.commonOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -68,17 +68,17 @@ func newUpdateEdgeRouterPolicyCmd(f cmdutil.Factory, out io.Writer, errOut io.Wr
|
||||
}
|
||||
|
||||
func runUpdateEdgeRouterPolicy(o *updateEdgeRouterPolicyOptions) error {
|
||||
id, err := mapNameToID("edge-router-policies", o.Args[0])
|
||||
id, err := mapNameToID("edge-router-policies", o.Args[0], o.commonOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
edgeRouterRoles, err := convertNamesToIds(o.edgeRouterRoles, "edge-routers")
|
||||
edgeRouterRoles, err := convertNamesToIds(o.edgeRouterRoles, "edge-routers", o.commonOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
identityRoles, err := convertNamesToIds(o.identityRoles, "identities")
|
||||
identityRoles, err := convertNamesToIds(o.identityRoles, "identities", o.commonOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ func newUpdateIdentityCmd(f cmdutil.Factory, out io.Writer, errOut io.Writer) *c
|
||||
|
||||
// runUpdateIdentity update a new identity on the Ziti Edge Controller
|
||||
func runUpdateIdentity(o *updateIdentityOptions) error {
|
||||
id, err := mapNameToID("identities", o.Args[0])
|
||||
id, err := mapNameToID("identities", o.Args[0], o.commonOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -63,17 +63,17 @@ func newUpdateIdentityConfigsCmd(f cmdutil.Factory, out io.Writer, errOut io.Wri
|
||||
|
||||
// runupdateIdentityConfigs update a new identity on the Ziti Edge Controller
|
||||
func runupdateIdentityConfigs(o *updateIdentityConfigsOptions) error {
|
||||
id, err := mapNameToID("identities", o.Args[0])
|
||||
id, err := mapNameToID("identities", o.Args[0], o.commonOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
serviceId, err := mapNameToID("services", o.Args[1])
|
||||
serviceId, err := mapNameToID("services", o.Args[1], o.commonOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
configId, err := mapNameToID("configs", o.Args[2])
|
||||
configId, err := mapNameToID("configs", o.Args[2], o.commonOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ func newUpdatePostureCheckMacCmd(f cmdutil.Factory, out io.Writer, errOut io.Wri
|
||||
|
||||
// runUpdatePostureCheckMac update a new identity on the Ziti Edge Controller
|
||||
func runUpdatePostureCheckMac(o *updatePostureCheckMacOptions) error {
|
||||
id, err := mapNameToID("posture-checks", o.Args[0])
|
||||
id, err := mapNameToID("posture-checks", o.Args[0], o.commonOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -177,7 +177,7 @@ func newUpdatePostureCheckDomainCmd(f cmdutil.Factory, out io.Writer, errOut io.
|
||||
|
||||
// runUpdatePostureCheckDomain update a new identity on the Ziti Edge Controller
|
||||
func runUpdatePostureCheckDomain(o *updatePostureCheckDomainOptions) error {
|
||||
id, err := mapNameToID("posture-checks", o.Args[0])
|
||||
id, err := mapNameToID("posture-checks", o.Args[0], o.commonOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -256,7 +256,7 @@ func newUpdatePostureCheckProcessCmd(f cmdutil.Factory, out io.Writer, errOut io
|
||||
|
||||
// runUpdatePostureCheckProcess update a new identity on the Ziti Edge Controller
|
||||
func runUpdatePostureCheckProcess(o *updatePostureCheckProcessOptions) error {
|
||||
id, err := mapNameToID("posture-checks", o.Args[0])
|
||||
id, err := mapNameToID("posture-checks", o.Args[0], o.commonOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -358,7 +358,7 @@ func newUpdatePostureCheckOsCmd(f cmdutil.Factory, out io.Writer, errOut io.Writ
|
||||
|
||||
// runUpdatePostureCheckOs update a new identity on the Ziti Edge Controller
|
||||
func runUpdatePostureCheckOs(o *updatePostureCheckOsOptions) error {
|
||||
id, err := mapNameToID("posture-checks", o.Args[0])
|
||||
id, err := mapNameToID("posture-checks", o.Args[0], o.commonOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ func newUpdateServiceCmd(f cmdutil.Factory, out io.Writer, errOut io.Writer) *co
|
||||
|
||||
// runUpdateService update a new service on the Ziti Edge Controller
|
||||
func runUpdateService(o *updateServiceOptions) error {
|
||||
id, err := mapNameToID("services", o.Args[0])
|
||||
id, err := mapNameToID("services", o.Args[0], o.commonOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -68,17 +68,17 @@ func newUpdateServiceEdgeRouterPolicyCmd(f cmdutil.Factory, out io.Writer, errOu
|
||||
}
|
||||
|
||||
func runUpdateServiceEdgeRouterPolicy(o *updateServiceEdgeRouterPolicyOptions) error {
|
||||
id, err := mapNameToID("service-edge-router-policies", o.Args[0])
|
||||
id, err := mapNameToID("service-edge-router-policies", o.Args[0], o.commonOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
edgeRouterRoles, err := convertNamesToIds(o.edgeRouterRoles, "edge-routers")
|
||||
edgeRouterRoles, err := convertNamesToIds(o.edgeRouterRoles, "edge-routers", o.commonOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
serviceRoles, err := convertNamesToIds(o.serviceRoles, "services")
|
||||
serviceRoles, err := convertNamesToIds(o.serviceRoles, "services", o.commonOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -70,22 +70,22 @@ func newUpdateServicePolicyCmd(f cmdutil.Factory, out io.Writer, errOut io.Write
|
||||
}
|
||||
|
||||
func runUpdateServicePolicy(o *updateServicePolicyOptions) error {
|
||||
id, err := mapNameToID("service-policies", o.Args[0])
|
||||
id, err := mapNameToID("service-policies", o.Args[0], o.commonOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
serviceRoles, err := convertNamesToIds(o.serviceRoles, "services")
|
||||
serviceRoles, err := convertNamesToIds(o.serviceRoles, "services", o.commonOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
identityRoles, err := convertNamesToIds(o.identityRoles, "identities")
|
||||
identityRoles, err := convertNamesToIds(o.identityRoles, "identities", o.commonOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
postureCheckRoles, err := convertNamesToIds(o.postureCheckRoles, "posture-checks")
|
||||
postureCheckRoles, err := convertNamesToIds(o.postureCheckRoles, "posture-checks", o.commonOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ func newUpdateTerminatorCmd(f cmdutil.Factory, out io.Writer, errOut io.Writer)
|
||||
func runUpdateTerminator(o *updateTerminatorOptions) (err error) {
|
||||
entityData := gabs.New()
|
||||
|
||||
router, err := mapNameToID("edge-routers", o.router)
|
||||
router, err := mapNameToID("edge-routers", o.router, o.commonOptions)
|
||||
if err != nil {
|
||||
router = o.router // might be a pure fabric router, id might not be UUID
|
||||
}
|
||||
|
||||
@@ -44,5 +44,5 @@ func newVerifyCmd(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Com
|
||||
|
||||
// createEntityOfType create an entity of the given type on the Ziti Edge Controller
|
||||
func verifyEntityOfType(entityType, body, id string, options *commonOptions) error {
|
||||
return util.EdgeControllerVerify(entityType, id, body, options.Out, options.OutputJSONResponse)
|
||||
return util.EdgeControllerVerify(entityType, id, body, options.Out, options.OutputJSONResponse, options.Timeout, options.Verbose)
|
||||
}
|
||||
|
||||
@@ -135,14 +135,14 @@ func newVerifyCaCmd(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.C
|
||||
|
||||
func runValidateCa(options *verifyCaOptions) error {
|
||||
var err error
|
||||
options.caId, err = mapCaNameToID(options.caNameOrId)
|
||||
options.caId, err = mapCaNameToID(options.caNameOrId, options.commonOptions)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if options.isGenerateCert {
|
||||
jsonContainer, err := util.EdgeControllerRequest("cas/"+options.caId, options.Out, options.OutputJSONResponse, func(request *resty.Request, url string) (*resty.Response, error) { return request.Get(url) })
|
||||
jsonContainer, err := util.EdgeControllerRequest("cas/"+options.caId, options.Out, options.OutputJSONResponse, options.commonOptions.Timeout, options.commonOptions.Verbose, func(request *resty.Request, url string) (*resty.Response, error) { return request.Get(url) })
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not request ca [%s] (%v}", options.caId, err)
|
||||
@@ -161,7 +161,7 @@ func runValidateCa(options *verifyCaOptions) error {
|
||||
}
|
||||
}
|
||||
|
||||
return util.EdgeControllerVerify("cas", options.caId, string(options.certPemBytes), options.Out, options.OutputJSONResponse)
|
||||
return util.EdgeControllerVerify("cas", options.caId, string(options.certPemBytes), options.Out, options.OutputJSONResponse, options.commonOptions.Timeout, options.commonOptions.Verbose)
|
||||
}
|
||||
|
||||
func generateCert(options *verifyCaOptions, token string) ([]byte, crypto.Signer, error) {
|
||||
|
||||
@@ -59,7 +59,7 @@ func newVersionCmd(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Co
|
||||
|
||||
// Run implements this command
|
||||
func (o *versionOptions) Run() error {
|
||||
jsonParsed, err := util.EdgeControllerList("version", nil, o.OutputJSONResponse, o.Out)
|
||||
jsonParsed, err := util.EdgeControllerList("version", nil, o.OutputJSONResponse, o.Out, o.commonOptions.Timeout, o.commonOptions.Verbose)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -76,7 +76,6 @@ func NewCmdInstall(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Co
|
||||
cmd.AddCommand(NewCmdInstallZitiTunnel(f, out, errOut))
|
||||
cmd.AddCommand(NewCmdInstallZitiEdgeTunnel(f, out, errOut))
|
||||
cmd.AddCommand(NewCmdInstallZitiEnroller(f, out, errOut))
|
||||
cmd.AddCommand(NewCmdInstallZitiProxy(f, out, errOut))
|
||||
cmd.AddCommand(NewCmdInstallZitiProxC(f, out, errOut))
|
||||
|
||||
// cmd.AddCommand(NewCmdInstallAnsible(f, out, errOut)) // Disable/hide this for now
|
||||
|
||||
@@ -120,11 +120,6 @@ func (o *InstallZitiALLOptions) Run() error {
|
||||
log.Errorf("Error: install failed %s \n", err.Error())
|
||||
}
|
||||
|
||||
err = o.install(c.ZITI_PROXY)
|
||||
if err != nil {
|
||||
log.Errorf("Error: install failed %s \n", err.Error())
|
||||
}
|
||||
|
||||
err = o.install(c.ZITI_PROX_C)
|
||||
if err != nil {
|
||||
log.Errorf("Error: install failed %s \n", err.Error())
|
||||
|
||||
@@ -19,13 +19,13 @@ package cmd
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/blang/semver"
|
||||
"github.com/openziti/ziti/common/version"
|
||||
cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory"
|
||||
cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
|
||||
"github.com/openziti/ziti/ziti/cmd/ziti/cmd/templates"
|
||||
c "github.com/openziti/ziti/ziti/cmd/ziti/constants"
|
||||
"github.com/openziti/ziti/ziti/cmd/ziti/internal/log"
|
||||
"github.com/openziti/ziti/common/version"
|
||||
"github.com/blang/semver"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -79,7 +79,7 @@ func NewCmdInstallZitiProxC(f cmdutil.Factory, out io.Writer, errOut io.Writer)
|
||||
|
||||
// Run implements the command
|
||||
func (o *InstallZitiProxCOptions) Run() error {
|
||||
newVersion, err := o.getLatestZitiAppVersion(version.GetBranch(), c.ZITI_PROX_C)
|
||||
newVersion, err := o.getLatestGitHubReleaseVersion(version.GetBranch(), c.ZITI_SDK_C_GITHUB)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -90,5 +90,5 @@ func (o *InstallZitiProxCOptions) Run() error {
|
||||
|
||||
log.Infoln("Attempting to install '" + c.ZITI_PROX_C + "' version: " + newVersion.String())
|
||||
|
||||
return o.installZitiApp(version.GetBranch(), c.ZITI_PROX_C, false, newVersion.String())
|
||||
return o.installGitHubRelease(version.GetBranch(), c.ZITI_PROX_C, c.ZITI_SDK_C_GITHUB, false, newVersion.String())
|
||||
}
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
Copyright NetFoundry, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
https://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory"
|
||||
cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
|
||||
"github.com/openziti/ziti/ziti/cmd/ziti/cmd/templates"
|
||||
c "github.com/openziti/ziti/ziti/cmd/ziti/constants"
|
||||
"github.com/openziti/ziti/ziti/cmd/ziti/internal/log"
|
||||
"github.com/openziti/ziti/common/version"
|
||||
"github.com/blang/semver"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
installZitiProxyLong = templates.LongDesc(`
|
||||
Installs the Ziti Proxy app if it has not been installed already
|
||||
`)
|
||||
|
||||
installZitiProxyExample = templates.Examples(`
|
||||
# Install the Ziti Proxy app
|
||||
ziti install ziti-proxy
|
||||
`)
|
||||
)
|
||||
|
||||
// InstallZitiProxyOptions the options for the upgrade ziti-proxy command
|
||||
type InstallZitiProxyOptions struct {
|
||||
InstallOptions
|
||||
|
||||
Version string
|
||||
}
|
||||
|
||||
// NewCmdInstallZitiProxy defines the command
|
||||
func NewCmdInstallZitiProxy(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
options := &InstallZitiProxyOptions{
|
||||
InstallOptions: InstallOptions{
|
||||
CommonOptions: CommonOptions{
|
||||
Factory: f,
|
||||
Out: out,
|
||||
Err: errOut,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "ziti-proxy",
|
||||
Short: "Installs the Ziti Proxy app - if it has not been installed already",
|
||||
Aliases: []string{"proxy"},
|
||||
Long: installZitiProxyLong,
|
||||
Example: installZitiProxyExample,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
options.Cmd = cmd
|
||||
options.Args = args
|
||||
err := options.Run()
|
||||
cmdhelper.CheckErr(err)
|
||||
},
|
||||
}
|
||||
cmd.Flags().StringVarP(&options.Version, "version", "v", "", "The specific version to install")
|
||||
options.addCommonFlags(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// Run implements the command
|
||||
func (o *InstallZitiProxyOptions) Run() error {
|
||||
newVersion, err := o.getLatestZitiAppVersion(version.GetBranch(), c.ZITI_PROXY)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if o.Version != "" {
|
||||
newVersion, err = semver.Make(o.Version)
|
||||
}
|
||||
|
||||
log.Infoln("Attempting to install '" + c.ZITI_PROXY + "' version: " + newVersion.String())
|
||||
|
||||
return o.installZitiApp(version.GetBranch(), c.ZITI_PROXY, false, newVersion.String())
|
||||
}
|
||||
@@ -37,9 +37,6 @@ type PsOptions struct {
|
||||
CommonOptions
|
||||
|
||||
Flags PsFlags
|
||||
|
||||
DisableImport bool
|
||||
OutDir string
|
||||
}
|
||||
|
||||
type PsFlags struct {
|
||||
|
||||
@@ -17,12 +17,13 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/openziti/foundation/agent"
|
||||
cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory"
|
||||
cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
|
||||
"errors"
|
||||
"github.com/openziti/ziti/ziti/signal"
|
||||
"github.com/spf13/cobra"
|
||||
"io"
|
||||
"strconv"
|
||||
"os"
|
||||
)
|
||||
|
||||
// PsGcOptions the options for the create spring command
|
||||
@@ -44,7 +45,8 @@ func NewCmdPsGc(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Comma
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "gc",
|
||||
Use: "gc <optional-target>",
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
options.Cmd = cmd
|
||||
options.Args = args
|
||||
@@ -54,30 +56,15 @@ func NewCmdPsGc(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Comma
|
||||
}
|
||||
|
||||
options.addCommonFlags(cmd)
|
||||
cmd.Flags().StringVarP(&options.Flags.Pid, "pid", "", "", "pid (target of sub-cmd)")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// Run implements the command
|
||||
func (o *PsGcOptions) Run() error {
|
||||
pidStr := o.Args[0]
|
||||
_, err := strconv.Atoi(o.Args[0])
|
||||
addr, err := agent.ParseGopsAddress(o.Args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
addr, err := targetToAddr(pidStr)
|
||||
if err != nil {
|
||||
return errors.New("Could not resolve pid -- may not have 'cliagent' enabled")
|
||||
}
|
||||
fn, ok := pscmds["gc"]
|
||||
if !ok {
|
||||
return errors.New("internal error")
|
||||
}
|
||||
var params []string
|
||||
params = append(params, pidStr)
|
||||
if err := fn(*addr, params); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return agent.MakeRequest(addr, signal.GC, nil, os.Stdout)
|
||||
}
|
||||
|
||||
@@ -17,12 +17,13 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/openziti/foundation/agent"
|
||||
cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory"
|
||||
cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
|
||||
"errors"
|
||||
"github.com/openziti/ziti/ziti/signal"
|
||||
"github.com/spf13/cobra"
|
||||
"io"
|
||||
"strconv"
|
||||
"os"
|
||||
)
|
||||
|
||||
// PsGoversionOptions the options for the create spring command
|
||||
@@ -44,7 +45,8 @@ func NewCmdPsGoversion(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobr
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "goversion",
|
||||
Use: "goversion <optional-target>",
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
options.Cmd = cmd
|
||||
options.Args = args
|
||||
@@ -54,30 +56,15 @@ func NewCmdPsGoversion(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobr
|
||||
}
|
||||
|
||||
options.addCommonFlags(cmd)
|
||||
cmd.Flags().StringVarP(&options.Flags.Pid, "pid", "", "", "pid (target of sub-cmd)")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// Run implements the command
|
||||
func (o *PsGoversionOptions) Run() error {
|
||||
pidStr := o.Args[0]
|
||||
_, err := strconv.Atoi(o.Args[0])
|
||||
addr, err := agent.ParseGopsAddress(o.Args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
addr, err := targetToAddr(pidStr)
|
||||
if err != nil {
|
||||
return errors.New("Could not resolve pid -- may not have 'cliagent' enabled")
|
||||
}
|
||||
fn, ok := pscmds["goversion"]
|
||||
if !ok {
|
||||
return errors.New("internal error")
|
||||
}
|
||||
var params []string
|
||||
params = append(params, pidStr)
|
||||
if err := fn(*addr, params); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return agent.MakeRequest(addr, signal.Version, nil, os.Stdout)
|
||||
}
|
||||
|
||||
@@ -17,12 +17,13 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/openziti/foundation/agent"
|
||||
cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory"
|
||||
cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
|
||||
"errors"
|
||||
"github.com/openziti/ziti/ziti/signal"
|
||||
"github.com/spf13/cobra"
|
||||
"io"
|
||||
"strconv"
|
||||
"os"
|
||||
)
|
||||
|
||||
// PsMemstatsOptions the options for the create spring command
|
||||
@@ -44,7 +45,8 @@ func NewCmdPsMemstats(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "memstats",
|
||||
Use: "memstats <optional-target>",
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
options.Cmd = cmd
|
||||
options.Args = args
|
||||
@@ -54,30 +56,15 @@ func NewCmdPsMemstats(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra
|
||||
}
|
||||
|
||||
options.addCommonFlags(cmd)
|
||||
cmd.Flags().StringVarP(&options.Flags.Pid, "pid", "", "", "pid (target of sub-cmd)")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// Run implements the command
|
||||
func (o *PsMemstatsOptions) Run() error {
|
||||
pidStr := o.Args[0]
|
||||
_, err := strconv.Atoi(o.Args[0])
|
||||
addr, err := agent.ParseGopsAddress(o.Args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
addr, err := targetToAddr(pidStr)
|
||||
if err != nil {
|
||||
return errors.New("Could not resolve pid -- may not have 'cliagent' enabled")
|
||||
}
|
||||
fn, ok := pscmds["memstats"]
|
||||
if !ok {
|
||||
return errors.New("internal error")
|
||||
}
|
||||
var params []string
|
||||
params = append(params, pidStr)
|
||||
if err := fn(*addr, params); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return agent.MakeRequest(addr, signal.MemStats, nil, os.Stdout)
|
||||
}
|
||||
|
||||
@@ -17,12 +17,13 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/openziti/foundation/agent"
|
||||
cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory"
|
||||
cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
|
||||
"errors"
|
||||
"github.com/openziti/ziti/ziti/signal"
|
||||
"github.com/spf13/cobra"
|
||||
"io"
|
||||
"strconv"
|
||||
"os"
|
||||
)
|
||||
|
||||
// PsPprofCpuOptions the options for the create spring command
|
||||
@@ -44,7 +45,8 @@ func NewCmdPsPprofCpu(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "pprof-cpu",
|
||||
Use: "pprof-cpu",
|
||||
Args: cobra.MaximumNArgs(2),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
options.Cmd = cmd
|
||||
options.Args = args
|
||||
@@ -54,30 +56,25 @@ func NewCmdPsPprofCpu(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra
|
||||
}
|
||||
|
||||
options.addCommonFlags(cmd)
|
||||
cmd.Flags().StringVarP(&options.Flags.Pid, "pid", "", "", "pid (target of sub-cmd)")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// Run implements the command
|
||||
func (o *PsPprofCpuOptions) Run() error {
|
||||
pidStr := o.Args[0]
|
||||
_, err := strconv.Atoi(o.Args[0])
|
||||
addr, err := agent.ParseGopsAddress(o.Args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
addr, err := targetToAddr(pidStr)
|
||||
if err != nil {
|
||||
return errors.New("Could not resolve pid -- may not have 'cliagent' enabled")
|
||||
|
||||
var out io.WriteCloser = os.Stdout
|
||||
if len(o.Args) > 1 {
|
||||
out, err = os.Create(o.Args[1])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer out.Close()
|
||||
}
|
||||
fn, ok := pscmds["pprof-cpu"]
|
||||
if !ok {
|
||||
return errors.New("internal error")
|
||||
}
|
||||
var params []string
|
||||
params = append(params, pidStr)
|
||||
if err := fn(*addr, params); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
return agent.MakeRequest(addr, signal.CPUProfile, nil, out)
|
||||
}
|
||||
|
||||
@@ -17,18 +17,18 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/openziti/foundation/agent"
|
||||
cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory"
|
||||
cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
|
||||
"errors"
|
||||
"github.com/openziti/ziti/ziti/signal"
|
||||
"github.com/spf13/cobra"
|
||||
"io"
|
||||
"strconv"
|
||||
"os"
|
||||
)
|
||||
|
||||
// PsPprofHeapOptions the options for the create spring command
|
||||
type PsPprofHeapOptions struct {
|
||||
PsOptions
|
||||
CtrlListener string
|
||||
}
|
||||
|
||||
// NewCmdPsPprofHeap creates a command object for the "create" command
|
||||
@@ -54,30 +54,25 @@ func NewCmdPsPprofHeap(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobr
|
||||
}
|
||||
|
||||
options.addCommonFlags(cmd)
|
||||
cmd.Flags().StringVarP(&options.Flags.Pid, "pid", "", "", "pid (target of sub-cmd)")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// Run implements the command
|
||||
func (o *PsPprofHeapOptions) Run() error {
|
||||
pidStr := o.Args[0]
|
||||
_, err := strconv.Atoi(o.Args[0])
|
||||
addr, err := agent.ParseGopsAddress(o.Args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
addr, err := targetToAddr(pidStr)
|
||||
if err != nil {
|
||||
return errors.New("Could not resolve pid -- may not have 'cliagent' enabled")
|
||||
|
||||
var out io.WriteCloser = os.Stdout
|
||||
if len(o.Args) > 1 {
|
||||
out, err = os.Create(o.Args[1])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer out.Close()
|
||||
}
|
||||
fn, ok := pscmds["pprof-heap"]
|
||||
if !ok {
|
||||
return errors.New("internal error")
|
||||
}
|
||||
var params []string
|
||||
params = append(params, pidStr)
|
||||
if err := fn(*addr, params); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
return agent.MakeRequest(addr, signal.HeapProfile, nil, out)
|
||||
}
|
||||
|
||||
@@ -17,11 +17,14 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"github.com/openziti/foundation/agent"
|
||||
cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory"
|
||||
cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
|
||||
"errors"
|
||||
"github.com/openziti/ziti/ziti/signal"
|
||||
"github.com/spf13/cobra"
|
||||
"io"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
@@ -44,7 +47,8 @@ func NewCmdPsSetgc(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Co
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "setgc",
|
||||
Use: "setgc target gc-percentage",
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
options.Cmd = cmd
|
||||
options.Args = args
|
||||
@@ -54,30 +58,33 @@ func NewCmdPsSetgc(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Co
|
||||
}
|
||||
|
||||
options.addCommonFlags(cmd)
|
||||
cmd.Flags().StringVarP(&options.Flags.Pid, "pid", "", "", "pid (target of sub-cmd)")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// Run implements the command
|
||||
func (o *PsSetgcOptions) Run() error {
|
||||
pidStr := o.Args[0]
|
||||
_, err := strconv.Atoi(o.Args[0])
|
||||
var addr string
|
||||
var err error
|
||||
var pctArg string
|
||||
if len(o.Args) == 1 {
|
||||
addr, err = agent.ParseGopsAddress(nil)
|
||||
pctArg = o.Args[0]
|
||||
} else {
|
||||
addr, err = agent.ParseGopsAddress(o.Args)
|
||||
pctArg = o.Args[1]
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
addr, err := targetToAddr(pidStr)
|
||||
|
||||
perc, err := strconv.ParseInt(pctArg, 10, strconv.IntSize)
|
||||
if err != nil {
|
||||
return errors.New("Could not resolve pid -- may not have 'cliagent' enabled")
|
||||
}
|
||||
fn, ok := pscmds["setgc"]
|
||||
if !ok {
|
||||
return errors.New("internal error")
|
||||
}
|
||||
var params []string
|
||||
params = append(params, o.Args[1])
|
||||
if err := fn(*addr, params); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
buf := make([]byte, binary.MaxVarintLen64)
|
||||
binary.PutVarint(buf, perc)
|
||||
|
||||
return agent.MakeRequest(addr, signal.SetGCPercent, buf, os.Stdout)
|
||||
}
|
||||
|
||||
@@ -17,12 +17,13 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/openziti/foundation/agent"
|
||||
cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory"
|
||||
cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
|
||||
"errors"
|
||||
"github.com/openziti/ziti/ziti/signal"
|
||||
"github.com/spf13/cobra"
|
||||
"io"
|
||||
"strconv"
|
||||
"os"
|
||||
)
|
||||
|
||||
// PsStackOptions the options for the create spring command
|
||||
@@ -44,7 +45,8 @@ func NewCmdPsStack(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Co
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "stack",
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
Use: "stack <optional-target>",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
options.Cmd = cmd
|
||||
options.Args = args
|
||||
@@ -54,30 +56,15 @@ func NewCmdPsStack(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Co
|
||||
}
|
||||
|
||||
options.addCommonFlags(cmd)
|
||||
cmd.Flags().StringVarP(&options.Flags.Pid, "pid", "", "", "pid (target of sub-cmd)")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// Run implements the command
|
||||
func (o *PsStackOptions) Run() error {
|
||||
pidStr := o.Args[0]
|
||||
_, err := strconv.Atoi(o.Args[0])
|
||||
addr, err := agent.ParseGopsAddress(o.Args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
addr, err := targetToAddr(pidStr)
|
||||
if err != nil {
|
||||
return errors.New("Could not resolve pid -- may not have 'cliagent' enabled")
|
||||
}
|
||||
fn, ok := pscmds["stack"]
|
||||
if !ok {
|
||||
return errors.New("internal error")
|
||||
}
|
||||
var params []string
|
||||
params = append(params, pidStr)
|
||||
if err := fn(*addr, params); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return agent.MakeRequest(addr, signal.StackTrace, nil, os.Stdout)
|
||||
}
|
||||
|
||||
@@ -17,12 +17,13 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/openziti/foundation/agent"
|
||||
cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory"
|
||||
cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
|
||||
"errors"
|
||||
"github.com/openziti/ziti/ziti/signal"
|
||||
"github.com/spf13/cobra"
|
||||
"io"
|
||||
"strconv"
|
||||
"os"
|
||||
)
|
||||
|
||||
// PsStatsOptions the options for the create spring command
|
||||
@@ -44,7 +45,8 @@ func NewCmdPsStats(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Co
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "stats",
|
||||
Use: "stats <optional-target>",
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
options.Cmd = cmd
|
||||
options.Args = args
|
||||
@@ -54,30 +56,15 @@ func NewCmdPsStats(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Co
|
||||
}
|
||||
|
||||
options.addCommonFlags(cmd)
|
||||
cmd.Flags().StringVarP(&options.Flags.Pid, "pid", "", "", "pid (target of sub-cmd)")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// Run implements the command
|
||||
func (o *PsStatsOptions) Run() error {
|
||||
pidStr := o.Args[0]
|
||||
_, err := strconv.Atoi(o.Args[0])
|
||||
addr, err := agent.ParseGopsAddress(o.Args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
addr, err := targetToAddr(pidStr)
|
||||
if err != nil {
|
||||
return errors.New("Could not resolve pid -- may not have 'cliagent' enabled")
|
||||
}
|
||||
fn, ok := pscmds["stats"]
|
||||
if !ok {
|
||||
return errors.New("internal error")
|
||||
}
|
||||
var params []string
|
||||
params = append(params, pidStr)
|
||||
if err := fn(*addr, params); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return agent.MakeRequest(addr, signal.Stats, nil, os.Stdout)
|
||||
}
|
||||
|
||||
@@ -17,18 +17,18 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/openziti/foundation/agent"
|
||||
cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory"
|
||||
cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
|
||||
"errors"
|
||||
"github.com/openziti/ziti/ziti/signal"
|
||||
"github.com/spf13/cobra"
|
||||
"io"
|
||||
"strconv"
|
||||
"os"
|
||||
)
|
||||
|
||||
// PsTraceOptions the options for the create spring command
|
||||
type PsTraceOptions struct {
|
||||
PsOptions
|
||||
CtrlListener string
|
||||
}
|
||||
|
||||
// NewCmdPsTrace creates a command object for the "create" command
|
||||
@@ -54,30 +54,15 @@ func NewCmdPsTrace(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Co
|
||||
}
|
||||
|
||||
options.addCommonFlags(cmd)
|
||||
cmd.Flags().StringVarP(&options.Flags.Pid, "pid", "", "", "pid (target of sub-cmd)")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// Run implements the command
|
||||
func (o *PsTraceOptions) Run() error {
|
||||
pidStr := o.Args[0]
|
||||
_, err := strconv.Atoi(o.Args[0])
|
||||
addr, err := agent.ParseGopsAddress(o.Args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
addr, err := targetToAddr(pidStr)
|
||||
if err != nil {
|
||||
return errors.New("Could not resolve pid -- may not have 'cliagent' enabled")
|
||||
}
|
||||
fn, ok := pscmds["trace"]
|
||||
if !ok {
|
||||
return errors.New("internal error")
|
||||
}
|
||||
var params []string
|
||||
params = append(params, pidStr)
|
||||
if err := fn(*addr, params); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return agent.MakeRequest(addr, signal.Trace, nil, os.Stdout)
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -32,57 +31,6 @@ import (
|
||||
"github.com/openziti/ziti/ziti/util"
|
||||
)
|
||||
|
||||
var pscmds = map[string](func(addr net.TCPAddr, params []string) error){
|
||||
"stack": stackTrace,
|
||||
"gc": gc,
|
||||
"memstats": memStats,
|
||||
"goversion": goversion,
|
||||
"pprof-heap": pprofHeap,
|
||||
"pprof-cpu": pprofCPU,
|
||||
"stats": stats,
|
||||
"trace": trace,
|
||||
"setgc": setGC,
|
||||
}
|
||||
|
||||
func setGC(addr net.TCPAddr, params []string) error {
|
||||
if len(params) != 1 {
|
||||
return errors.New("missing gc percentage")
|
||||
}
|
||||
perc, err := strconv.ParseInt(params[0], 10, strconv.IntSize)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
buf := make([]byte, binary.MaxVarintLen64)
|
||||
binary.PutVarint(buf, perc)
|
||||
return cmdWithPrint(addr, signal.SetGCPercent, buf...)
|
||||
}
|
||||
|
||||
func stackTrace(addr net.TCPAddr, _ []string) error {
|
||||
return cmdWithPrint(addr, signal.StackTrace)
|
||||
}
|
||||
|
||||
func gc(addr net.TCPAddr, _ []string) error {
|
||||
_, err := cmd(addr, signal.GC)
|
||||
return err
|
||||
}
|
||||
|
||||
func memStats(addr net.TCPAddr, _ []string) error {
|
||||
return cmdWithPrint(addr, signal.MemStats)
|
||||
}
|
||||
|
||||
func goversion(addr net.TCPAddr, _ []string) error {
|
||||
return cmdWithPrint(addr, signal.Version)
|
||||
}
|
||||
|
||||
func pprofHeap(addr net.TCPAddr, _ []string) error {
|
||||
return pprof(addr, signal.HeapProfile)
|
||||
}
|
||||
|
||||
func pprofCPU(addr net.TCPAddr, _ []string) error {
|
||||
fmt.Println("Profiling CPU now, will take 30 secs...")
|
||||
return pprof(addr, signal.CPUProfile)
|
||||
}
|
||||
|
||||
func trace(addr net.TCPAddr, _ []string) error {
|
||||
fmt.Println("Tracing now, will take 5 secs...")
|
||||
out, err := cmd(addr, signal.Trace)
|
||||
@@ -113,71 +61,6 @@ func trace(addr net.TCPAddr, _ []string) error {
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
func pprof(addr net.TCPAddr, p byte) error {
|
||||
|
||||
tmpDumpFile, err := ioutil.TempFile("", "profile")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
{
|
||||
out, err := cmd(addr, p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(out) == 0 {
|
||||
return errors.New("failed to read the profile")
|
||||
}
|
||||
if err := ioutil.WriteFile(tmpDumpFile.Name(), out, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("Profile dump saved to: %s\n", tmpDumpFile.Name())
|
||||
// If go tool chain not found, stopping here and keep dump file.
|
||||
if _, err := exec.LookPath("go"); err != nil {
|
||||
return nil
|
||||
}
|
||||
defer os.Remove(tmpDumpFile.Name())
|
||||
}
|
||||
// Download running binary
|
||||
tmpBinFile, err := ioutil.TempFile("", "binary")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
{
|
||||
out, err := cmd(addr, signal.BinaryDump)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read the binary: %v", err)
|
||||
}
|
||||
if len(out) == 0 {
|
||||
return errors.New("failed to read the binary")
|
||||
}
|
||||
defer os.Remove(tmpBinFile.Name())
|
||||
if err := ioutil.WriteFile(tmpBinFile.Name(), out, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
fmt.Printf("Profiling dump saved to: %s\n", tmpDumpFile.Name())
|
||||
fmt.Printf("Binary file saved to: %s\n", tmpBinFile.Name())
|
||||
cmd := exec.Command("go", "tool", "pprof", tmpBinFile.Name(), tmpDumpFile.Name())
|
||||
cmd.Env = os.Environ()
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
func stats(addr net.TCPAddr, _ []string) error {
|
||||
return cmdWithPrint(addr, signal.Stats)
|
||||
}
|
||||
|
||||
func cmdWithPrint(addr net.TCPAddr, c byte, params ...byte) error {
|
||||
out, err := cmd(addr, c, params...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("%s", out)
|
||||
return nil
|
||||
}
|
||||
|
||||
// targetToAddr tries to parse the target string, be it remote host:port
|
||||
// or local process's PID.
|
||||
func targetToAddr(target string) (*net.TCPAddr, error) {
|
||||
|
||||
@@ -74,7 +74,6 @@ func NewCmdUnInstall(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.
|
||||
cmd.AddCommand(NewCmdUnInstallZitiTunnel(f, out, errOut))
|
||||
cmd.AddCommand(NewCmdUnInstallZitiEdgeTunnel(f, out, errOut))
|
||||
cmd.AddCommand(NewCmdUnInstallZitiEnroller(f, out, errOut))
|
||||
cmd.AddCommand(NewCmdUnInstallZitiProxy(f, out, errOut))
|
||||
cmd.AddCommand(NewCmdUnInstallZitiProxC(f, out, errOut))
|
||||
|
||||
return cmd
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
Copyright NetFoundry, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
https://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory"
|
||||
cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
|
||||
"github.com/openziti/ziti/ziti/cmd/ziti/cmd/templates"
|
||||
c "github.com/openziti/ziti/ziti/cmd/ziti/constants"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
uninstallZitiProxyLong = templates.LongDesc(`
|
||||
UnInstalls the Ziti Proxy app if it has previously been installed
|
||||
`)
|
||||
|
||||
uninstallZitiProxyExample = templates.Examples(`
|
||||
# UnInstall the Ziti Proxy app
|
||||
ziti uninstall ziti-proxy
|
||||
`)
|
||||
)
|
||||
|
||||
// UnInstallZitiProxyOptions the options for the upgrade ziti-proxy command
|
||||
type UnInstallZitiProxyOptions struct {
|
||||
UnInstallOptions
|
||||
|
||||
Version string
|
||||
}
|
||||
|
||||
// NewCmdUnInstallZitiProxy defines the command
|
||||
func NewCmdUnInstallZitiProxy(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
options := &UnInstallZitiProxyOptions{
|
||||
UnInstallOptions: UnInstallOptions{
|
||||
CommonOptions: CommonOptions{
|
||||
Factory: f,
|
||||
Out: out,
|
||||
Err: errOut,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "ziti-proxy",
|
||||
Short: "UnInstalls the Ziti Proxy app - if it has previously been installed",
|
||||
Aliases: []string{"proxy"},
|
||||
Long: uninstallZitiProxyLong,
|
||||
Example: uninstallZitiProxyExample,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
options.Cmd = cmd
|
||||
options.Args = args
|
||||
err := options.Run()
|
||||
cmdhelper.CheckErr(err)
|
||||
},
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
// Run implements the command
|
||||
func (o *UnInstallZitiProxyOptions) Run() error {
|
||||
o.deleteInstalledBinary(c.ZITI_PROXY)
|
||||
return nil
|
||||
}
|
||||
@@ -74,8 +74,8 @@ func NewCmdUpgrade(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Co
|
||||
cmd.AddCommand(NewCmdUpgradeZitiRouter(f, out, errOut))
|
||||
cmd.AddCommand(NewCmdUpgradeZitiTunnel(f, out, errOut))
|
||||
cmd.AddCommand(NewCmdUpgradeZitiEnroller(f, out, errOut))
|
||||
cmd.AddCommand(NewCmdUpgradeZitiProxy(f, out, errOut))
|
||||
cmd.AddCommand(NewCmdUpgradeZitiProxC(f, out, errOut))
|
||||
cmd.AddCommand(NewCmdUpgradeZitiEdgeTunnel(f, out, errOut))
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -90,5 +90,5 @@ func (o *UpgradeZitiEdgeTunnelOptions) Run() error {
|
||||
|
||||
o.deleteInstalledBinary(c.ZITI_EDGE_TUNNEL)
|
||||
|
||||
return o.installZitiApp(version.GetBranch(), c.ZITI_EDGE_TUNNEL, true, newVersionStr)
|
||||
return o.installGitHubRelease(version.GetBranch(), c.ZITI_EDGE_TUNNEL, c.ZITI_EDGE_TUNNEL_GITHUB, true, newVersionStr)
|
||||
}
|
||||
|
||||
@@ -19,11 +19,11 @@ package cmd
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/openziti/ziti/common/version"
|
||||
cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory"
|
||||
cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
|
||||
"github.com/openziti/ziti/ziti/cmd/ziti/cmd/templates"
|
||||
c "github.com/openziti/ziti/ziti/cmd/ziti/constants"
|
||||
"github.com/openziti/ziti/common/version"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -77,7 +77,7 @@ func NewCmdUpgradeZitiProxC(f cmdutil.Factory, out io.Writer, errOut io.Writer)
|
||||
|
||||
// Run implements the command
|
||||
func (o *UpgradeZitiProxCOptions) Run() error {
|
||||
newVersion, err := o.getLatestZitiAppVersion(version.GetBranch(), c.ZITI_PROX_C)
|
||||
newVersion, err := o.getLatestGitHubReleaseVersion(version.GetBranch(), c.ZITI_SDK_C_GITHUB)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -90,5 +90,5 @@ func (o *UpgradeZitiProxCOptions) Run() error {
|
||||
|
||||
o.deleteInstalledBinary(c.ZITI_PROX_C)
|
||||
|
||||
return o.installZitiApp(version.GetBranch(), c.ZITI_PROX_C, true, newVersionStr)
|
||||
return o.installGitHubRelease(version.GetBranch(), c.ZITI_PROX_C, c.ZITI_SDK_C_GITHUB, true, newVersionStr)
|
||||
}
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
Copyright NetFoundry, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
https://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory"
|
||||
cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
|
||||
"github.com/openziti/ziti/ziti/cmd/ziti/cmd/templates"
|
||||
c "github.com/openziti/ziti/ziti/cmd/ziti/constants"
|
||||
"github.com/openziti/ziti/common/version"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
upgradeZitiProxyLong = templates.LongDesc(`
|
||||
Upgrades the Ziti Proxy app if there is a newer release
|
||||
`)
|
||||
|
||||
upgradeZitiProxyExample = templates.Examples(`
|
||||
# Upgrades the Ziti Proxy app
|
||||
ziti upgrade ziti-proxy
|
||||
`)
|
||||
)
|
||||
|
||||
// UpgradeZitiProxyOptions the options for the upgrade ziti-proxy command
|
||||
type UpgradeZitiProxyOptions struct {
|
||||
CreateOptions
|
||||
|
||||
Version string
|
||||
}
|
||||
|
||||
// NewCmdUpgradeZitiProxy defines the command
|
||||
func NewCmdUpgradeZitiProxy(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
options := &UpgradeZitiProxyOptions{
|
||||
CreateOptions: CreateOptions{
|
||||
CommonOptions: CommonOptions{
|
||||
Factory: f,
|
||||
Out: out,
|
||||
Err: errOut,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "ziti-proxy",
|
||||
Short: "Upgrades the Ziti Proxy app - if there is a new version available",
|
||||
Aliases: []string{"proxy"},
|
||||
Long: upgradeZitiProxyLong,
|
||||
Example: upgradeZitiProxyExample,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
options.Cmd = cmd
|
||||
options.Args = args
|
||||
err := options.Run()
|
||||
cmdhelper.CheckErr(err)
|
||||
},
|
||||
}
|
||||
cmd.Flags().StringVarP(&options.Version, "version", "v", "", "The specific version to upgrade to")
|
||||
options.addCommonFlags(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// Run implements the command
|
||||
func (o *UpgradeZitiProxyOptions) Run() error {
|
||||
newVersion, err := o.getLatestZitiAppVersion(version.GetBranch(), c.ZITI_PROXY)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
newVersionStr := newVersion.String()
|
||||
|
||||
if o.Version != "" {
|
||||
newVersionStr = o.Version
|
||||
}
|
||||
|
||||
o.deleteInstalledBinary(c.ZITI_PROXY)
|
||||
|
||||
return o.installZitiApp(version.GetBranch(), c.ZITI_PROXY, true, newVersionStr)
|
||||
}
|
||||
@@ -145,10 +145,6 @@ func (o *UseOptions) Run() error {
|
||||
if err != nil {
|
||||
log.Errorf("Error: install failed %s \n", err.Error())
|
||||
}
|
||||
err = o.install(branch, c.ZITI_PROXY)
|
||||
if err != nil {
|
||||
log.Errorf("Error: install failed %s \n", err.Error())
|
||||
}
|
||||
err = o.install(branch, c.ZITI_PROX_C)
|
||||
if err != nil {
|
||||
log.Errorf("Error: install failed %s \n", err.Error())
|
||||
|
||||
@@ -87,7 +87,6 @@ func (o *VersionOptions) Run() error {
|
||||
o.versionPrintZitiApp(c.ZITI_FABRIC, &table)
|
||||
o.versionPrintZitiApp(c.ZITI_FABRIC_GW, &table)
|
||||
o.versionPrintZitiApp(c.ZITI_FABRIC_TEST, &table)
|
||||
o.versionPrintZitiApp(c.ZITI_PROXY, &table)
|
||||
o.versionPrintZitiApp(c.ZITI_PROX_C, &table)
|
||||
o.versionPrintZitiApp(c.ZITI_ROUTER, &table)
|
||||
o.versionPrintZitiApp(c.ZITI_TUNNEL, &table)
|
||||
@@ -136,7 +135,6 @@ func (o *VersionOptions) versionCheck() error {
|
||||
o.versionCheckZitiApp(c.ZITI_FABRIC)
|
||||
o.versionCheckZitiApp(c.ZITI_FABRIC_TEST)
|
||||
o.versionCheckZitiApp(c.ZITI_FABRIC_GW)
|
||||
o.versionCheckZitiApp(c.ZITI_PROXY)
|
||||
o.versionCheckZitiApp(c.ZITI_PROX_C)
|
||||
o.versionCheckZitiApp(c.ZITI_ROUTER)
|
||||
o.versionCheckZitiApp(c.ZITI_TUNNEL)
|
||||
@@ -164,16 +162,14 @@ func (o *VersionOptions) versionCheckZitiApp(zitiApp string) error {
|
||||
newVersion, err = o.getLatestZitiAppVersion(version.GetBranch(), c.ZITI_FABRIC_TEST)
|
||||
case c.ZITI_FABRIC_GW:
|
||||
newVersion, err = o.getLatestZitiAppVersion(version.GetBranch(), c.ZITI_FABRIC_GW)
|
||||
case c.ZITI_PROXY:
|
||||
newVersion, err = o.getLatestZitiAppVersion(version.GetBranch(), c.ZITI_PROXY)
|
||||
case c.ZITI_PROX_C:
|
||||
newVersion, err = o.getLatestZitiAppVersion(version.GetBranch(), c.ZITI_PROX_C)
|
||||
newVersion, err = o.getLatestGitHubReleaseVersion(version.GetBranch(), c.ZITI_SDK_C_GITHUB)
|
||||
case c.ZITI_ROUTER:
|
||||
newVersion, err = o.getLatestZitiAppVersion(version.GetBranch(), c.ZITI_ROUTER)
|
||||
case c.ZITI_TUNNEL:
|
||||
newVersion, err = o.getLatestZitiAppVersion(version.GetBranch(), c.ZITI_TUNNEL)
|
||||
case c.ZITI_EDGE_TUNNEL:
|
||||
newVersion, err = o.getLatestZitiAppVersion(version.GetBranch(), c.ZITI_EDGE_TUNNEL)
|
||||
newVersion, err = o.getLatestGitHubReleaseVersion(version.GetBranch(), c.ZITI_EDGE_TUNNEL_GITHUB)
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
@@ -210,8 +206,6 @@ func (o *VersionOptions) versionCheckZitiApp(zitiApp string) error {
|
||||
err = o.upgradeZitiFabricTest()
|
||||
case c.ZITI_FABRIC_GW:
|
||||
err = o.upgradeZitiMgmtGw()
|
||||
case c.ZITI_PROXY:
|
||||
err = o.upgradeZitiProxy()
|
||||
case c.ZITI_PROX_C:
|
||||
err = o.upgradeZitiProxC()
|
||||
case c.ZITI_ROUTER:
|
||||
@@ -278,15 +272,6 @@ func (o *VersionOptions) upgradeZitiMgmtGw() error {
|
||||
return options.Run()
|
||||
}
|
||||
|
||||
func (o *VersionOptions) upgradeZitiProxy() error {
|
||||
options := &UpgradeZitiProxyOptions{
|
||||
CreateOptions: CreateOptions{
|
||||
CommonOptions: o.CommonOptions,
|
||||
},
|
||||
}
|
||||
return options.Run()
|
||||
}
|
||||
|
||||
func (o *VersionOptions) upgradeZitiProxC() error {
|
||||
options := &UpgradeZitiProxCOptions{
|
||||
CreateOptions: CreateOptions{
|
||||
|
||||
@@ -27,8 +27,8 @@ const (
|
||||
ZITI_EDGE_TUNNEL = "ziti-edge-tunnel"
|
||||
ZITI_EDGE_TUNNEL_GITHUB = "ziti-tunnel-sdk-c"
|
||||
ZITI_ENROLLER = "ziti-enroller"
|
||||
ZITI_PROXY = "ziti-proxy"
|
||||
ZITI_PROX_C = "ziti-prox-c"
|
||||
ZITI_SDK_C_GITHUB = "ziti-sdk-c"
|
||||
|
||||
TERRAFORM_PROVIDER_PREFIX = "terraform-provider-"
|
||||
TERRAFORM_PROVIDER_EDGE_CONTROLLER = "edgecontroller"
|
||||
|
||||
+28
-11
@@ -534,7 +534,7 @@ func Unzip(src, dest string) error {
|
||||
}
|
||||
|
||||
// EdgeControllerLogin will authenticate to the given Edge Controller
|
||||
func EdgeControllerLogin(url string, cert string, authentication string, out io.Writer, logJSON bool) (*gabs.Container, error) {
|
||||
func EdgeControllerLogin(url string, cert string, authentication string, out io.Writer, logJSON bool, timeout int, verbose bool) (*gabs.Container, error) {
|
||||
client := newClient()
|
||||
|
||||
if cert != "" {
|
||||
@@ -542,6 +542,8 @@ func EdgeControllerLogin(url string, cert string, authentication string, out io.
|
||||
}
|
||||
|
||||
resp, err := client.
|
||||
SetTimeout(time.Duration(time.Duration(timeout)*time.Second)).
|
||||
SetDebug(verbose).
|
||||
R().
|
||||
SetQueryParam("method", "password").
|
||||
SetHeader("Content-Type", "application/json").
|
||||
@@ -581,7 +583,7 @@ func outputJson(out io.Writer, data []byte) {
|
||||
}
|
||||
}
|
||||
|
||||
func EdgeControllerDetailEntity(entityType, entityId string, logJSON bool, out io.Writer) (*gabs.Container, error) {
|
||||
func EdgeControllerDetailEntity(entityType, entityId string, logJSON bool, out io.Writer, timeout int, verbose bool) (*gabs.Container, error) {
|
||||
session := &Session{}
|
||||
if err := session.Load(); err != nil {
|
||||
return nil, err
|
||||
@@ -595,7 +597,10 @@ func EdgeControllerDetailEntity(entityType, entityId string, logJSON bool, out i
|
||||
|
||||
queryUrl := session.GetBaseUrl() + "/" + path.Join(entityType, entityId)
|
||||
|
||||
resp, err := client.R().
|
||||
resp, err := client.
|
||||
SetTimeout(time.Duration(time.Duration(timeout)*time.Second)).
|
||||
SetDebug(verbose).
|
||||
R().
|
||||
SetHeader("Content-Type", "application/json").
|
||||
SetHeader(constants.ZitiSession, session.GetToken()).
|
||||
Get(queryUrl)
|
||||
@@ -623,16 +628,16 @@ func EdgeControllerDetailEntity(entityType, entityId string, logJSON bool, out i
|
||||
}
|
||||
|
||||
// EdgeControllerListSubEntities will list entities of the given type in the given Edge Controller
|
||||
func EdgeControllerListSubEntities(entityType, subType, entityId string, filter string, logJSON bool, out io.Writer) (*gabs.Container, error) {
|
||||
func EdgeControllerListSubEntities(entityType, subType, entityId string, filter string, logJSON bool, out io.Writer, timeout int, verbose bool) (*gabs.Container, error) {
|
||||
params := url.Values{}
|
||||
if filter != "" {
|
||||
params.Add("filter", filter)
|
||||
}
|
||||
return EdgeControllerList(entityType+"/"+entityId+"/"+subType, params, logJSON, out)
|
||||
return EdgeControllerList(entityType+"/"+entityId+"/"+subType, params, logJSON, out, timeout, verbose)
|
||||
}
|
||||
|
||||
// EdgeControllerList will list entities of the given type in the given Edge Controller
|
||||
func EdgeControllerList(path string, params url.Values, logJSON bool, out io.Writer) (*gabs.Container, error) {
|
||||
func EdgeControllerList(path string, params url.Values, logJSON bool, out io.Writer, timeout int, verbose bool) (*gabs.Container, error) {
|
||||
session := &Session{}
|
||||
if err := session.Load(); err != nil {
|
||||
return nil, err
|
||||
@@ -651,6 +656,8 @@ func EdgeControllerList(path string, params url.Values, logJSON bool, out io.Wri
|
||||
}
|
||||
|
||||
resp, err := client.
|
||||
SetTimeout(time.Duration(time.Duration(timeout)*time.Second)).
|
||||
SetDebug(verbose).
|
||||
R().
|
||||
SetHeader("Content-Type", "application/json").
|
||||
SetHeader(constants.ZitiSession, session.GetToken()).
|
||||
@@ -679,7 +686,7 @@ func EdgeControllerList(path string, params url.Values, logJSON bool, out io.Wri
|
||||
}
|
||||
|
||||
// EdgeControllerCreate will create entities of the given type in the given Edge Controller
|
||||
func EdgeControllerCreate(entityType string, body string, out io.Writer, logJSON bool) (*gabs.Container, error) {
|
||||
func EdgeControllerCreate(entityType string, body string, out io.Writer, logJSON bool, timeout int, verbose bool) (*gabs.Container, error) {
|
||||
session := &Session{}
|
||||
if err := session.Load(); err != nil {
|
||||
return nil, err
|
||||
@@ -691,6 +698,8 @@ func EdgeControllerCreate(entityType string, body string, out io.Writer, logJSON
|
||||
client.SetRootCertificate(session.Cert)
|
||||
}
|
||||
resp, err := client.
|
||||
SetTimeout(time.Duration(time.Duration(timeout)*time.Second)).
|
||||
SetDebug(verbose).
|
||||
R().
|
||||
SetHeader("Content-Type", "application/json").
|
||||
SetHeader(constants.ZitiSession, session.Token).
|
||||
@@ -720,7 +729,7 @@ func EdgeControllerCreate(entityType string, body string, out io.Writer, logJSON
|
||||
}
|
||||
|
||||
// EdgeControllerDelete will delete entities of the given type in the given Edge Controller
|
||||
func EdgeControllerDelete(entityType string, id string, out io.Writer, logJSON bool) (*gabs.Container, error) {
|
||||
func EdgeControllerDelete(entityType string, id string, out io.Writer, logJSON bool, timeout int, verbose bool) (*gabs.Container, error) {
|
||||
session := &Session{}
|
||||
if err := session.Load(); err != nil {
|
||||
return nil, err
|
||||
@@ -735,6 +744,8 @@ func EdgeControllerDelete(entityType string, id string, out io.Writer, logJSON b
|
||||
fullUrl := session.Host + "/" + entityPath
|
||||
|
||||
resp, err := client.
|
||||
SetTimeout(time.Duration(time.Duration(timeout)*time.Second)).
|
||||
SetDebug(verbose).
|
||||
R().
|
||||
SetHeader("Content-Type", "application/json").
|
||||
SetHeader(constants.ZitiSession, session.Token).
|
||||
@@ -763,7 +774,7 @@ func EdgeControllerDelete(entityType string, id string, out io.Writer, logJSON b
|
||||
}
|
||||
|
||||
// EdgeControllerUpdate will update entities of the given type in the given Edge Controller
|
||||
func EdgeControllerUpdate(entityType string, body string, out io.Writer, method string, logRequestJson, logResponseJSON bool) (*gabs.Container, error) {
|
||||
func EdgeControllerUpdate(entityType string, body string, out io.Writer, method string, logRequestJson, logResponseJSON bool, timeout int, verbose bool) (*gabs.Container, error) {
|
||||
session := &Session{}
|
||||
if err := session.Load(); err != nil {
|
||||
return nil, err
|
||||
@@ -781,6 +792,8 @@ func EdgeControllerUpdate(entityType string, body string, out io.Writer, method
|
||||
}
|
||||
|
||||
resp, err := client.
|
||||
SetTimeout(time.Duration(time.Duration(timeout)*time.Second)).
|
||||
SetDebug(verbose).
|
||||
R().
|
||||
SetHeader("Content-Type", "application/json").
|
||||
SetHeader(constants.ZitiSession, session.Token).
|
||||
@@ -814,7 +827,7 @@ func EdgeControllerUpdate(entityType string, body string, out io.Writer, method
|
||||
}
|
||||
|
||||
// EdgeControllerVerify will create entities of the given type in the given Edge Controller
|
||||
func EdgeControllerVerify(entityType, id, body string, out io.Writer, logJSON bool) error {
|
||||
func EdgeControllerVerify(entityType, id, body string, out io.Writer, logJSON bool, timeout int, verbose bool) error {
|
||||
session := &Session{}
|
||||
if err := session.Load(); err != nil {
|
||||
return err
|
||||
@@ -826,6 +839,8 @@ func EdgeControllerVerify(entityType, id, body string, out io.Writer, logJSON bo
|
||||
client.SetRootCertificate(session.Cert)
|
||||
}
|
||||
resp, err := client.
|
||||
SetTimeout(time.Duration(time.Duration(timeout)*time.Second)).
|
||||
SetDebug(verbose).
|
||||
R().
|
||||
SetHeader("Content-Type", "text/plain").
|
||||
SetHeader(constants.ZitiSession, session.Token).
|
||||
@@ -848,7 +863,7 @@ func EdgeControllerVerify(entityType, id, body string, out io.Writer, logJSON bo
|
||||
return nil
|
||||
}
|
||||
|
||||
func EdgeControllerRequest(entityType string, out io.Writer, logJSON bool, doRequest func(*resty.Request, string) (*resty.Response, error)) (*gabs.Container, error) {
|
||||
func EdgeControllerRequest(entityType string, out io.Writer, logJSON bool, timeout int, verbose bool, doRequest func(*resty.Request, string) (*resty.Response, error)) (*gabs.Container, error) {
|
||||
session := &Session{}
|
||||
if err := session.Load(); err != nil {
|
||||
return nil, err
|
||||
@@ -861,6 +876,8 @@ func EdgeControllerRequest(entityType string, out io.Writer, logJSON bool, doReq
|
||||
}
|
||||
|
||||
request := client.
|
||||
SetTimeout(time.Duration(time.Duration(timeout)*time.Second)).
|
||||
SetDebug(verbose).
|
||||
R().
|
||||
SetHeader("Content-Type", "application/json").
|
||||
SetHeader(constants.ZitiSession, session.Token)
|
||||
|
||||
Reference in New Issue
Block a user