From 17134b05ad2a19672a228656d0b690554c8c4b6e Mon Sep 17 00:00:00 2001 From: gberl002 Date: Fri, 28 Jul 2023 15:02:55 -0400 Subject: [PATCH 1/6] Fixed getZiti not respecting user input when asking to use default path or not. Signed-off-by: gberl002 --- CHANGELOG.md | 1 + quickstart/docker/image/ziti-cli-functions.sh | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b3b83895..037c587e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ## Component Updates and Bug Fixes * github.com/openziti/ziti: [v0.29.0 -> v0.29.1](https://github.com/openziti/ziti/compare/v0.29.0...v0.29.1) * [Issue #1212](https://github.com/openziti/ziti/issues/1212) - Fixed getZiti function on Mac/ZSH + * [Issue #1220](https://github.com/openziti/ziti/issues/1220) - Fixed getZiti function not respecting user input for custom path # Release 0.29.0 diff --git a/quickstart/docker/image/ziti-cli-functions.sh b/quickstart/docker/image/ziti-cli-functions.sh index d209c6318..3d86a929f 100644 --- a/quickstart/docker/image/ziti-cli-functions.sh +++ b/quickstart/docker/image/ziti-cli-functions.sh @@ -602,11 +602,11 @@ function getZiti { default_path="${ZITI_HOME}/ziti-bin/ziti-${ZITI_BINARIES_VERSION}" echo -en "The path for ziti binaries has not been set, use the default (${default_path})? (Y/n) " read -r reply - if [[ -z "${reply}" || ${reply} =~ [yY]* ]]; then + if [[ -z "${reply}" || ${reply} =~ [yY] ]]; then echo "INFO: using the default path ${default_path}" ZITI_BIN_DIR="${default_path}" else - echo -en "Enter the preferred path and press (the path will be created if necessary) " + echo -en "Enter the preferred fully qualified path and press (the path will be created if necessary) " read -r ZITI_BIN_DIR fi fi From 729404c1d92c29014e6d7d95fd9191d998966021 Mon Sep 17 00:00:00 2001 From: ekoby <7406535+ekoby@users.noreply.github.com> Date: Mon, 31 Jul 2023 14:21:09 -0400 Subject: [PATCH 2/6] enable to run controller and router listeners on a single port (#1224) * enable to run controller and router listeners on a single port [fixes #1135] technical notes: uses TLS ALPN feature to select proper handler for incoming connection the following application protocols are defined: - ziti-ctrl - control channel - ziti-link - link channel - ziti-edge - edge connection (also accepts ''(blank) for backward compatibility) - Controller REST API endpoint uses standard protocols: 'h2', 'http/1.1', and ''(blank) for SDK clients - Edge Router WSS endpoint uses standard protocols: 'h2', 'http/1.1' * update zititest/go.mod --- go.mod | 22 ++++++---------------- go.sum | 45 ++++++++++++--------------------------------- zititest/go.mod | 12 ++++++------ zititest/go.sum | 24 ++++++++++++------------ 4 files changed, 36 insertions(+), 67 deletions(-) diff --git a/go.mod b/go.mod index e4e1b6b9d..a3961b11d 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,6 @@ require ( github.com/Jeffail/gabs/v2 v2.7.0 github.com/MakeNowJust/heredoc v1.0.0 github.com/blang/semver v3.5.1+incompatible - github.com/docker/docker v20.10.24+incompatible github.com/fatih/color v1.15.0 github.com/fullsailor/pkcs7 v0.0.0-20190404230743-d7302db945fa github.com/go-acme/lego/v4 v4.2.0 @@ -20,17 +19,17 @@ require ( github.com/jedib0t/go-pretty/v6 v6.4.0 github.com/michaelquigley/pfxlog v0.6.10 github.com/openziti/agent v1.0.14 - github.com/openziti/channel/v2 v2.0.84 - github.com/openziti/edge v0.24.364 + github.com/openziti/channel/v2 v2.0.87 + github.com/openziti/edge v0.24.372 github.com/openziti/edge-api v0.25.30 - github.com/openziti/fabric v0.23.45 + github.com/openziti/fabric v0.23.52 github.com/openziti/foundation/v2 v2.0.28 github.com/openziti/identity v1.0.59 github.com/openziti/runzmd v1.0.28 - github.com/openziti/sdk-golang v0.20.78 + github.com/openziti/sdk-golang v0.20.80 github.com/openziti/storage v0.2.11 - github.com/openziti/transport/v2 v2.0.93 - github.com/openziti/xweb/v2 v2.0.2 + github.com/openziti/transport/v2 v2.0.96 + github.com/openziti/xweb/v2 v2.1.0 github.com/openziti/ziti-db-explorer v1.1.1 github.com/pkg/errors v0.9.1 github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 @@ -56,7 +55,6 @@ require ( github.com/AppsFlyer/go-sundheit v0.5.0 // indirect github.com/MichaelMure/go-term-markdown v0.1.4 // indirect github.com/MichaelMure/go-term-text v0.3.1 // indirect - github.com/Microsoft/go-winio v0.6.0 // indirect github.com/alecthomas/chroma v0.10.0 // indirect github.com/andybalholm/brotli v1.0.5 // indirect github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20211106181442-e4c1a74c66bd // indirect @@ -73,8 +71,6 @@ require ( github.com/dineshappavoo/basex v0.0.0-20170425072625-481a6f6dc663 // indirect github.com/disintegration/imaging v1.6.2 // indirect github.com/dlclark/regexp2 v1.10.0 // indirect - github.com/docker/distribution v2.8.2+incompatible // indirect - github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-units v0.5.0 // indirect github.com/ef-ds/deque v1.0.4 // indirect github.com/eliukblau/pixterm/pkg/ansimage v0.0.0-20191210081756-9fb6cf8c2f75 // indirect @@ -92,7 +88,6 @@ require ( github.com/go-openapi/spec v0.20.9 // indirect github.com/go-openapi/swag v0.22.4 // indirect github.com/go-openapi/validate v0.22.1 // indirect - github.com/gogo/protobuf v1.3.2 // indirect github.com/golang-jwt/jwt v3.2.2+incompatible // indirect github.com/gomarkdown/markdown v0.0.0-20230322041520-c84983bdbf2a // indirect github.com/google/uuid v1.3.0 // indirect @@ -132,12 +127,8 @@ require ( github.com/miekg/pkcs11 v1.1.1 // indirect github.com/mitchellh/go-ps v1.0.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect - github.com/moby/term v0.0.0-20221120202655-abb19827d345 // indirect - github.com/morikuni/aec v1.0.0 // indirect github.com/natefinch/lumberjack v2.0.0+incompatible // indirect github.com/oklog/ulid v1.3.1 // indirect - github.com/opencontainers/go-digest v1.0.0 // indirect - github.com/opencontainers/image-spec v1.0.2 // indirect github.com/opentracing/opentracing-go v1.2.0 // indirect github.com/openziti/dilithium v0.3.3 // indirect github.com/openziti/jwks v1.0.3 // indirect @@ -186,6 +177,5 @@ require ( google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect gopkg.in/ini.v1 v1.66.2 // indirect gopkg.in/square/go-jose.v2 v2.5.1 // indirect - gotest.tools/v3 v3.4.0 // indirect nhooyr.io/websocket v1.8.7 // indirect ) diff --git a/go.sum b/go.sum index 99d9299c8..dabb68a29 100644 --- a/go.sum +++ b/go.sum @@ -48,7 +48,6 @@ git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGy github.com/AppsFlyer/go-sundheit v0.5.0 h1:/VxpyigCfJrq1r97mn9HPiAB2qrhcTFHwNIIDr15CZM= github.com/AppsFlyer/go-sundheit v0.5.0/go.mod h1:2ZM0BnfqT/mljBQO224VbL5XH06TgWuQ6Cn+cTtCpTY= github.com/Azure/azure-sdk-for-go v32.4.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= -github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= github.com/Azure/go-autorest/autorest v0.1.0/go.mod h1:AKyIcETwSUFxIcs/Wnq/C+kwCtlEYGUVd7FPNb2slmg= github.com/Azure/go-autorest/autorest v0.5.0/go.mod h1:9HLKlQjVBH6U3oDfsXOeVc56THsLPw1L03yban4xThw= github.com/Azure/go-autorest/autorest/adal v0.1.0/go.mod h1:MeS4XhScH55IST095THyTxElntu7WqB7pNbZo8Q5G3E= @@ -76,8 +75,6 @@ github.com/MichaelMure/go-term-markdown v0.1.4 h1:Ir3kBXDUtOX7dEv0EaQV8CNPpH+T7A github.com/MichaelMure/go-term-markdown v0.1.4/go.mod h1:EhcA3+pKYnlUsxYKBJ5Sn1cTQmmBMjeNlpV8nRb+JxA= github.com/MichaelMure/go-term-text v0.3.1 h1:Kw9kZanyZWiCHOYu9v/8pWEgDQ6UVN9/ix2Vd2zzWf0= github.com/MichaelMure/go-term-text v0.3.1/go.mod h1:QgVjAEDUnRMlzpS6ky5CGblux7ebeiLnuy9dAaFZu8o= -github.com/Microsoft/go-winio v0.6.0 h1:slsWYD/zyx7lCXoZVlvQrj0hPTM1HI4+v1sIda2yDvg= -github.com/Microsoft/go-winio v0.6.0/go.mod h1:cTAf44im0RAYeL23bpB+fzCyDH2MJiz2BO69KH/soAE= github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8 h1:xzYJEypr/85nBpB11F9br+3HUrpgb+fcm5iADzXXYEw= github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8/go.mod h1:oX5x61PbNXchhh0oikYAH+4Pcfw5LKv21+Jnpr6r6Pc= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= @@ -189,12 +186,6 @@ github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55k github.com/dlclark/regexp2 v1.10.0 h1:+/GIL799phkJqYW+3YbOd8LCcbHzT0Pbo8zl70MHsq0= github.com/dlclark/regexp2 v1.10.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= github.com/dnsimple/dnsimple-go v0.63.0/go.mod h1:O5TJ0/U6r7AfT8niYNlmohpLbCSG+c71tQlGr9SeGrg= -github.com/docker/distribution v2.8.2+incompatible h1:T3de5rq0dB1j30rp0sA2rER+m322EBzniBPB6ZIzuh8= -github.com/docker/distribution v2.8.2+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= -github.com/docker/docker v20.10.24+incompatible h1:Ugvxm7a8+Gz6vqQYQQ2W7GYq5EUPaAiuPgIfVyI3dYE= -github.com/docker/docker v20.10.24+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= -github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= -github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= @@ -345,7 +336,6 @@ github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRx github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= -github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A= github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY= @@ -665,8 +655,6 @@ github.com/mitchellh/mapstructure v1.3.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RR github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= -github.com/moby/term v0.0.0-20221120202655-abb19827d345 h1:J9c53/kxIH+2nTKBEfZYFMlhghtHpIHSXpm5VRGHSnU= -github.com/moby/term v0.0.0-20221120202655-abb19827d345/go.mod h1:15ce4BGCFxt7I5NQKT+HV0yEDxmf6fSysfEDiVo3zFM= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -674,8 +662,6 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= -github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= -github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/namedotcom/go v0.0.0-20180403034216-08470befbe04/go.mod h1:5sN+Lt1CaY4wsPvgQH/jsuJi4XO2ssZbdsIizr4CVC8= github.com/natefinch/lumberjack v2.0.0+incompatible h1:4QJd3OLAMgj7ph+yZTuX13Ld4UpgHp07nNdFX7mqFfM= @@ -705,26 +691,22 @@ github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7J github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.10.5/go.mod h1:gza4q3jKQJijlu05nKWRCW/GavJumGt8aNRxWg7mt48= github.com/onsi/gomega v1.13.0 h1:7lLHu94wT9Ij0o6EWWclhu0aOh32VxhkwEJvzuWPeak= -github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= -github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= -github.com/opencontainers/image-spec v1.0.2 h1:9yCKha/T5XdGtO0q9Q9a6T5NUCsTn/DrBg0D7ufOcFM= -github.com/opencontainers/image-spec v1.0.2/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8= github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw= github.com/openziti/agent v1.0.14 h1:OTYhj2HeIlFwaFNcVT5BlYf7s4xa0TNmhnjmBpN8Afg= github.com/openziti/agent v1.0.14/go.mod h1:zfm53+PVWoGFzjGGgQdKby5749G6VRYHe+eQJmoVKy4= -github.com/openziti/channel/v2 v2.0.84 h1:bIdg2Z2SZan0HqSz2sbtY6Ibo33BH9Ir+qbuzyt9Rhs= -github.com/openziti/channel/v2 v2.0.84/go.mod h1:njjvl7YH6TfbJPbYxz6Y7+7uhv4Ea2GdLEJIcQOZMU8= +github.com/openziti/channel/v2 v2.0.87 h1:+54diAb1NjwnQ3qADptq76gq3IFF+hW+uLD5st5ULAo= +github.com/openziti/channel/v2 v2.0.87/go.mod h1:GggAVKAlOf2ezo8VvgQ2yRK5Gokp6wlvS4kBhmoKn1g= github.com/openziti/dilithium v0.3.3 h1:PLgQ6PMNLSTzCFbX/h98cmudgz/cU6TmjdSv5NAPD8k= github.com/openziti/dilithium v0.3.3/go.mod h1:vsCjI2AU/hon9e+dLhUFbCNGesJDj2ASgkySOcpmvjo= -github.com/openziti/edge v0.24.364 h1:58X9C0CcmoEpAWkutxe49vW+Xf46h8iRlfVKXDaoDp0= -github.com/openziti/edge v0.24.364/go.mod h1:tKl9mG3dko3QQc1FQ1YUSF1B2KTW8MUcHMRezjbGiaU= +github.com/openziti/edge v0.24.372 h1:B9zMZUDnoqKu+epTkWEdfm1ugX8X+S0u/Tg23k3+mPc= +github.com/openziti/edge v0.24.372/go.mod h1:nkYAlBPh8q+pbtM5RACeq0/lsxrutqSKeQ5hlYGe49U= github.com/openziti/edge-api v0.25.30 h1:40pAcd3Y2yT8hYYHTJTkSTLA0pvbDCw4prt72JdQMuI= github.com/openziti/edge-api v0.25.30/go.mod h1:ODMG0fB9Dj1pL0UqDC8jzSUAlUZy8aYhzF3xHPg6Xm0= -github.com/openziti/fabric v0.23.45 h1:TnPtN215KX5SBrWLzTVZLS1+xalVkpa+9kb+6U3YNl8= -github.com/openziti/fabric v0.23.45/go.mod h1:GijkTVVj4gUXlez2l+mdedCV15qP91YzX0EdM3tCSA8= +github.com/openziti/fabric v0.23.52 h1:8F4jt00RDrZJz6YiKliJ8UGnknE3jSuWwxsK3641ehE= +github.com/openziti/fabric v0.23.52/go.mod h1:wLYKhlnhthLR7FBqfGlfdCZ0hbQCcSnr5b2wpjA4/vM= github.com/openziti/foundation/v2 v2.0.28 h1:AAdHhtUj1tCIXollSpbDlKwPKRasNAgADpTZAF1WCOQ= github.com/openziti/foundation/v2 v2.0.28/go.mod h1:psKxxQw/zRo5+oKN7AR+MKYaeR3mbBPhb65qq8rqB0U= github.com/openziti/identity v1.0.59 h1:YShXqxa9nTbCnPtIAji10hx7BG1nQukg4ddUJExNXa8= @@ -735,18 +717,18 @@ github.com/openziti/metrics v1.2.30 h1:0ZV9UWPupcBvHigzET1wf47idrTflYSHInNgDtZqk github.com/openziti/metrics v1.2.30/go.mod h1:8xSr4Rl0527Lyp5IKvUYwPNObIFkO8AS3nO2RjvDPSQ= github.com/openziti/runzmd v1.0.28 h1:8VNgENRAm1pfp0YoJWYoW6uBtyMD6ccVTsC24kx2gpk= github.com/openziti/runzmd v1.0.28/go.mod h1:4r4uNOK34lKbilrV7yaiDiPwRGIvj1XQSl6E6U8NmAw= -github.com/openziti/sdk-golang v0.20.78 h1:ts1AXB9rtja/pfnzsaUzojVUNtEDmtHrNLCrokbpBHQ= -github.com/openziti/sdk-golang v0.20.78/go.mod h1:t97RrYAaFq0mGHc08T5OVCnuNvqO4/ERDfXpUvDgN7U= +github.com/openziti/sdk-golang v0.20.80 h1:TG+G4QrVjcA7Q2kiZf8OlplfyHRkoVO7Z1yilUHrEis= +github.com/openziti/sdk-golang v0.20.80/go.mod h1:SvKwsnV7wgRrGq+E+C2ASCEN06t9camcTBANYXXYWro= github.com/openziti/secretstream v0.1.10 h1:aLheoP6vVAv96mItwkXxWr9Ym0tTooJ5o9H1j2fAh04= github.com/openziti/secretstream v0.1.10/go.mod h1:HrS6P9G0jjHNHuKESMaybNdxBHjD1b0SzxSi0rDzshY= github.com/openziti/storage v0.2.11 h1:Ws23any7NtbEKQroFJt6DJmeEFGMPjZqjAK2/Re9LIE= github.com/openziti/storage v0.2.11/go.mod h1:M46XIxPYwTDTgaamI6o9cyEJkYvUYfhJjwvZtQu4tUQ= -github.com/openziti/transport/v2 v2.0.93 h1:CCADtZQki2gMtTYuGuNpxIVuWofxFIWmGbeRZp2MNTY= -github.com/openziti/transport/v2 v2.0.93/go.mod h1:a39vnp7P/ldeSegyRLwYLM+UrK1PjI6pryG3N+lKx6o= +github.com/openziti/transport/v2 v2.0.96 h1:onLHb0oNS+xzmqnAVYHDGb00qtLODzyPVubq+2h5SoY= +github.com/openziti/transport/v2 v2.0.96/go.mod h1:L0MZ3LZsJ9Jheg05Bp6QYJBfuq4fDtjoL9stcTSmtko= github.com/openziti/x509-claims v1.0.3 h1:HNdQ8Nf1agB3lBs1gahcO6zfkeS4S5xoQ2/PkY4HRX0= github.com/openziti/x509-claims v1.0.3/go.mod h1:Z0WIpBm6c4ecrpRKrou6Gk2wrLWxJO/+tuUwKh8VewE= -github.com/openziti/xweb/v2 v2.0.2 h1:XYlVFriTq/U1wcUrc+XPnWJGhXh9NJPhtQ7+r3aC0cU= -github.com/openziti/xweb/v2 v2.0.2/go.mod h1:KQOOlnJk08EZT3TWkvDj/pbIUEVbgG0IrrNzl8gsi40= +github.com/openziti/xweb/v2 v2.1.0 h1:Xhh3C2pZkq/Prr65V+SfFSibLDYteoc4f62KQCcTZF4= +github.com/openziti/xweb/v2 v2.1.0/go.mod h1:wPkjm5y45RYCV8AafjcAXP/ZM4DBOofXhRwSGgjF8w8= github.com/openziti/ziti-db-explorer v1.1.1 h1:G0eoTby+aIjjt5TxEfR+FMI2CWd4RvZFjzaIMX2lEBw= github.com/openziti/ziti-db-explorer v1.1.1/go.mod h1:h76h7Tsb+khb0v+CqYKL6ifUfJbUMjGBFU2IvupfBE4= github.com/oracle/oci-go-sdk v24.2.0+incompatible/go.mod h1:VQb79nF8Z2cwLkLS35ukwStZIg5F66tcBccjip/j888= @@ -1300,7 +1282,6 @@ golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxb golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e h1:EHBhcS0mlXEAVwNyO2dLfjToGsyY4j24pTs2ScHnX7s= golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -1538,8 +1519,6 @@ gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o= -gotest.tools/v3 v3.4.0/go.mod h1:CtbdzLSsqVhDgMtKsx03ird5YTGB3ar27v0u/yKBW5g= grpc.go4.org v0.0.0-20170609214715-11d0a25b4919/go.mod h1:77eQGdRu53HpSqPFJFmuJdjuHRquDANNeA4x7B8WQ9o= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/zititest/go.mod b/zititest/go.mod index 5cf4282de..01e873413 100644 --- a/zititest/go.mod +++ b/zititest/go.mod @@ -9,15 +9,15 @@ require ( github.com/Jeffail/gabs/v2 v2.7.0 github.com/google/uuid v1.3.0 github.com/michaelquigley/pfxlog v0.6.10 - github.com/openziti/channel/v2 v2.0.84 - github.com/openziti/edge v0.24.364 + github.com/openziti/channel/v2 v2.0.87 + github.com/openziti/edge v0.24.372 github.com/openziti/fablab v0.5.5 - github.com/openziti/fabric v0.23.45 + github.com/openziti/fabric v0.23.52 github.com/openziti/foundation/v2 v2.0.28 github.com/openziti/identity v1.0.59 - github.com/openziti/sdk-golang v0.20.78 + github.com/openziti/sdk-golang v0.20.80 github.com/openziti/storage v0.2.11 - github.com/openziti/transport/v2 v2.0.93 + github.com/openziti/transport/v2 v2.0.96 github.com/openziti/ziti v0.28.3 github.com/pkg/errors v0.9.1 github.com/sirupsen/logrus v1.9.3 @@ -129,7 +129,7 @@ require ( github.com/openziti/runzmd v1.0.28 // indirect github.com/openziti/secretstream v0.1.10 // indirect github.com/openziti/x509-claims v1.0.3 // indirect - github.com/openziti/xweb/v2 v2.0.2 // indirect + github.com/openziti/xweb/v2 v2.1.0 // indirect github.com/openziti/ziti-db-explorer v1.1.1 // indirect github.com/orcaman/concurrent-map/v2 v2.0.1 // indirect github.com/parallaxsecond/parsec-client-go v0.0.0-20221025095442-f0a77d263cf9 // indirect diff --git a/zititest/go.sum b/zititest/go.sum index 3044ead6b..2de16b914 100644 --- a/zititest/go.sum +++ b/zititest/go.sum @@ -641,16 +641,16 @@ github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYr github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw= github.com/openziti/agent v1.0.14 h1:OTYhj2HeIlFwaFNcVT5BlYf7s4xa0TNmhnjmBpN8Afg= github.com/openziti/agent v1.0.14/go.mod h1:zfm53+PVWoGFzjGGgQdKby5749G6VRYHe+eQJmoVKy4= -github.com/openziti/channel/v2 v2.0.84 h1:bIdg2Z2SZan0HqSz2sbtY6Ibo33BH9Ir+qbuzyt9Rhs= -github.com/openziti/channel/v2 v2.0.84/go.mod h1:njjvl7YH6TfbJPbYxz6Y7+7uhv4Ea2GdLEJIcQOZMU8= -github.com/openziti/edge v0.24.364 h1:58X9C0CcmoEpAWkutxe49vW+Xf46h8iRlfVKXDaoDp0= -github.com/openziti/edge v0.24.364/go.mod h1:tKl9mG3dko3QQc1FQ1YUSF1B2KTW8MUcHMRezjbGiaU= +github.com/openziti/channel/v2 v2.0.87 h1:+54diAb1NjwnQ3qADptq76gq3IFF+hW+uLD5st5ULAo= +github.com/openziti/channel/v2 v2.0.87/go.mod h1:GggAVKAlOf2ezo8VvgQ2yRK5Gokp6wlvS4kBhmoKn1g= +github.com/openziti/edge v0.24.372 h1:B9zMZUDnoqKu+epTkWEdfm1ugX8X+S0u/Tg23k3+mPc= +github.com/openziti/edge v0.24.372/go.mod h1:nkYAlBPh8q+pbtM5RACeq0/lsxrutqSKeQ5hlYGe49U= github.com/openziti/edge-api v0.25.30 h1:40pAcd3Y2yT8hYYHTJTkSTLA0pvbDCw4prt72JdQMuI= github.com/openziti/edge-api v0.25.30/go.mod h1:ODMG0fB9Dj1pL0UqDC8jzSUAlUZy8aYhzF3xHPg6Xm0= github.com/openziti/fablab v0.5.5 h1:wz5rkuGhdDbmNPXC8XtsyHhWk6WJtxCgfhXt5XVWXmY= github.com/openziti/fablab v0.5.5/go.mod h1:xkvaXX6C+bGHH5R4G8/vkz1pbBlwS1EzghF37wcNetM= -github.com/openziti/fabric v0.23.45 h1:TnPtN215KX5SBrWLzTVZLS1+xalVkpa+9kb+6U3YNl8= -github.com/openziti/fabric v0.23.45/go.mod h1:GijkTVVj4gUXlez2l+mdedCV15qP91YzX0EdM3tCSA8= +github.com/openziti/fabric v0.23.52 h1:8F4jt00RDrZJz6YiKliJ8UGnknE3jSuWwxsK3641ehE= +github.com/openziti/fabric v0.23.52/go.mod h1:wLYKhlnhthLR7FBqfGlfdCZ0hbQCcSnr5b2wpjA4/vM= github.com/openziti/foundation/v2 v2.0.28 h1:AAdHhtUj1tCIXollSpbDlKwPKRasNAgADpTZAF1WCOQ= github.com/openziti/foundation/v2 v2.0.28/go.mod h1:psKxxQw/zRo5+oKN7AR+MKYaeR3mbBPhb65qq8rqB0U= github.com/openziti/identity v1.0.59 h1:YShXqxa9nTbCnPtIAji10hx7BG1nQukg4ddUJExNXa8= @@ -661,18 +661,18 @@ github.com/openziti/metrics v1.2.30 h1:0ZV9UWPupcBvHigzET1wf47idrTflYSHInNgDtZqk github.com/openziti/metrics v1.2.30/go.mod h1:8xSr4Rl0527Lyp5IKvUYwPNObIFkO8AS3nO2RjvDPSQ= github.com/openziti/runzmd v1.0.28 h1:8VNgENRAm1pfp0YoJWYoW6uBtyMD6ccVTsC24kx2gpk= github.com/openziti/runzmd v1.0.28/go.mod h1:4r4uNOK34lKbilrV7yaiDiPwRGIvj1XQSl6E6U8NmAw= -github.com/openziti/sdk-golang v0.20.78 h1:ts1AXB9rtja/pfnzsaUzojVUNtEDmtHrNLCrokbpBHQ= -github.com/openziti/sdk-golang v0.20.78/go.mod h1:t97RrYAaFq0mGHc08T5OVCnuNvqO4/ERDfXpUvDgN7U= +github.com/openziti/sdk-golang v0.20.80 h1:TG+G4QrVjcA7Q2kiZf8OlplfyHRkoVO7Z1yilUHrEis= +github.com/openziti/sdk-golang v0.20.80/go.mod h1:SvKwsnV7wgRrGq+E+C2ASCEN06t9camcTBANYXXYWro= github.com/openziti/secretstream v0.1.10 h1:aLheoP6vVAv96mItwkXxWr9Ym0tTooJ5o9H1j2fAh04= github.com/openziti/secretstream v0.1.10/go.mod h1:HrS6P9G0jjHNHuKESMaybNdxBHjD1b0SzxSi0rDzshY= github.com/openziti/storage v0.2.11 h1:Ws23any7NtbEKQroFJt6DJmeEFGMPjZqjAK2/Re9LIE= github.com/openziti/storage v0.2.11/go.mod h1:M46XIxPYwTDTgaamI6o9cyEJkYvUYfhJjwvZtQu4tUQ= -github.com/openziti/transport/v2 v2.0.93 h1:CCADtZQki2gMtTYuGuNpxIVuWofxFIWmGbeRZp2MNTY= -github.com/openziti/transport/v2 v2.0.93/go.mod h1:a39vnp7P/ldeSegyRLwYLM+UrK1PjI6pryG3N+lKx6o= +github.com/openziti/transport/v2 v2.0.96 h1:onLHb0oNS+xzmqnAVYHDGb00qtLODzyPVubq+2h5SoY= +github.com/openziti/transport/v2 v2.0.96/go.mod h1:L0MZ3LZsJ9Jheg05Bp6QYJBfuq4fDtjoL9stcTSmtko= github.com/openziti/x509-claims v1.0.3 h1:HNdQ8Nf1agB3lBs1gahcO6zfkeS4S5xoQ2/PkY4HRX0= github.com/openziti/x509-claims v1.0.3/go.mod h1:Z0WIpBm6c4ecrpRKrou6Gk2wrLWxJO/+tuUwKh8VewE= -github.com/openziti/xweb/v2 v2.0.2 h1:XYlVFriTq/U1wcUrc+XPnWJGhXh9NJPhtQ7+r3aC0cU= -github.com/openziti/xweb/v2 v2.0.2/go.mod h1:KQOOlnJk08EZT3TWkvDj/pbIUEVbgG0IrrNzl8gsi40= +github.com/openziti/xweb/v2 v2.1.0 h1:Xhh3C2pZkq/Prr65V+SfFSibLDYteoc4f62KQCcTZF4= +github.com/openziti/xweb/v2 v2.1.0/go.mod h1:wPkjm5y45RYCV8AafjcAXP/ZM4DBOofXhRwSGgjF8w8= github.com/openziti/ziti-db-explorer v1.1.1 h1:G0eoTby+aIjjt5TxEfR+FMI2CWd4RvZFjzaIMX2lEBw= github.com/openziti/ziti-db-explorer v1.1.1/go.mod h1:h76h7Tsb+khb0v+CqYKL6ifUfJbUMjGBFU2IvupfBE4= github.com/oracle/oci-go-sdk v24.2.0+incompatible/go.mod h1:VQb79nF8Z2cwLkLS35ukwStZIg5F66tcBccjip/j888= From c02051f3d4b07ef7165db665673403ccd5ad1ba0 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Mon, 31 Jul 2023 15:09:52 -0400 Subject: [PATCH 3/6] fix/rearrange quickstart to work as prior --- quickstart/docker/image/run-router.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/quickstart/docker/image/run-router.sh b/quickstart/docker/image/run-router.sh index 563b09db7..1ab5ab8dd 100755 --- a/quickstart/docker/image/run-router.sh +++ b/quickstart/docker/image/run-router.sh @@ -2,12 +2,6 @@ . "${ZITI_SCRIPTS}/ziti-cli-functions.sh" -# wait for the controller to come online -_wait_for_controller - -# after coming online, give the controller just a second to ramp up in case running via docker compose -sleep 1 - if [[ "${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS-}" == "" ]]; then export ZITI_CTRL_EDGE_ADVERTISED_ADDRESS="ziti-edge-controller"; fi if [[ "${ZITI_CTRL_EDGE_ADVERTISED_PORT-}" == "" ]]; then export ZITI_CTRL_EDGE_ADVERTISED_PORT="3022"; fi if [[ "${ZITI_ROUTER_PORT-}" == "" ]]; then export ZITI_ROUTER_PORT="3022"; fi @@ -20,6 +14,12 @@ fi . ${ZITI_HOME}/ziti.env +# wait for the controller to come online +_wait_for_controller + +# after coming online, give the controller just a second to ramp up in case running via docker compose +sleep 1 + if [[ "${_ZITI_ROUTER_NAME}" != "" ]]; then export ZITI_ROUTER_NAME="${_ZITI_ROUTER_NAME}" echo "ZITI_ROUTER_NAME set to: ${ZITI_ROUTER_NAME}" From b37e0f92a06169b4e68e61329bb1d02b601c46cf Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Mon, 31 Jul 2023 15:14:55 -0400 Subject: [PATCH 4/6] fix the default port of the controller bug --- quickstart/docker/image/run-router.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quickstart/docker/image/run-router.sh b/quickstart/docker/image/run-router.sh index 1ab5ab8dd..d3c2172f9 100755 --- a/quickstart/docker/image/run-router.sh +++ b/quickstart/docker/image/run-router.sh @@ -3,7 +3,7 @@ . "${ZITI_SCRIPTS}/ziti-cli-functions.sh" if [[ "${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS-}" == "" ]]; then export ZITI_CTRL_EDGE_ADVERTISED_ADDRESS="ziti-edge-controller"; fi -if [[ "${ZITI_CTRL_EDGE_ADVERTISED_PORT-}" == "" ]]; then export ZITI_CTRL_EDGE_ADVERTISED_PORT="3022"; fi +if [[ "${ZITI_CTRL_EDGE_ADVERTISED_PORT-}" == "" ]]; then export ZITI_CTRL_EDGE_ADVERTISED_PORT="1280"; fi if [[ "${ZITI_ROUTER_PORT-}" == "" ]]; then export ZITI_ROUTER_PORT="3022"; fi if [[ "${ZITI_ROUTER_ROLES}" == "" ]]; then export ZITI_ROUTER_ROLES="${ZITI_ROUTER_NAME}"; fi From 4c6e60a5d9bcf7317921a980a598ccbb0062383c Mon Sep 17 00:00:00 2001 From: gberl002 Date: Mon, 31 Jul 2023 16:13:11 -0400 Subject: [PATCH 5/6] Fixed some routers intermittently being unable to connect to the controller due to "ziti not found" Signed-off-by: gberl002 --- quickstart/docker/image/run-router.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quickstart/docker/image/run-router.sh b/quickstart/docker/image/run-router.sh index d3c2172f9..2e72ab363 100755 --- a/quickstart/docker/image/run-router.sh +++ b/quickstart/docker/image/run-router.sh @@ -27,9 +27,9 @@ fi _UNIQUE_NAME="${ZITI_HOME}/${ZITI_ROUTER_NAME}-${HOSTNAME}.init" if [ ! -f "${_UNIQUE_NAME}" ]; then echo "system has not been initialized. initializing..." - ziti edge login ${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}:${ZITI_CTRL_EDGE_ADVERTISED_PORT} -u $ZITI_USER -p $ZITI_PWD -y + "${ZITI_BIN_DIR-}/ziti" edge login ${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}:${ZITI_CTRL_EDGE_ADVERTISED_PORT} -u $ZITI_USER -p $ZITI_PWD -y - echo "---------- Creating edge-router ${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}...." + echo "---------- Creating edge-router ${ZITI_ROUTER_NAME}...." if [[ "$1" == "edge" ]]; then echo "CREATING EDGE ROUTER CONFIG: ${ZITI_ROUTER_NAME}" From 220be23c04f70eba70755e370c62d06528105786 Mon Sep 17 00:00:00 2001 From: Paul Lorenz Date: Fri, 4 Aug 2023 15:08:00 -0400 Subject: [PATCH 6/6] Fix linter reported issues --- common/enrollment/enroll.go | 10 +- common/getziti/github.go | 3 +- quickstart/test/quickstart_test.go | 135 +------------- ziti-fabric-test/subcmd/client/http.go | 6 +- ziti-fabric-test/subcmd/loop2/protocol.go | 38 ++-- ziti-fabric-test/subcmd/loop2/scenario.go | 4 +- ziti-fabric-test/subcmd/loop3/dialer.go | 2 +- ziti-fabric-test/subcmd/loop3/messages.go | 6 +- .../subcmd/loop3/messages_test.go | 9 +- ziti-fabric-test/subcmd/loop3/protocol.go | 46 +++-- ziti-fabric-test/subcmd/loop3/scenario.go | 4 +- ziti/cmd/agentcli/agent_cluster_list.go | 2 +- ziti/cmd/agentcli/agent_ps.go | 5 +- ziti/cmd/cmd.go | 1 - ziti/cmd/color/color.go | 99 ----------- ziti/cmd/common.go | 6 + ziti/cmd/common_commands.go | 161 ----------------- ziti/cmd/common_init.go | 167 ------------------ ziti/cmd/create_config_environment.go | 1 - ziti/cmd/create_config_router_test.go | 22 +-- ziti/cmd/database/du.go | 19 -- ziti/cmd/demo/echo_server.go | 11 -- ziti/cmd/edge/create_config.go | 7 +- ziti/cmd/edge/create_config_type.go | 7 +- ziti/cmd/edge/create_enrollment.go | 1 - ziti/cmd/edge/create_posture_check.go | 1 - ziti/cmd/edge/create_service.go | 5 +- ziti/cmd/edge/delete.go | 4 - ziti/cmd/edge/encryption_var.go | 2 +- ziti/cmd/edge/list.go | 24 --- ziti/cmd/edge/update_config.go | 7 +- ziti/cmd/edge/update_service.go | 4 +- ziti/cmd/edge/verify.go | 7 - ziti/cmd/edge/verify_ca.go | 18 +- ziti/cmd/fabric/inspect.go | 2 +- ziti/cmd/fabric/stream_traces.go | 8 +- ziti/cmd/helpers/helpers.go | 34 +--- ziti/cmd/install/common_install.go | 101 ----------- ...tall_terraform_provider_edge_controller.go | 3 + ziti/cmd/install/install_ziti_ALL.go | 3 + ziti/cmd/install/install_ziti_controller.go | 3 + ziti/cmd/install/install_ziti_router.go | 3 + ziti/cmd/install/install_ziti_tunnel.go | 3 + ziti/cmd/install/version.go | 30 +++- ziti/cmd/lets_encrypt/KeyTypeVar.go | 25 +-- ziti/cmd/lets_encrypt/accounts_storage.go | 10 +- ziti/cmd/lets_encrypt/certs_storage.go | 10 +- ziti/cmd/lets_encrypt/create.go | 14 +- ziti/cmd/lets_encrypt/list.go | 10 +- ziti/cmd/lets_encrypt/renew.go | 12 +- ziti/cmd/lets_encrypt/revoke.go | 8 +- ziti/cmd/lets_encrypt/setup.go | 45 +---- ziti/cmd/pki_create.go | 33 ++-- ziti/cmd/templates/templater.go | 9 - ziti/cmd/unwrap_identity.go | 10 +- ziti/pki/store/local.go | 9 +- ziti/router/enrollgw.go | 8 +- ziti/router/run.go | 2 +- ziti/util/certs.go | 16 +- ziti/util/commands.go | 126 ------------- ziti/util/dirs.go | 5 +- ziti/util/files.go | 13 +- 62 files changed, 251 insertions(+), 1148 deletions(-) delete mode 100644 ziti/cmd/color/color.go delete mode 100644 ziti/cmd/common_commands.go delete mode 100644 ziti/cmd/common_init.go diff --git a/common/enrollment/enroll.go b/common/enrollment/enroll.go index 1ba66d9f9..3dc7acfb4 100644 --- a/common/enrollment/enroll.go +++ b/common/enrollment/enroll.go @@ -22,7 +22,6 @@ import ( "github.com/openziti/identity/engines" "github.com/openziti/sdk-golang/ziti" "github.com/openziti/ziti/ziti/cmd/common" - "io/ioutil" "os" "strings" @@ -36,7 +35,6 @@ import ( // global state used by all subcommands are located here for easy discovery -const verboseDesc = "Enable verbose logging." const outpathDesc = "Output configuration file." const jwtpathDesc = "Enrollment token (JWT file). Required" const certDesc = "The certificate to present when establishing a connection." @@ -113,10 +111,12 @@ func NewEnrollCommand(p common.OptionsProvider) *cobra.Command { enrollSubCmd.Flags().BoolVar(&action.RemoveJwt, "rm", false, "Remove the JWT on success") enrollSubCmd.Flags().BoolVarP(&action.Verbose, "verbose", "v", false, "Enable verbose logging") - action.KeyAlg.Set("RSA") // set default + if err := action.KeyAlg.Set("RSA"); err != nil { // set default + panic(err) + } enrollSubCmd.Flags().VarP(&action.KeyAlg, "keyAlg", "a", "Crypto algorithm to use when generating private key") - var keyDesc = "" + var keyDesc string certEngines := engines.ListEngines() if len(certEngines) > 0 { keyDesc = fmt.Sprintf("The key to use with the certificate. Optionally specify the engine to use. supported engines: %v", certEngines) @@ -153,7 +153,7 @@ func (e *EnrollAction) Run() error { return fmt.Errorf("the output path must not be the same as the jwt path") } - tokenStr, _ := ioutil.ReadFile(e.JwtPath) + tokenStr, _ := os.ReadFile(e.JwtPath) pfxlog.Logger().Debugf("jwt to parse: %s", tokenStr) tkn, _, err := enroll.ParseToken(string(tokenStr)) diff --git a/common/getziti/github.go b/common/getziti/github.go index 0e62f9687..229c3c445 100644 --- a/common/getziti/github.go +++ b/common/getziti/github.go @@ -129,7 +129,8 @@ func GetLatestGitHubReleaseAsset(appName string, appGitHub string, version strin version = "tags/" + version } - ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) + ctx, cancelF := context.WithTimeout(context.Background(), 10*time.Second) + defer cancelF() resp, err := getRequest(verbose). SetContext(ctx). diff --git a/quickstart/test/quickstart_test.go b/quickstart/test/quickstart_test.go index 1e048b1a3..c697e167e 100644 --- a/quickstart/test/quickstart_test.go +++ b/quickstart/test/quickstart_test.go @@ -1,7 +1,6 @@ package test import ( - "archive/tar" "context" "crypto/tls" "crypto/x509" @@ -9,18 +8,14 @@ import ( "fmt" "github.com/openziti/edge-api/rest_management_api_client" api_client_config "github.com/openziti/edge-api/rest_management_api_client/config" - "github.com/openziti/edge-api/rest_management_api_client/edge_router" - "github.com/openziti/edge-api/rest_management_api_client/edge_router_policy" "github.com/openziti/edge-api/rest_management_api_client/identity" "github.com/openziti/edge-api/rest_management_api_client/service" - "github.com/openziti/edge-api/rest_management_api_client/service_edge_router_policy" "github.com/openziti/edge-api/rest_management_api_client/service_policy" "github.com/openziti/edge-api/rest_management_api_client/terminator" "github.com/openziti/edge-api/rest_model" "github.com/openziti/edge-api/rest_util" "github.com/openziti/sdk-golang/ziti" "github.com/openziti/sdk-golang/ziti/enroll" - "github.com/pkg/errors" log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "io" @@ -33,69 +28,6 @@ import ( "time" ) -func iterateDir(dirPath string) []string { - dir, err := os.Open(dirPath) - if err != nil { - fmt.Println(err) - log.Fatal("Failed to parse ziti.ignore") - } - defer dir.Close() - fis, err := dir.Readdir(0) - if err != nil { - fmt.Println(err) - log.Fatal("Failed to read directory") - } - var filePaths []string - for _, fi := range fis { - curPath := dirPath + "/" + fi.Name() - if fi.IsDir() { - //TarGzWrite( curPath, tw, fi ) - filePaths = append(filePaths, iterateDir(curPath)...) - } else { - filePaths = append(filePaths, curPath) - //err = addToTar(tw, curPath) - if err != nil { - fmt.Println(err) - log.Fatal("Failed add " + curPath) - } - //TarGzWrite( curPath, tw, fi ) - } - } - return filePaths -} - -func addFileToTarWriter(filePath string, tarWriter *tar.Writer) error { - file, err := os.Open(filePath) - if err != nil { - return errors.New(fmt.Sprintf("Could not open file '%s', got error '%s'", filePath, err.Error())) - } - defer file.Close() - - stat, err := file.Stat() - if err != nil { - return errors.New(fmt.Sprintf("Could not get stat for file '%s', got error '%s'", filePath, err.Error())) - } - - header := &tar.Header{ - Name: filePath, - Size: stat.Size(), - Mode: int64(stat.Mode()), - ModTime: stat.ModTime(), - } - - err = tarWriter.WriteHeader(header) - if err != nil { - return errors.New(fmt.Sprintf("Could not write header for file '%s', got error '%s'", filePath, err.Error())) - } - - _, err = io.Copy(tarWriter, file) - if err != nil { - return errors.New(fmt.Sprintf("Could not copy the file '%s' data to the tarball, got error '%s'", filePath, err.Error())) - } - - return nil -} - /* This is a manually run test that will, with the default values except the admin password, confirm the docker-compose ziti network is running as expected. The values can be edited to confirm other ziti networks but will require an http @@ -127,10 +59,10 @@ func TestSimpleWebService(t *testing.T) { } ctrlAddress := "https://" + advAddy + ":" + advPort - bindHostAddress := os.Getenv("ZITI_QUICKSTART_TEST_ADDRESS") - if bindHostAddress == "" { - bindHostAddress = ctrlAddress - } + //bindHostAddress := os.Getenv("ZITI_QUICKSTART_TEST_ADDRESS") + //if bindHostAddress == "" { + // bindHostAddress = ctrlAddress + //} hostingRouterName := erName dialAddress := "simple.web.smoke.test" dialPort := 80 @@ -367,41 +299,6 @@ func getServiceByName(client *rest_management_api_client.ZitiEdgeManagement, nam return resp.GetPayload().Data[0] } -func getEdgeRouterByName(client *rest_management_api_client.ZitiEdgeManagement, name string) rest_model.EdgeRouterDetail { - filterValues := "name=\"" + name + "\"" - listParams := &edge_router.ListEdgeRoutersParams{ - Filter: &filterValues, - } - listParams.SetTimeout(30 * time.Second) - resp, err := client.EdgeRouter.ListEdgeRouters(listParams, nil) - if err != nil { - fmt.Println(err) - log.Fatal("Could not get edge router filtered by name") - } - return *resp.GetPayload().Data[0] -} - -func createEdgeRouterPolicy(client *rest_management_api_client.ZitiEdgeManagement, name string, roles rest_model.Roles) service_edge_router_policy.CreateServiceEdgeRouterPolicyCreated { - defaultSemantic := rest_model.SemanticAllOf - serp := &rest_model.ServiceEdgeRouterPolicyCreate{ - EdgeRouterRoles: roles, - Name: &name, - Semantic: &defaultSemantic, - ServiceRoles: roles, - } - serpParams := &service_edge_router_policy.CreateServiceEdgeRouterPolicyParams{ - Policy: serp, - Context: context.Background(), - } - serpParams.SetTimeout(30 * time.Second) - resp, err := client.ServiceEdgeRouterPolicy.CreateServiceEdgeRouterPolicy(serpParams, nil) - if err != nil { - fmt.Println(err) - log.Fatal("Could not create service edge router policy") - } - return *resp -} - func createInterceptV1ServiceConfig(client *rest_management_api_client.ZitiEdgeManagement, name string, protocols []string, addresses []string, portRangeLow int, portRangeHigh int) rest_model.CreateLocation { configTypeID := *getConfigTypeByName(client, "intercept.v1").ID interceptData := map[string]interface{}{ @@ -531,30 +428,6 @@ func waitForTerminatorCountByRouterName(client *rest_management_api_client.ZitiE return false } -func deleteEdgeRouterPolicyByID(client *rest_management_api_client.ZitiEdgeManagement, id string) *edge_router_policy.DeleteEdgeRouterPolicyOK { - deleteParams := &edge_router_policy.DeleteEdgeRouterPolicyParams{ - ID: id, - } - deleteParams.SetTimeout(30 * time.Second) - resp, err := client.EdgeRouterPolicy.DeleteEdgeRouterPolicy(deleteParams, nil) - if err != nil { - fmt.Println(err) - } - return resp -} - -func deleteServiceEdgeRouterPolicyByID(client *rest_management_api_client.ZitiEdgeManagement, id string) *service_edge_router_policy.DeleteServiceEdgeRouterPolicyOK { - deleteParams := &service_edge_router_policy.DeleteServiceEdgeRouterPolicyParams{ - ID: id, - } - deleteParams.SetTimeout(30 * time.Second) - resp, err := client.ServiceEdgeRouterPolicy.DeleteServiceEdgeRouterPolicy(deleteParams, nil) - if err != nil { - fmt.Println(err) - } - return resp -} - func deleteServiceConfigByID(client *rest_management_api_client.ZitiEdgeManagement, id string) *api_client_config.DeleteConfigOK { deleteParams := &api_client_config.DeleteConfigParams{ ID: id, diff --git a/ziti-fabric-test/subcmd/client/http.go b/ziti-fabric-test/subcmd/client/http.go index c40961a21..99e4fa975 100644 --- a/ziti-fabric-test/subcmd/client/http.go +++ b/ziti-fabric-test/subcmd/client/http.go @@ -22,12 +22,12 @@ import ( "fmt" "github.com/michaelquigley/pfxlog" "github.com/openziti/fabric/router/xgress_transport" - "github.com/openziti/identity/dotziti" "github.com/openziti/identity" + "github.com/openziti/identity/dotziti" "github.com/openziti/transport/v2" "github.com/openziti/ziti/ziti-fabric-test/subcmd" "github.com/spf13/cobra" - "io/ioutil" + "io" "net" "net/http" ) @@ -83,7 +83,7 @@ func doHttp(cmd *cobra.Command, args []string) { request.Host = httpCmdHost } if response, err := c.Do(request); err == nil { - body, err := ioutil.ReadAll(response.Body) + body, err := io.ReadAll(response.Body) if err != nil { panic(err) } diff --git a/ziti-fabric-test/subcmd/loop2/protocol.go b/ziti-fabric-test/subcmd/loop2/protocol.go index 25014ad0d..dfb419116 100644 --- a/ziti-fabric-test/subcmd/loop2/protocol.go +++ b/ziti-fabric-test/subcmd/loop2/protocol.go @@ -17,16 +17,16 @@ package loop2 import ( - "github.com/openziti/ziti/ziti-fabric-test/subcmd/loop2/pb" - "github.com/openziti/foundation/v2/info" "bytes" "crypto/sha512" "encoding/binary" "encoding/hex" "fmt" - "google.golang.org/protobuf/proto" "github.com/michaelquigley/pfxlog" + "github.com/openziti/foundation/v2/info" + "github.com/openziti/ziti/ziti-fabric-test/subcmd/loop2/pb" "github.com/pkg/errors" + "google.golang.org/protobuf/proto" "io" "math/rand" "time" @@ -89,29 +89,27 @@ func (p *protocol) txer(done chan bool) { defer log.Debug("complete") for p.txCount < p.test.TxRequests { - select { - case block := <-p.txGenerator.blocks: - if block != nil { - if err := p.txBlock(block); err == nil { - p.txCount++ + block := <-p.txGenerator.blocks + if block != nil { + if err := p.txBlock(block); 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)) } - - } else { - log.Errorf("error sending block (%s)", err) - p.errors <- err - return + time.Sleep(time.Duration(int(p.test.TxPacing)+jitter) * time.Millisecond) } + } else { - log.Errorf("tx blocks chan closed") + log.Errorf("error sending block (%s)", err) + p.errors <- err return } + } else { + log.Errorf("tx blocks chan closed") + return } } diff --git a/ziti-fabric-test/subcmd/loop2/scenario.go b/ziti-fabric-test/subcmd/loop2/scenario.go index ff9d4ab09..8586cd77f 100644 --- a/ziti-fabric-test/subcmd/loop2/scenario.go +++ b/ziti-fabric-test/subcmd/loop2/scenario.go @@ -18,7 +18,7 @@ package loop2 import ( "gopkg.in/yaml.v2" - "io/ioutil" + "os" ) type Scenario struct { @@ -43,7 +43,7 @@ type Test struct { } func LoadScenario(path string) (*Scenario, error) { - data, err := ioutil.ReadFile(path) + data, err := os.ReadFile(path) if err != nil { return nil, err } diff --git a/ziti-fabric-test/subcmd/loop3/dialer.go b/ziti-fabric-test/subcmd/loop3/dialer.go index ef47515c9..be2f51a74 100644 --- a/ziti-fabric-test/subcmd/loop3/dialer.go +++ b/ziti-fabric-test/subcmd/loop3/dialer.go @@ -202,7 +202,7 @@ func (cmd *dialerCmd) connect() net.Conn { } } - ConnectionTime.Update(time.Now().Sub(start)) + ConnectionTime.Update(time.Since(start)) return conn } diff --git a/ziti-fabric-test/subcmd/loop3/messages.go b/ziti-fabric-test/subcmd/loop3/messages.go index 724823abc..336792843 100644 --- a/ziti-fabric-test/subcmd/loop3/messages.go +++ b/ziti-fabric-test/subcmd/loop3/messages.go @@ -89,8 +89,8 @@ func (r *Result) Rx(p *protocol) error { const ( BlockTypePlain byte = 1 - BlockTypeLatencyRequest = 2 - BlockTypeLatencyResponse = 3 + BlockTypeLatencyRequest byte = 2 + BlockTypeLatencyResponse byte = 3 ) type Block interface { @@ -233,7 +233,7 @@ func (block *RandHashedBlock) Rx(p *protocol) error { BytesRxRate.Mark(int64(8 + length)) if block.Type == BlockTypeLatencyResponse { - elapsed := time.Now().Sub(block.Timestamp) + elapsed := time.Since(block.Timestamp) MsgLatency.Update(elapsed) } diff --git a/ziti-fabric-test/subcmd/loop3/messages_test.go b/ziti-fabric-test/subcmd/loop3/messages_test.go index f7603ffc6..379fcd0d5 100644 --- a/ziti-fabric-test/subcmd/loop3/messages_test.go +++ b/ziti-fabric-test/subcmd/loop3/messages_test.go @@ -2,11 +2,11 @@ package loop3 import ( "bytes" + "crypto/rand" "crypto/sha512" "github.com/google/go-cmp/cmp" loop3_pb "github.com/openziti/ziti/ziti-fabric-test/subcmd/loop3/pb" "github.com/stretchr/testify/require" - "math/rand" "reflect" "testing" ) @@ -22,7 +22,8 @@ func (t *testPeer) Close() error { func Test_MessageSerDeser(t *testing.T) { req := require.New(t) data := make([]byte, 4192) - rand.Read(data) + _, err := rand.Read(data) + req.NoError(err) hash := sha512.Sum512(data) @@ -50,7 +51,9 @@ func Test_MessageSerDeser(t *testing.T) { req.True(reflect.DeepEqual(block, readBlock), cmp.Diff(block, readBlock)) data = make([]byte, 4192) - rand.Read(data) + _, err = rand.Read(data) + req.NoError(err) + hash = sha512.Sum512(data) block = &RandHashedBlock{ diff --git a/ziti-fabric-test/subcmd/loop3/protocol.go b/ziti-fabric-test/subcmd/loop3/protocol.go index 3e625db08..3eb7da4bc 100644 --- a/ziti-fabric-test/subcmd/loop3/protocol.go +++ b/ziti-fabric-test/subcmd/loop3/protocol.go @@ -20,11 +20,11 @@ import ( "bytes" "encoding/binary" "fmt" - "google.golang.org/protobuf/proto" "github.com/michaelquigley/pfxlog" "github.com/openziti/foundation/v2/info" "github.com/openziti/ziti/ziti-fabric-test/subcmd/loop3/pb" "github.com/pkg/errors" + "google.golang.org/protobuf/proto" "io" "math/rand" "sync/atomic" @@ -144,36 +144,34 @@ func (p *protocol) txer(done chan bool) { time.Sleep(p.txPauseFor) lastPause = time.Now() } - select { - case block := <-p.blocks: - if block != nil { - if p.txPacing > 0 { - jitter := time.Duration(0) - if p.txMaxJitter > 0 { - jitter = time.Duration(rand.Intn(int(p.txMaxJitter))) - } - - nextSend := lastSend.Add(p.txPacing + jitter) - if nextSend.After(now) { - time.Sleep(nextSend.Sub(now)) - lastSend = nextSend - } else { - lastSend = now - } + block := <-p.blocks + if block != nil { + if p.txPacing > 0 { + jitter := time.Duration(0) + if p.txMaxJitter > 0 { + jitter = time.Duration(rand.Intn(int(p.txMaxJitter))) } - block.PrepForSend(p) - if err := block.Tx(p); err == nil { - atomic.AddInt32(&p.txCount, 1) + nextSend := lastSend.Add(p.txPacing + jitter) + if nextSend.After(now) { + time.Sleep(nextSend.Sub(now)) + lastSend = nextSend } else { - log.Errorf("error sending block (%s)", err) - p.errors <- err - return + lastSend = now } + } + + block.PrepForSend(p) + if err := block.Tx(p); err == nil { + atomic.AddInt32(&p.txCount, 1) } else { - log.Errorf("tx blocks chan closed") + log.Errorf("error sending block (%s)", err) + p.errors <- err return } + } else { + log.Errorf("tx blocks chan closed") + return } } diff --git a/ziti-fabric-test/subcmd/loop3/scenario.go b/ziti-fabric-test/subcmd/loop3/scenario.go index 797c4c61f..1995e20e5 100644 --- a/ziti-fabric-test/subcmd/loop3/scenario.go +++ b/ziti-fabric-test/subcmd/loop3/scenario.go @@ -19,7 +19,7 @@ package loop3 import ( loop3_pb "github.com/openziti/ziti/ziti-fabric-test/subcmd/loop3/pb" "gopkg.in/yaml.v2" - "io/ioutil" + "os" "time" ) @@ -108,7 +108,7 @@ type Metrics struct { } func LoadScenario(path string) (*Scenario, error) { - data, err := ioutil.ReadFile(path) + data, err := os.ReadFile(path) if err != nil { return nil, err } diff --git a/ziti/cmd/agentcli/agent_cluster_list.go b/ziti/cmd/agentcli/agent_cluster_list.go index ca5423598..f186420e1 100644 --- a/ziti/cmd/agentcli/agent_cluster_list.go +++ b/ziti/cmd/agentcli/agent_cluster_list.go @@ -18,8 +18,8 @@ package agentcli import ( "fmt" + "google.golang.org/protobuf/proto" - "github.com/golang/protobuf/proto" "github.com/jedib0t/go-pretty/v6/table" "github.com/openziti/channel/v2" "github.com/openziti/fabric/pb/mgmt_pb" diff --git a/ziti/cmd/agentcli/agent_ps.go b/ziti/cmd/agentcli/agent_ps.go index 71587e33b..61ded1ce4 100644 --- a/ziti/cmd/agentcli/agent_ps.go +++ b/ziti/cmd/agentcli/agent_ps.go @@ -105,7 +105,9 @@ func (self *AgentPsAction) Run() error { fmt.Fprint(buf, p.Path) fmt.Fprintln(buf) - buf.WriteTo(os.Stdout) + if _, err := buf.WriteTo(os.Stdout); err != nil { + return err + } } return nil @@ -169,6 +171,7 @@ func FindAll() []P { path, version, agent, ok, err := isGo(pr) if err != nil { // TODO(jbd): Return a list of errors. + return } if !ok { return diff --git a/ziti/cmd/cmd.go b/ziti/cmd/cmd.go index 9169909aa..58e8a752b 100644 --- a/ziti/cmd/cmd.go +++ b/ziti/cmd/cmd.go @@ -76,7 +76,6 @@ func exitWithError(err error) { // Execute is ... func Execute() { - goflag.CommandLine.Parse([]string{}) if err := rootCommand.cobraCommand.Execute(); err != nil { exitWithError(err) } diff --git a/ziti/cmd/color/color.go b/ziti/cmd/color/color.go deleted file mode 100644 index ff8a79f41..000000000 --- a/ziti/cmd/color/color.go +++ /dev/null @@ -1,99 +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 color - -import ( - "github.com/fatih/color" - "github.com/openziti/ziti/ziti/util" - "sort" -) - -var colorMap = map[string]color.Attribute{ - // formatting - "bold": color.Bold, - "faint": color.Faint, - "italic": color.Italic, - "underline": color.Underline, - "blinkslow": color.BlinkSlow, - "blinkrapid": color.BlinkRapid, - "reversevideo": color.ReverseVideo, - "concealed": color.Concealed, - "crossedout": color.CrossedOut, - - // Foreground text colors - "black": color.FgBlack, - "red": color.FgRed, - "green": color.FgGreen, - "yellow": color.FgYellow, - "blue": color.FgBlue, - "magenta": color.FgMagenta, - "cyan": color.FgCyan, - "white": color.FgWhite, - - // Foreground Hi-Intensity text colors - "hiblack": color.FgHiBlack, - "hired": color.FgHiRed, - "higreen": color.FgHiGreen, - "hiyellow": color.FgHiYellow, - "hiblue": color.FgHiBlue, - "himagenta": color.FgHiMagenta, - "hicyan": color.FgHiCyan, - "hiwhite": color.FgHiWhite, - - // Background text colors - "bgblack": color.BgBlack, - "bgred": color.BgRed, - "bggreen": color.BgGreen, - "bgyellow": color.BgYellow, - "BgBlue": color.BgBlue, - "bgmagenta": color.BgMagenta, - "bgcyan": color.BgCyan, - "bgwhite": color.BgWhite, - - // Background Hi-Intensity text colors - "bghiblack": color.BgHiBlack, - "bghired": color.BgHiRed, - "bghigreen": color.BgHiGreen, - "bghiyellow": color.BgHiYellow, - "bghiblue": color.BgHiBlue, - "bghimagenta": color.BgHiMagenta, - "bghicyan": color.BgHiCyan, - "bghiwhite": color.BgHiWhite, -} - -// GetColor returns the color for the list of colour names and option name -func GetColor(optionName string, colorNames []string) (*color.Color, error) { - attributes := []color.Attribute{} - for _, colorName := range colorNames { - a := colorMap[colorName] - if a == color.Attribute(0) { - return nil, util.InvalidOption(optionName, colorName, ColorNameValues()) - } - attributes = append(attributes, a) - } - return color.New(attributes...), nil -} - -// ColorNameValues returns all the color names sorted -func ColorNameValues() []string { - answer := []string{} - for k, _ := range colorMap { - answer = append(answer, k) - } - sort.Strings(answer) - return answer -} diff --git a/ziti/cmd/common.go b/ziti/cmd/common.go index 824cb5df8..2deb44796 100644 --- a/ziti/cmd/common.go +++ b/ziti/cmd/common.go @@ -42,3 +42,9 @@ func (options *CommonOptions) AddCommonFlags(cmd *cobra.Command) { cmd.Flags().IntVarP(&options.Timeout, "timeout", "t", 5, "Timeout for REST operations (specified in seconds)") options.Cmd = cmd } + +func (options *CommonOptions) panicOnErr(err error) { + if err != nil { + panic(err) + } +} diff --git a/ziti/cmd/common_commands.go b/ziti/cmd/common_commands.go deleted file mode 100644 index e0be196a1..000000000 --- a/ziti/cmd/common_commands.go +++ /dev/null @@ -1,161 +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 ( - "fmt" - "github.com/openziti/ziti/ziti/internal/log" - "github.com/openziti/ziti/ziti/util" - "io/ioutil" - "os" - "os/exec" - "strings" -) - -var cliAgentEnabled bool - -func (o *CommonOptions) startCommandFromDir(dir, name string, args ...string) error { - if cliAgentEnabled { - args = append(args, "--cliagent") - } - e := exec.Command(name, args...) - if dir != "" { - e.Dir = dir - } - e.Stdout = o.Out - e.Stderr = o.Err - os.Setenv("PATH", util.PathWithBinary()) - err := e.Start() - if err != nil { - log.Errorf("Error: Command failed %s/%s %s\n", dir, name, strings.Join(args, " ")) - } - - return err -} - -func (o *CommonOptions) runCommandFromDir(dir, name string, args ...string) error { - e := exec.Command(name, args...) - if dir != "" { - e.Dir = dir - } - e.Stdout = o.Out - e.Stderr = o.Err - os.Setenv("PATH", util.PathWithBinary()) - err := e.Run() - if err != nil { - log.Errorf("Error: Command failed %s/%s %s\n", dir, name, strings.Join(args, " ")) - } - return err -} - -func (o *CommonOptions) runCommand(name string, args ...string) error { - e := exec.Command(name, args...) - if o.Verbose { - e.Stdout = o.Out - e.Stderr = o.Err - } - os.Setenv("PATH", util.PathWithBinary()) - err := e.Run() - if err != nil { - log.Errorf("Error: Command failed %s %s\n", name, strings.Join(args, " ")) - } - return err -} - -func (o *CommonOptions) runCommandVerbose(name string, args ...string) error { - e := exec.Command(name, args...) - e.Stdout = o.Out - e.Stderr = o.Err - os.Setenv("PATH", util.PathWithBinary()) - err := e.Run() - if err != nil { - log.Errorf("Error: Command failed %s %s\n", name, strings.Join(args, " ")) - } - return err -} - -func (o *CommonOptions) runCommandVerboseAt(dir string, name string, args ...string) error { - e := exec.Command(name, args...) - if dir != "" { - e.Dir = dir - } - e.Stdout = o.Out - e.Stderr = o.Err - os.Setenv("PATH", util.PathWithBinary()) - err := e.Run() - if err != nil { - log.Errorf("Error: Command failed %s %s\n", name, strings.Join(args, " ")) - } - return err -} - -func (o *CommonOptions) runCommandQuietly(name string, args ...string) error { - e := exec.Command(name, args...) - e.Stdout = ioutil.Discard - e.Stderr = ioutil.Discard - os.Setenv("PATH", util.PathWithBinary()) - return e.Run() -} - -func (o *CommonOptions) runCommandInteractive(interactive bool, name string, args ...string) error { - e := exec.Command(name, args...) - e.Stdout = o.Out - e.Stderr = o.Err - if interactive { - e.Stdin = os.Stdin - } - os.Setenv("PATH", util.PathWithBinary()) - err := e.Run() - if err != nil { - log.Errorf("Error: Command failed %s %s\n", name, strings.Join(args, " ")) - } - return err -} - -func (o *CommonOptions) runCommandInteractiveInDir(interactive bool, dir string, name string, args ...string) error { - e := exec.Command(name, args...) - e.Stdout = o.Out - e.Stderr = o.Err - if interactive { - e.Stdin = os.Stdin - } - if dir != "" { - e.Dir = dir - } - os.Setenv("PATH", util.PathWithBinary()) - err := e.Run() - if err != nil { - log.Errorf("Error: Command failed %s %s\n", name, strings.Join(args, " ")) - } - return err -} - -// getCommandOutput evaluates the given command and returns the trimmed output -func (o *CommonOptions) getCommandOutput(dir string, name string, args ...string) (string, error) { - os.Setenv("PATH", util.PathWithBinary()) - e := exec.Command(name, args...) - if dir != "" { - e.Dir = dir - } - data, err := e.CombinedOutput() - text := string(data) - text = strings.TrimSpace(text) - if err != nil { - return "", fmt.Errorf("command failed '%s %s': %s %s", name, strings.Join(args, " "), text, err) - } - return text, err -} diff --git a/ziti/cmd/common_init.go b/ziti/cmd/common_init.go deleted file mode 100644 index b1f271d13..000000000 --- a/ziti/cmd/common_init.go +++ /dev/null @@ -1,167 +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 ( - "fmt" - c "github.com/openziti/ziti/ziti/constants" - "github.com/openziti/ziti/ziti/util" - "github.com/spf13/viper" - "gopkg.in/AlecAivazis/survey.v1" - "os" - "path/filepath" -) - -var ZITI_COMPONENTS = []string{ - c.ZITI, - c.ZITI_CONTROLLER, - c.ZITI_PROX_C, - c.ZITI_ROUTER, - c.ZITI_TUNNEL, - c.ZITI_EDGE_TUNNEL, -} - -func (o *CommonOptions) GetZitiComponent(p string) (string, error) { - if p == "" { - prompt := &survey.Select{ - Message: "Ziti Component", - Options: ZITI_COMPONENTS, - Default: c.ZITI, - Help: "Choose the Ziti component for which you want to do config initialization", - } - - survey.AskOne(prompt, &p, nil) - } - return p, nil -} - -func (o *CommonOptions) createInitialZitiConfig() error { - - zitiConfigDir, err := util.ZitiAppConfigDir(c.ZITI) - if err != nil { - return err - } - - _, err = util.EnvironmentsDir() - if err != nil { - return err - } - - fileName := filepath.Join(zitiConfigDir, c.CONFIGFILENAME) + ".json" - - _, err = os.Stat(fileName) - if err == nil { - return fmt.Errorf("config file (%s) already exists", fileName) - } - - cfgfile, err := os.OpenFile(fileName, os.O_RDWR|os.O_CREATE, 0644) - if err != nil { - return err - } - if err := cfgfile.Close(); err != nil { - return err - } - - viper.SetConfigType("json") - viper.SetConfigName(c.CONFIGFILENAME) - viper.AddConfigPath(zitiConfigDir) - - // Set some default values - viper.SetDefault("bin", util.HomeDir()+"/Repos/nf/ziti/bin") - - // Capture AWS creds - awsAccessKey, err := util.PickPassword("AWS_ACCESS_KEY_ID:") - if err != nil { - return err - } - viper.SetDefault("AWS_ACCESS_KEY_ID", awsAccessKey) - awsSecretAccessKey, err := util.PickPassword("AWS_SECRET_ACCESS_KEY:") - if err != nil { - return err - } - viper.SetDefault("AWS_SECRET_ACCESS_KEY", awsSecretAccessKey) - - err = viper.WriteConfig() - if err != nil { - return err - } - - return nil -} - -func (o *CommonOptions) createInitialControllerConfig() error { - - configDir, err := util.ConfigDir() - if err != nil { - return err - } - - controllerConfigDir, err := util.ZitiAppConfigDir(c.ZITI_CONTROLLER) - if err != nil { - return err - } - - fileName := filepath.Join(controllerConfigDir, c.CONFIGFILENAME) + ".json" - - _, err = os.Stat(fileName) - if err == nil { - return fmt.Errorf("config file (%s) already exists", fileName) - } - - cfgfile, err := os.OpenFile(fileName, os.O_RDWR|os.O_CREATE, 0644) - if err != nil { - return err - } - if err := cfgfile.Close(); err != nil { - return err - } - - viper.SetConfigType("json") - viper.SetConfigName(c.CONFIGFILENAME) - viper.AddConfigPath(controllerConfigDir) - - /* - { - "identity": { - "cert": "etc/ca/intermediate/certs/ctrl-client.cert.pem", - "server_cert": "etc/ca/intermediate/certs/ctrl-server.cert.pem", - "key": "etc/ca/intermediate/private/ctrl.key.pem", - "ca": "etc/ca/intermediate/certs/ca-chain.cert.pem" - }, - - "ctrlListener": "quic:0.0.0.0:6262", - "mgmtListener": "tls:0.0.0.0:10000", - "dbPath": "bin/ctrl.db" - } - */ - - // Set some default values - viper.SetDefault("identity.cert", configDir+"/etc/ca/intermediate/certs/ctrl-client.cert.pem") - viper.SetDefault("identity.server_cert", configDir+"/etc/ca/intermediate/certs/ctrl-server.cert.pem") - viper.SetDefault("identity.key", configDir+"/etc/ca/intermediate/private/ctrl.key.pem") - viper.SetDefault("identity.ca", configDir+"/etc/ca/intermediate/certs/ca-chain.cert.pem") - viper.SetDefault("ctrlListener", "quic:0.0.0.0:6262") - viper.SetDefault("mgmtListener", "tls:0.0.0.0:10000") - viper.SetDefault("dbPath", "ctrl.db") - - err = viper.WriteConfig() - if err != nil { - return err - } - - return nil -} diff --git a/ziti/cmd/create_config_environment.go b/ziti/cmd/create_config_environment.go index d9a0c4fdb..51ae64091 100644 --- a/ziti/cmd/create_config_environment.go +++ b/ziti/cmd/create_config_environment.go @@ -69,7 +69,6 @@ var environmentOptions *CreateConfigEnvironmentOptions type CreateConfigEnvironmentOptions struct { CreateConfigOptions EnvVariableTemplateData - output string } // NewCmdCreateConfigEnvironment creates a command object for the "environment" command diff --git a/ziti/cmd/create_config_router_test.go b/ziti/cmd/create_config_router_test.go index edcdc42b1..01d454d50 100644 --- a/ziti/cmd/create_config_router_test.go +++ b/ziti/cmd/create_config_router_test.go @@ -82,17 +82,17 @@ type Transport struct { } type Ws struct { - writeTimeout int `yaml:"writeTimeout"` - readTimeout int `yaml:"readTimeout"` - idleTimeout int `yaml:"idleTimeout"` - pongTimeout int `yaml:"pongTimeout"` - pingInterval int `yaml:"pingInterval"` - handshakeTimeout int `yaml:"handshakeTimeout"` - readBufferSize int `yaml:"readBufferSize"` - writeBufferSize int `yaml:"writeBufferSize"` - enableCompression string `yaml:"enableCompression"` - server_cert string `yaml:"server_Cert"` - key string `yaml:"key"` + WriteTimeout int `yaml:"writeTimeout"` + ReadTimeout int `yaml:"readTimeout"` + IdleTimeout int `yaml:"idleTimeout"` + PongTimeout int `yaml:"pongTimeout"` + PingInterval int `yaml:"pingInterval"` + HandshakeTimeout int `yaml:"handshakeTimeout"` + ReadBufferSize int `yaml:"readBufferSize"` + WriteBufferSize int `yaml:"writeBufferSize"` + EnableCompression string `yaml:"enableCompression"` + Server_cert string `yaml:"server_Cert"` + Key string `yaml:"key"` } type Forwarder struct { diff --git a/ziti/cmd/database/du.go b/ziti/cmd/database/du.go index f4f9ff4bc..76c1e2625 100644 --- a/ziti/cmd/database/du.go +++ b/ziti/cmd/database/du.go @@ -21,7 +21,6 @@ import ( "github.com/openziti/storage/boltz" "github.com/spf13/cobra" "go.etcd.io/bbolt" - "strings" ) type DiskUsageAction struct { @@ -114,12 +113,6 @@ func (self *sizeVisitor) VisitKeyValue(path string, key, value []byte) bool { return true } -func (self *sizeVisitor) getParent(path string) *sizeNode { - parentPath := self.getParentPath(path) - fmt.Printf("%v has parent %v\n", path, parentPath) - return self.getNode(parentPath) -} - func (self *sizeVisitor) getNode(path string) *sizeNode { if path == "" { return self.getNode("/") @@ -133,15 +126,3 @@ func (self *sizeVisitor) getNode(path string) *sizeNode { } return node } - -func (self *sizeVisitor) getParentPath(path string) string { - idx := strings.LastIndexByte(path, '/') - if idx < 0 { - return path - } - parent := path[0:idx] - if parent == "" { - return "/" - } - return parent -} diff --git a/ziti/cmd/demo/echo_server.go b/ziti/cmd/demo/echo_server.go index 80878ba4e..55f652891 100644 --- a/ziti/cmd/demo/echo_server.go +++ b/ziti/cmd/demo/echo_server.go @@ -17,7 +17,6 @@ package demo import ( - "bufio" "fmt" "github.com/michaelquigley/pfxlog" "github.com/openziti/agent" @@ -343,13 +342,3 @@ func (self *echoServer) SendOpResult(request *channel.Message, ch channel.Channe log.WithError(err).Error("failed to send result") } } - -func (self *echoServer) handleResult(err error, bconn *bufio.ReadWriter) error { - if err != nil { - return err - } - if _, err = bconn.WriteString("OK"); err != nil { - return err - } - return bconn.Flush() -} diff --git a/ziti/cmd/edge/create_config.go b/ziti/cmd/edge/create_config.go index 66f97f205..8474046e0 100644 --- a/ziti/cmd/edge/create_config.go +++ b/ziti/cmd/edge/create_config.go @@ -21,10 +21,9 @@ import ( "fmt" "github.com/openziti/ziti/ziti/cmd/api" cmdhelper "github.com/openziti/ziti/ziti/cmd/helpers" - "io" - "io/ioutil" - "github.com/pkg/errors" + "io" + "os" "github.com/Jeffail/gabs" "github.com/spf13/cobra" @@ -76,7 +75,7 @@ func runCreateConfig(o *createConfigOptions) error { return errors.New("config json specified both in file and on command line. please pick one") } var err error - if jsonBytes, err = ioutil.ReadFile(o.jsonFile); err != nil { + if jsonBytes, err = os.ReadFile(o.jsonFile); err != nil { return fmt.Errorf("failed to read config json file %v: %w", o.jsonFile, err) } } diff --git a/ziti/cmd/edge/create_config_type.go b/ziti/cmd/edge/create_config_type.go index d0338cf86..f3bb48666 100644 --- a/ziti/cmd/edge/create_config_type.go +++ b/ziti/cmd/edge/create_config_type.go @@ -21,10 +21,9 @@ import ( "fmt" "github.com/openziti/ziti/ziti/cmd/api" cmdhelper "github.com/openziti/ziti/ziti/cmd/helpers" - "io" - "io/ioutil" - "github.com/pkg/errors" + "io" + "os" "github.com/Jeffail/gabs" "github.com/spf13/cobra" @@ -78,7 +77,7 @@ func runCreateConfigType(o *createConfigTypeOptions) error { return errors.New("schema specified both in file and on command line. please pick one") } var err error - if schemaBytes, err = ioutil.ReadFile(o.schemaFile); err != nil { + if schemaBytes, err = os.ReadFile(o.schemaFile); err != nil { return fmt.Errorf("failed to read schema file %v: %w", o.schemaFile, err) } } diff --git a/ziti/cmd/edge/create_enrollment.go b/ziti/cmd/edge/create_enrollment.go index 41a31c0d4..4c9dd3952 100644 --- a/ziti/cmd/edge/create_enrollment.go +++ b/ziti/cmd/edge/create_enrollment.go @@ -45,7 +45,6 @@ func newCreateEnrollmentCmd(out io.Writer, errOut io.Writer) *cobra.Command { type createEnrollmentOptions struct { api.Options - name string duration int64 } diff --git a/ziti/cmd/edge/create_posture_check.go b/ziti/cmd/edge/create_posture_check.go index 407ff7ca3..c1599f012 100644 --- a/ziti/cmd/edge/create_posture_check.go +++ b/ziti/cmd/edge/create_posture_check.go @@ -48,7 +48,6 @@ func newCreatePostureCheckCmd(out io.Writer, errOut io.Writer) *cobra.Command { type createPostureCheckOptions struct { api.EntityOptions - name string roleAttributes []string } diff --git a/ziti/cmd/edge/create_service.go b/ziti/cmd/edge/create_service.go index 700d3531b..df3be3bcc 100644 --- a/ziti/cmd/edge/create_service.go +++ b/ziti/cmd/edge/create_service.go @@ -29,7 +29,6 @@ type createServiceOptions struct { terminatorStrategy string roleAttributes []string configs []string - requireEncryption bool encryption encryptionVar } @@ -58,7 +57,9 @@ func newCreateServiceCmd(out io.Writer, errOut io.Writer) *cobra.Command { cmd.Flags().StringSliceVarP(&options.roleAttributes, "role-attributes", "a", nil, "Role attributes of the new service") cmd.Flags().StringSliceVarP(&options.configs, "configs", "c", nil, "Configuration id or names to be associated with the new service") cmd.Flags().StringVar(&options.terminatorStrategy, "terminator-strategy", "", "Specifies the terminator strategy for the service") - options.encryption.Set("ON") + if err := options.encryption.Set("ON"); err != nil { + panic(err) + } cmd.Flags().VarP(&options.encryption, "encryption", "e", "Controls end-to-end encryption for the service") options.AddCommonFlags(cmd) diff --git a/ziti/cmd/edge/delete.go b/ziti/cmd/edge/delete.go index 0c8b07051..526a2f5e3 100644 --- a/ziti/cmd/edge/delete.go +++ b/ziti/cmd/edge/delete.go @@ -173,7 +173,3 @@ func getPlural(entityType string) string { } return entityType + "s" } - -func deleteEntityOfType(entityType string, id string, options *api.Options) error { - return util.ControllerDelete("edge", entityType, id, "", options.Out, options.OutputJSONRequest, options.OutputJSONResponse, options.Timeout, options.Verbose) -} diff --git a/ziti/cmd/edge/encryption_var.go b/ziti/cmd/edge/encryption_var.go index 570b28193..2c30bb443 100644 --- a/ziti/cmd/edge/encryption_var.go +++ b/ziti/cmd/edge/encryption_var.go @@ -31,7 +31,7 @@ func (f *encryptionVar) String() string { func (f *encryptionVar) Set(value string) error { value = strings.ToUpper(value) if value != "ON" && value != "OFF" && value != "TRUE" && value != "FALSE" { - return errors.New("Invalid option -- must specify either 'ON' or 'OFF'") + return errors.New("invalid option -- must specify either 'ON' or 'OFF'") } *f = encryptionVar(value) return nil diff --git a/ziti/cmd/edge/list.go b/ziti/cmd/edge/list.go index f5a7a28b8..d411cf955 100644 --- a/ziti/cmd/edge/list.go +++ b/ziti/cmd/edge/list.go @@ -691,30 +691,6 @@ func runListEnrollments(o *api.Options) error { return outputEnrollments(o, children, pagingInfo) } -func outputExtJwtSigners(o *api.Options, children []*gabs.Container, pagingInfo *api.Paging) error { - if o.OutputJSONResponse { - return nil - } - - t := table.NewWriter() - t.SetStyle(table.StyleRounded) - t.AppendHeader(table.Row{"ID", "Method", "Identity Id", "Identity Name", "Expires At", "Token", "JWT"}) - - for _, entity := range children { - id, _ := entity.Path("id").Data().(string) - method := entity.Path("method").Data().(string) - identityId := entity.Path("identityId").Data().(string) - identityName := entity.Path("identity.name").Data().(string) - expiresAt := entity.Path("expiresAt").Data().(string) - token := entity.Path("token").Data().(string) - jwt := "See json" - - t.AppendRow(table.Row{id, method, identityId, identityName, expiresAt, token, jwt}) - } - api.RenderTable(o, t, pagingInfo) - return nil -} - func runListTerminators(o *api.Options) error { children, pagingInfo, err := listEntitiesWithOptions("terminators", o) if err != nil { diff --git a/ziti/cmd/edge/update_config.go b/ziti/cmd/edge/update_config.go index f9d9f9a27..f8e68fa5d 100644 --- a/ziti/cmd/edge/update_config.go +++ b/ziti/cmd/edge/update_config.go @@ -21,10 +21,9 @@ import ( "fmt" "github.com/openziti/ziti/ziti/cmd/api" cmdhelper "github.com/openziti/ziti/ziti/cmd/helpers" - "io" - "io/ioutil" - "github.com/pkg/errors" + "io" + "os" "github.com/Jeffail/gabs" "github.com/spf13/cobra" @@ -93,7 +92,7 @@ func runUpdateConfig(o *updateConfigOptions) error { return errors.New("only one of --data and --json-file is allowed") } var err error - if jsonBytes, err = ioutil.ReadFile(o.jsonFile); err != nil { + if jsonBytes, err = os.ReadFile(o.jsonFile); err != nil { return fmt.Errorf("failed to read config json file %v: %w", o.jsonFile, err) } } diff --git a/ziti/cmd/edge/update_service.go b/ziti/cmd/edge/update_service.go index cde1885c1..57fac1030 100644 --- a/ziti/cmd/edge/update_service.go +++ b/ziti/cmd/edge/update_service.go @@ -62,7 +62,9 @@ func newUpdateServiceCmd(out io.Writer, errOut io.Writer) *cobra.Command { cmd.Flags().StringVar(&options.terminatorStrategy, "terminator-strategy", "", "Specifies the terminator strategy for the service") cmd.Flags().StringSliceVarP(&options.roleAttributes, "role-attributes", "a", nil, "Set role attributes of the service. Use --role-attributes '' to set an empty list") - options.encryption.Set("ON") + if err := options.encryption.Set("ON"); err != nil { + panic(err) + } cmd.Flags().VarP(&options.encryption, "encryption", "e", "Controls end-to-end encryption for the service") cmd.Flags().StringSliceVarP(&options.configs, "configs", "c", nil, "Configuration id or names to be associated with the new service") diff --git a/ziti/cmd/edge/verify.go b/ziti/cmd/edge/verify.go index 14c79fe6a..d0cb49814 100644 --- a/ziti/cmd/edge/verify.go +++ b/ziti/cmd/edge/verify.go @@ -17,9 +17,7 @@ package edge import ( - "github.com/openziti/ziti/ziti/cmd/api" cmdhelper "github.com/openziti/ziti/ziti/cmd/helpers" - "github.com/openziti/ziti/ziti/util" "io" "github.com/spf13/cobra" @@ -41,8 +39,3 @@ func newVerifyCmd(out io.Writer, errOut io.Writer) *cobra.Command { return cmd } - -// createEntityOfType create an entity of the given type on the Ziti Edge Controller -func verifyEntityOfType(entityType, body, id string, options *api.Options) error { - return util.EdgeControllerVerify(entityType, id, body, options.Out, options.OutputJSONResponse, options.Timeout, options.Verbose) -} diff --git a/ziti/cmd/edge/verify_ca.go b/ziti/cmd/edge/verify_ca.go index 2a6ea51aa..e18dcfe6b 100644 --- a/ziti/cmd/edge/verify_ca.go +++ b/ziti/cmd/edge/verify_ca.go @@ -35,8 +35,8 @@ import ( "github.com/spf13/cobra" "gopkg.in/resty.v1" "io" - "io/ioutil" "math/big" + "os" "time" ) @@ -85,7 +85,7 @@ func newVerifyCaCmd(out io.Writer, errOut io.Writer) *cobra.Command { if options.certPath != "" { var err error - options.certPemBytes, err = ioutil.ReadFile(options.certPath) + options.certPemBytes, err = os.ReadFile(options.certPath) if err != nil { return fmt.Errorf("could not read --cert file (%s): %v", options.certPath, err) @@ -93,13 +93,13 @@ func newVerifyCaCmd(out io.Writer, errOut io.Writer) *cobra.Command { options.isGenerateCert = false } else if options.caCertPath != "" && options.caKeyPath != "" { var err error - options.caKeyPemBytes, err = ioutil.ReadFile(options.caKeyPath) + options.caKeyPemBytes, err = os.ReadFile(options.caKeyPath) if err != nil { return fmt.Errorf("could not read --cakey file (%s): %v", options.caKeyPath, err) } - options.caCertPemBytes, err = ioutil.ReadFile(options.caCertPath) + options.caCertPemBytes, err = os.ReadFile(options.caCertPath) if err != nil { return fmt.Errorf("could not read --cacert file (%s): %v", options.caCertPath, err) @@ -165,7 +165,7 @@ func runValidateCa(options *verifyCaOptions) error { func generateCert(options *verifyCaOptions, token string) ([]byte, crypto.Signer, error) { - certBlocks := nfpem.PemToX509(string(options.caCertPemBytes)) + certBlocks := nfpem.PemStringToCertificates(string(options.caCertPemBytes)) if len(certBlocks) == 0 { return nil, nil, errors.New("could not parse cert file, 0 PEM blocks detected1") @@ -199,19 +199,17 @@ func generateCert(options *verifyCaOptions, token string) ([]byte, crypto.Signer } } - var signerInterface crypto.Signer + var caKey crypto.Signer if caPrivateKeyBlock.Type == "EC PRIVATE KEY" { - signerInterface, err = x509.ParseECPrivateKey(caPrivateKeyBlock.Bytes) + caKey, err = x509.ParseECPrivateKey(caPrivateKeyBlock.Bytes) } else { - signerInterface, err = x509.ParsePKCS1PrivateKey(caPrivateKeyBlock.Bytes) + caKey, err = x509.ParsePKCS1PrivateKey(caPrivateKeyBlock.Bytes) } if err != nil { return nil, nil, fmt.Errorf("could not parse key file (%s)", err) } - caKey := signerInterface.(crypto.Signer) - if caKey == nil { return nil, nil, fmt.Errorf("key was not of correct type, could not be used as signer") } diff --git a/ziti/cmd/fabric/inspect.go b/ziti/cmd/fabric/inspect.go index a22ca3199..3923b4c6a 100644 --- a/ziti/cmd/fabric/inspect.go +++ b/ziti/cmd/fabric/inspect.go @@ -127,7 +127,7 @@ func (self *InspectAction) inspect(appRegex string, requestValues ...string) err if idx > 0 { fmt.Println() } - fmt.Printf(color.New(color.FgGreen, color.Bold).Sprintf("%v.%v\n", appId, name)) + fmt.Print(color.New(color.FgGreen, color.Bold).Sprintf("%v.%v\n", appId, name)) out = os.Stdout } if err = self.prettyPrint(out, value.Value, 0); err != nil { diff --git a/ziti/cmd/fabric/stream_traces.go b/ziti/cmd/fabric/stream_traces.go index a9691f833..f6cc40134 100644 --- a/ziti/cmd/fabric/stream_traces.go +++ b/ziti/cmd/fabric/stream_traces.go @@ -192,13 +192,13 @@ func (self *streamTracesAction) DecodeTraceAndFormat(decode []byte) string { out += k out += "=[" v := meta[k] - switch v.(type) { + switch val := v.(type) { case string: - out += v.(string) + out += val case float64: - out += fmt.Sprintf("%0.0f", v.(float64)) + out += fmt.Sprintf("%0.0f", val) case bool: - out += fmt.Sprintf("%t", v.(bool)) + out += fmt.Sprintf("%t", val) default: out += fmt.Sprintf("<%s>", reflect.TypeOf(v)) } diff --git a/ziti/cmd/helpers/helpers.go b/ziti/cmd/helpers/helpers.go index e255e4956..9ebcf2557 100644 --- a/ziti/cmd/helpers/helpers.go +++ b/ziti/cmd/helpers/helpers.go @@ -19,38 +19,18 @@ package helpers import ( "fmt" "github.com/michaelquigley/pfxlog" + "github.com/pkg/errors" "net/url" "os" "strings" - - "github.com/spf13/cobra" ) const ( DefaultErrorExitCode = 1 - - DefaultWritePermissions = 0760 ) -type debugError interface { - DebugError() (msg string, args []interface{}) -} - var fatalErrHandler = fatal -// BehaviorOnFatal allows you to override the default behavior when a fatal -// error occurs, which is to call os.Exit(code). You can pass 'panic' as a function -// here if you prefer the panic() over os.Exit(1). -func BehaviorOnFatal(f func(string, int)) { - fatalErrHandler = f -} - -// DefaultBehaviorOnFatal allows you to undo any previous override. Useful in -// tests. -func DefaultBehaviorOnFatal() { - fatalErrHandler = fatal -} - // fatal prints the message (if provided) and then exits. func fatal(msg string, code int) { if len(msg) > 0 { @@ -76,11 +56,6 @@ func CheckErr(err error) { checkErr("", err, fatalErrHandler) } -// checkErrWithPrefix works like CheckErr, but adds a caller-defined prefix to non-nil errors -func checkErrWithPrefix(prefix string, err error) { - checkErr(prefix, err, fatalErrHandler) -} - // checkErr formats a given error as a string and calls the passed handleErr // func with that string and an kubectl exit code. func checkErr(prefix string, err error, handleErr func(string, int)) { @@ -166,14 +141,9 @@ func StandardErrorMessage(err error) (string, bool) { return "", false } -func UsageError(cmd *cobra.Command, format string, args ...interface{}) error { - msg := fmt.Sprintf(format, args...) - return fmt.Errorf("%s\nSee '%s -h' for help and examples.", msg, cmd.CommandPath()) -} - func JFrogAPIKey() string { if h := os.Getenv("JFROG_API_KEY"); h != "" { return h } - panic(fmt.Sprintf("ERROR: the JFROG_API_KEY env variable has not been set")) + panic(errors.New("ERROR: the JFROG_API_KEY env variable has not been set")) } diff --git a/ziti/cmd/install/common_install.go b/ziti/cmd/install/common_install.go index c004079ef..c67e91f3e 100644 --- a/ziti/cmd/install/common_install.go +++ b/ziti/cmd/install/common_install.go @@ -17,13 +17,11 @@ package install import ( - "fmt" "github.com/blang/semver" "github.com/openziti/ziti/common/getziti" c "github.com/openziti/ziti/ziti/constants" "github.com/openziti/ziti/ziti/internal/log" "github.com/openziti/ziti/ziti/util" - "gopkg.in/AlecAivazis/survey.v1" "gopkg.in/resty.v1" "os" "os/exec" @@ -32,50 +30,6 @@ import ( "strings" ) -// installRequirements installs any requirements needed to run the ziti CLI -func (o *InstallOptions) installRequirements(extraDependencies ...string) error { - var deps []string - - for _, dep := range extraDependencies { - deps = o.addRequiredBinary(dep, deps) - } - - return o.installMissingDependencies(deps) -} - -func (o *InstallOptions) addRequiredBinary(binName string, deps []string) []string { - d := binaryShouldBeInstalled(binName) - if d != "" && util.StringArrayIndex(deps, d) < 0 { - deps = append(deps, d) - } - return deps -} - -// appends the binary to the deps array if it cannot be found on the $PATH -func binaryShouldBeInstalled(d string) string { - _, err := exec.LookPath(d) - if err != nil { - // look for windows exec - if runtime.GOOS == "windows" { - d = d + ".exe" - _, err = exec.LookPath(d) - if err == nil { - return "" - } - } - binDir, err := util.BinaryLocation() - if err == nil { - exists, err := util.FileExists(filepath.Join(binDir, d)) - if err == nil && exists { - return "" - } - } - log.Infof("%s not found\n", d) - return d - } - return "" -} - func isBinaryInstalled(d string) bool { binDir, err := util.BinaryLocation() if err == nil { @@ -104,47 +58,6 @@ func (o *InstallOptions) deleteInstalledBinary(d string) bool { return false } -func (o *InstallOptions) installMissingDependencies(deps []string) error { - - if len(deps) == 0 { - return nil - } - - if o.BatchMode { - return fmt.Errorf("run without batch mode or manually install missing dependencies %v", deps) - } - install := []string{} - prompt := &survey.MultiSelect{ - Message: "Installing required dependencies, deselect to avoid auto installing:", - Options: deps, - Default: deps, - } - survey.AskOne(prompt, &install, nil) - - return o.doInstallMissingDependencies(install) -} - -func (o *InstallOptions) doInstallMissingDependencies(install []string) error { - - for _, i := range install { - var err error - switch i { - case "aws": - err = o.installAWSCli() - default: - return fmt.Errorf("unknown dependency to install %s", i) - } - if err != nil { - return fmt.Errorf("error installing %s: %v", i, err) - } - } - return nil -} - -func (o *InstallOptions) installAWSCli() error { - return fmt.Errorf("Ziti's ability to auto-install the AWS CLI is curently un-implemented; For now, you must manually install the AWS CLI") -} - func (o *InstallOptions) shouldInstallBinary(binDir string, name string) (fileName string, download bool, err error) { fileName = name download = false @@ -170,20 +83,6 @@ func (o *InstallOptions) shouldInstallBinary(binDir string, name string) (fileNa return } -func (o *InstallOptions) downloadFile(clientURL string, fullPath string) error { - log.Infof("Downloading %s to %s...\n", util.ColorInfo(clientURL), util.ColorInfo(fullPath)) - err := util.DownloadFile(fullPath, clientURL) - if err != nil { - return fmt.Errorf("Unable to download file %s from %s due to: %v", fullPath, clientURL, err) - } - log.Infof("Downloaded %s\n", util.ColorInfo(fullPath)) - return nil -} - -func (o *InstallOptions) getLatestZitiVersion(branch string) (semver.Version, error) { - return util.GetLatestVersionFromArtifactory(o.Verbose, o.Staging, branch, c.ZITI) -} - func (o *InstallOptions) getLatestZitiAppVersion(branch string, zitiApp string) (semver.Version, error) { return util.GetLatestVersionFromArtifactory(o.Verbose, o.Staging, branch, zitiApp) } diff --git a/ziti/cmd/install/install_terraform_provider_edge_controller.go b/ziti/cmd/install/install_terraform_provider_edge_controller.go index 56c7f0557..46e80b165 100644 --- a/ziti/cmd/install/install_terraform_provider_edge_controller.go +++ b/ziti/cmd/install/install_terraform_provider_edge_controller.go @@ -86,6 +86,9 @@ func (o *InstallTerraformProviderEdgeControllerOptions) Run() error { if o.Version != "" { newVersion, err = semver.Make(o.Version) + if err != nil { + return err + } } log.Infoln("Attempting to install Terraform Provider '" + c.TERRAFORM_PROVIDER_EDGE_CONTROLLER + "' version: " + newVersion.String()) diff --git a/ziti/cmd/install/install_ziti_ALL.go b/ziti/cmd/install/install_ziti_ALL.go index 5416d7960..54b4c4f83 100644 --- a/ziti/cmd/install/install_ziti_ALL.go +++ b/ziti/cmd/install/install_ziti_ALL.go @@ -85,6 +85,9 @@ func (o *InstallZitiALLOptions) install(zitiApp string) error { if o.Version != "" { newVersion, err = semver.Make(o.Version) + if err != nil { + return err + } } log.Infoln("Attempting to install '" + zitiApp + "' version: " + newVersion.String()) diff --git a/ziti/cmd/install/install_ziti_controller.go b/ziti/cmd/install/install_ziti_controller.go index fd84463cc..f7d82b6a5 100644 --- a/ziti/cmd/install/install_ziti_controller.go +++ b/ziti/cmd/install/install_ziti_controller.go @@ -85,6 +85,9 @@ func (o *InstallZitiControllerOptions) Run() error { if o.Version != "" { newVersion, err = semver.Make(o.Version) + if err != nil { + return err + } } log.Infoln("Attempting to install '" + c.ZITI_CONTROLLER + "' version: " + newVersion.String()) diff --git a/ziti/cmd/install/install_ziti_router.go b/ziti/cmd/install/install_ziti_router.go index 26610adc6..bb18bdfcd 100644 --- a/ziti/cmd/install/install_ziti_router.go +++ b/ziti/cmd/install/install_ziti_router.go @@ -85,6 +85,9 @@ func (o *InstallZitiRouterOptions) Run() error { if o.Version != "" { newVersion, err = semver.Make(o.Version) + if err != nil { + return err + } } log.Infoln("Attempting to install '" + c.ZITI_ROUTER + "' version: " + newVersion.String()) diff --git a/ziti/cmd/install/install_ziti_tunnel.go b/ziti/cmd/install/install_ziti_tunnel.go index 809908770..f411ae8ad 100644 --- a/ziti/cmd/install/install_ziti_tunnel.go +++ b/ziti/cmd/install/install_ziti_tunnel.go @@ -85,6 +85,9 @@ func (o *InstallZitiTunnelOptions) Run() error { if o.Version != "" { newVersion, err = semver.Make(o.Version) + if err != nil { + return err + } } log.Infoln("Attempting to install '" + c.ZITI_TUNNEL + "' version: " + newVersion.String()) diff --git a/ziti/cmd/install/version.go b/ziti/cmd/install/version.go index 1c46ecdca..f398866fe 100644 --- a/ziti/cmd/install/version.go +++ b/ziti/cmd/install/version.go @@ -72,8 +72,10 @@ func NewCmdVersion(out io.Writer, errOut io.Writer) *cobra.Command { // Run ... func (o *VersionOptions) Run() error { - - util.ConfigDir() + _, err := util.ConfigDir() + if err != nil { + return err + } info := util.ColorInfo @@ -126,12 +128,24 @@ func (o *VersionOptions) versionPrintZitiApp(zitiApp string, table *table.Table) } func (o *VersionOptions) versionCheck() error { - o.versionCheckZitiApp(c.ZITI) - o.versionCheckZitiApp(c.ZITI_CONTROLLER) - o.versionCheckZitiApp(c.ZITI_PROX_C) - o.versionCheckZitiApp(c.ZITI_ROUTER) - o.versionCheckZitiApp(c.ZITI_TUNNEL) - o.versionCheckZitiApp(c.ZITI_EDGE_TUNNEL) + if err := o.versionCheckZitiApp(c.ZITI); err != nil { + return err + } + if err := o.versionCheckZitiApp(c.ZITI_CONTROLLER); err != nil { + return err + } + if err := o.versionCheckZitiApp(c.ZITI_PROX_C); err != nil { + return err + } + if err := o.versionCheckZitiApp(c.ZITI_ROUTER); err != nil { + return err + } + if err := o.versionCheckZitiApp(c.ZITI_TUNNEL); err != nil { + return err + } + if err := o.versionCheckZitiApp(c.ZITI_EDGE_TUNNEL); err != nil { + return err + } return nil } diff --git a/ziti/cmd/lets_encrypt/KeyTypeVar.go b/ziti/cmd/lets_encrypt/KeyTypeVar.go index 4af713e3c..e52116fa5 100644 --- a/ziti/cmd/lets_encrypt/KeyTypeVar.go +++ b/ziti/cmd/lets_encrypt/KeyTypeVar.go @@ -60,38 +60,23 @@ func (f *KeyTypeVar) Set(value string) error { } func (f *KeyTypeVar) EC256() bool { - if certcrypto.KeyType(*f) == certcrypto.EC256 { - return true - } - return false + return certcrypto.KeyType(*f) == certcrypto.EC256 } func (f *KeyTypeVar) EC384() bool { - if certcrypto.KeyType(*f) == certcrypto.EC384 { - return true - } - return false + return certcrypto.KeyType(*f) == certcrypto.EC384 } func (f *KeyTypeVar) RSA2048() bool { - if certcrypto.KeyType(*f) == certcrypto.RSA2048 { - return true - } - return false + return certcrypto.KeyType(*f) == certcrypto.RSA2048 } func (f *KeyTypeVar) RSA4096() bool { - if certcrypto.KeyType(*f) == certcrypto.RSA4096 { - return true - } - return false + return certcrypto.KeyType(*f) == certcrypto.RSA4096 } func (f *KeyTypeVar) RSA8192() bool { - if certcrypto.KeyType(*f) == certcrypto.RSA8192 { - return true - } - return false + return certcrypto.KeyType(*f) == certcrypto.RSA8192 } func (f *KeyTypeVar) Get() certcrypto.KeyType { diff --git a/ziti/cmd/lets_encrypt/accounts_storage.go b/ziti/cmd/lets_encrypt/accounts_storage.go index 45faf02c4..f55787c6d 100644 --- a/ziti/cmd/lets_encrypt/accounts_storage.go +++ b/ziti/cmd/lets_encrypt/accounts_storage.go @@ -22,9 +22,7 @@ import ( "encoding/json" "encoding/pem" "errors" - "fmt" "github.com/openziti/ziti/ziti/internal/log" - "io/ioutil" "net/url" "os" "path/filepath" @@ -132,11 +130,11 @@ func (s *AccountsStorage) Save(account *Account) error { return err } - return ioutil.WriteFile(s.accountFilePath, jsonBytes, filePerm) + return os.WriteFile(s.accountFilePath, jsonBytes, filePerm) } func (s *AccountsStorage) LoadAccount(options *leOptions, privateKey crypto.PrivateKey) *Account { - fileBytes, err := ioutil.ReadFile(s.accountFilePath) + fileBytes, err := os.ReadFile(s.accountFilePath) if err != nil { log.Fatalf("Could not load file for account %s: %v", s.userID, err) } @@ -217,7 +215,7 @@ func generatePrivateKey(file string, keyType certcrypto.KeyType) (crypto.Private } func loadPrivateKey(file string) (crypto.PrivateKey, error) { - keyBytes, err := ioutil.ReadFile(file) + keyBytes, err := os.ReadFile(file) if err != nil { return nil, err } @@ -238,7 +236,7 @@ func tryRecoverRegistration(options *leOptions, privateKey crypto.PrivateKey) (* // couldn't load account but got a key. Try to look the account up. config := lego.NewConfig(&Account{key: privateKey}) config.CADirURL = options.acmeserver - config.UserAgent = fmt.Sprintf("ziti-cli") + config.UserAgent = "ziti-cli" client, err := lego.NewClient(config) if err != nil { diff --git a/ziti/cmd/lets_encrypt/certs_storage.go b/ziti/cmd/lets_encrypt/certs_storage.go index c19e2f3ab..fa78159d5 100644 --- a/ziti/cmd/lets_encrypt/certs_storage.go +++ b/ziti/cmd/lets_encrypt/certs_storage.go @@ -21,7 +21,6 @@ import ( "crypto/x509" "encoding/json" "github.com/openziti/ziti/ziti/internal/log" - "io/ioutil" "os" "path/filepath" "strconv" @@ -165,7 +164,7 @@ func (s *CertificatesStorage) ExistsFile(domain, extension string) bool { } func (s *CertificatesStorage) ReadFile(domain, extension string) ([]byte, error) { - return ioutil.ReadFile(s.GetFileName(domain, extension)) + return os.ReadFile(s.GetFileName(domain, extension)) } func (s *CertificatesStorage) GetFileName(domain, extension string) string { @@ -184,12 +183,9 @@ func (s *CertificatesStorage) ReadCertificate(domain, extension string) ([]*x509 } func (s *CertificatesStorage) WriteFile(domain, extension string, data []byte) error { - var baseFileName string - baseFileName = sanitizedDomain(domain) - + baseFileName := sanitizedDomain(domain) filePath := filepath.Join(s.rootPath, baseFileName+extension) - - return ioutil.WriteFile(filePath, data, filePerm) + return os.WriteFile(filePath, data, filePerm) } func (s *CertificatesStorage) MoveToArchive(domain string) error { diff --git a/ziti/cmd/lets_encrypt/create.go b/ziti/cmd/lets_encrypt/create.go index 4f34029b2..88171275e 100644 --- a/ziti/cmd/lets_encrypt/create.go +++ b/ziti/cmd/lets_encrypt/create.go @@ -30,8 +30,6 @@ import ( const acmeStaging string = "https://acme-staging-v02.api.letsencrypt.org/directory" const acmeProd string = "https://acme-v02.api.letsencrypt.org/directory" -const rootPathWarningMessage = `!!!! HEADS UP !!!!` - // We need a user or account type that implements acme.User type AcmeUser struct { Email string @@ -70,14 +68,20 @@ func newCreateCmd(out io.Writer, errOut io.Writer) *cobra.Command { cmd.Flags().SetInterspersed(true) cmd.Flags().StringVarP(&options.domain, "domain", "d", "", "Domain for which Cert is being generated (e.g. me.example.com)") - cmd.MarkFlagRequired("domain") + if err := cmd.MarkFlagRequired("domain"); err != nil { + panic(err) + } cmd.Flags().BoolVarP(&options.staging, "staging", "s", false, "Enable creation of 'staging' Certs (instead of production Certs)") cmd.Flags().StringVarP(&options.acmeserver, "acmeserver", "a", acmeProd, "ACME CA hostname") cmd.Flags().StringVarP(&options.email, "email", "e", "openziti@netfoundry.io", "Email used for registration and recovery contact") - options.keyType.Set("RSA4096") // set default + if err := options.keyType.Set("RSA4096"); err != nil { // set default + panic(err) + } cmd.Flags().VarP(&options.keyType, "keytype", "k", "Key type to use for private keys") cmd.Flags().StringVarP(&options.path, "path", "p", "", "Directory to use for storing the data") - cmd.MarkFlagRequired("path") + if err := cmd.MarkFlagRequired("path"); err != nil { + panic(err) + } cmd.Flags().StringVarP(&options.port, "port", "o", "80", "Port to listen on for HTTP based ACME challenges") cmd.Flags().StringVarP(&options.csr, "csr", "", "", "Certificate Signing Request filename, if an external CSR is to be used") diff --git a/ziti/cmd/lets_encrypt/list.go b/ziti/cmd/lets_encrypt/list.go index 20aac1cdf..5c4cbdde4 100644 --- a/ziti/cmd/lets_encrypt/list.go +++ b/ziti/cmd/lets_encrypt/list.go @@ -21,8 +21,8 @@ import ( "fmt" cmdhelper "github.com/openziti/ziti/ziti/cmd/helpers" "io" - "io/ioutil" "net/url" + "os" "path/filepath" "strings" @@ -52,7 +52,9 @@ func newListCmd(out io.Writer, errOut io.Writer) *cobra.Command { cmd.Flags().BoolVarP(&options.accounts, "accounts", "a", false, "Display Account info") cmd.Flags().BoolVarP(&options.names, "names", "n", false, "Display Names info") cmd.Flags().StringVarP(&options.path, "path", "p", "", "Directory where data is stored") - cmd.MarkFlagRequired("path") + if err := cmd.MarkFlagRequired("path"); err != nil { + panic(err) + } return cmd } @@ -83,7 +85,7 @@ func listAccount(options *leOptions) error { fmt.Println("Found the following accounts:") for _, filename := range matches { - data, err := ioutil.ReadFile(filename) + data, err := os.ReadFile(filename) if err != nil { return err } @@ -132,7 +134,7 @@ func listCertificates(options *leOptions) error { continue } - data, err := ioutil.ReadFile(filename) + data, err := os.ReadFile(filename) if err != nil { return err } diff --git a/ziti/cmd/lets_encrypt/renew.go b/ziti/cmd/lets_encrypt/renew.go index 75e811e9c..cc6505fca 100644 --- a/ziti/cmd/lets_encrypt/renew.go +++ b/ziti/cmd/lets_encrypt/renew.go @@ -56,13 +56,19 @@ func newRenewCmd(out io.Writer, errOut io.Writer) *cobra.Command { cmd.Flags().SetInterspersed(true) cmd.Flags().StringVarP(&options.domain, "domain", "d", "", "Domain for which Cert is being generated (e.g. me.example.com)") - cmd.MarkFlagRequired("domain") + if err := cmd.MarkFlagRequired("domain"); err != nil { + panic(err) + } cmd.Flags().StringVarP(&options.path, "path", "p", "", "Directory where data is stored") - cmd.MarkFlagRequired("path") + if err := cmd.MarkFlagRequired("path"); err != nil { + panic(err) + } cmd.Flags().IntVarP(&options.days, "days", "", 14, "The number of days left on a certificate to renew it") cmd.Flags().BoolVarP(&options.reuseKey, "reuse-key", "r", true, "Used to indicate you want to reuse your current private key for the renewed certificate") cmd.Flags().StringVarP(&options.email, "email", "e", "openziti@netfoundry.io", "Email used for registration and recovery contact") - options.keyType.Set("RSA4096") // set default + if err := options.keyType.Set("RSA4096"); err != nil { // set default + panic(err) + } cmd.Flags().VarP(&options.keyType, "keytype", "k", "Key type to use for private keys") cmd.Flags().StringVarP(&options.acmeserver, "acmeserver", "a", acmeProd, "ACME CA hostname") cmd.Flags().BoolVarP(&options.staging, "staging", "s", false, "Enable creation of 'staging' Certs (instead of production Certs)") diff --git a/ziti/cmd/lets_encrypt/revoke.go b/ziti/cmd/lets_encrypt/revoke.go index db2ccb288..3cf95a457 100644 --- a/ziti/cmd/lets_encrypt/revoke.go +++ b/ziti/cmd/lets_encrypt/revoke.go @@ -44,9 +44,13 @@ func newRevokeCmd(out io.Writer, errOut io.Writer) *cobra.Command { cmd.Flags().SetInterspersed(true) cmd.Flags().StringVarP(&options.domain, "domain", "d", "", "Domain for which Cert is being generated (e.g. me.example.com)") - cmd.MarkFlagRequired("domain") + if err := cmd.MarkFlagRequired("domain"); err != nil { + panic(err) + } cmd.Flags().StringVarP(&options.path, "path", "p", "", "Directory where data is stored") - cmd.MarkFlagRequired("path") + if err := cmd.MarkFlagRequired("path"); err != nil { + panic(err) + } cmd.Flags().StringVarP(&options.email, "email", "e", "openziti@netfoundry.io", "Email used for registration and recovery contact") cmd.Flags().StringVarP(&options.acmeserver, "acmeserver", "a", acmeProd, "ACME CA hostname") cmd.Flags().BoolVarP(&options.staging, "staging", "s", false, "Enable creation of 'staging' Certs (instead of production Certs)") diff --git a/ziti/cmd/lets_encrypt/setup.go b/ziti/cmd/lets_encrypt/setup.go index c52bf3d4f..df31dac55 100644 --- a/ziti/cmd/lets_encrypt/setup.go +++ b/ziti/cmd/lets_encrypt/setup.go @@ -17,11 +17,7 @@ package lets_encrypt import ( - "crypto/x509" - "encoding/pem" - "fmt" "github.com/openziti/ziti/ziti/internal/log" - "io/ioutil" "os" "time" @@ -59,7 +55,7 @@ func newClient(options *leOptions, acc registration.User) *lego.Client { KeyType: options.keyType.Get(), Timeout: time.Duration(30) * time.Second, // Only used when obtaining certificates } - config.UserAgent = fmt.Sprintf("zitii-cli") + config.UserAgent = "ziti-cli" client, err := lego.NewClient(config) if err != nil { @@ -69,14 +65,6 @@ func newClient(options *leOptions, acc registration.User) *lego.Client { return client } -func getEmail(options *leOptions) string { - email := options.email - if len(email) == 0 { - log.Fatal("You have to pass an account (email address) to the program using --email or -m") - } - return email -} - func createNonExistingFolder(path string) error { if _, err := os.Stat(path); os.IsNotExist(err) { return os.MkdirAll(path, 0o700) @@ -85,34 +73,3 @@ func createNonExistingFolder(path string) error { } return nil } - -func readCSRFile(filename string) (*x509.CertificateRequest, error) { - bytes, err := ioutil.ReadFile(filename) - if err != nil { - return nil, err - } - raw := bytes - - // see if we can find a PEM-encoded CSR - var p *pem.Block - rest := bytes - for { - // decode a PEM block - p, rest = pem.Decode(rest) - - // did we fail? - if p == nil { - break - } - - // did we get a CSR? - if p.Type == "CERTIFICATE REQUEST" { - raw = p.Bytes - } - } - - // no PEM-encoded CSR - // assume we were given a DER-encoded ASN.1 CSR - // (if this assumption is wrong, parsing these bytes will fail) - return x509.ParseCertificateRequest(raw) -} diff --git a/ziti/cmd/pki_create.go b/ziti/cmd/pki_create.go index 4ad54c0d4..fe26d2dc0 100644 --- a/ziti/cmd/pki_create.go +++ b/ziti/cmd/pki_create.go @@ -25,8 +25,8 @@ import ( cmdhelper "github.com/openziti/ziti/ziti/cmd/helpers" "github.com/openziti/ziti/ziti/util" "io" - "io/ioutil" "net" + "os" "strings" "sync" "time" @@ -77,38 +77,39 @@ func NewCmdPKICreate(out io.Writer, errOut io.Writer) *cobra.Command { func (options *PKICreateOptions) addPKICreateFlags(cmd *cobra.Command) { viperLock.Lock() + defer viperLock.Unlock() + cmd.PersistentFlags().StringVarP(&options.Flags.PKIRoot, "pki-root", "", "", "Directory in which to store CA") - cmd.MarkFlagRequired("pki-root") - viper.BindPFlag("pki_root", cmd.PersistentFlags().Lookup("pki-root")) + err := viper.BindPFlag("pki_root", cmd.PersistentFlags().Lookup("pki-root")) + options.panicOnErr(err) cmd.PersistentFlags().StringVarP(&options.Flags.PKIOrganization, "pki-organization", "", "NetFoundry", "Organization") - cmd.MarkFlagRequired("pki-organization") - viper.BindPFlag("pki-organization", cmd.PersistentFlags().Lookup("pki-organization")) + err = viper.BindPFlag("pki-organization", cmd.PersistentFlags().Lookup("pki-organization")) + options.panicOnErr(err) cmd.PersistentFlags().StringVarP(&options.Flags.PKIOrganizationalUnit, "pki-organizational-unit", "", "ADV-DEV", "Organization unit") - cmd.MarkFlagRequired("pki-organizational-unit") - viper.BindPFlag("pki-organizational-unit", cmd.PersistentFlags().Lookup("pki-organizational-unit")) + err = viper.BindPFlag("pki-organizational-unit", cmd.PersistentFlags().Lookup("pki-organizational-unit")) + options.panicOnErr(err) cmd.PersistentFlags().StringVarP(&options.Flags.PKICountry, "pki-country", "", "US", "Country") - cmd.MarkFlagRequired("pki-country") - viper.BindPFlag("pki-country", cmd.PersistentFlags().Lookup("pki-country")) + err = viper.BindPFlag("pki-country", cmd.PersistentFlags().Lookup("pki-country")) + options.panicOnErr(err) cmd.PersistentFlags().StringVarP(&options.Flags.PKILocality, "pki-locality", "", "Charlotte", "Locality/Location") - cmd.MarkFlagRequired("pki-locality") - viper.BindPFlag("pki-locality", cmd.PersistentFlags().Lookup("pki-locality")) + err = viper.BindPFlag("pki-locality", cmd.PersistentFlags().Lookup("pki-locality")) + options.panicOnErr(err) // cmd.PersistentFlags().StringVarP(&options.Flags.PKILocality, "pki-location", "", "Charlotte", "Location/Locality") // cmd.MarkFlagRequired("pki-location") // viper.BindPFlag("pki-location", cmd.PersistentFlags().Lookup("pki-location")) cmd.PersistentFlags().StringVarP(&options.Flags.PKIProvince, "pki-province", "", "NC", "Province/State") - cmd.MarkFlagRequired("pki-province") - viper.BindPFlag("pki-province", cmd.PersistentFlags().Lookup("pki-province")) + err = viper.BindPFlag("pki-province", cmd.PersistentFlags().Lookup("pki-province")) + options.panicOnErr(err) // cmd.PersistentFlags().StringVarP(&options.Flags.PKIProvince, "pki-state", "", "NC", "State/Province") // cmd.MarkFlagRequired("pki-state") // viper.BindPFlag("pki-state", cmd.PersistentFlags().Lookup("pki-state")) - viperLock.Unlock() } // Run implements this command @@ -250,7 +251,7 @@ func (o *PKICreateOptions) ObtainCAName(pkiroot string) (string, error) { caname = viper.GetString("ca-name") if caname == "" { var err error - files, err := ioutil.ReadDir(pkiroot) + files, err := os.ReadDir(pkiroot) if err != nil { return "", err } @@ -332,7 +333,7 @@ func (o *PKICreateOptions) ObtainKeyName(pkiroot string) (string, error) { keyname := viper.GetString("key-name") if keyname == "" { var err error - files, err := ioutil.ReadDir(pkiroot) + files, err := os.ReadDir(pkiroot) if err != nil { return "", err } diff --git a/ziti/cmd/templates/templater.go b/ziti/cmd/templates/templater.go index deae8e1c2..e60a141b2 100644 --- a/ziti/cmd/templates/templater.go +++ b/ziti/cmd/templates/templater.go @@ -256,15 +256,6 @@ func rpad(s string, padding int) string { return fmt.Sprintf(template, s) } -func indentLines(s string, indentation int) string { - r := []string{} - for _, line := range strings.Split(s, "\n") { - indented := strings.Repeat(" ", indentation) + line - r = append(r, indented) - } - return strings.Join(r, "\n") -} - func appendIfNotPresent(s, stringToAppend string) string { if strings.Contains(s, stringToAppend) { return s diff --git a/ziti/cmd/unwrap_identity.go b/ziti/cmd/unwrap_identity.go index 2917a9c74..6eda43b1f 100644 --- a/ziti/cmd/unwrap_identity.go +++ b/ziti/cmd/unwrap_identity.go @@ -6,7 +6,7 @@ import ( "github.com/openziti/identity" "github.com/spf13/cobra" "io" - "io/ioutil" + "os" "strings" ) @@ -42,7 +42,7 @@ func NewUnwrapIdentityFileCommand(out io.Writer, errOut io.Writer) *cobra.Comman outCaFile = rootFileName + ".ca" } - identityJson, err := ioutil.ReadFile(identityFile) + identityJson, err := os.ReadFile(identityFile) if err != nil { _, _ = fmt.Fprintf(errOut, "error opening file %s: %v\n", args[0], err) @@ -57,7 +57,7 @@ func NewUnwrapIdentityFileCommand(out io.Writer, errOut io.Writer) *cobra.Comman if strings.HasPrefix(config.ID.Cert, "pem:") { data := strings.TrimPrefix(config.ID.Cert, "pem:") - if err := ioutil.WriteFile(outCertFile, []byte(data), 0); err != nil { + if err := os.WriteFile(outCertFile, []byte(data), 0); err != nil { _, _ = fmt.Fprintf(errOut, "error writing certificate to file [%s]: %v\n", outCertFile, err) return } @@ -67,7 +67,7 @@ func NewUnwrapIdentityFileCommand(out io.Writer, errOut io.Writer) *cobra.Comman if strings.HasPrefix(config.ID.Key, "pem:") { data := strings.TrimPrefix(config.ID.Key, "pem:") - if err := ioutil.WriteFile(outKeyFile, []byte(data), 0); err != nil { + if err := os.WriteFile(outKeyFile, []byte(data), 0); err != nil { _, _ = fmt.Fprintf(errOut, "error writing private key to file [%s]: %v\n", outKeyFile, err) return } @@ -77,7 +77,7 @@ func NewUnwrapIdentityFileCommand(out io.Writer, errOut io.Writer) *cobra.Comman if strings.HasPrefix(config.ID.Key, "pem:") { data := strings.TrimPrefix(config.ID.CA, "pem:") - if err := ioutil.WriteFile(outCaFile, []byte(data), 0); err != nil { + if err := os.WriteFile(outCaFile, []byte(data), 0); err != nil { _, _ = fmt.Fprintf(errOut, "error writing CAs to file [%s]: %v\n", outCaFile, err) return } diff --git a/ziti/pki/store/local.go b/ziti/pki/store/local.go index 2cdea6ec4..0151a6fb9 100644 --- a/ziti/pki/store/local.go +++ b/ziti/pki/store/local.go @@ -377,8 +377,13 @@ func (l *Local) Update(caName string, sn *big.Int, st certificate.State) error { } } - f.Truncate(0) - f.Seek(0, 0) + if err = f.Truncate(0); err != nil { + return err + } + + if _, err = f.Seek(0, 0); err != nil { + return err + } for _, line := range lines { n, err := fmt.Fprintln(f, line) diff --git a/ziti/router/enrollgw.go b/ziti/router/enrollgw.go index fd0175ff4..dce15c515 100644 --- a/ziti/router/enrollgw.go +++ b/ziti/router/enrollgw.go @@ -22,7 +22,7 @@ import ( "github.com/openziti/fabric/router" "github.com/openziti/sdk-golang/ziti" "github.com/spf13/cobra" - "io/ioutil" + "os" ) var jwtPath *string @@ -39,7 +39,9 @@ func NewEnrollGwCmd() *cobra.Command { jwtPath = enrollEdgeRouterCmd.Flags().StringP("jwt", "j", "", "The path to a JWT file") engine = enrollEdgeRouterCmd.Flags().StringP("engine", "e", "", "An engine") - keyAlg.Set("RSA") // set default + if err := keyAlg.Set("RSA"); err != nil { // set default + panic(err) + } enrollEdgeRouterCmd.Flags().VarP(&keyAlg, "keyAlg", "a", "Crypto algorithm to use when generating private key") return enrollEdgeRouterCmd @@ -57,7 +59,7 @@ func enrollGw(cmd *cobra.Command, args []string) { log.Panicf("could not load config: %s", err) } - jwtBuf, err := ioutil.ReadFile(*jwtPath) + jwtBuf, err := os.ReadFile(*jwtPath) if err != nil { log.Panicf("could not load JWT file from path [%s]", *jwtPath) } diff --git a/ziti/router/run.go b/ziti/router/run.go index 4d623469d..533ea0b50 100644 --- a/ziti/router/run.go +++ b/ziti/router/run.go @@ -131,7 +131,7 @@ func getFlags(cmd *cobra.Command) map[string]*pflag.Flag { func waitForShutdown(r *router.Router, config *router.Config) { ch := make(chan os.Signal, 1) - signal.Notify(ch, os.Interrupt, syscall.SIGQUIT, syscall.SIGINT, syscall.SIGKILL, syscall.SIGTERM) + signal.Notify(ch, os.Interrupt, syscall.SIGQUIT, syscall.SIGINT, syscall.SIGTERM) s := <-ch diff --git a/ziti/util/certs.go b/ziti/util/certs.go index c72622361..7398b9e6b 100644 --- a/ziti/util/certs.go +++ b/ziti/util/certs.go @@ -8,7 +8,7 @@ import ( "encoding/pem" "fmt" "github.com/openziti/ziti/ziti/cmd/common" - "io/ioutil" + "io" "net/http" "net/url" "os" @@ -31,7 +31,7 @@ func WriteCert(p common.Printer, id string, cert []byte) (string, error) { return "", errors.Wrapf(err, "unable to create ziti certs dir %v", certsDir) } certFile := filepath.Join(certsDir, id) - if err = ioutil.WriteFile(certFile, cert, 0600); err != nil { + if err = os.WriteFile(certFile, cert, 0600); err != nil { return "", err } p.Printf("Server certificate chain written to %v\n", certFile) @@ -51,7 +51,7 @@ func ReadCert(id string) ([]byte, string, error) { } return nil, "", errors.Wrapf(err, "error while statting cert file for %v", id) } - result, err := ioutil.ReadFile(certFile) + result, err := os.ReadFile(certFile) if err != nil { return nil, "", errors.Wrapf(err, "error while reading cert for %v", id) } @@ -81,11 +81,11 @@ func AreCertsTrusted(host string, certs []byte) (bool, error) { tlsConfig.RootCAs.AppendCertsFromPEM(certs) - transport := *http.DefaultTransport.(*http.Transport) + transport := http.DefaultTransport.(*http.Transport).Clone() transport.TLSClientConfig = tlsConfig client := http.Client{ - Transport: &transport, + Transport: transport, } resp, err := client.Get(fmt.Sprintf("%v/.well-known/est/cacerts", host)) @@ -100,12 +100,12 @@ func AreCertsTrusted(host string, certs []byte) (bool, error) { } func GetWellKnownCerts(host string) ([]byte, []*x509.Certificate, error) { - transport := *http.DefaultTransport.(*http.Transport) + transport := http.DefaultTransport.(*http.Transport).Clone() transport.TLSClientConfig = &tls.Config{ InsecureSkipVerify: true, } client := http.Client{ - Transport: &transport, + Transport: transport, } resp, err := client.Get(fmt.Sprintf("%v/.well-known/est/cacerts", host)) @@ -113,7 +113,7 @@ func GetWellKnownCerts(host string) ([]byte, []*x509.Certificate, error) { return nil, nil, err } defer func() { _ = resp.Body.Close() }() - encoded, err := ioutil.ReadAll(resp.Body) + encoded, err := io.ReadAll(resp.Body) if err != nil { return nil, nil, err } diff --git a/ziti/util/commands.go b/ziti/util/commands.go index 7135774d4..ac9d1c71e 100644 --- a/ziti/util/commands.go +++ b/ziti/util/commands.go @@ -17,13 +17,8 @@ package util import ( - "fmt" - "github.com/openziti/ziti/ziti/internal/log" "github.com/spf13/cobra" - "github.com/spf13/viper" "os" - "os/exec" - "strings" ) const ( @@ -36,127 +31,6 @@ func PathWithBinary() string { return binDir + string(os.PathListSeparator) + path } -// GetCommandOutput evaluates the given command and returns the trimmed output -func GetCommandOutput(dir string, name string, args ...string) (string, error) { - os.Setenv("PATH", PathWithBinary()) - e := exec.Command(name, args...) - if dir != "" { - e.Dir = dir - } - data, err := e.CombinedOutput() - text := string(data) - text = strings.TrimSpace(text) - if err != nil { - return text, fmt.Errorf("error: command failed %s %s %s %s", name, strings.Join(args, " "), text, err) - } - return text, err -} - -// RunCommand evaluates the given command and returns the trimmed output -func RunCommand(dir string, name string, args ...string) error { - os.Setenv("PATH", PathWithBinary()) - e := exec.Command(name, args...) - if dir != "" { - e.Dir = dir - } - e.Stdout = os.Stdout - e.Stderr = os.Stdin - err := e.Run() - if err != nil { - log.Errorf("command failed %s %s\n", name, strings.Join(args, " ")) - } - return err -} - -// RunAWSCommand evaluates the given AWS CLI command and returns the trimmed output -func RunAWSCommand(args ...string) error { - os.Setenv("PATH", PathWithBinary()) - e := exec.Command("aws", args...) - accessKey, err := getAWSConfigValue("AWS_ACCESS_KEY_ID") - if err != nil { - return fmt.Errorf("Cannot find AWS_ACCESS_KEY_ID in config; Please run 'ziti init'") - } - secretKey, err := getAWSConfigValue("AWS_SECRET_ACCESS_KEY") - if err != nil { - return fmt.Errorf("Cannot find AWS_SECRET_ACCESS_KEY in config; Please run 'ziti init'") - } - e.Env = os.Environ() - e.Env = append(e.Env, "AWS_ACCESS_KEY_ID="+accessKey) - e.Env = append(e.Env, "AWS_SECRET_ACCESS_KEY="+secretKey) - e.Stdout = os.Stdout - e.Stderr = os.Stdin - err = e.Run() - if err != nil { - log.Errorf("Command failed %s\n", strings.Join(args, " ")) - } - return err -} - -// getCommandOutput evaluates the given command and returns the trimmed output -func getCommandOutput(dir string, name string, args ...string) (string, error) { - err := os.Setenv("PATH", PathWithBinary()) - - if err != nil { - return "", fmt.Errorf("could not set environment variable PATH: %s", err) - } - - e := exec.Command(name, args...) - if dir != "" { - e.Dir = dir - } - data, err := e.CombinedOutput() - text := string(data) - text = strings.TrimSpace(text) - if err != nil { - return "", fmt.Errorf("command failed 'aws %s %s': %s %s", name, strings.Join(args, " "), text, err) - } - return text, err -} - -// getAWSCommandOutput evaluates the given AWS CLI command and returns the trimmed output -func getAWSCommandOutput(args ...string) (string, error) { - os.Setenv("PATH", PathWithBinary()) - e := exec.Command("aws", args...) - accessKey, err := getAWSConfigValue("AWS_ACCESS_KEY_ID") - if err != nil { - return "", fmt.Errorf("Cannot find AWS_ACCESS_KEY_ID in config; Please run 'ziti init'") - } - secretKey, err := getAWSConfigValue("AWS_SECRET_ACCESS_KEY") - if err != nil { - return "", fmt.Errorf("Cannot find AWS_SECRET_ACCESS_KEY in config; Please run 'ziti init'") - } - e.Env = os.Environ() - e.Env = append(e.Env, "AWS_ACCESS_KEY_ID="+accessKey) - e.Env = append(e.Env, "AWS_SECRET_ACCESS_KEY="+secretKey) - data, err := e.CombinedOutput() - text := string(data) - text = strings.TrimSpace(text) - if err != nil { - return "", fmt.Errorf("command failed 'aws %s': %s %s", strings.Join(args, " "), text, err) - } - return text, err -} - -// getAWSCommandOutput evaluates the given AWS CLI command and returns the trimmed output -func getAWSConfigValue(key string) (string, error) { - viper := viper.New() - viper.SetConfigType("json") - viper.SetConfigName(CONFIGFILENAME) - zitiConfigDir, err := ZitiAppConfigDir("ziti") - if err != nil { - return "", err - } - viper.AddConfigPath(zitiConfigDir) - err = viper.ReadInConfig() - if err != nil { - return "", err - } - - val := viper.GetString(key) - - return val, nil -} - // NewEmptyParentCmd creates a new cobra command with no parent func NewEmptyParentCmd(name string, description string) *cobra.Command { diff --git a/ziti/util/dirs.go b/ziti/util/dirs.go index 9c28744ce..37d2e341c 100644 --- a/ziti/util/dirs.go +++ b/ziti/util/dirs.go @@ -19,7 +19,6 @@ package util import ( "encoding/json" "fmt" - "io/ioutil" "os" "path/filepath" "runtime" @@ -186,7 +185,7 @@ func WriteZitiAppFile(zitiApp string, fileType string, appData interface{}) erro return err } - return ioutil.WriteFile(filePath, data, 0600) + return os.WriteFile(filePath, data, 0600) } // ReadZitiAppConfigFile reads in the config file data for the given Ziti application from an appropriate location @@ -203,7 +202,7 @@ func ReadZitiAppFile(zitiApp string, fileType string, configData interface{}) er filePath := filepath.Join(configDir, fileType+".json") - data, err := ioutil.ReadFile(filePath) + data, err := os.ReadFile(filePath) if err != nil { return err } diff --git a/ziti/util/files.go b/ziti/util/files.go index 659e05509..305f50c00 100644 --- a/ziti/util/files.go +++ b/ziti/util/files.go @@ -19,7 +19,6 @@ package util import ( "fmt" "io" - "io/ioutil" "os" "path/filepath" "strconv" @@ -27,8 +26,6 @@ import ( const ( DefaultWritePermissions = 0760 - - MaximumNewDirectoryAttempts = 1000 ) func FileExists(path string) (bool, error) { @@ -134,7 +131,7 @@ func CopyDir(src string, dst string, force bool) (err error) { return } - entries, err := ioutil.ReadDir(src) + entries, err := os.ReadDir(src) if err != nil { return } @@ -150,7 +147,7 @@ func CopyDir(src string, dst string, force bool) (err error) { } } else { // Skip symlinks. - if entry.Mode()&os.ModeSymlink != 0 { + if entry.Type()&os.ModeSymlink != 0 { continue } @@ -227,7 +224,7 @@ func CopyDirOverwrite(src string, dst string) (err error) { return } - entries, err := ioutil.ReadDir(src) + entries, err := os.ReadDir(src) if err != nil { return } @@ -243,7 +240,7 @@ func CopyDirOverwrite(src string, dst string) (err error) { } } else { // Skip symlinks. - if entry.Mode()&os.ModeSymlink != 0 { + if entry.Type()&os.ModeSymlink != 0 { continue } @@ -259,7 +256,7 @@ func CopyDirOverwrite(src string, dst string) (err error) { // loads a file func LoadBytes(dir, name string) ([]byte, error) { path := filepath.Join(dir, name) // relative path - bytes, err := ioutil.ReadFile(path) + bytes, err := os.ReadFile(path) if err != nil { return nil, fmt.Errorf("error loading file %s in directory %s, %v", name, dir, err) }