diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..8d7488b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +.idea +.vscode +x.json +zz.yaml \ No newline at end of file diff --git a/.github/workflows/push.yaml b/.github/workflows/push.yaml index f504192..b1f9cc8 100644 --- a/.github/workflows/push.yaml +++ b/.github/workflows/push.yaml @@ -9,7 +9,6 @@ on: - CHANGELOG.md - LICENSE pull_request: - # Sequence of patterns matched against refs/heads branches: - main paths-ignore: @@ -18,71 +17,109 @@ on: - LICENSE env: IMAGE_NAME: 'router' + ADAPTOR_IMAGE_NAME: 'router-adaptor' jobs: - build: - runs-on: ubuntu-20.04 - strategy: - matrix: - platform: - - linux/amd64 - - linux/386 - - linux/arm/v6 - - linux/arm/v7 - - linux/arm64 + version: + name: Set version + runs-on: ubuntu-latest permissions: - actions: write - checks: write - contents: write - deployments: write - id-token: write - issues: write - discussions: write - packages: write - pages: write - pull-requests: write - repository-projects: write - security-events: write - statuses: write - name: Build and Publish + contents: read + outputs: + VERSION: ${{ steps.tags.outputs.VERSION }} steps: - - uses: actions/checkout@v3 - - name: 'Get Previous tag' - id: previoustag - uses: "WyriHaximus/github-action-get-previous-tag@v1" - with: - fallback: 0.0.0 - - name: Set image tag - shell: bash - id: tags - run: | - if [[ ${{ github.ref_name }} =~ ^v.* ]] ; then - VERSION=${{ github.ref_name }} - echo "VERSION=${VERSION:1}" >> "${GITHUB_OUTPUT}" - else + - uses: actions/checkout@v4 + - name: Get Previous tag + id: previoustag + uses: "WyriHaximus/github-action-get-previous-tag@v1" + with: + fallback: 0.0.0 + - name: Set image tag + shell: bash + id: tags + run: | + if [[ ${{ github.ref_name }} =~ ^v.* ]] ; then + VERSION=${{ github.ref_name }} + echo "VERSION=${VERSION:1}" >> "${GITHUB_OUTPUT}" + else VERSION=${{ steps.previoustag.outputs.tag }} echo "VERSION=${VERSION:1}-${{ github.run_number }}" >> "${GITHUB_OUTPUT}" - fi + fi - - name: Login to Github Container Registry - - uses: docker/login-action@v2 - with: - registry: "ghcr.io" - username: ${{ github.actor }} - password: ${{ secrets.PAT }} + build_amd64: + name: Build amd64 + needs: version + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v4 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to Github Container Registry + uses: docker/login-action@v3 + with: + registry: "ghcr.io" + username: ${{ github.actor }} + password: ${{ secrets.PAT }} + - name: Build and push amd64 image + uses: docker/build-push-action@v5 + with: + context: . + file: Dockerfile + platforms: linux/amd64 + push: ${{ github.event_name == 'push' }} + tags: | + ghcr.io/datasance/${{ env.IMAGE_NAME }}:build-${{ github.run_id }}-amd64 - - name: Build and Push to ghcr - - uses: docker/build-push-action@v3 - id: build_push_ghcr - with: - file: Dockerfile - platforms: ${{ matrix.platforms }} - push: true - outputs: type=image,name=target,annotation-index.org.opencontainers.image.description=Router - tags: | - ghcr.io/datasance/${{ env.IMAGE_NAME }}:${{ steps.tags.outputs.VERSION }} - ghcr.io/datasance/${{ env.IMAGE_NAME }}:latest - ghcr.io/datasance/${{ env.IMAGE_NAME }}:main + build_arm64: + name: Build arm64 + needs: version + runs-on: ubuntu-24.04-arm + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v4 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to Github Container Registry + uses: docker/login-action@v3 + with: + registry: "ghcr.io" + username: ${{ github.actor }} + password: ${{ secrets.PAT }} + - name: Build and push arm64 image + uses: docker/build-push-action@v5 + with: + context: . + file: Dockerfile + platforms: linux/arm64 + push: ${{ github.event_name == 'push' }} + tags: | + ghcr.io/datasance/${{ env.IMAGE_NAME }}:build-${{ github.run_id }}-arm64 + merge_manifest: + name: Merge multi-platform manifest + needs: [version, build_amd64, build_arm64] + if: github.event_name == 'push' + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Login to Github Container Registry + uses: docker/login-action@v3 + with: + registry: "ghcr.io" + username: ${{ github.actor }} + password: ${{ secrets.PAT }} + - name: Create and push multi-platform manifest + run: | + docker buildx imagetools create \ + -t ghcr.io/datasance/${{ env.IMAGE_NAME }}:${{ needs.version.outputs.VERSION }} \ + -t ghcr.io/datasance/${{ env.IMAGE_NAME }}:latest \ + -t ghcr.io/datasance/${{ env.IMAGE_NAME }}:main \ + ghcr.io/datasance/${{ env.IMAGE_NAME }}:build-${{ github.run_id }}-amd64 \ + ghcr.io/datasance/${{ env.IMAGE_NAME }}:build-${{ github.run_id }}-arm64 diff --git a/.gitignore b/.gitignore index d48c759..8d7488b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .idea -.vscode \ No newline at end of file +.vscode +x.json +zz.yaml \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 4abe6f1..aa8a0e5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,74 +1,94 @@ -# Build Apache Qpid Dispatch -FROM ubuntu:latest AS qpid-builder +FROM registry.access.redhat.com/ubi9/ubi-minimal:latest AS builder + +# upgrade first to avoid fixable vulnerabilities +# do this in builder as well as in buildee, so builder does not have different pkg versions from buildee image +RUN microdnf -y upgrade --refresh --best --nodocs --noplugins --setopt=install_weak_deps=0 --setopt=keepcache=0 \ + && microdnf clean all -y + +RUN microdnf -y --setopt=install_weak_deps=0 --setopt=tsflags=nodocs install \ + rpm-build \ + gcc gcc-c++ make cmake pkgconfig \ + cyrus-sasl-devel openssl-devel libuuid-devel \ + python3-devel python3-pip python3-wheel \ + libnghttp2-devel \ + wget tar patch findutils git \ + libtool \ + && microdnf clean all -y + +WORKDIR /build +# Clone skupper-router so repo contents are in /build (not /build/skupper-router) +RUN git clone --depth 1 --branch main https://github.com/skupperproject/skupper-router.git . +ENV PROTON_VERSION=main +ENV PROTON_SOURCE_URL=${PROTON_SOURCE_URL:-https://github.com/apache/qpid-proton/archive/${PROTON_VERSION}.tar.gz} +ENV LWS_VERSION=v4.3.3 +ENV LIBUNWIND_VERSION=v1.8.1 +ENV LWS_SOURCE_URL=${LWS_SOURCE_URL:-https://github.com/warmcat/libwebsockets/archive/refs/tags/${LWS_VERSION}.tar.gz} +ENV LIBUNWIND_SOURCE_URL=${LIBUNWIND_SOURCE_URL:-https://github.com/libunwind/libunwind/archive/refs/tags/${LIBUNWIND_VERSION}.tar.gz} +ENV PKG_CONFIG_PATH=/usr/local/lib/pkgconfig + +ARG VERSION=0.0.0 +ENV VERSION=$VERSION +ARG TARGETARCH +ENV PLATFORM=$TARGETARCH +RUN .github/scripts/compile.sh +RUN mkdir -p /image && if [ "$PLATFORM" = "amd64" ]; then tar zxpf /qpid-proton-image.tar.gz -C /image && tar zxpf /skupper-router-image.tar.gz -C /image && tar zxpf /libwebsockets-image.tar.gz -C /image && tar zxpf /libunwind-image.tar.gz -C /image; fi +RUN if [ "$PLATFORM" = "arm64" ]; then tar zxpf /qpid-proton-image.tar.gz -C /image && tar zxpf /skupper-router-image.tar.gz -C /image && tar zxpf /libwebsockets-image.tar.gz -C /image; fi +RUN if [ "$PLATFORM" = "s390x" ]; then tar zxpf /qpid-proton-image.tar.gz -C /image && tar zxpf /skupper-router-image.tar.gz -C /image && tar zxpf /libwebsockets-image.tar.gz -C /image; fi +RUN if [ "$PLATFORM" = "ppc64le" ]; then tar zxpf /qpid-proton-image.tar.gz -C /image && tar zxpf /skupper-router-image.tar.gz -C /image && tar zxpf /libwebsockets-image.tar.gz -C /image; fi + +RUN mkdir /image/licenses && cp ./LICENSE /image/licenses + +FROM registry.access.redhat.com/ubi9/ubi:latest AS packager + +RUN dnf -y --setopt=install_weak_deps=0 --nodocs \ + --installroot /output install \ + coreutils-single \ + cyrus-sasl-lib cyrus-sasl-plain openssl \ + python3 \ + libnghttp2 \ + hostname iputils \ + shadow-utils \ + && chroot /output useradd --uid 10000 runner \ + && dnf -y --installroot /output remove shadow-utils \ + && dnf clean all --installroot /output +RUN [ -d /usr/share/buildinfo ] && cp -a /usr/share/buildinfo /output/usr/share/buildinfo ||: +RUN [ -d /root/buildinfo ] && cp -a /root/buildinfo /output/root/buildinfo ||: + +FROM golang:1.23-alpine AS go-builder + +ARG TARGETOS +ARG TARGETARCH -ENV TZ=America/New_York -ENV DEBIAN_FRONTEND=noninteractive +RUN mkdir -p /go/src/github.com/datasance/router +WORKDIR /go/src/github.com/datasance/router +COPY . /go/src/github.com/datasance/router +RUN go fmt ./... +RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -trimpath -ldflags="-s -w" -o bin/router . -RUN apt-get update && \ - apt-get install -y curl gcc g++ automake libwebsockets-dev libtool zlib1g-dev cmake libsasl2-dev libssl-dev python3 python3-dev libuv1-dev sasl2-bin swig maven git && \ - apt-get -y clean +FROM registry.access.redhat.com/ubi9/ubi-minimal:latest AS tz +RUN microdnf install -y tzdata && microdnf reinstall -y tzdata -RUN git clone -b 1.18.0 --single-branch https://gitbox.apache.org/repos/asf/qpid-dispatch.git +FROM scratch -WORKDIR /qpid-dispatch -RUN git submodule add -b v3.0-stable https://github.com/warmcat/libwebsockets -RUN git submodule add https://gitbox.apache.org/repos/asf/qpid-proton.git && cd qpid-proton/ && git checkout 0.39.0 +COPY --from=packager /output / +COPY --from=packager /etc/yum.repos.d /etc/yum.repos.d -# Transform deprecated errors into warning until we get this qpid thing sorted out -RUN sed -i 's/-Werror/-Werror -Wno-error=deprecated-declarations/g' /qpid-dispatch/libwebsockets/CMakeLists.txt -RUN sed -i 's/-Werror/-Werror -Wno-error=deprecated-declarations/g' /qpid-dispatch/qpid-proton/CMakeLists.txt +USER 10000 -RUN mkdir libwebsockets/build && cd /qpid-dispatch/libwebsockets/build && cmake .. -DCMAKE_INSTALL_PREFIX=/usr && make install +COPY --from=builder /image / -WORKDIR /qpid-dispatch -RUN mkdir qpid-proton/build && cd qpid-proton/build && cmake .. -DSYSINSTALL_BINDINGS=ON -DCMAKE_INSTALL_PREFIX=/usr -DSYSINSTALL_PYTHON=ON && make install +WORKDIR /home/skrouterd/bin +COPY ./scripts/* /home/skrouterd/bin/ -WORKDIR /qpid-dispatch -RUN mkdir build && cd build && cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DUSE_VALGRIND=NO && cmake --build . --target install +ARG version=latest +ENV VERSION=${version} +ENV QDROUTERD_HOME=/home/skrouterd -# Build ioFog Router utility -FROM golang:1.21.5 AS go-builder +COPY LICENSE /licenses/LICENSE +COPY --from=go-builder /go/src/github.com/datasance/router/bin/router /home/skrouterd/bin/router -RUN mkdir -p /go/src/github.com/datasance/router -WORKDIR /go/src/github.com/datasance/router -COPY . /go/src/github.com/datasance/router -RUN go build -o bin/router - -# Build final image -FROM ubuntu:latest - -RUN apt-get update && \ - apt-get install -y python3 python3-dev iputils-ping libsasl2-modules nano && \ - apt-get -y clean - -COPY --from=qpid-builder /usr/lib/lib* /usr/lib/ -COPY --from=qpid-builder /usr/lib/python3 /usr/lib/python3 -COPY --from=qpid-builder /usr/lib/python3.10 /usr/lib/python3.10 -COPY --from=qpid-builder /usr/lib/ssl /usr/lib/ssl -COPY --from=qpid-builder /usr/lib/sasl2 /usr/lib/sasl2 -COPY --from=qpid-builder /usr/lib/openssh /usr/lib/openssh -COPY --from=qpid-builder /usr/lib/*-linux-* /usr/lib/ -COPY --from=qpid-builder /usr/sbin/qdrouterd /usr/sbin/qdrouterd -COPY --from=qpid-builder /usr/bin/qdmanage /usr/bin/qdmanage -COPY --from=qpid-builder /usr/bin/qdstat /usr/bin/qdstat - -COPY --from=qpid-builder /usr/lib/qpid-dispatch /usr/lib/qpid-dispatch -COPY --from=qpid-builder /usr/include/qpid /usr/include/qpid - -COPY --from=qpid-builder /usr/share/proton /usr/share/proton -COPY --from=qpid-builder /usr/include/proton /usr/include/proton -COPY --from=qpid-builder /usr/lib/pkgconfig/libqpid* /usr/lib/pkgconfig/ -COPY --from=qpid-builder /usr/lib/cmake/Proton /usr/lib/cmake/Proton -COPY --from=qpid-builder /usr/share/proton /usr/share/proton - -# Silly hack to fix layer issue in Azure Devops :-/ -RUN true -COPY --from=go-builder /go/src/github.com/datasance/router/bin/router /qpid-dispatch/router - -COPY scripts/launch.sh /qpid-dispatch/launch.sh - -ENV PYTHONPATH=/usr/lib/python3.10/site-packages -LABEL org.opencontainers.image.description Router -LABEL org.opencontainers.image.source=https://github.com/datasance/Router -LABEL org.opencontainers.image.licenses=EPL2.0 -CMD ["/qpid-dispatch/router"] +COPY --from=tz /usr/share/zoneinfo /usr/share/zoneinfo + +# Env: SKUPPER_PLATFORM=pot|kubernetes (default pot), QDROUTERD_CONF (default /tmp/skrouterd.json), +# SSL_PROFILE_PATH (default /etc/skupper-router-certs). In K8s mode operator mounts config at QDROUTERD_CONF. +CMD ["/home/skrouterd/bin/router"] \ No newline at end of file diff --git a/Dockerfile-dev b/Dockerfile-dev new file mode 100644 index 0000000..bb408ba --- /dev/null +++ b/Dockerfile-dev @@ -0,0 +1,23 @@ +FROM golang:1.23-alpine AS go-builder + +ARG TARGETOS +ARG TARGETARCH + +RUN mkdir -p /go/src/github.com/datasance/router +WORKDIR /go/src/github.com/datasance/router +COPY . /go/src/github.com/datasance/router +RUN go fmt ./... +RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -trimpath -ldflags="-s -w" -o bin/router . + +FROM registry.access.redhat.com/ubi9/ubi-minimal:latest AS tz +RUN microdnf install -y tzdata && microdnf reinstall -y tzdata + +FROM quay.io/skupper/skupper-router:main +COPY LICENSE /licenses/LICENSE +COPY --from=go-builder /go/src/github.com/datasance/router/bin/router /home/skrouterd/bin/router +COPY scripts/launch.sh /home/skrouterd/bin/launch.sh +COPY --from=tz /usr/share/zoneinfo /usr/share/zoneinfo + +# Env: SKUPPER_PLATFORM=pot|kubernetes (default pot), QDROUTERD_CONF (default /tmp/skrouterd.json), +# SSL_PROFILE_PATH (default /etc/skupper-router-certs). In K8s mode operator mounts config at QDROUTERD_CONF. +CMD ["/home/skrouterd/bin/router"] diff --git a/Dockerfile.adaptor b/Dockerfile.adaptor new file mode 100644 index 0000000..c10ba5c --- /dev/null +++ b/Dockerfile.adaptor @@ -0,0 +1,3 @@ +FROM quay.io/skupper/kube-adaptor:2.0.1 + +COPY LICENSE /licenses/LICENSE diff --git a/README.md b/README.md index 6fec2fc..d34b435 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,13 @@ # iofog-router -Builds an image of the Apache Qpid Dispatch Router designed for use with Eclipse ioFog +Builds an image of the Apache Qpid Dispatch Router designed for use with Eclipse ioFog and Datasance Pot. The router can run in **Pot** mode (config from iofog agent) or **Kubernetes** mode (config from a volume-mounted file at `QDROUTERD_CONF`). + +## Environment variables + +| Variable | Default | Description | +|----------|---------|-------------| +| `SKUPPER_PLATFORM` | `pot` | Mode: `pot` (config from iofog SDK) or `kubernetes` (config from file at `QDROUTERD_CONF`). | +| `QDROUTERD_CONF` | `/tmp/skrouterd.json` | Path to the router JSON config file. In Kubernetes mode the operator must volume-mount the router ConfigMap at this path. | +| `SSL_PROFILE_PATH` | `/etc/skupper-router-certs` | Directory under which SSL profile certs reside (e.g. `SSL_PROFILE_PATH//ca.crt`, `tls.crt`, `tls.key`). Certs are mounted here in both K8s and Pot. | + +In Kubernetes mode the router does not use the Kubernetes API; the operator is responsible for mounting the router config at `QDROUTERD_CONF`. Config file changes are watched and applied to the running router via qdr (same as Pot mode). diff --git a/go.mod b/go.mod index f6b52ed..fa169cd 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,29 @@ module github.com/datasance/router -go 1.16 +go 1.23.0 + +toolchain go1.24.3 + +require ( + github.com/datasance/iofog-go-sdk/v3 v3.7.0 + github.com/fsnotify/fsnotify v1.7.0 + github.com/interconnectedcloud/go-amqp v0.12.6-0.20200506124159-f51e540008b5 + gotest.tools/v3 v3.5.2 + k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 +) require ( - github.com/eclipse-iofog/iofog-go-sdk/v3 v3.0.0 + github.com/Azure/azure-sdk-for-go v68.0.0+incompatible // indirect + github.com/Azure/go-autorest/autorest v0.11.30 // indirect + github.com/Azure/go-autorest/autorest/adal v0.9.24 // indirect + github.com/Azure/go-autorest/autorest/to v0.4.1 // indirect + github.com/Azure/go-autorest/autorest/validation v0.3.2 // indirect + github.com/eapache/channels v1.1.0 // indirect + github.com/eapache/queue v1.1.0 // indirect + github.com/fortytw2/leaktest v1.3.0 // indirect + github.com/google/go-cmp v0.6.0 // indirect + github.com/gorilla/websocket v1.5.0 // indirect + github.com/pkg/errors v0.9.1 // indirect + golang.org/x/crypto v0.28.0 // indirect + golang.org/x/sys v0.26.0 // indirect ) diff --git a/go.sum b/go.sum index e584723..6038ece 100644 --- a/go.sum +++ b/go.sum @@ -1,540 +1,107 @@ -cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= -cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= -cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= -cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= -cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= -cloud.google.com/go v0.51.0/go.mod h1:hWtGJ6gnXH+KgDv+V0zFGDvpi07n3z8ZNj3T1RW0Gcw= -cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= -cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= -cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= -cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= -dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8= -github.com/Azure/go-autorest/autorest v0.9.0/go.mod h1:xyHB1BMZT0cuDHU7I0+g046+BFDTQ8rEZB0s4Yfa6bI= -github.com/Azure/go-autorest/autorest v0.9.6/go.mod h1:/FALq9T/kS7b5J5qsQ+RSTUdAmGFqi0vUdVNNx8q630= -github.com/Azure/go-autorest/autorest/adal v0.5.0/go.mod h1:8Z9fGy2MpX0PvDjB1pEgQTmVqjGhiHBW7RJJEciWzS0= -github.com/Azure/go-autorest/autorest/adal v0.8.2/go.mod h1:ZjhuQClTqx435SRJ2iMlOxPYt3d2C/T/7TiQCVZSn3Q= -github.com/Azure/go-autorest/autorest/date v0.1.0/go.mod h1:plvfp3oPSKwf2DNjlBjWF/7vwR+cUD/ELuzDCXwHUVA= -github.com/Azure/go-autorest/autorest/date v0.2.0/go.mod h1:vcORJHLJEh643/Ioh9+vPmf1Ij9AEBM5FuBIXLmIy0g= -github.com/Azure/go-autorest/autorest/mocks v0.1.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0= -github.com/Azure/go-autorest/autorest/mocks v0.2.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0= -github.com/Azure/go-autorest/autorest/mocks v0.3.0/go.mod h1:a8FDP3DYzQ4RYfVAxAN3SVSiiO77gL2j2ronKKP0syM= -github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6LSNgds39diKLz7Vrc= -github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbtp2fGCgRFtBroKn4Dk= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= -github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= -github.com/PuerkitoBio/purell v1.1.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= -github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= -github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= -github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= -github.com/agnivade/levenshtein v1.0.1/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM= -github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= -github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= -github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= -github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= -github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= -github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= -github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= -github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= -github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= -github.com/blang/semver v3.5.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= -github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= -github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= -github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= -github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8= -github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= -github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= -github.com/coreos/go-oidc v2.1.0+incompatible/go.mod h1:CgnwVTmzoESiwO9qyAFEMiHoZ1nMCKZlZ9V6mm3/LKc= -github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= -github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= -github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= -github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= -github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= -github.com/coreos/pkg v0.0.0-20180108230652-97fdf19511ea/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= -github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= -github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= +github.com/Azure/azure-sdk-for-go v68.0.0+incompatible h1:fcYLmCpyNYRnvJbPerq7U0hS+6+I79yEDJBqVNcqUzU= +github.com/Azure/azure-sdk-for-go v68.0.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= +github.com/Azure/go-autorest v14.2.0+incompatible h1:V5VMDjClD3GiElqLWO7mz2MxNAK/vTfRHdAubSIPRgs= +github.com/Azure/go-autorest v14.2.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24= +github.com/Azure/go-autorest/autorest v0.11.30 h1:iaZ1RGz/ALZtN5eq4Nr1SOFSlf2E4pDI3Tcsl+dZPVE= +github.com/Azure/go-autorest/autorest v0.11.30/go.mod h1:t1kpPIOpIVX7annvothKvb0stsrXa37i7b+xpmBW8Fs= +github.com/Azure/go-autorest/autorest/adal v0.9.22/go.mod h1:XuAbAEUv2Tta//+voMI038TrJBqjKam0me7qR+L8Cmk= +github.com/Azure/go-autorest/autorest/adal v0.9.24 h1:BHZfgGsGwdkHDyZdtQRQk1WeUdW0m2WPAwuHZwUi5i4= +github.com/Azure/go-autorest/autorest/adal v0.9.24/go.mod h1:7T1+g0PYFmACYW5LlG2fcoPiPlFHjClyRGL7dRlP5c8= +github.com/Azure/go-autorest/autorest/date v0.3.0 h1:7gUk1U5M/CQbp9WoqinNzJar+8KY+LPI6wiWrP/myHw= +github.com/Azure/go-autorest/autorest/date v0.3.0/go.mod h1:BI0uouVdmngYNUzGWeSYnokU+TrmwEsOqdt8Y6sso74= +github.com/Azure/go-autorest/autorest/mocks v0.4.1/go.mod h1:LTp+uSrOhSkaKrUy935gNZuuIPPVsHlr9DSOxSayd+k= +github.com/Azure/go-autorest/autorest/mocks v0.4.2/go.mod h1:Vy7OitM9Kei0i1Oj+LvyAWMXJHeKH1MVlzFugfVrmyU= +github.com/Azure/go-autorest/autorest/to v0.4.1 h1:CxNHBqdzTr7rLtdrtb5CMjJcDut+WNGCVv7OmS5+lTc= +github.com/Azure/go-autorest/autorest/to v0.4.1/go.mod h1:EtaofgU4zmtvn1zT2ARsjRFdq9vXx0YWtmElwL+GZ9M= +github.com/Azure/go-autorest/autorest/validation v0.3.2 h1:myD3tcvs+Fk1bkJ1Xx7xidop4z4FWvWADiMGMXeVd2E= +github.com/Azure/go-autorest/autorest/validation v0.3.2/go.mod h1:4z7eU88lSINAB5XL8mhfPumiUdoAQo/c7qXwbsM8Zhc= +github.com/Azure/go-autorest/logger v0.2.1 h1:IG7i4p/mDa2Ce4TRyAO8IHnVhAVF3RFU+ZtXWSmf4Tg= +github.com/Azure/go-autorest/logger v0.2.1/go.mod h1:T9E3cAhj2VqvPOtCYAvby9aBXkZmbF5NWuPV8+WeEW8= +github.com/Azure/go-autorest/tracing v0.6.0 h1:TYi4+3m5t6K48TGI9AUdb+IzbnSxvnvUMfuitfgcfuo= +github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBpUA79WCAKPPZVC2DeU= +github.com/datasance/iofog-go-sdk/v3 v3.7.0 h1:j9ceWQdOXVvF2xAjAtZ+19/28c2WUuM5g4kKG+LVYQQ= +github.com/datasance/iofog-go-sdk/v3 v3.7.0/go.mod h1:mLHD3oHazNzKsV8HoWDsI4g613fHs+rKPUFtYf0tB/U= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= -github.com/docker/docker v0.7.3-0.20190327010347-be7ac8be2ae0/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= -github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= -github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= -github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM= -github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE= -github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= -github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/eapache/channels v1.1.0 h1:F1taHcn7/F0i8DYqKXJnyhJcVpp2kgFcNePxXtnyu4k= github.com/eapache/channels v1.1.0/go.mod h1:jMm2qB5Ubtg9zLd+inMZd2/NUvXgzmWXsDaLyQIGfH0= github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc= github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= -github.com/eclipse-iofog/iofog-go-sdk v1.3.0 h1:6OD+WUw6bl/gDflGMID8xAvZDPGlKQcK/ONxTQa100k= -github.com/eclipse-iofog/iofog-go-sdk v1.3.0/go.mod h1:X9xGwzS9ySY5iqY5hpEK6mtWBvwr5EH8377kq+ohSVY= -github.com/eclipse-iofog/iofog-go-sdk/v3 v3.0.0 h1:tz80C5WKk5oMnCESJyPht3VNva5Fa034yg5Ok6Y6RO4= -github.com/eclipse-iofog/iofog-go-sdk/v3 v3.0.0/go.mod h1:qt3TNwMFti7JTxEmykMn0DgYvZ/fqmweBedu5H+VkbY= -github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= -github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= -github.com/emicklei/go-restful v2.9.5+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= -github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= -github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= -github.com/evanphx/json-patch v4.5.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= -github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= -github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= -github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q= -github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q= -github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= -github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= -github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= -github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas= -github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU= -github.com/go-logr/zapr v0.1.0/go.mod h1:tabnROwaDl0UNxkVeFRbY8bwB37GwRv0P8lg6aAiEnk= -github.com/go-openapi/analysis v0.0.0-20180825180245-b006789cd277/go.mod h1:k70tL6pCuVxPJOHXQ+wIac1FUrvNkHolPie/cLEU6hI= -github.com/go-openapi/analysis v0.17.0/go.mod h1:IowGgpVeD0vNm45So8nr+IcQ3pxVtpRoBWb8PVZO0ik= -github.com/go-openapi/analysis v0.18.0/go.mod h1:IowGgpVeD0vNm45So8nr+IcQ3pxVtpRoBWb8PVZO0ik= -github.com/go-openapi/analysis v0.19.2/go.mod h1:3P1osvZa9jKjb8ed2TPng3f0i/UY9snX6gxi44djMjk= -github.com/go-openapi/analysis v0.19.5/go.mod h1:hkEAkxagaIvIP7VTn8ygJNkd4kAYON2rCu0v0ObL0AU= -github.com/go-openapi/errors v0.17.0/go.mod h1:LcZQpmvG4wyF5j4IhA73wkLFQg+QJXOQHVjmcZxhka0= -github.com/go-openapi/errors v0.18.0/go.mod h1:LcZQpmvG4wyF5j4IhA73wkLFQg+QJXOQHVjmcZxhka0= -github.com/go-openapi/errors v0.19.2/go.mod h1:qX0BLWsyaKfvhluLejVpVNwNRdXZhEbTA4kxxpKBC94= -github.com/go-openapi/jsonpointer v0.0.0-20160704185906-46af16f9f7b1/go.mod h1:+35s3my2LFTysnkMfxsJBAMHj/DoqoB9knIWoYG/Vk0= -github.com/go-openapi/jsonpointer v0.17.0/go.mod h1:cOnomiV+CVVwFLk0A/MExoFMjwdsUdVpsRhURCKh+3M= -github.com/go-openapi/jsonpointer v0.18.0/go.mod h1:cOnomiV+CVVwFLk0A/MExoFMjwdsUdVpsRhURCKh+3M= -github.com/go-openapi/jsonpointer v0.19.2/go.mod h1:3akKfEdA7DF1sugOqz1dVQHBcuDBPKZGEoHC/NkiQRg= -github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= -github.com/go-openapi/jsonreference v0.0.0-20160704190145-13c6e3589ad9/go.mod h1:W3Z9FmVs9qj+KR4zFKmDPGiLdk1D9Rlm7cyMvf57TTg= -github.com/go-openapi/jsonreference v0.17.0/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3HfopLOL6uZrK/VgnsK9I= -github.com/go-openapi/jsonreference v0.18.0/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3HfopLOL6uZrK/VgnsK9I= -github.com/go-openapi/jsonreference v0.19.2/go.mod h1:jMjeRr2HHw6nAVajTXJ4eiUwohSTlpa0o73RUL1owJc= -github.com/go-openapi/jsonreference v0.19.3/go.mod h1:rjx6GuL8TTa9VaixXglHmQmIL98+wF9xc8zWvFonSJ8= -github.com/go-openapi/loads v0.17.0/go.mod h1:72tmFy5wsWx89uEVddd0RjRWPZm92WRLhf7AC+0+OOU= -github.com/go-openapi/loads v0.18.0/go.mod h1:72tmFy5wsWx89uEVddd0RjRWPZm92WRLhf7AC+0+OOU= -github.com/go-openapi/loads v0.19.0/go.mod h1:72tmFy5wsWx89uEVddd0RjRWPZm92WRLhf7AC+0+OOU= -github.com/go-openapi/loads v0.19.2/go.mod h1:QAskZPMX5V0C2gvfkGZzJlINuP7Hx/4+ix5jWFxsNPs= -github.com/go-openapi/loads v0.19.4/go.mod h1:zZVHonKd8DXyxyw4yfnVjPzBjIQcLt0CCsn0N0ZrQsk= -github.com/go-openapi/runtime v0.0.0-20180920151709-4f900dc2ade9/go.mod h1:6v9a6LTXWQCdL8k1AO3cvqx5OtZY/Y9wKTgaoP6YRfA= -github.com/go-openapi/runtime v0.19.0/go.mod h1:OwNfisksmmaZse4+gpV3Ne9AyMOlP1lt4sK4FXt0O64= -github.com/go-openapi/runtime v0.19.4/go.mod h1:X277bwSUBxVlCYR3r7xgZZGKVvBd/29gLDlFGtJ8NL4= -github.com/go-openapi/spec v0.0.0-20160808142527-6aced65f8501/go.mod h1:J8+jY1nAiCcj+friV/PDoE1/3eeccG9LYBs0tYvLOWc= -github.com/go-openapi/spec v0.17.0/go.mod h1:XkF/MOi14NmjsfZ8VtAKf8pIlbZzyoTvZsdfssdxcBI= -github.com/go-openapi/spec v0.18.0/go.mod h1:XkF/MOi14NmjsfZ8VtAKf8pIlbZzyoTvZsdfssdxcBI= -github.com/go-openapi/spec v0.19.2/go.mod h1:sCxk3jxKgioEJikev4fgkNmwS+3kuYdJtcsZsD5zxMY= -github.com/go-openapi/spec v0.19.3/go.mod h1:FpwSN1ksY1eteniUU7X0N/BgJ7a4WvBFVA8Lj9mJglo= -github.com/go-openapi/strfmt v0.17.0/go.mod h1:P82hnJI0CXkErkXi8IKjPbNBM6lV6+5pLP5l494TcyU= -github.com/go-openapi/strfmt v0.18.0/go.mod h1:P82hnJI0CXkErkXi8IKjPbNBM6lV6+5pLP5l494TcyU= -github.com/go-openapi/strfmt v0.19.0/go.mod h1:+uW+93UVvGGq2qGaZxdDeJqSAqBqBdl+ZPMF/cC8nDY= -github.com/go-openapi/strfmt v0.19.3/go.mod h1:0yX7dbo8mKIvc3XSKp7MNfxw4JytCfCD6+bY1AVL9LU= -github.com/go-openapi/swag v0.0.0-20160704191624-1d0bd113de87/go.mod h1:DXUve3Dpr1UfpPtxFw+EFuQ41HhCWZfha5jSVRG7C7I= -github.com/go-openapi/swag v0.17.0/go.mod h1:AByQ+nYG6gQg71GINrmuDXCPWdL640yX49/kXLo40Tg= -github.com/go-openapi/swag v0.18.0/go.mod h1:AByQ+nYG6gQg71GINrmuDXCPWdL640yX49/kXLo40Tg= -github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= -github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= -github.com/go-openapi/validate v0.18.0/go.mod h1:Uh4HdOzKt19xGIGm1qHf/ofbX1YQ4Y+MYsct2VUrAJ4= -github.com/go-openapi/validate v0.19.2/go.mod h1:1tRCw7m3jtI8eNWEEliiAqUIcBztB2KDnRCRMUi7GTA= -github.com/go-openapi/validate v0.19.5/go.mod h1:8DJv2CVJQ6kGNpFW6eV9N3JviE1C85nY1c2z52x1Gk4= -github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/gogo/protobuf v1.1.1/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.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= -github.com/golang/protobuf v0.0.0-20161109072736-4bd1920723d7/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= -github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= -github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= -github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= -github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= -github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= -github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= +github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= +github.com/golang-jwt/jwt/v4 v4.0.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg= +github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= +github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= -github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= -github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= -github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= -github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= -github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= -github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= -github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY= -github.com/googleapis/gnostic v0.1.0/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY= -github.com/googleapis/gnostic v0.3.1/go.mod h1:on+2t9HRStVgn95RSsFWFz+6Q0Snyqv1awfrALZdbtU= -github.com/googleapis/gnostic v0.4.1/go.mod h1:LRhVm6pbyptWbWbuZ38d1eyptfvIytN3ir6b65WBswg= -github.com/gophercloud/gophercloud v0.1.0/go.mod h1:vxM41WHh5uqHVBMZHzuwNOHh8XEoIEcSTewFxm1c5g8= -github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= -github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= -github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM= -github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= -github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= -github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= -github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= -github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= -github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= -github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= -github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= -github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= -github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= -github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= -github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= -github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= -github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= -github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= -github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= -github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= -github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= -github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= -github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= -github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= -github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= -github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= -github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= -github.com/mailru/easyjson v0.7.0/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs= -github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= -github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= -github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= -github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= -github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= -github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= -github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= -github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw= -github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= -github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= -github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.11.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= -github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= -github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= -github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= -github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= -github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= -github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= -github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= +github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/interconnectedcloud/go-amqp v0.12.6-0.20200506124159-f51e540008b5 h1:n3J6cCOpmsEXSEEFpXszM5kNsqtb7XiX3Q2bxeplWeQ= +github.com/interconnectedcloud/go-amqp v0.12.6-0.20200506124159-f51e540008b5/go.mod h1:laGtnFhRcIocSgShx6P6FqnRqQoaXGEz87QpNXSnPS8= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/pquerna/cachecontrol v0.0.0-20171018203845-0dec1b30a021/go.mod h1:prYjPmNq4d1NPVmpShWobRqXY3q7Vp+80DqgxxUrUIA= -github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= -github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= -github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= -github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= -github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= -github.com/prometheus/procfs v0.0.11/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= -github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= -github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= -github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= -github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= -github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= -github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= -github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= -github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= -github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= -github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= -github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= -github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= -github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= -github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= -github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= -github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= -github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= -github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= -github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= -github.com/vektah/gqlparser v1.1.2/go.mod h1:1ycwN7Ij5njmMkPPAOaRFY4rET2Enx7IkVv3vaXspKw= -github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= -github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= -go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= -go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg= -go.mongodb.org/mongo-driver v1.0.3/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM= -go.mongodb.org/mongo-driver v1.1.1/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM= -go.mongodb.org/mongo-driver v1.1.2/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM= -go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= -go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= -go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= -go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= -go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= -go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= -go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= -golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190320223903-b7391e95e576/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190617133340-57b3e21c3d56/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= -golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= -golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= -golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= -golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= -golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= -golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= -golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= -golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= -golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= -golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= -golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= -golang.org/x/net v0.0.0-20170114055629-f2499483f923/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181005035420-146acd28ed58/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190320064053-1272bf9dcd53/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= -golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= +golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw= +golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20170830134202-bb24a47a89ea/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190209173611-3b5209105503/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190321052220-f7bb7a8bee54/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191022100944-742c48ecaeb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200622214017-ed371f2e16b4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= +golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= +golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -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/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20181011042414-1f849cf54d09/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190125232054-d66bd3c5d5a6/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190614205625-5aca471b1d59/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190617190820-da514acc4774/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20190920225731-5eefd052ad72/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -gomodules.xyz/jsonpatch/v2 v2.0.1/go.mod h1:IhYNNY4jnS53ZnfE4PAmpKtDpTCj1JFXc+3mwe7XcUU= -google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= -google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= -google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= -google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= -google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= -google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= -google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= -google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= -google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= -google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= -google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= -google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= -google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= -google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= -gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= -gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= -gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= -gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= -gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= -gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= -gopkg.in/square/go-jose.v2 v2.2.2/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= -gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= -gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= -honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= -k8s.io/api v0.18.6/go.mod h1:eeyxr+cwCjMdLAmr2W3RyDI0VvTawSg/3RFFBEnmZGI= -k8s.io/api v0.19.4/go.mod h1:SbtJ2aHCItirzdJ36YslycFNzWADYH3tgOhvBEFtZAk= -k8s.io/apiextensions-apiserver v0.18.6/go.mod h1:lv89S7fUysXjLZO7ke783xOwVTm6lKizADfvUM/SS/M= -k8s.io/apimachinery v0.18.6/go.mod h1:OaXp26zu/5J7p0f92ASynJa1pZo06YlV9fG7BoWbCko= -k8s.io/apimachinery v0.19.4/go.mod h1:DnPGDnARWFvYa3pMHgSxtbZb7gpzzAZ1pTfaUNDVlmA= -k8s.io/apiserver v0.18.6/go.mod h1:Zt2XvTHuaZjBz6EFYzpp+X4hTmgWGy8AthNVnTdm3Wg= -k8s.io/client-go v0.18.6/go.mod h1:/fwtGLjYMS1MaM5oi+eXhKwG+1UHidUEXRh6cNsdO0Q= -k8s.io/client-go v0.19.4/go.mod h1:ZrEy7+wj9PjH5VMBCuu/BDlvtUAku0oVFk4MmnW9mWA= -k8s.io/code-generator v0.18.6/go.mod h1:TgNEVx9hCyPGpdtCWA34olQYLkh3ok9ar7XfSsr8b6c= -k8s.io/component-base v0.18.6/go.mod h1:knSVsibPR5K6EW2XOjEHik6sdU5nCvKMrzMt2D4In14= -k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= -k8s.io/gengo v0.0.0-20200114144118-36b2048a9120/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= -k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= -k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= -k8s.io/klog v0.3.0/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= -k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I= -k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE= -k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y= -k8s.io/kube-openapi v0.0.0-20200410145947-61e04a5be9a6/go.mod h1:GRQhZsXIAJ1xR0C9bd8UpWHZ5plfAS9fzPjJuQ6JL3E= -k8s.io/kube-openapi v0.0.0-20200805222855-6aeccd4b50c6/go.mod h1:UuqjUnNftUyPE5H64/qeyjQoUZhGpeFDVdxjTeEVN2o= -k8s.io/utils v0.0.0-20200324210504-a9aa75ae1b89/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew= -k8s.io/utils v0.0.0-20200603063816-c1c6865ac451/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= -k8s.io/utils v0.0.0-20200729134348-d5654de09c73/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= -rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= -sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.7/go.mod h1:PHgbrJT7lCHcxMU+mDHEm+nx46H4zuuHZkDP6icnhu0= -sigs.k8s.io/controller-runtime v0.6.4/go.mod h1:WlZNXcM0++oyaQt4B7C2lEE5JYRs8vJUzRP4N4JpdAY= -sigs.k8s.io/structured-merge-diff/v3 v3.0.0-20200116222232-67a7b8c61874/go.mod h1:PlARxl6Hbt/+BC80dRLi1qAmnMqwqDg62YvvVkZjemw= -sigs.k8s.io/structured-merge-diff/v3 v3.0.0/go.mod h1:PlARxl6Hbt/+BC80dRLi1qAmnMqwqDg62YvvVkZjemw= -sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw= -sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= -sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q= +gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA= +k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 h1:M3sRQVHv7vB20Xc2ybTt7ODCeFj6JSWYFzOFnYeS6Ro= +k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= diff --git a/internal/config/env.go b/internal/config/env.go new file mode 100644 index 0000000..e361cc5 --- /dev/null +++ b/internal/config/env.go @@ -0,0 +1,30 @@ +package config + +import ( + "os" + + "github.com/datasance/router/internal/resources/types" +) + +const ( + DefaultConfigPath = "/tmp/skrouterd.json" + DefaultSSLProfilePath = "/etc/skupper-router-certs" +) + +// GetConfigPath returns the router config file path from QDROUTERD_CONF, +// or DefaultConfigPath if unset. +func GetConfigPath() string { + if p := os.Getenv(types.TransportEnvConfig); p != "" { + return p + } + return DefaultConfigPath +} + +// GetSSLProfilePath returns the directory under which SSL profile certs +// reside (SSL_PROFILE_PATH env), or DefaultSSLProfilePath if unset. +func GetSSLProfilePath() string { + if p := os.Getenv(types.EnvSSLProfilePath); p != "" { + return p + } + return DefaultSSLProfilePath +} diff --git a/internal/config/env_test.go b/internal/config/env_test.go new file mode 100644 index 0000000..b21b8ee --- /dev/null +++ b/internal/config/env_test.go @@ -0,0 +1,44 @@ +package config + +import ( + "os" + "testing" + + "github.com/datasance/router/internal/resources/types" +) + +func TestGetConfigPath(t *testing.T) { + key := types.TransportEnvConfig + defer func() { _ = os.Unsetenv(key) }() + + // Default when unset + os.Unsetenv(key) + if got := GetConfigPath(); got != DefaultConfigPath { + t.Errorf("GetConfigPath() with unset env = %q, want %q", got, DefaultConfigPath) + } + + // Uses env when set + want := "/custom/skrouterd.json" + os.Setenv(key, want) + if got := GetConfigPath(); got != want { + t.Errorf("GetConfigPath() with env set = %q, want %q", got, want) + } +} + +func TestGetSSLProfilePath(t *testing.T) { + key := types.EnvSSLProfilePath + defer func() { _ = os.Unsetenv(key) }() + + // Default when unset + os.Unsetenv(key) + if got := GetSSLProfilePath(); got != DefaultSSLProfilePath { + t.Errorf("GetSSLProfilePath() with unset env = %q, want %q", got, DefaultSSLProfilePath) + } + + // Uses env when set + want := "/custom/certs" + os.Setenv(key, want) + if got := GetSSLProfilePath(); got != want { + t.Errorf("GetSSLProfilePath() with env set = %q, want %q", got, want) + } +} diff --git a/internal/config/platform.go b/internal/config/platform.go new file mode 100644 index 0000000..fd2b5b4 --- /dev/null +++ b/internal/config/platform.go @@ -0,0 +1,73 @@ +package config + +import ( + "os" + "slices" + "strings" + + "github.com/datasance/router/internal/resources/types" + "github.com/datasance/router/internal/utils" + "k8s.io/utils/ptr" +) + +var ( + Platform string + configuredPlatform *types.Platform +) + +func ClearPlatform() { + configuredPlatform = nil +} + +// GetPlatform returns the runtime platform defined, +// where the lookup goes through the following sequence: +// - Platform variable, +// - SKUPPER_PLATFORM environment variable +// - Static platform defined by skupper switch +// - Default platform "kubernetes" otherwise. +// In case the defined platform is invalid, "kubernetes" +// will be returned. +func GetPlatform() types.Platform { + if configuredPlatform != nil { + return *configuredPlatform + } + + var platform types.Platform + for i, arg := range os.Args { + if slices.Contains([]string{"--platform", "-p"}, arg) && i+1 < len(os.Args) { + platformArg := os.Args[i+1] + platform = types.Platform(platformArg) + break + } else if strings.HasPrefix(arg, "--platform=") || strings.HasPrefix(arg, "-p=") { + platformArg := strings.Split(arg, "=")[1] + platform = types.Platform(platformArg) + break + } + } + if platform == "" { + platform = types.Platform(utils.DefaultStr(Platform, + os.Getenv(types.ENV_PLATFORM), + string(types.PlatformKubernetes))) + } + switch platform { + case types.PlatformPodman: + configuredPlatform = &platform + case types.PlatformDocker: + configuredPlatform = &platform + case types.PlatformLinux: + configuredPlatform = &platform + case types.PlatformPot: + configuredPlatform = &platform + case types.PlatformKubernetes: + configuredPlatform = &platform + default: + configuredPlatform = ptr.To(types.PlatformKubernetes) + } + return *configuredPlatform +} + +// IsKubernetesRouterMode returns true when SKUPPER_PLATFORM is "kubernetes" +// (router config from ConfigMap). Default is pot (config from iofog SDK). +func IsKubernetesRouterMode() bool { + return os.Getenv(types.ENV_PLATFORM) == string(types.PlatformKubernetes) +} diff --git a/internal/exec/exec.go b/internal/exec/exec.go index 838860a..806c2e0 100644 --- a/internal/exec/exec.go +++ b/internal/exec/exec.go @@ -22,7 +22,7 @@ import ( ) func Run(ch chan<- error, command string, args []string, env []string) { - log.Printf("Running command: %s with args: %v and env vars: %v", command, args, env) + // log.Printf("Running command: %s with args: %v and env vars: %v", command, args, env) cmd := exec.Command(command, args...) cmd.Env = append(os.Environ(), env...) diff --git a/internal/messaging/messaging.go b/internal/messaging/messaging.go new file mode 100644 index 0000000..ad16a2f --- /dev/null +++ b/internal/messaging/messaging.go @@ -0,0 +1,27 @@ +package messaging + +import ( + amqp "github.com/interconnectedcloud/go-amqp" +) + +type ConnectionFactory interface { + Connect() (Connection, error) + Url() string +} + +type Connection interface { + Sender(address string) (Sender, error) + Receiver(address string, credit uint32) (Receiver, error) + Close() +} + +type Sender interface { + Send(msg *amqp.Message) error + Close() error +} + +type Receiver interface { + Receive() (*amqp.Message, error) + Accept(*amqp.Message) error + Close() error +} diff --git a/internal/qdr/amqp_mgmt.go b/internal/qdr/amqp_mgmt.go new file mode 100644 index 0000000..980ea55 --- /dev/null +++ b/internal/qdr/amqp_mgmt.go @@ -0,0 +1,1379 @@ +package qdr + +import ( + "context" + "encoding/json" + "fmt" + "log" + "os" + "strconv" + "strings" + "time" + + "github.com/datasance/router/internal/config" + "github.com/datasance/router/internal/resources/types" + "github.com/datasance/router/internal/utils" + amqp "github.com/interconnectedcloud/go-amqp" +) + +type RouterNode struct { + Id string `json:"id"` + Name string `json:"name"` + NextHop string `json:"nextHop"` + Address string `json:"address"` +} + +func (r *RouterNode) IsSelf() bool { + return r.NextHop == "(self)" +} + +type Connection struct { + Container string `json:"container"` + OperStatus string `json:"operStatus"` + Host string `json:"host"` + Role string `json:"role"` + Active bool `json:"active"` + Dir string `json:"dir"` +} + +type Agent struct { + connection *amqp.Client + session *amqp.Session + sender *amqp.Sender + anonymous *amqp.Sender + receiver *amqp.Receiver + local *Router + closed bool +} + +type Router struct { + Id string + Address string + Edge bool + Site SiteMetadata + Version string + ConnectedTo []string +} + +type SiteMetadata struct { + Id string `json:"id,omitempty"` + Version string `json:"version,omitempty"` + Platform string `json:"platform,omitempty"` +} + +func GetSiteMetadata(metadata string) SiteMetadata { + result := SiteMetadata{} + err := json.Unmarshal([]byte(metadata), &result) + if err != nil { + log.Printf("Assuming old format for router metadata %s: %s", metadata, err) + // assume old format, where metadata just holds site id + result.Id = metadata + } + return result +} + +func getSiteMetadataString(siteId string, version string) string { + siteDetails := SiteMetadata{ + Id: siteId, + Version: version, + Platform: string(config.GetPlatform()), + } + metadata, _ := json.Marshal(siteDetails) + return string(metadata) +} + +type recordType interface { + toRecord() Record +} + +type Record map[string]interface{} + +func (r Record) AsString(field string) string { + if value, ok := r[field].(string); ok { + return value + } else { + return "" + } +} + +func (r Record) AsBool(field string) bool { + if value, ok := r[field].(bool); ok { + return value + } else { + return false + } +} + +func (r Record) AsInt(field string) int { + value, _ := AsInt(r[field]) + return value +} + +func (r Record) AsUint64(field string) uint64 { + value, _ := AsUint64(r[field]) + return value +} + +func (r Record) AsRecord(field string) Record { + if value, ok := r[field].(map[string]interface{}); ok { + return value + } else { + return nil + } +} + +func asTcpEndpoint(record Record) TcpEndpoint { + endpoint := TcpEndpoint{ + Name: record.AsString("name"), + Host: record.AsString("host"), + Port: record.AsString("port"), + Address: record.AsString("address"), + SiteId: record.AsString("siteId"), + SslProfile: record.AsString("sslProfile"), + ProcessID: record.AsString("processId"), + } + if value, ok := record["verifyHostname"]; ok { + if verify, ok := value.(bool); ok { + endpoint.VerifyHostname = &verify + } + } + return endpoint +} + +func asConnection(record Record) Connection { + return Connection{ + Role: record.AsString("role"), + Container: record.AsString("container"), + Host: record.AsString("host"), + OperStatus: record.AsString("operStatus"), + Dir: record.AsString("dir"), + Active: record.AsBool("active"), + } +} + +func asRouterNode(record Record) RouterNode { + return RouterNode{ + Id: record.AsString("id"), + Name: record.AsString("name"), + Address: record.AsString("address"), + NextHop: record.AsString("nextHop"), + } +} + +func asRouter(record Record) *Router { + r := Router{ + Id: record.AsString("id"), + Site: GetSiteMetadata(record.AsString("metadata")), + Version: record.AsString("version"), + } + if record.AsString("mode") == "edge" { + r.Edge = true + } else { + r.Edge = false + } + r.Address = GetRouterAgentAddress(r.Id, r.Edge) + return &r +} + +func (node *RouterNode) AsRouter() *Router { + return &Router{ + Id: node.Id, + // SiteId ??? + Address: node.Address, + Edge: false, /*RouterNode is always an interior*/ + } +} + +type AgentPool struct { + url string + config TlsConfigRetriever + pool chan *Agent +} + +func NewAgentPool(url string, config TlsConfigRetriever) *AgentPool { + return &AgentPool{ + url: url, + config: config, + pool: make(chan *Agent, 10), + } +} + +func (p *AgentPool) Get() (*Agent, error) { + var a *Agent + var err error + select { + case a = <-p.pool: + default: + a, err = Connect(p.url, p.config) + } + return a, err +} + +func (p *AgentPool) Put(a *Agent) { + if !a.closed { + select { + case p.pool <- a: + default: + a.Close() + } + } +} + +func Connect(url string, config TlsConfigRetriever) (*Agent, error) { + factory := ConnectionFactory{ + url: url, + config: config, + } + return newAgent(&factory) +} + +func newAgent(factory *ConnectionFactory) (*Agent, error) { + client, err := factory.Connect() + if err != nil { + return nil, fmt.Errorf("Failed to create connection: %s", err) + } + connection := client.(*AmqpConnection) + receiver, err := connection.session.NewReceiver( + amqp.LinkSourceAddress(""), + amqp.LinkAddressDynamic(), + amqp.LinkCredit(10), + ) + if err != nil { + return nil, fmt.Errorf("Failed to create receiver: %s", err) + } + sender, err := connection.session.NewSender( + amqp.LinkTargetAddress("$management"), + ) + if err != nil { + return nil, fmt.Errorf("Failed to create sender: %s", err) + } + anonymous, err := connection.session.NewSender() + if err != nil { + return nil, fmt.Errorf("Failed to create anonymous sender: %s", err) + } + a := &Agent{ + connection: connection.client, + session: connection.session, + sender: sender, + anonymous: anonymous, + receiver: receiver, + } + a.local, err = a.GetLocalRouter() + if err != nil { + return a, fmt.Errorf("Failed to lookup local router details: %s", err) + } + return a, nil +} + +func (a *Agent) newReceiver(address string) (*amqp.Receiver, error) { + return a.session.NewReceiver( + amqp.LinkSourceAddress(address), + amqp.LinkCredit(10), + ) +} + +func (a *Agent) Close() error { + a.closed = true + return a.connection.Close() +} + +func isOk(code int) bool { + return code >= 200 && code < 300 +} + +func cleanup(input interface{}) interface{} { + switch input.(type) { + case map[interface{}]interface{}: + m := make(map[string]interface{}) + for k, v := range input.(map[interface{}]interface{}) { + m[k.(string)] = cleanup(v) + } + return m + case map[string]interface{}: + m := input.(map[string]interface{}) + for k, v := range m { + m[k] = cleanup(v) + } + return m + default: + return input + } +} + +func makeRecord(fields []string, values []interface{}) Record { + record := Record{} + for i, name := range fields { + record[name] = cleanup(values[i]) + } + return record +} + +func stringify(items []interface{}) []string { + s := make([]string, len(items)) + for i := range items { + s[i] = fmt.Sprintf("%v", items[i]) + } + return s +} + +func GetRouterAgentAddress(id string, edge bool) string { + if edge { + return "amqp:/_edge/" + id + "/$management" + } else { + return "amqp:/_topo/0/" + id + "/$management" + } +} + +func GetRouterAddress(id string, edge bool) string { + if edge { + return "amqp:/_edge/" + id + } else { + return "amqp:/_topo/0/" + id + } +} + +func (a *Agent) request(operation string, typename string, name string, attributes map[string]interface{}) error { + ctx, cancel := context.WithTimeout(context.TODO(), 5*time.Second) + defer cancel() + + var request amqp.Message + var properties amqp.MessageProperties + properties.ReplyTo = a.receiver.Address() + properties.CorrelationID = uint64(1) + request.Properties = &properties + request.ApplicationProperties = make(map[string]interface{}) + request.ApplicationProperties["operation"] = operation + request.ApplicationProperties["type"] = typename + request.ApplicationProperties["name"] = name + if attributes != nil { + request.Value = attributes + } + + if err := a.sender.Send(ctx, &request); err != nil { + a.Close() + return fmt.Errorf("Could not send request: %s", err) + } + + response, err := a.receiver.Receive(ctx) + if err != nil { + a.Close() + return fmt.Errorf("Failed to receive response: %s", err) + } + response.Accept() + if status, ok := AsInt(response.ApplicationProperties["statusCode"]); !ok && !isOk(status) { + return fmt.Errorf("Query failed with: %s", response.ApplicationProperties["statusDescription"]) + } + return nil +} + +func (a *Agent) Create(typename string, name string, entity recordType) error { + attributes := entity.toRecord() + log.Println("CREATE", typename, name, attributes) + return a.request("CREATE", typename, name, attributes) +} + +func (a *Agent) Update(typename string, name string, entity recordType) error { + attributes := entity.toRecord() + log.Println("UPDATE", typename, name, attributes) + return a.request("UPDATE", typename, name, attributes) +} + +func (a *Agent) Delete(typename string, name string) error { + if name == "" { + return fmt.Errorf("Cannot delete entity of type %s with no name", typename) + } + log.Println("DELETE", typename, name) + return a.request("DELETE", typename, name, nil) +} + +func (a *Agent) Query(typename string, attributes []string) ([]Record, error) { + return a.QueryRouterNode(typename, attributes, nil) +} + +func (a *Agent) QueryRouterNode(typename string, attributes []string, node *RouterNode) ([]Record, error) { + var address string + if node != nil { + address = node.Address + } + return a.QueryByAgentAddress(typename, attributes, address) +} + +func AsInt(value interface{}) (int, bool) { + switch value.(type) { + case uint8: + return int(value.(uint8)), true + case uint16: + return int(value.(uint16)), true + case uint32: + return int(value.(uint32)), true + case uint64: + return int(value.(uint64)), true + case int8: + return int(value.(int8)), true + case int16: + return int(value.(int16)), true + case int32: + return int(value.(int32)), true + case int64: + return int(value.(int64)), true + case int: + return value.(int), true + default: + return 0, false + } +} + +func AsUint64(value interface{}) (uint64, bool) { + switch value.(type) { + case uint8: + return uint64(value.(uint8)), true + case uint16: + return uint64(value.(uint16)), true + case uint32: + return uint64(value.(uint32)), true + case uint64: + return value.(uint64), true + case int8: + return uint64(value.(int8)), true + case int16: + return uint64(value.(int16)), true + case int32: + return uint64(value.(int32)), true + case int64: + return uint64(value.(int64)), true + case int: + return uint64(value.(int)), true + default: + return 0, false + } +} + +func (a *Agent) QueryByAgentAddress(typename string, attributes []string, agent string) ([]Record, error) { + ctx, cancel := context.WithTimeout(context.TODO(), 5*time.Second) + defer cancel() + + var request amqp.Message + var properties amqp.MessageProperties + properties.ReplyTo = a.receiver.Address() + properties.CorrelationID = uint64(1) + request.Properties = &properties + request.ApplicationProperties = make(map[string]interface{}) + request.ApplicationProperties["operation"] = "QUERY" + request.ApplicationProperties["entityType"] = typename + var body = make(map[string]interface{}) + body["attributeNames"] = attributes + request.Value = body + + var err error + if agent == "" { + err = a.sender.Send(ctx, &request) + } else { + request.Properties.To = agent + err = a.anonymous.Send(ctx, &request) + } + if err != nil { + a.Close() + return nil, fmt.Errorf("Could not send request: %s", err) + } + + response, err := a.receiver.Receive(ctx) + if err != nil { + a.Close() + return nil, fmt.Errorf("Failed to receive response: %s", err) + } + response.Accept() + if status, ok := AsInt(response.ApplicationProperties["statusCode"]); ok && isOk(status) { + if top, ok := response.Value.(map[string]interface{}); ok { + records := []Record{} + fields := stringify(top["attributeNames"].([]interface{})) + results := top["results"].([]interface{}) + for _, r := range results { + o := r.([]interface{}) + records = append(records, makeRecord(fields, o)) + } + return records, nil + } else { + return nil, fmt.Errorf("Bad response: %s", response.Value) + } + } else { + return nil, fmt.Errorf("Query failed with: %s", response.ApplicationProperties["statusDescription"]) + } +} + +type Query struct { + typename string + attributes []string + agent string +} + +func queryAllAgents(typename string, agents []string) []Query { + queries := make([]Query, len(agents)) + for i, a := range agents { + queries[i].typename = typename + queries[i].attributes = []string{} + queries[i].agent = a + } + return queries +} + +func queryAllTypes(typenames []string, agent string) []Query { + queries := make([]Query, len(typenames)) + for i, t := range typenames { + queries[i].typename = t + queries[i].attributes = []string{} + queries[i].agent = agent + } + return queries +} + +func queryAllAgentsForAllTypes(typenames []string, agents []string) []Query { + queries := make([]Query, len(agents)*len(typenames)) + i := 0 + for _, t := range typenames { + for _, a := range agents { + queries[i].typename = t + queries[i].attributes = []string{} + queries[i].agent = a + i++ + } + } + return queries +} + +func (a *Agent) BatchQuery(queries []Query) ([][]Record, error) { + fmt.Printf("BatchQuery(%v)\n", queries) + ctx, cancel := context.WithTimeout(context.TODO(), 5*time.Second) + defer cancel() + + batchResults := make([][]Record, len(queries)) + for i, q := range queries { + var request amqp.Message + var properties amqp.MessageProperties + properties.ReplyTo = a.receiver.Address() + properties.CorrelationID = uint64(i) + request.Properties = &properties + request.ApplicationProperties = make(map[string]interface{}) + request.ApplicationProperties["operation"] = "QUERY" + request.ApplicationProperties["entityType"] = q.typename + var body = make(map[string]interface{}) + body["attributeNames"] = q.attributes + request.Value = body + + var err error + if q.agent == "" { + err = a.sender.Send(ctx, &request) + } else { + request.Properties.To = q.agent + err = a.anonymous.Send(ctx, &request) + } + if err != nil { + a.Close() + return nil, fmt.Errorf("Could not send request: %s", err) + } + } + errors := []string{} + for i := 0; i < len(queries); i++ { + fmt.Printf("Waiting for response %d of %d\n", (i + 1), len(queries)) + response, err := a.receiver.Receive(ctx) + if err != nil { + a.Close() + return nil, fmt.Errorf("Failed to receive response: %s", err) + } + response.Accept() + responseIndex, ok := response.Properties.CorrelationID.(uint64) + if !ok { + errors = append(errors, fmt.Sprintf("Could not get correct correlation id from response: %#v (%T)", response.Properties.CorrelationID, response.Properties.CorrelationID)) + } else { + if status, ok := AsInt(response.ApplicationProperties["statusCode"]); ok && isOk(status) { + if top, ok := response.Value.(map[string]interface{}); ok { + records := []Record{} + fields := stringify(top["attributeNames"].([]interface{})) + results := top["results"].([]interface{}) + for _, r := range results { + o := r.([]interface{}) + records = append(records, makeRecord(fields, o)) + } + batchResults[responseIndex] = records + } else { + errors = append(errors, fmt.Sprintf("Bad response: %s", response.Value)) + } + } else { + errors = append(errors, fmt.Sprintf("Query failed with: %s", response.ApplicationProperties["statusDescription"])) + } + } + } + if len(errors) > 0 { + return nil, fmt.Errorf(strings.Join(errors, ", ")) + } + return batchResults, nil +} + +func (a *Agent) GetInteriorNodes() ([]RouterNode, error) { + var address string + var err error + if a.isEdgeRouter() { + address, err = a.getInteriorAddressForUplink() + if err != nil { + return nil, fmt.Errorf("Could not determine interior agent address for edge router: %s", err) + } + } + records, err := a.QueryByAgentAddress("io.skupper.router.router.node", []string{}, address) + if err != nil { + return nil, err + } + fmt.Printf("Interior nodes are %v\n", records) + nodes := make([]RouterNode, len(records)) + for i, r := range records { + nodes[i] = asRouterNode(r) + } + return nodes, nil +} + +func (a *Agent) GetConnections() ([]Connection, error) { + return a.GetConnectionsFor("") +} + +func (a *Agent) GetConnectionsFor(agent string) ([]Connection, error) { + records, err := a.Query("io.skupper.router.connection", []string{}) + if err != nil { + return nil, err + } + connections := make([]Connection, len(records)) + for i, r := range records { + connections[i] = asConnection(r) + } + return connections, nil +} + +func getAddressesFor(routers []Router) []string { + agents := make([]string, len(routers)) + for i, r := range routers { + agents[i] = r.Address + "/$management" + } + return agents +} + +func getBridgeServerAddressesFor(routers []Router) []string { + agents := make([]string, len(routers)) + for i, r := range routers { + agents[i] = r.Id + "/bridge-server/$management" + } + return agents +} + +func GetRoutersForSite(routers []Router, siteId string) []Router { + list := []Router{} + for _, r := range routers { + if r.Site.Id == siteId { + list = append(list, r) + } + } + return list +} + +func (a *Agent) GetAllRouters() ([]Router, error) { + nodes, err := a.GetInteriorNodes() + if err != nil { + return nil, err + } + routers := []Router{} + routersFiltered := []Router{} + for _, n := range nodes { + routers = append(routers, *n.AsRouter()) + } + edges, err := a.getAllEdgeRouters(getAddressesFor(routers)) + if err != nil { + return nil, err + } + for _, e := range edges { + routers = append(routers, e) + } + err = a.getSiteIds(routers) + if err != nil { + return nil, err + } + isSvcRouter := func(edgeId string) bool { + for _, r := range routers { + if r.Edge { + continue + } + // podman svc + if strings.HasPrefix(edgeId, r.Site.Id+"-") { + return true + } else if strings.HasSuffix(edgeId, "-"+r.Site.Id) { + return true + } + } + return false + } + for _, r := range routers { + if !r.Edge || !isSvcRouter(r.Site.Id) { + routersFiltered = append(routersFiltered, r) + } + } + routers = routersFiltered + err = a.getConnectedTo(routers) + if err != nil { + return nil, err + } + return routers, nil +} + +func (a *Agent) getConnectionsForAll(agents []string) ([]Connection, error) { + connections := []Connection{} + results, err := a.BatchQuery(queryAllAgents("io.skupper.router.connection", agents)) + if err != nil { + return nil, err + } + for _, records := range results { + for _, r := range records { + connections = append(connections, asConnection(r)) + } + } + return connections, nil +} + +func (a *Agent) getSiteIds(routers []Router) error { + results, err := a.BatchQuery(queryAllAgents("io.skupper.router.router", getAddressesFor(routers))) + if err != nil { + return err + } + for i, records := range results { + if len(records) == 1 { + routers[i].Site = GetSiteMetadata(records[0].AsString("metadata")) + } else { + return fmt.Errorf("Unexpected number of router records: %d", len(records)) + } + } + return nil +} + +func (a *Agent) getConnectedTo(routers []Router) error { + results, err := a.BatchQuery(queryAllAgents("io.skupper.router.connection", getAddressesFor(routers))) + if err != nil { + return err + } + for i, records := range results { + routers[i].ConnectedTo = []string{} + for _, r := range records { + c := asConnection(r) + if c.Dir == "out" && (c.Role == "edge" || c.Role == "inter-router") { + routers[i].ConnectedTo = append(routers[i].ConnectedTo, c.Container) + } + } + } + return nil +} + +func getBridgeTypes() []string { + return []string{ + "io.skupper.router.tcpConnector", + "io.skupper.router.tcpListener", + "io.skupper.router.httpConnector", + "io.skupper.router.httpListener", + } +} + +type TcpEndpointFilter func(*TcpEndpoint) bool + +func asTcpEndpoints(records []Record, filter TcpEndpointFilter) []TcpEndpoint { + endpoints := []TcpEndpoint{} + for _, record := range records { + endpoint := asTcpEndpoint(record) + if filter == nil || filter(&endpoint) { + endpoints = append(endpoints, endpoint) + } + } + return endpoints +} + +func (a *Agent) getLocalTcpEndpoints(typename string, filter TcpEndpointFilter) ([]TcpEndpoint, error) { + results, err := a.Query(typename, []string{}) + if err != nil { + return nil, err + } + records := asTcpEndpoints(results, filter) + return records, nil +} + +func (a *Agent) GetConnectorByName(name string) (*Connector, error) { + + results, err := a.Query("io.skupper.router.connector", []string{}) + if err != nil { + return nil, err + } + for _, record := range results { + + result := asConnector(record) + + if result.Name == name { + return &result, nil + } + } + + return nil, nil +} + +func (a *Agent) GetSslProfileByName(name string) (*SslProfile, error) { + + results, err := a.Query("io.skupper.router.sslProfile", []string{}) + if err != nil { + return nil, err + } + for _, record := range results { + + result := asSslProfile(record) + + if result.Name == name { + return &result, nil + } + } + + return nil, nil +} + +func (a *Agent) GetSslProfiles() (map[string]SslProfile, error) { + results, err := a.Query("io.skupper.router.sslProfile", []string{}) + if err != nil { + return nil, err + } + profiles := map[string]SslProfile{} + for _, record := range results { + profile := asSslProfile(record) + profiles[profile.Name] = profile + } + + return profiles, nil +} + +func (a *Agent) GetLocalTcpListeners(filter TcpEndpointFilter) ([]TcpEndpoint, error) { + return a.getLocalTcpEndpoints("io.skupper.router.tcpListener", filter) +} + +func (a *Agent) GetLocalTcpConnectors(filter TcpEndpointFilter) ([]TcpEndpoint, error) { + return a.getLocalTcpEndpoints("io.skupper.router.tcpConnector", filter) +} + +func (a *Agent) GetLocalBridgeConfig() (*BridgeConfig, error) { + config := NewBridgeConfig() + + results, err := a.Query("io.skupper.router.tcpConnector", []string{}) + if err != nil { + return nil, err + } + for _, record := range results { + config.AddTcpConnector(asTcpEndpoint(record)) + } + + results, err = a.Query("io.skupper.router.tcpListener", []string{}) + if err != nil { + return nil, err + } + for _, record := range results { + config.AddTcpListener(asTcpEndpoint(record)) + } + + return &config, nil +} + +func (a *Agent) UpdateLocalBridgeConfig(changes *BridgeConfigDifference) error { + for _, deleted := range changes.TcpConnectors.Deleted { + if err := a.Delete("io.skupper.router.tcpConnector", deleted); err != nil { + return fmt.Errorf("Error deleting tcp connectors: %s", err) + } + } + for _, deleted := range changes.TcpListeners.Deleted { + if err := a.Delete("io.skupper.router.tcpListener", deleted); err != nil { + return fmt.Errorf("Error deleting tcp listeners: %s", err) + } + } + for _, added := range changes.TcpConnectors.Added { + if err := a.Create("io.skupper.router.tcpConnector", added.Name, added); err != nil { + return fmt.Errorf("Error adding tcp connectors: %s", err) + } + } + for _, added := range changes.TcpListeners.Added { + if err := a.Create("io.skupper.router.tcpListener", added.Name, added); err != nil { + return fmt.Errorf("Error adding tcp listeners: %s", err) + } + } + return nil +} + +func (a *Agent) GetBridges(routers []Router) ([]BridgeConfig, error) { + configs := []BridgeConfig{} + agents := getAddressesFor(routers) + for _, agent := range agents { + config := NewBridgeConfig() + + results, err := a.QueryByAgentAddress("io.skupper.router.tcpConnector", []string{}, agent) + if err != nil { + return nil, err + } + for _, record := range results { + config.AddTcpConnector(asTcpEndpoint(record)) + } + results, err = a.QueryByAgentAddress("io.skupper.router.tcpListener", []string{}, agent) + if err != nil { + return nil, err + } + for _, record := range results { + config.AddTcpListener(asTcpEndpoint(record)) + } + + configs = append(configs, config) + } + return configs, nil +} + +const ( + DirectionIn string = "in" + DirectionOut string = "out" +) + +type TcpConnection struct { + Name string `json:"name"` + Host string `json:"host"` + Address string `json:"address"` + Direction string `json:"direction"` + BytesIn int `json:"bytesIn"` + BytesOut int `json:"bytesOut"` + Uptime uint64 `json:"uptimeSeconds"` + LastIn uint64 `json:"lastInSeconds"` + LastOut uint64 `json:"lastOutSeconds"` +} + +func getTcpConnectionsFromRecords(records []Record) ([]TcpConnection, error) { + conns := []TcpConnection{} + for _, record := range records { + var conn TcpConnection + if err := convert(record, &conn); err != nil { + return conns, fmt.Errorf("Failed to convert to TcpConnection: %s", err) + } + conns = append(conns, conn) + } + return conns, nil +} + +func (a *Agent) GetTcpConnections(routers []Router) ([][]TcpConnection, error) { + queries := queryAllAgents("io.skupper.router.tcpConnection", getAddressesFor(routers)) + results, err := a.BatchQuery(queries) + if err != nil { + return nil, err + } + converted := [][]TcpConnection{} + for _, records := range results { + conns, err := getTcpConnectionsFromRecords(records) + if err != nil { + return converted, err + } + converted = append(converted, conns) + } + return converted, nil +} + +func (a *Agent) GetLocalTcpConnections() ([]TcpConnection, error) { + records, err := a.Query("io.skupper.router.tcpConnection", []string{}) + if err != nil { + return nil, err + } + return getTcpConnectionsFromRecords(records) +} + +func (a *Agent) getAllEdgeRouters(agents []string) ([]Router, error) { + edges := []Router{} + + connections, err := a.getConnectionsForAll(agents) + if err != nil { + return nil, err + } + for _, c := range connections { + if c.Role == "edge" && c.Dir == DirectionIn { + router := Router{ + Id: c.Container, + Edge: true, + Address: GetRouterAddress(c.Container, true), + } + edges = append(edges, router) + } + } + return edges, nil +} + +func (a *Agent) getEdgeRouters(agent string) ([]Router, error) { + connections, err := a.GetConnectionsFor(agent) + if err != nil { + return nil, err + } + edges := []Router{} + for _, c := range connections { + if c.Role == "edge" && c.Dir == DirectionIn { + router := Router{ + Id: c.Container, + Edge: true, + Address: GetRouterAddress(c.Container, true), + } + edges = append(edges, router) + } + } + return edges, nil +} + +func (a *Agent) GetLocalGateways() ([]Router, error) { + gateways := []Router{} + connections, err := a.GetConnections() + if err != nil { + return gateways, err + } + for _, c := range connections { + if c.Role == "edge" && c.Dir == DirectionIn && isGateway(c.Container) { + router := Router{ + Id: c.Container, + Edge: true, + Address: GetRouterAddress(c.Container, true), + } + gateways = append(gateways, router) + } + } + err = a.getSiteIds(gateways) + return gateways, err +} + +func (a *Agent) GetLocalRouter() (*Router, error) { + records, err := a.Query("io.skupper.router.router", []string{}) + if err != nil { + return nil, err + } + if len(records) == 1 { + return asRouter(records[0]), nil + } else { + return nil, fmt.Errorf("Unexpected number of router records: %d", len(records)) + } +} + +func (a *Agent) isEdgeRouter() bool { + return a.local.Edge +} + +func (a *Agent) getInteriorAddressForUplink() (string, error) { + connections, err := a.GetConnections() + if err != nil { + return "", err + } + return GetInteriorAddressForUplink(connections) +} + +func GetInteriorAddressForUplink(connections []Connection) (string, error) { + for _, c := range connections { + if c.Role == "edge" && c.Dir == "out" { + return GetRouterAgentAddress(c.Container, false), nil + } + } + return "", fmt.Errorf("Could not find uplink connection") +} + +type ConnectorStatus struct { + Name string + Host string + Port string + Role string + Cost int + Status string + Description string +} + +func asConnectorStatus(record Record) ConnectorStatus { + return ConnectorStatus{ + Name: record.AsString("name"), + Host: record.AsString("host"), + Port: record.AsString("port"), + Role: record.AsString("role"), + Cost: record.AsInt("cost"), + Status: record.AsString("connectionStatus"), + Description: record.AsString("connectionMsg"), + } +} + +func asConnector(record Record) Connector { + return Connector{ + Name: record.AsString("name"), + Host: record.AsString("host"), + Port: record.AsString("port"), + RouteContainer: record.AsBool("routeContainer"), + VerifyHostname: record.AsBool("verifyHostname"), + SslProfile: record.AsString("sslProfile"), + } +} + +func asInt32(s string) int32 { + ival, _ := strconv.Atoi(s) + return int32(ival) +} + +func asListener(record Record) Listener { + return Listener{ + Name: record.AsString("name"), + Role: asRole(record.AsString("role")), + Host: record.AsString("host"), + Port: asInt32(record.AsString("port")), + Cost: int32(record.AsInt("cost")), + LinkCapacity: int32(record.AsInt("linkCapacity")), + AuthenticatePeer: record.AsBool("authenticatePeer"), + SaslMechanisms: record.AsString("saslMechanisms"), + RouteContainer: record.AsBool("routeContainer"), + Http: record.AsBool("http"), + HttpRootDir: record.AsString("httpRootDir"), + Websockets: record.AsBool("websockets"), + Healthz: record.AsBool("healthz"), + Metrics: record.AsBool("metrics"), + SslProfile: record.AsString("sslProfile"), + MaxFrameSize: record.AsInt("maxFrameSize"), + MaxSessionFrames: record.AsInt("maxSessionFrames"), + } +} + +func asSslProfile(record Record) SslProfile { + return SslProfile{ + Name: record.AsString("name"), + CertFile: record.AsString("certFile"), + PrivateKeyFile: record.AsString("privateKeyFile"), + CaCertFile: record.AsString("caCertFile"), + } +} + +func (a *Agent) UpdateConnectorConfig(changes *ConnectorDifference) error { + for _, deleted := range changes.Deleted { + if err := a.Delete("io.skupper.router.connector", deleted.Name); err != nil { + return fmt.Errorf("Error deleting connectors: %s", err) + } + } + + for _, added := range changes.Added { + + if len(added.Host) == 0 { + return fmt.Errorf("No host specified while creating a connector") + } + + if len(added.Port) == 0 { + return fmt.Errorf("No port specified while creating a connector") + } + + if len(added.SslProfile) > 0 { + sslProfile, err := a.GetSslProfileByName(added.SslProfile) + if err != nil { + return err + } + + if sslProfile.CaCertFile != "" { + _, err = os.Stat(sslProfile.CaCertFile) + if err != nil { + return err + } + } + + if sslProfile.CertFile != "" { + _, err = os.Stat(sslProfile.CertFile) + if err != nil { + return err + } + } + + if sslProfile.PrivateKeyFile != "" { + _, err = os.Stat(sslProfile.PrivateKeyFile) + if err != nil { + return err + } + } + } + + if err := a.Create("io.skupper.router.connector", added.Name, added); err != nil { + return fmt.Errorf("Error adding connectors: %s", err) + } + + } + + return nil +} + +func (a *Agent) GetLocalConnectorStatus() (map[string]ConnectorStatus, error) { + results, err := a.Query("io.skupper.router.connector", []string{}) + if err != nil { + return nil, err + } + connectors := map[string]ConnectorStatus{} + for _, record := range results { + c := asConnectorStatus(record) + connectors[c.Name] = c + } + return connectors, nil +} + +func (a *Agent) GetLocalConnectors() (map[string]Connector, error) { + results, err := a.Query("io.skupper.router.connector", []string{}) + if err != nil { + return nil, err + } + connectors := map[string]Connector{} + for _, record := range results { + c := asConnector(record) + connectors[c.Name] = c + } + return connectors, nil +} + +func (a *Agent) UpdateListenerConfig(changes *ListenerDifference) error { + for _, deleted := range changes.Deleted { + if err := a.Delete("io.skupper.router.listener", deleted.Name); err != nil { + return fmt.Errorf("Error deleting listeners: %s", err) + } + } + + for _, added := range changes.Added { + if err := a.Create("io.skupper.router.listener", added.Name, added); err != nil { + return fmt.Errorf("Error adding listeners: %s", err) + } + + } + + return nil +} + +func (a *Agent) GetLocalListeners() (map[string]Listener, error) { + results, err := a.Query("io.skupper.router.listener", []string{}) + if err != nil { + return nil, err + } + listeners := map[string]Listener{} + for _, record := range results { + l := asListener(record) + listeners[l.Name] = l + } + return listeners, nil +} + +func (a *Agent) Request(request *Request) (*Response, error) { + ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) + defer cancel() + + requestMsg := amqp.Message{ + Properties: &amqp.MessageProperties{ + To: request.Address, + Subject: request.Type, + ReplyTo: a.receiver.Address(), + }, + ApplicationProperties: map[string]interface{}{}, + Value: nil, + } + if request.Body != "" { + requestMsg.Value = request.Body + } + for k, v := range request.Properties { + requestMsg.ApplicationProperties[k] = v + } + requestMsg.ApplicationProperties[VersionProperty] = request.Version + + err := a.anonymous.Send(ctx, &requestMsg) + if err != nil { + a.Close() + return nil, fmt.Errorf("Could not send %s request: %s", request.Type, err) + } + responseMsg, err := a.receiver.Receive(ctx) + if err != nil { + a.Close() + return nil, fmt.Errorf("Failed to receive response: %s", err) + } + responseMsg.Accept() + + response := Response{ + Type: responseMsg.Properties.Subject, + } + for k, v := range responseMsg.ApplicationProperties { + if k == VersionProperty { + if version, ok := v.(string); ok { + response.Version = version + } + } else { + response.Properties[k] = v + } + } + if body, ok := responseMsg.Value.(string); ok { + response.Body = body + } + return &response, nil +} + +func (r *Router) IsGateway() bool { + return isGateway(r.Id) +} + +func isGateway(routerId string) bool { + return strings.HasPrefix(routerId, "skupper-gateway-") +} + +func GetSiteNameForGateway(gateway *Router) string { + return strings.TrimPrefix(gateway.Id, "skupper-gateway-") +} + +func (a *Agent) CreateSslProfile(profile SslProfile) error { + + result, err := a.GetSslProfileByName(profile.Name) + if err != nil { + return err + } + + // Trying to create a ssl profile that already exists will generate an error in the router. + if result != nil { + return nil + } + + if err := a.Create("io.skupper.router.sslProfile", profile.Name, profile); err != nil { + return fmt.Errorf("Error adding SSL Profile: %s", err) + } + + return nil +} + +func (a *Agent) ReloadSslProfile(name string) error { + + profile, err := a.GetSslProfileByName(name) + if err != nil { + return err + } + + // A profile is expected to be returned + if profile == nil { + return fmt.Errorf("No SSL Profile with name %s found", name) + } + + if err := a.Update("io.skupper.router.sslProfile", profile.Name, profile); err != nil { + return fmt.Errorf("Error updating SSL Profile: %s", err) + } + + return nil +} + +func ConnectedSitesInfo(selfId string, routers []Router) types.TransportConnectedSites { + var connectedSites types.TransportConnectedSites + var self *Router + for _, r := range routers { + if r.Site.Id == selfId { + self = &r + break + } + } + if self == nil { + return connectedSites + } + for _, r := range routers { + if r.Edge && len(r.ConnectedTo) > 1 { + connectedSites.Warnings = append(connectedSites.Warnings, "There are edge uplinks to distinct networks, please verify topology (connected counts may not be accurate).") + } + if utils.StringSliceContains(r.ConnectedTo, self.Id) { + connectedSites.Direct += 1 + } + } + connectedSites.Total = len(routers) - 1 + connectedSites.Direct += len(self.ConnectedTo) + connectedSites.Indirect = connectedSites.Total - connectedSites.Direct + return connectedSites +} diff --git a/internal/qdr/messaging.go b/internal/qdr/messaging.go new file mode 100644 index 0000000..48ac4db --- /dev/null +++ b/internal/qdr/messaging.go @@ -0,0 +1,113 @@ +package qdr + +import ( + "context" + "crypto/tls" + + amqp "github.com/interconnectedcloud/go-amqp" + + "github.com/datasance/router/internal/messaging" +) + +type TlsConfigRetriever interface { + GetTlsConfig() (*tls.Config, error) +} + +type ConnectionFactory struct { + url string + config TlsConfigRetriever +} + +func (f *ConnectionFactory) Connect() (messaging.Connection, error) { + if f.config == nil { + return dial(f.url, amqp.ConnMaxFrameSize(4294967295)) + } else { + tlsConfig, err := f.config.GetTlsConfig() + if err != nil { + return nil, err + } + return dial(f.url, amqp.ConnSASLExternal(), amqp.ConnMaxFrameSize(4294967295), amqp.ConnTLSConfig(tlsConfig)) + } +} + +func dial(addr string, opts ...amqp.ConnOption) (*AmqpConnection, error) { + client, err := amqp.Dial(addr, opts...) + if err != nil { + return nil, err + } + session, err := client.NewSession() + if err != nil { + client.Close() + return nil, err + } + return &AmqpConnection{client: client, session: session}, nil +} + +func (f *ConnectionFactory) Url() string { + return f.url +} + +func NewConnectionFactory(url string, config TlsConfigRetriever) *ConnectionFactory { + return &ConnectionFactory{ + url: url, + config: config, + } +} + +type AmqpConnection struct { + client *amqp.Client + session *amqp.Session +} + +type AmqpSender struct { + connection *AmqpConnection + sender *amqp.Sender +} + +type AmqpReceiver struct { + connection *AmqpConnection + receiver *amqp.Receiver +} + +func (c *AmqpConnection) Close() { + c.client.Close() +} + +func (c *AmqpConnection) Sender(address string) (messaging.Sender, error) { + sender, err := c.session.NewSender(amqp.LinkTargetAddress(address)) + if err != nil { + return nil, err + } + return &AmqpSender{connection: c, sender: sender}, nil +} + +func (c *AmqpConnection) Receiver(address string, credit uint32) (messaging.Receiver, error) { + receiver, err := c.session.NewReceiver( + amqp.LinkSourceAddress(address), + amqp.LinkCredit(credit), + ) + if err != nil { + return nil, err + } + return &AmqpReceiver{connection: c, receiver: receiver}, nil +} + +func (s *AmqpSender) Send(msg *amqp.Message) error { + return s.sender.Send(context.Background(), msg) +} + +func (s *AmqpSender) Close() error { + return s.sender.Close(context.Background()) +} + +func (s *AmqpReceiver) Receive() (*amqp.Message, error) { + return s.receiver.Receive(context.Background()) +} + +func (s *AmqpReceiver) Accept(msg *amqp.Message) error { + return msg.Accept() +} + +func (s *AmqpReceiver) Close() error { + return s.receiver.Close(context.Background()) +} diff --git a/internal/qdr/qdr.go b/internal/qdr/qdr.go new file mode 100644 index 0000000..0fa31a6 --- /dev/null +++ b/internal/qdr/qdr.go @@ -0,0 +1,1149 @@ +package qdr + +import ( + "encoding/json" + "fmt" + "log" + "net" + path_ "path" + "reflect" + "strconv" + "strings" + + "github.com/datasance/router/internal/resources/types" +) + +type RouterConfig struct { + Metadata RouterMetadata + SslProfiles map[string]SslProfile + Listeners map[string]Listener + Connectors map[string]Connector + Addresses map[string]Address + LogConfig map[string]LogConfig + SiteConfig *SiteConfig + Bridges BridgeConfig +} + +type RouterConfigHandler interface { + GetRouterConfig() (*RouterConfig, error) + SaveRouterConfig(*RouterConfig) error + RemoveRouterConfig() error +} + +type TcpEndpointMap map[string]TcpEndpoint + +type BridgeConfig struct { + TcpListeners TcpEndpointMap + TcpConnectors TcpEndpointMap +} + +func InitialConfig(id string, siteId string, version string, edge bool, helloAge int) RouterConfig { + config := RouterConfig{ + Metadata: RouterMetadata{ + Id: id, + HelloMaxAgeSeconds: strconv.Itoa(helloAge), + Metadata: getSiteMetadataString(siteId, version), + }, + Addresses: map[string]Address{}, + SslProfiles: map[string]SslProfile{}, + Listeners: map[string]Listener{}, + Connectors: map[string]Connector{}, + LogConfig: map[string]LogConfig{}, + Bridges: BridgeConfig{ + TcpListeners: map[string]TcpEndpoint{}, + TcpConnectors: map[string]TcpEndpoint{}, + }, + } + if edge { + config.Metadata.Mode = ModeEdge + } else { + config.Metadata.Mode = ModeInterior + } + return config +} + +func (r *RouterConfig) AddHealthAndMetricsListener(port int32) { + r.AddListener(Listener{ + Port: port, + Role: "normal", + Http: true, + HttpRootDir: "disabled", + Websockets: false, + Healthz: true, + Metrics: true, + }) +} + +func NewBridgeConfig() BridgeConfig { + return BridgeConfig{ + TcpListeners: map[string]TcpEndpoint{}, + TcpConnectors: map[string]TcpEndpoint{}, + } +} + +func NewBridgeConfigCopy(src BridgeConfig) BridgeConfig { + newBridges := NewBridgeConfig() + for k, v := range src.TcpListeners { + newBridges.TcpListeners[k] = v + } + for k, v := range src.TcpConnectors { + newBridges.TcpConnectors[k] = v + } + return newBridges +} + +func (r *RouterConfig) AddListener(l Listener) bool { + if l.Name == "" { + l.Name = fmt.Sprintf("%s@%d", l.Host, l.Port) + } + if original, ok := r.Listeners[l.Name]; ok && original == l { + return false + } + r.Listeners[l.Name] = l + return true +} + +func (r *RouterConfig) RemoveListener(name string) (bool, Listener) { + c, ok := r.Listeners[name] + if ok { + delete(r.Listeners, name) + return true, c + } else { + return false, Listener{} + } +} + +func (r *RouterConfig) AddConnector(c Connector) bool { + if original, ok := r.Connectors[c.Name]; ok && original == c { + return false + } + r.Connectors[c.Name] = c + return true +} + +func (r *RouterConfig) RemoveConnector(name string) (bool, Connector) { + c, ok := r.Connectors[name] + if ok { + delete(r.Connectors, name) + return true, c + } else { + return false, Connector{} + } +} + +func (r *RouterConfig) IsEdge() bool { + return r.Metadata.Mode == ModeEdge +} + +// ConfigureSslProfile builds an SslProfile with file paths under the given base path. +// For the default SSL profile directory, use config.GetSSLProfilePath(). +func ConfigureSslProfile(name string, path string, clientAuth bool) SslProfile { + profile := SslProfile{ + Name: name, + CaCertFile: path_.Join(path, name, "ca.crt"), + } + if clientAuth { + profile.CertFile = path_.Join(path, name, "tls.crt") + profile.PrivateKeyFile = path_.Join(path, name, "tls.key") + } + return profile +} + +func (r *RouterConfig) AddSslProfile(s SslProfile) bool { + if original, ok := r.SslProfiles[s.Name]; ok && original == s { + return false + } + r.SslProfiles[s.Name] = s + return true +} + +func (r *RouterConfig) RemoveSslProfile(name string) bool { + _, ok := r.SslProfiles[name] + if ok { + delete(r.SslProfiles, name) + return true + } else { + return false + } +} + +func (r *RouterConfig) RemoveUnreferencedSslProfiles() bool { + unreferenced := r.UnreferencedSslProfiles() + changed := false + for _, profile := range unreferenced { + if r.RemoveSslProfile(profile.Name) { + changed = true + } + } + return changed +} + +func (r *RouterConfig) UnreferencedSslProfiles() map[string]SslProfile { + results := map[string]SslProfile{} + for _, profile := range r.SslProfiles { + results[profile.Name] = profile + } + //remove any that are referenced + for _, o := range r.Listeners { + delete(results, o.SslProfile) + } + for _, o := range r.Connectors { + delete(results, o.SslProfile) + } + for _, o := range r.Bridges.TcpListeners { + delete(results, o.SslProfile) + } + for _, o := range r.Bridges.TcpConnectors { + delete(results, o.SslProfile) + } + + return results +} + +func (r *RouterConfig) AddAddress(a Address) { + r.Addresses[a.Prefix] = a +} + +func (r *RouterConfig) AddTcpConnector(e TcpEndpoint) { + r.Bridges.AddTcpConnector(e) +} + +func (r *RouterConfig) RemoveTcpConnector(name string) (bool, TcpEndpoint) { + return r.Bridges.RemoveTcpConnector(name) +} + +func (r *RouterConfig) AddTcpListener(e TcpEndpoint) { + r.Bridges.AddTcpListener(e) +} + +func (r *RouterConfig) RemoveTcpListener(name string) (bool, TcpEndpoint) { + return r.Bridges.RemoveTcpListener(name) +} + +func (r *RouterConfig) UpdateBridgeConfig(desired BridgeConfig) bool { + if reflect.DeepEqual(r.Bridges, desired) { + return false + } else { + r.Bridges = desired + return true + } +} + +func (r *RouterConfig) GetSiteMetadata() SiteMetadata { + return GetSiteMetadata(r.Metadata.Metadata) +} + +func (r *RouterConfig) SetSiteMetadata(site *SiteMetadata) { + r.Metadata.Metadata = getSiteMetadataString(site.Id, site.Version) +} + +func (bc *BridgeConfig) AddTcpConnector(e TcpEndpoint) { + bc.TcpConnectors[e.Name] = e +} + +func (bc *BridgeConfig) RemoveTcpConnector(name string) (bool, TcpEndpoint) { + tc, ok := bc.TcpConnectors[name] + if ok { + delete(bc.TcpConnectors, name) + return true, tc + } else { + return false, TcpEndpoint{} + } +} + +func (bc *BridgeConfig) AddTcpListener(e TcpEndpoint) { + bc.TcpListeners[e.Name] = e +} + +func (bc *BridgeConfig) RemoveTcpListener(name string) (bool, TcpEndpoint) { + tc, ok := bc.TcpListeners[name] + if ok { + delete(bc.TcpListeners, name) + return true, tc + } else { + return false, TcpEndpoint{} + } +} + +func GetTcpConnectors(bridges []BridgeConfig) []TcpEndpoint { + connectors := []TcpEndpoint{} + for _, bridge := range bridges { + for _, connector := range bridge.TcpConnectors { + connectors = append(connectors, connector) + } + } + return connectors +} + +func (r *RouterConfig) SetLogLevel(module string, level string) bool { + if level != "" { + config := LogConfig{ + Module: module, + Enable: level, + } + if module == "" { + config.Module = "DEFAULT" + } + if !strings.HasSuffix(level, "+") { + config.Enable = level + "+" + } + if r.LogConfig == nil { + r.LogConfig = map[string]LogConfig{} + } + if r.LogConfig[config.Module] != config { + r.LogConfig[config.Module] = config + return true + } + } + return false +} + +func (r *RouterConfig) SetLogLevels(levels map[string]string) bool { + keys := map[string]bool{} + for k, _ := range levels { + if k == "" { + keys["DEFAULT"] = true + } else { + keys[k] = true + } + } + changed := false + for name, level := range levels { + if r.SetLogLevel(name, level) { + changed = true + } + } + for key, _ := range r.LogConfig { + if _, ok := keys[key]; !ok { + delete(r.LogConfig, key) + changed = true + } + } + return changed +} + +type Role string + +const ( + RoleInterRouter Role = "inter-router" + RoleEdge = "edge" + RoleNormal = "normal" + RoleDefault = "" +) + +func asRole(name string) Role { + if name == "edge" { + return RoleEdge + } + if name == "inter-router" { + return RoleInterRouter + } + if name == "normal" { + return RoleNormal + } + return RoleDefault +} + +func GetRole(name string) Role { + if name == "edge" { + return RoleEdge + } else if name == "normal" { + return RoleNormal + } + return RoleInterRouter +} + +type Mode string + +const ( + ModeInterior Mode = "interior" + ModeEdge = "edge" +) + +type RouterMetadata struct { + Id string `json:"id,omitempty"` + Mode Mode `json:"mode,omitempty"` + HelloMaxAgeSeconds string `json:"helloMaxAgeSeconds,omitempty"` + DataConnectionCount string `json:"dataConnectionCount,omitempty"` + Metadata string `json:"metadata,omitempty"` +} + +type SslProfile struct { + Name string `json:"name,omitempty"` + CertFile string `json:"certFile,omitempty"` + PrivateKeyFile string `json:"privateKeyFile,omitempty"` + CaCertFile string `json:"caCertFile,omitempty"` +} + +func (p SslProfile) toRecord() Record { + result := make(map[string]any) + if p.Name != "" { + result["name"] = p.Name + } + if p.CertFile != "" { + result["certFile"] = p.CertFile + } + if p.PrivateKeyFile != "" { + result["privateKeyFile"] = p.PrivateKeyFile + } + if p.CaCertFile != "" { + result["caCertFile"] = p.CaCertFile + } + return result +} + +type LogConfig struct { + Module string `json:"module"` + Enable string `json:"enable"` +} + +type Listener struct { + Name string `json:"name,omitempty" yaml:"name,omitempty"` + Role Role `json:"role,omitempty" yaml:"role,omitempty"` + Host string `json:"host,omitempty" yaml:"host,omitempty"` + Port int32 `json:"port" yaml:"port,omitempty"` + RouteContainer bool `json:"routeContainer,omitempty" yaml:"route-container,omitempty"` + Http bool `json:"http,omitempty" yaml:"http,omitempty"` + Cost int32 `json:"cost,omitempty" yaml:"cost,omitempty"` + SslProfile string `json:"sslProfile,omitempty" yaml:"ssl-profile,omitempty"` + SaslMechanisms string `json:"saslMechanisms,omitempty" yaml:"sasl-mechanisms,omitempty"` + AuthenticatePeer bool `json:"authenticatePeer,omitempty" yaml:"authenticate-peer,omitempty"` + LinkCapacity int32 `json:"linkCapacity,omitempty" yaml:"link-capacity,omitempty"` + HttpRootDir string `json:"httpRootDir,omitempty" yaml:"http-rootdir,omitempty"` + Websockets bool `json:"websockets,omitempty" yaml:"web-sockets,omitempty"` + Healthz bool `json:"healthz,omitempty" yaml:"healthz,omitempty"` + Metrics bool `json:"metrics,omitempty" yaml:"metrics,omitempty"` + MaxFrameSize int `json:"maxFrameSize,omitempty" yaml:"max-frame-size,omitempty"` + MaxSessionFrames int `json:"maxSessionFrames,omitempty" yaml:"max-session-frames,omitempty"` +} + +func (listener Listener) toRecord() Record { + record := map[string]any{} + record["name"] = listener.Name + record["role"] = string(listener.Role) + record["host"] = listener.Host + record["port"] = strconv.Itoa(int(listener.Port)) + if listener.Cost > 0 { + record["cost"] = listener.Cost + } + if listener.LinkCapacity > 0 { + record["linkCapacity"] = listener.LinkCapacity + } + if len(listener.SslProfile) > 0 { + record["sslProfile"] = listener.SslProfile + } + if listener.AuthenticatePeer { + record["authenticatePeer"] = listener.AuthenticatePeer + } + if len(listener.SaslMechanisms) > 0 { + record["saslMechanisms"] = listener.SaslMechanisms + } + if listener.MaxFrameSize > 0 { + record["maxFrameSize"] = listener.MaxFrameSize + } + if listener.MaxSessionFrames > 0 { + record["maxSessionFrames"] = listener.MaxSessionFrames + } + if listener.RouteContainer { + record["routeContainer"] = listener.RouteContainer + } + if listener.Http { + record["http"] = listener.Http + } + if len(listener.HttpRootDir) > 0 { + record["httpRootDir"] = listener.HttpRootDir + } + if listener.Websockets { + record["websockets"] = listener.Websockets + } + if listener.Healthz { + record["healthz"] = listener.Healthz + } + if listener.Metrics { + record["metrics"] = listener.Metrics + } + + return record +} +func (l *Listener) SetMaxFrameSize(value int) { + l.MaxFrameSize = value +} + +func (l *Listener) SetMaxSessionFrames(value int) { + l.MaxSessionFrames = value +} + +type Connector struct { + Name string `json:"name,omitempty"` + Role Role `json:"role,omitempty"` + Host string `json:"host"` + Port string `json:"port"` + RouteContainer bool `json:"routeContainer,omitempty"` + Cost int32 `json:"cost,omitempty"` + VerifyHostname bool `json:"verifyHostname,omitempty"` + SslProfile string `json:"sslProfile,omitempty"` + LinkCapacity int32 `json:"linkCapacity,omitempty"` + MaxFrameSize int `json:"maxFrameSize,omitempty"` + MaxSessionFrames int `json:"maxSessionFrames,omitempty"` +} + +func (connector Connector) toRecord() Record { + record := map[string]any{} + record["name"] = connector.Name + record["role"] = string(connector.Role) + record["host"] = connector.Host + record["port"] = connector.Port + if connector.Cost > 0 { + record["cost"] = connector.Cost + } + if len(connector.SslProfile) > 0 { + record["sslProfile"] = connector.SslProfile + } + if connector.MaxFrameSize > 0 { + record["maxFrameSize"] = connector.MaxFrameSize + } + if connector.MaxSessionFrames > 0 { + record["maxSessionFrames"] = connector.MaxSessionFrames + } + return record +} + +func (c *Connector) SetMaxFrameSize(value int) { + c.MaxFrameSize = value +} + +func (c *Connector) SetMaxSessionFrames(value int) { + c.MaxSessionFrames = value +} + +type Distribution string + +const ( + DistributionBalanced Distribution = "balanced" + DistributionMulticast = "multicast" + DistributionClosest = "closest" +) + +type Address struct { + Prefix string `json:"prefix,omitempty"` + Distribution string `json:"distribution,omitempty"` +} + +type TcpEndpoint struct { + Name string `json:"name,omitempty"` + Host string `json:"host,omitempty"` + Port string `json:"port,omitempty"` + Address string `json:"address,omitempty"` + SiteId string `json:"siteId,omitempty"` + SslProfile string `json:"sslProfile,omitempty"` + VerifyHostname *bool `json:"verifyHostname,omitempty"` + ProcessID string `json:"processId,omitempty"` +} + +func (e TcpEndpoint) toRecord() Record { + result := make(map[string]any) + if e.Name != "" { + result["name"] = e.Name + } + if e.Host != "" { + result["host"] = e.Host + } + if e.Port != "" { + result["port"] = e.Port + } + if e.Address != "" { + result["address"] = e.Address + } + if e.SiteId != "" { + result["siteId"] = e.SiteId + } + if e.SslProfile != "" { + result["sslProfile"] = e.SslProfile + } + if e.VerifyHostname != nil { + result["verifyHostname"] = e.VerifyHostname + } + if e.ProcessID != "" { + result["processId"] = e.ProcessID + } + return result +} + +type SiteConfig struct { + Name string `json:"name,omitempty"` + Location string `json:"location,omitempty"` + Provider string `json:"provider,omitempty"` + Platform string `json:"platform,omitempty"` + Namespace string `json:"namespace,omitempty"` + Version string `json:"version,omitempty"` +} + +func convert(from interface{}, to interface{}) error { + data, err := json.Marshal(from) + if err != nil { + return err + } + err = json.Unmarshal(data, to) + if err != nil { + return err + } + return nil +} + +func RouterConfigEquals(actual, desired string) bool { + actualConfig, err := UnmarshalRouterConfig(actual) + if err != nil { + return false + } + desiredConfig, err := UnmarshalRouterConfig(desired) + if err != nil { + return false + } + return reflect.DeepEqual(actualConfig, desiredConfig) +} + +func UnmarshalRouterConfig(config string) (RouterConfig, error) { + result := RouterConfig{ + Metadata: RouterMetadata{}, + Addresses: map[string]Address{}, + SslProfiles: map[string]SslProfile{}, + Listeners: map[string]Listener{}, + Connectors: map[string]Connector{}, + LogConfig: map[string]LogConfig{}, + Bridges: BridgeConfig{ + TcpListeners: map[string]TcpEndpoint{}, + TcpConnectors: map[string]TcpEndpoint{}, + }, + } + var obj interface{} + err := json.Unmarshal([]byte(config), &obj) + if err != nil { + return result, err + } + elements, ok := obj.([]interface{}) + if !ok { + return result, fmt.Errorf("Invalid JSON for router configuration, expected array at top level got %#v", obj) + } + for _, e := range elements { + element, ok := e.([]interface{}) + if !ok || len(element) != 2 { + return result, fmt.Errorf("Invalid JSON for router configuration, expected array with type and value got %#v", e) + } + entityType, ok := element[0].(string) + if !ok { + return result, fmt.Errorf("Invalid JSON for router configuration, expected entity type as string got %#v", element[0]) + } + switch entityType { + case "router": + metadata := RouterMetadata{} + err = convert(element[1], &metadata) + if err != nil { + return result, fmt.Errorf("Invalid %s element got %#v", entityType, element[1]) + } + result.Metadata = metadata + case "address": + address := Address{} + err = convert(element[1], &address) + if err != nil { + return result, fmt.Errorf("Invalid %s element got %#v", entityType, element[1]) + } + result.Addresses[address.Prefix] = address + case "connector": + connector := Connector{} + err = convert(element[1], &connector) + if err != nil { + return result, fmt.Errorf("Invalid %s element got %#v", entityType, element[1]) + } + result.Connectors[connector.Name] = connector + case "listener": + listener := Listener{} + err = convert(element[1], &listener) + if err != nil { + return result, fmt.Errorf("Invalid %s element got %#v", entityType, element[1]) + } + result.Listeners[listener.Name] = listener + case "sslProfile": + sslProfile := SslProfile{} + err = convert(element[1], &sslProfile) + if err != nil { + return result, fmt.Errorf("Invalid %s element got %#v", entityType, element[1]) + } + result.SslProfiles[sslProfile.Name] = sslProfile + case "log": + logConfig := LogConfig{} + err = convert(element[1], &logConfig) + if err != nil { + return result, fmt.Errorf("Invalid %s element got %#v", entityType, element[1]) + } + result.LogConfig[logConfig.Module] = logConfig + case "site": + siteConfig := &SiteConfig{} + err = convert(element[1], siteConfig) + if err != nil { + return result, fmt.Errorf("Invalid %s element got %#v", entityType, element[1]) + } + result.SiteConfig = siteConfig + case "tcpConnector": + connector := TcpEndpoint{} + err = convert(element[1], &connector) + if err != nil { + return result, fmt.Errorf("Invalid %s element got %#v", entityType, element[1]) + } + result.Bridges.TcpConnectors[connector.Name] = connector + case "tcpListener": + listener := TcpEndpoint{} + err = convert(element[1], &listener) + if err != nil { + return result, fmt.Errorf("Invalid %s element got %#v", entityType, element[1]) + } + result.Bridges.TcpListeners[listener.Name] = listener + default: + } + } + return result, nil +} + +func MarshalRouterConfig(config RouterConfig) (string, error) { + elements := [][]interface{}{} + tuple := []interface{}{ + "router", + config.Metadata, + } + elements = append(elements, tuple) + for _, e := range config.SslProfiles { + tuple := []interface{}{ + "sslProfile", + e, + } + elements = append(elements, tuple) + } + for _, e := range config.Connectors { + tuple := []interface{}{ + "connector", + e, + } + elements = append(elements, tuple) + } + for _, e := range config.Listeners { + tuple := []interface{}{ + "listener", + e, + } + elements = append(elements, tuple) + } + for _, e := range config.Addresses { + tuple := []interface{}{ + "address", + e, + } + elements = append(elements, tuple) + } + for _, e := range config.Bridges.TcpConnectors { + tuple := []interface{}{ + "tcpConnector", + e, + } + elements = append(elements, tuple) + } + for _, e := range config.Bridges.TcpListeners { + tuple := []interface{}{ + "tcpListener", + e, + } + elements = append(elements, tuple) + } + for _, e := range config.LogConfig { + tuple := []interface{}{ + "log", + e, + } + elements = append(elements, tuple) + } + if config.SiteConfig != nil { + tuple := []interface{}{ + "site", + *config.SiteConfig, + } + elements = append(elements, tuple) + } + data, err := json.MarshalIndent(elements, "", " ") + if err != nil { + return "", err + } + return string(data), nil +} + +func AsConfigMapData(config string) map[string]string { + return map[string]string{ + types.TransportConfigFile: config, + } +} + +func (r *RouterConfig) AsConfigMapData() (map[string]string, error) { + result := map[string]string{} + marshalled, err := MarshalRouterConfig(*r) + if err != nil { + return result, err + } + result[types.TransportConfigFile] = marshalled + return result, nil +} + +type ListenerPredicate func(Listener) bool + +func IsNotNormalListener(l Listener) bool { + return l.Role != "normal" && l.Role != "" +} + +func FilterListeners(in map[string]Listener, predicate ListenerPredicate) map[string]Listener { + results := map[string]Listener{} + for key, listener := range in { + if predicate(listener) { + results[key] = listener + } + } + return results +} + +func (config *RouterConfig) GetMatchingListeners(predicate ListenerPredicate) map[string]Listener { + return FilterListeners(config.Listeners, predicate) +} + +type ConnectorDifference struct { + Deleted []Connector + Added []Connector + AddedSslProfiles map[string]SslProfile +} + +type TcpEndpointDifference struct { + Deleted []string + Added []TcpEndpoint +} + +type BridgeConfigDifference struct { + TcpListeners TcpEndpointDifference + TcpConnectors TcpEndpointDifference + AddedSslProfiles []string + DeletedSSlProfiles []string +} + +func isAddrAny(host string) bool { + ip := net.ParseIP(host) + return ip.Equal(net.IPv4zero) || ip.Equal(net.IPv6zero) +} + +func equivalentHost(a string, b string) bool { + if a == b { + return true + } else if a == "" { + return isAddrAny(b) + } else if b == "" { + return isAddrAny(a) + } else { + return false + } +} + +func (a TcpEndpoint) equivalentVerifyHostname(b TcpEndpoint) bool { + if a.VerifyHostname == nil { + return b.VerifyHostname == nil || *b.VerifyHostname == true + } + if b.VerifyHostname == nil { + return a.VerifyHostname == nil || *a.VerifyHostname == true + } + return *a.VerifyHostname == *b.VerifyHostname +} + +func (a TcpEndpoint) Equivalent(b TcpEndpoint) bool { + if !equivalentHost(a.Host, b.Host) || a.Port != b.Port || a.Address != b.Address || + a.SiteId != b.SiteId || a.ProcessID != b.ProcessID || !a.equivalentVerifyHostname(b) { + return false + } + return true +} + +func (a TcpEndpointMap) Difference(b TcpEndpointMap) TcpEndpointDifference { + result := TcpEndpointDifference{} + for key, v1 := range b { + v2, ok := a[key] + if !ok { + result.Added = append(result.Added, v1) + } else if !v1.Equivalent(v2) { + result.Deleted = append(result.Deleted, v1.Name) + result.Added = append(result.Added, v1) + } + } + for key, v1 := range a { + _, ok := b[key] + if !ok { + result.Deleted = append(result.Deleted, v1.Name) + } + } + return result +} + +func (a *BridgeConfig) Difference(b *BridgeConfig) *BridgeConfigDifference { + result := BridgeConfigDifference{ + TcpConnectors: a.TcpConnectors.Difference(b.TcpConnectors), + TcpListeners: a.TcpListeners.Difference(b.TcpListeners), + } + + result.AddedSslProfiles, result.DeletedSSlProfiles = getSslProfilesDifference(a, b) + + return &result +} + +type AddedSslProfiles []string +type DeletedSslProfiles []string + +func getSslProfilesDifference(before *BridgeConfig, desired *BridgeConfig) (AddedSslProfiles, DeletedSslProfiles) { + var addedProfiles AddedSslProfiles + var deletedProfiles DeletedSslProfiles + + originalSslConfig := make(map[string]string) + newSslConfig := make(map[string]string) + + for _, tcpConnector := range before.TcpConnectors { + originalSslConfig[tcpConnector.SslProfile] = tcpConnector.SslProfile + } + for _, tcpListener := range before.TcpListeners { + originalSslConfig[tcpListener.SslProfile] = tcpListener.SslProfile + } + + for _, tcpConnector := range desired.TcpConnectors { + newSslConfig[tcpConnector.SslProfile] = tcpConnector.SslProfile + } + for _, tcpListener := range desired.TcpListeners { + newSslConfig[tcpListener.SslProfile] = tcpListener.SslProfile + } + + //Auto-generated Skupper certs will be deleted if they are not used in the desired configuration + for key, name := range originalSslConfig { + _, ok := newSslConfig[key] + + if !ok && isGeneratedBySkupper(name) { + deletedProfiles = append(deletedProfiles, name) + } + } + + //New profiles associated with http or tcp connectors/listeners will be created in the router + for key, name := range newSslConfig { + _, ok := originalSslConfig[key] + + if !ok && name != types.ServiceClientSecret { + addedProfiles = append(addedProfiles, name) + } + } + + return addedProfiles, deletedProfiles +} + +func isGeneratedBySkupper(name string) bool { + return strings.HasPrefix(name, types.SkupperServiceCertPrefix) && name != types.ServiceClientSecret +} + +func (a *TcpEndpointDifference) Empty() bool { + return len(a.Deleted) == 0 && len(a.Added) == 0 +} + +func (a *BridgeConfigDifference) Empty() bool { + return a.TcpConnectors.Empty() && a.TcpListeners.Empty() +} + +func (a *BridgeConfigDifference) Print() { + log.Printf("TcpConnectors added=%v, deleted=%v", a.TcpConnectors.Added, a.TcpConnectors.Deleted) + log.Printf("TcpListeners added=%v, deleted=%v", a.TcpListeners.Added, a.TcpListeners.Deleted) + log.Printf("SslProfiles added=%v, deleted=%v", a.AddedSslProfiles, a.DeletedSSlProfiles) +} + +func ConnectorsDifference(actual map[string]Connector, desired *RouterConfig, ignorePrefix *string) *ConnectorDifference { + result := ConnectorDifference{} + result.AddedSslProfiles = make(map[string]SslProfile) + for key, v1 := range desired.Connectors { + _, ok := actual[key] + if !ok { + result.Added = append(result.Added, v1) + result.AddedSslProfiles[v1.SslProfile] = desired.SslProfiles[v1.SslProfile] + } + } + for key, v1 := range actual { + _, ok := desired.Connectors[key] + + allowedToDelete := true + if ignorePrefix != nil && len(*ignorePrefix) > 0 { + allowedToDelete = !strings.HasPrefix(v1.Name, *ignorePrefix) + } + + if !ok && allowedToDelete { + result.Deleted = append(result.Deleted, v1) + } + } + return &result +} + +func (a *ConnectorDifference) Empty() bool { + return len(a.Deleted) == 0 && len(a.Added) == 0 +} + +type ListenerDifference struct { + Deleted []Listener + Added []Listener +} + +func (desired Listener) Equivalent(actual Listener) bool { + return desired.Name == actual.Name && + desired.Role == actual.Role && + desired.Host == actual.Host && + desired.Port == actual.Port && + desired.RouteContainer == actual.RouteContainer && + desired.Http == actual.Http && + desired.SslProfile == actual.SslProfile && + desired.SaslMechanisms == actual.SaslMechanisms && + desired.AuthenticatePeer == actual.AuthenticatePeer && + (desired.Cost == 0 || desired.Cost == actual.Cost) && + (desired.MaxFrameSize == 0 || desired.MaxFrameSize == actual.MaxFrameSize) && + (desired.MaxSessionFrames == 0 || desired.MaxSessionFrames == actual.MaxSessionFrames) && + (desired.LinkCapacity == 0 || desired.LinkCapacity == actual.LinkCapacity) && + (desired.HttpRootDir == "" || desired.HttpRootDir == actual.HttpRootDir) + //Skip check for Websockets, Healthz and Metrics as they are + //always coming back as true at present and are not used where + //this method is required at present. +} + +func ListenersDifference(actual map[string]Listener, desired map[string]Listener) *ListenerDifference { + result := ListenerDifference{} + for key, desiredValue := range desired { + if actualValue, ok := actual[key]; ok { + if !desiredValue.Equivalent(actualValue) { + log.Printf("Listener definition does not match. Have %v want %v", actualValue, desiredValue) + // handle change as delete then add, so it also works over management protocol + result.Deleted = append(result.Deleted, desiredValue) + result.Added = append(result.Added, desiredValue) + } + } else { + result.Added = append(result.Added, desiredValue) + } + } + for key, value := range actual { + if _, ok := desired[key]; !ok { + result.Deleted = append(result.Deleted, value) + } + } + return &result +} + +func (a *ListenerDifference) Empty() bool { + return len(a.Deleted) == 0 && len(a.Added) == 0 +} + +// func GetRouterConfigForHeadlessProxy(definition types.ServiceInterface, siteId string, version string, namespace string, profilePath string) (string, error) { +// config := InitialConfig("${HOSTNAME}-"+siteId, siteId, version, true, 3) +// // add edge-connector +// config.AddSslProfile(ConfigureSslProfile(types.InterRouterProfile, profilePath, true)) +// config.AddConnector(Connector{ +// Name: "uplink", +// SslProfile: types.InterRouterProfile, +// Host: types.TransportServiceName + "." + namespace + ".svc.cluster.local", +// Port: strconv.Itoa(int(types.EdgeListenerPort)), +// Role: RoleEdge, +// }) +// config.AddListener(Listener{ +// Name: "amqp", +// Host: "localhost", +// Port: 5672, +// }) +// svcPorts := definition.Ports +// ports := map[int]int{} +// if len(definition.Targets) > 0 { +// ports = definition.Targets[0].TargetPorts +// } else { +// for _, sp := range svcPorts { +// ports[sp] = sp +// } +// } +// for iPort, ePort := range ports { +// address := fmt.Sprintf("%s-%s:%d", definition.Address, "${POD_ID}", iPort) +// if definition.IsOfLocalOrigin() { +// name := fmt.Sprintf("egress:%d", ePort) +// host := definition.Headless.Name + "-${POD_ID}." + definition.Address + "." + namespace +// // in the originating site, just have egress bindings +// switch definition.Protocol { +// case "tcp": +// config.AddTcpConnector(TcpEndpoint{ +// Name: name, +// Host: host, +// Port: strconv.Itoa(ePort), +// Address: address, +// SiteId: siteId, +// }) +// default: +// } +// } else { +// name := fmt.Sprintf("ingress:%d", ePort) +// // in all other sites, just have ingress bindings +// switch definition.Protocol { +// case "tcp": +// config.AddTcpListener(TcpEndpoint{ +// Name: name, +// Port: strconv.Itoa(iPort), +// Address: address, +// SiteId: siteId, +// }) +// default: +// } +// } +// } +// return MarshalRouterConfig(config) +// } + +func disableMutualTLS(l *Listener) { + l.SaslMechanisms = "" + l.AuthenticatePeer = false +} + +func InteriorListener(options types.RouterOptions) Listener { + l := Listener{ + Name: "interior-listener", + Role: RoleInterRouter, + Port: types.InterRouterListenerPort, + SslProfile: types.InterRouterProfile, // The skupper-internal profile needs to be filtered by the config-sync sidecar, in order to avoid deleting automesh connectors + SaslMechanisms: "EXTERNAL", + AuthenticatePeer: true, + MaxFrameSize: options.MaxFrameSize, + MaxSessionFrames: options.MaxSessionFrames, + } + if options.DisableMutualTLS { + disableMutualTLS(&l) + } + return l +} + +func EdgeListener(options types.RouterOptions) Listener { + l := Listener{ + Name: "edge-listener", + Role: RoleEdge, + Port: types.EdgeListenerPort, + SslProfile: types.InterRouterProfile, + SaslMechanisms: "EXTERNAL", + AuthenticatePeer: true, + MaxFrameSize: options.MaxFrameSize, + MaxSessionFrames: options.MaxSessionFrames, + } + if options.DisableMutualTLS { + disableMutualTLS(&l) + } + return l +} + +func GetInterRouterOrEdgeConnection(host string, connections []Connection) *Connection { + for _, c := range connections { + if (c.Role == "inter-router" || c.Role == "edge") && c.Host == host { + return &c + } + } + return nil +} + +type ConfigUpdate interface { + Apply(config *RouterConfig) bool +} diff --git a/internal/qdr/request.go b/internal/qdr/request.go new file mode 100644 index 0000000..6ef44bb --- /dev/null +++ b/internal/qdr/request.go @@ -0,0 +1,125 @@ +package qdr + +import ( + "context" + "fmt" + + amqp "github.com/interconnectedcloud/go-amqp" +) + +const ( + VersionProperty string = "version" +) + +type Request struct { + Address string + Type string + Version string + Properties map[string]interface{} + Body string +} + +type Response struct { + Type string + Version string + Properties map[string]interface{} + Body string +} + +type RequestResponse interface { + Request(request *Request) (*Response, error) +} + +type RequestServer struct { + pool *AgentPool + address string + handler RequestResponse +} + +func NewRequestServer(address string, handler RequestResponse, pool *AgentPool) *RequestServer { + return &RequestServer{ + pool, address, handler, + } +} + +func (s *RequestServer) Run(ctx context.Context) error { + agent, err := s.pool.Get() + if err != nil { + return fmt.Errorf("Could not get management agent: %s", err) + } + defer agent.Close() + + receiver, err := agent.newReceiver(s.address) + if err != nil { + return fmt.Errorf("Could not open receiver for %s: %s", s.address, err) + } + for { + err = s.serve(ctx, receiver, agent.anonymous) + if err != nil { + return fmt.Errorf("Error handling request for %s: %s", s.address, err) + } + } +} + +func (s *RequestServer) serve(ctx context.Context, receiver *amqp.Receiver, sender *amqp.Sender) error { + for { + requestMsg, err := receiver.Receive(ctx) + if err != nil { + return fmt.Errorf("Failed reading request from %s: %s", s.address, err.Error()) + } + + request := Request{ + Address: requestMsg.Properties.To, + Type: requestMsg.Properties.Subject, + Properties: map[string]interface{}{}, + } + for k, v := range requestMsg.ApplicationProperties { + if k == VersionProperty { + if version, ok := v.(string); ok { + request.Version = version + } + } else { + request.Properties[k] = v + } + } + if body, ok := requestMsg.Value.(string); ok { + request.Body = body + } + + response, err := s.handler.Request(&request) + if err != nil { + requestMsg.Reject(&amqp.Error{ + Condition: amqp.ErrorInternalError, + Description: err.Error(), + }) + return err + } else { + requestMsg.Accept() + responseMsg := amqp.Message{ + Properties: &amqp.MessageProperties{ + To: requestMsg.Properties.ReplyTo, + Subject: response.Type, + }, + ApplicationProperties: map[string]interface{}{}, + Value: response.Body, + } + correlationId, ok := AsUint64(requestMsg.Properties.CorrelationID) + if !ok { + responseMsg.Properties.CorrelationID = correlationId + } + for k, v := range response.Properties { + responseMsg.ApplicationProperties[k] = v + } + responseMsg.ApplicationProperties[VersionProperty] = response.Version + + err = sender.Send(ctx, &responseMsg) + if err != nil { + requestMsg.Reject(&amqp.Error{ + Condition: amqp.ErrorInternalError, + Description: "Could not send response: " + err.Error(), + }) + return fmt.Errorf("Could not send response: %s", err) + } + } + } +} diff --git a/internal/qdr/router_logging.go b/internal/qdr/router_logging.go new file mode 100644 index 0000000..73a9cb6 --- /dev/null +++ b/internal/qdr/router_logging.go @@ -0,0 +1,129 @@ +package qdr + +import ( + "fmt" + "strings" + + "github.com/datasance/router/internal/resources/types" +) + +func RouterLogConfigToString(config []types.RouterLogConfig) string { + items := []string{} + for _, l := range config { + if l.Module != "" && l.Level != "" { + items = append(items, l.Module+":"+l.Level) + } else if l.Level != "" { + items = append(items, l.Level) + } + } + return strings.Join(items, ",") +} + +func ConfigureRouterLogging(routerConfig *RouterConfig, logConfig []types.RouterLogConfig) bool { + levels := map[string]string{} + for _, l := range logConfig { + levels[l.Module] = l.Level + } + return routerConfig.SetLogLevels(levels) +} + +func GetRouterLogging(routerConfig *RouterConfig) []types.RouterLogConfig { + var ret []types.RouterLogConfig + if routerConfig == nil || len(routerConfig.LogConfig) == 0 { + return ret + } + for module, logConfig := range routerConfig.LogConfig { + lc := types.RouterLogConfig{Level: logConfig.Enable} + if module != "DEFAULT" || len(routerConfig.LogConfig) > 1 { + lc.Module = logConfig.Module + } + ret = append(ret, lc) + } + return ret +} + +func ParseRouterLogConfig(config string) ([]types.RouterLogConfig, error) { + items := strings.Split(config, ",") + parsed := []types.RouterLogConfig{} + for _, item := range items { + parts := strings.Split(item, ":") + var mod string + var level string + if len(parts) > 1 { + mod = parts[0] + level = parts[1] + } else if len(parts) > 0 { + level = parts[0] + } + err := checkLoggingModule(mod) + if err != nil { + return nil, err + } + err = checkLoggingLevel(level) + if err != nil { + return nil, err + } + parsed = append(parsed, types.RouterLogConfig{ + Module: mod, + Level: level, + }) + } + return parsed, nil +} + +var LoggingModules []string = []string{ + "", /*implies DEFAULT*/ + "ROUTER", + "ROUTER_CORE", + "ROUTER_HELLO", + "ROUTER_LS", + "ROUTER_MA", + "MESSAGE", + "SERVER", + "AGENT", + "AUTHSERVICE", + "CONTAINER", + "ERROR", + "POLICY", + "HTTP", + "CONN_MGR", + "PYTHON", + "PROTOCOL", + "TCP_ADAPTOR", + "HTTP_ADAPTOR", + "DEFAULT", +} +var LoggingLevels []string = []string{ + "trace", + "debug", + "info", + "notice", + "warning", + "error", + "critical", + "trace+", + "debug+", + "info+", + "notice+", + "warning+", + "error+", + "critical+", +} + +func checkLoggingModule(mod string) error { + for _, m := range LoggingModules { + if mod == m { + return nil + } + } + return fmt.Errorf("Invalid logging module for router: %s", mod) +} + +func checkLoggingLevel(level string) error { + for _, l := range LoggingLevels { + if level == l { + return nil + } + } + return fmt.Errorf("Invalid logging level for router: %s", level) +} diff --git a/internal/resources/types/types.go b/internal/resources/types/types.go new file mode 100644 index 0000000..6b4d1c9 --- /dev/null +++ b/internal/resources/types/types.go @@ -0,0 +1,409 @@ +/* +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 + + http://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 types + +import ( + "time" +) + +const ( + ENV_PLATFORM = "SKUPPER_PLATFORM" + EnvSSLProfilePath = "SSL_PROFILE_PATH" +) + +const ( + // NamespaceDefault means the VAN is in the skupper namespace which is applied when not specified by clients + NamespaceDefault string = "skupper" + DefaultVanName string = "skupper" + DefaultSiteName string = "skupper-site" + ClusterLocalPostfix string = ".svc.cluster.local" + SiteConfigMapName string = "skupper-site" + NetworkStatusConfigMapName string = "skupper-network-status" + SiteLeaderLockName string = "skupper-site-leader" +) + +const DefaultTimeoutDuration = time.Second * 120 + +// TransportMode describes how a qdr is intended to be deployed, either interior or edge +type TransportMode string + +const ( + // TransportModeInterior means the qdr will participate in inter-router protocol exchanges + TransportModeInterior TransportMode = "interior" + // TransportModeEdge means that the qdr will connect to interior routers for network access + TransportModeEdge TransportMode = "edge" +) + +// Transport constants +const ( + TransportDeploymentName string = "skupper-router" + TransportComponentName string = "router" + TransportContainerName string = "router" + ConfigSyncContainerName string = "config-sync" + TransportLivenessPort int32 = 9090 + TransportServiceAccountName string = "skupper-router" + TransportRoleName string = "skupper-router" + TransportRoleBindingName string = "skupper-router" + TransportEnvConfig string = "QDROUTERD_CONF" + TransportSaslConfig string = "skupper-sasl-config" + TransportConfigFile string = "skrouterd.json" + TransportConfigMapName string = "skupper-internal" + TransportServiceName string = "skupper-router" + LocalTransportServiceName string = "skupper-router-local" + RouterMaxFrameSizeDefault int = 16384 + RouterMaxSessionFramesDefault int = 640 +) + +// Controller and Collector constants +const ( + ControllerDeploymentName string = "skupper-service-controller" + ControllerComponentName string = "service-controller" + ControllerContainerName string = "service-controller" + ControllerServiceAccountName string = "skupper-service-controller" + ControllerRoleBindingName string = "skupper-service-controller" + ControllerClusterRoleBindingNsFormat string = "skupper-service-controller-%s" + ControllerRoleName string = "skupper-service-controller" + ControllerClusterRoleName string = "skupper-service-controller-basic" + ControllerExtendedClusterRoleName string = "skupper-service-controller-extended" + ControllerConfigPath string = "/etc/messaging/" + ControllerServiceName string = "skupper" + ControllerPodmanContainerName string = "skupper-controller-podman" + FlowCollectorContainerName string = "flow-collector" + PrometheusDeploymentName string = "skupper-prometheus" + PrometheusComponentName string = "prometheus" + PrometheusContainerName string = "prometheus-server" + PrometheusServiceAccountName string = "skupper-prometheus" + PrometheusServiceName string = "skupper-prometheus" + PrometheusRoleBindingName string = "skupper-prometheus" + PrometheusRoleName string = "skupper-prometheus" +) + +// Certificates/Secrets constants +const ( + LocalClientSecret string = "skupper-local-client" + LocalServerSecret string = "skupper-local-server" + LocalCaSecret string = "skupper-local-ca" + SiteServerSecret string = "skupper-site-server" + SiteCaSecret string = "skupper-site-ca" + ConsoleServerSecret string = "skupper-console-certs" + ConsoleUsersSecret string = "skupper-console-users" + PrometheusServerSecret string = "skupper-prometheus-certs" + OauthRouterConsoleSecret string = "skupper-router-console-certs" + ServiceCaSecret string = "skupper-service-ca" + ServiceClientSecret string = "skupper-service-client" // Secret that is used in sslProfiles for all http2 connectors with tls enabled +) + +// Skupper qualifiers +const ( + BaseQualifier string = "skupper.io" + InternalQualifier string = "internal." + BaseQualifier + AddressQualifier string = BaseQualifier + "/address" + PortQualifier string = BaseQualifier + "/port" + ProxyQualifier string = BaseQualifier + "/proxy" + TargetServiceQualifier string = BaseQualifier + "/target" + HeadlessQualifier string = BaseQualifier + "/headless" + IngressModeQualifier string = BaseQualifier + "/ingress" + CpuRequestAnnotation string = BaseQualifier + "/cpu-request" + MemoryRequestAnnotation string = BaseQualifier + "/memory-request" + CpuLimitAnnotation string = BaseQualifier + "/cpu-limit" + MemoryLimitAnnotation string = BaseQualifier + "/memory-limit" + AffinityAnnotation string = BaseQualifier + "/affinity" + AntiAffinityAnnotation string = BaseQualifier + "/anti-affinity" + NodeSelectorAnnotation string = BaseQualifier + "/node-selector" + ControlledQualifier string = InternalQualifier + "/controlled" + ServiceQualifier string = InternalQualifier + "/service" + OriginQualifier string = InternalQualifier + "/origin" + OriginalSelectorQualifier string = InternalQualifier + "/originalSelector" + OriginalTargetPortQualifier string = InternalQualifier + "/originalTargetPort" + OriginalAssignedQualifier string = InternalQualifier + "/originalAssignedPort" + InternalTypeQualifier string = InternalQualifier + "/type" + InternalMetadataQualifier string = InternalQualifier + "/metadata" + SkupperTypeQualifier string = BaseQualifier + "/type" + TypeProxyQualifier string = InternalTypeQualifier + "=proxy" + SkupperDisabledQualifier string = InternalQualifier + "/disabled" + TypeToken string = "connection-token" + TypeClaimRecord string = "token-claim-record" + TypeClaimRequest string = "token-claim" + TypeGatewayToken string = "gateway-connection-token" + TypeTokenQualifier string = BaseQualifier + "/type=connection-token" + TypeTokenRequestQualifier string = BaseQualifier + "/type=connection-token-request" + TokenGeneratedBy string = BaseQualifier + "/generated-by" + SiteVersion string = BaseQualifier + "/site-version" + SiteId string = BaseQualifier + "/site-id" + TokenCost string = BaseQualifier + "/cost" + TokenTemplate string = BaseQualifier + "/token-template" + UpdatedAnnotation string = InternalQualifier + "/updated" + AnnotationExcludes string = BaseQualifier + "/exclude-annotations" + LabelExcludes string = BaseQualifier + "/exclude-labels" + ServiceLabels string = BaseQualifier + "/service-labels" + ServiceAnnotations string = BaseQualifier + "/service-annotations" + ComponentAnnotation string = BaseQualifier + "/component" + SiteControllerIgnore string = InternalQualifier + "/site-controller-ignore" + RouterComponent string = "router" + ClaimExpiration string = BaseQualifier + "/claim-expiration" + ClaimsRemaining string = BaseQualifier + "/claims-remaining" + ClaimsMade string = BaseQualifier + "/claims-made" + ClaimUrlAnnotationKey string = BaseQualifier + "/url" + ClaimPasswordDataKey string = "password" + ClaimCaCertDataKey string = "ca.crt" + ClaimRequestSelector string = SkupperTypeQualifier + "=" + TypeClaimRequest + LastFailedAnnotationKey string = InternalQualifier + "/last-failed" + StatusAnnotationKey string = InternalQualifier + "/status" + GatewayQualifier string = InternalQualifier + "/gateway" + IngressOnlyQualifier string = BaseQualifier + "/ingress-only" + TlsCertQualifier string = BaseQualifier + "/tls-cert" + TlsTrustQualifier string = BaseQualifier + "/tls-trust" +) + +// Console and vFlow Collector constants +const ( + ConsolePortName string = "console" + ConsoleDefaultServicePort int32 = 8080 + ConsoleDefaultServiceTargetPort int32 = 8080 + FlowCollectorDefaultServicePort int32 = 8010 + FlowCollectorDefaultServiceTargetPort int32 = 8010 + ConsoleOpenShiftServicePort int32 = 8888 + ConsoleOpenShiftOauthServicePort int32 = 443 + ConsoleOpenShiftOauthServiceTargetPort int32 = 8443 + ConsoleRouteName string = "skupper" + RouterConsoleServiceName string = "skupper-router-console" +) + +const DefaultFlowTimeoutDuration = time.Minute * 15 + +type Platform string + +const ( + PlatformKubernetes Platform = "kubernetes" + PlatformPot Platform = "pot" + PlatformPodman Platform = "podman" + PlatformDocker Platform = "docker" + PlatformLinux Platform = "linux" +) + +func (p Platform) IsKubernetes() bool { + return p == "" || p == PlatformKubernetes +} + +func (p Platform) IsContainerEngine() bool { + return p == PlatformDocker || p == PlatformPodman +} + +type ConsoleAuthMode string + +const ( + ConsoleAuthModeOpenshift ConsoleAuthMode = "openshift" + ConsoleAuthModeInternal ConsoleAuthMode = "internal" + ConsoleAuthModeUnsecured ConsoleAuthMode = "unsecured" +) + +const ( + ClaimRedemptionPort int32 = 8081 + ClaimRedemptionPortName string = "claims" + ClaimRedemptionRouteName string = "skupper-claims" +) + +type PrometheusAuthMode string + +const ( + PrometheusAuthModeTls PrometheusAuthMode = "tls" + PrometheusAuthModeBasic PrometheusAuthMode = "basic" + PrometheusAuthModeUnsecured PrometheusAuthMode = "unsecured" +) + +// Prometheus server constants (note: use console auth mode) +const ( + PrometheusPortName string = "prometheus" + PrometheusServerDefaultServicePort int32 = 9090 + PrometheusServerDefaultServiceTargetPort int32 = 9090 + PrometheusRouteName string = "skupper-prometheus" +) + +// Assembly constants +const ( + AmqpDefaultPort int32 = 5672 + AmqpsDefaultPort int32 = 5671 + EdgeRole string = "edge" + EdgeRouteName string = "skupper-edge" + EdgeListenerPort int32 = 45671 + InterRouterRole string = "inter-router" + InterRouterListenerPort int32 = 55671 + InterRouterRouteName string = "skupper-inter-router" + InterRouterProfile string = "skupper-internal" + IngressName string = "skupper" +) + +// Service Sync constants +const ( + ServiceSyncAddress = "mc/$skupper-service-sync" +) + +const ( + SkupperServiceCertPrefix string = "skupper-tls-" +) + +// // RouterSpec is the specification of VAN network with router, controller and assembly +// type RouterSpec struct { +// Name string `json:"name,omitempty"` +// Namespace string `json:"namespace,omitempty"` +// AuthMode ConsoleAuthMode `json:"authMode,omitempty"` +// Transport DeploymentSpec `json:"transport,omitempty"` +// ConfigSync DeploymentSpec `json:"configSync,omitempty"` +// Controller DeploymentSpec `json:"controller,omitempty"` +// Collector DeploymentSpec `json:"collector,omitempty"` +// PrometheusServer DeploymentSpec `json:"prometheusServer,omitempty"` +// RouterConfig string `json:"routerConfig,omitempty"` +// Users []User `json:"users,omitempty"` +// CertAuthoritys []CertAuthority `json:"certAuthoritys,omitempty"` +// TransportCredentials []Credential `json:"transportCredentials,omitempty"` +// ControllerCredentials []Credential `json:"controllerCredentials,omitempty"` +// PrometheusCredentials []Credential `json:"prometheusCredentials,omitempty"` +// } + +// AssemblySpec for the links and connectors that form the VAN topology +type AssemblySpec struct { + Name string `json:"name,omitempty"` + Mode string `json:"mode,omitempty"` + Listeners []Listener `json:"listeners,omitempty"` + InterRouterListeners []Listener `json:"interRouterListeners,omitempty"` + EdgeListeners []Listener `json:"edgeListeners,omitempty"` + SslProfiles []SslProfile `json:"sslProfiles,omitempty"` + Connectors []Connector `json:"connectors,omitempty"` + InterRouterConnectors []Connector `json:"interRouterConnectors,omitempty"` + EdgeConnectors []Connector `json:"edgeConnectors,omitempty"` +} + +type RouterStatusSpec struct { + SiteName string `json:"siteName,omitempty"` + Mode string `json:"mode,omitempty"` + TransportReadyReplicas int32 `json:"transportReadyReplicas,omitempty"` + ConnectedSites TransportConnectedSites `json:"connectedSites,omitempty"` + BindingsCount int `json:"bindingsCount,omitempty"` +} + +type Listener struct { + Name string `json:"name,omitempty"` + Host string `json:"host,omitempty"` + Port int32 `json:"port"` + RouteContainer bool `json:"routeContainer,omitempty"` + Http bool `json:"http,omitempty"` + Cost int32 `json:"cost,omitempty"` + SslProfile string `json:"sslProfile,omitempty"` + SaslMechanisms string `json:"saslMechanisms,omitempty"` + AuthenticatePeer bool `json:"authenticatePeer,omitempty"` + LinkCapacity int32 `json:"linkCapacity,omitempty"` +} + +type SslProfile struct { + Name string `json:"name,omitempty"` + Cert string `json:"cert,omitempty"` + Key string `json:"key,omitempty"` + CaCert string `json:"caCert,omitempty"` +} + +type ConnectorRole string + +const ( + ConnectorRoleInterRouter ConnectorRole = "inter-router" + ConnectorRoleEdge ConnectorRole = "edge" +) + +const ( + ConsoleIngressPrefix = "skupper-console" + ClaimsIngressPrefix = "skupper-claims" + InterRouterIngressPrefix = "skupper-inter-router" + EdgeIngressPrefix = "skupper-edge" + PrometheusIngressPrefix = "skupper-prometheus" +) + +type Connector struct { + Name string `json:"name,omitempty"` + Role string `json:"role,omitempty"` + Host string `json:"host"` + Port string `json:"port"` + RouteContainer bool `json:"routeContainer,omitempty"` + Cost int32 `json:"cost,omitempty"` + VerifyHostname bool `json:"verifyHostname,omitempty"` + SslProfile string `json:"sslProfile,omitempty"` + LinkCapacity int32 `json:"linkCapacity,omitempty"` +} + +type Credential struct { + CA string + Name string + Subject string + Hosts []string + ConnectJson bool + Post bool + Data map[string][]byte + Simple bool `default:"false"` + Labels map[string]string + Expiration time.Duration +} + +type CertAuthority struct { + Name string + Labels map[string]string +} + +type User struct { + Name string + Password string +} + +type TransportConnectedSites struct { + Direct int + Indirect int + Total int + Warnings []string +} + +type RouterLogConfig struct { + Module string + Level string +} + +type Tuning struct { + NodeSelector string + Affinity string + AntiAffinity string + Cpu string + Memory string + CpuLimit string + MemoryLimit string +} + +type RouterOptions struct { + Tuning + Logging []RouterLogConfig + MaxFrameSize int + MaxSessionFrames int + DataConnectionCount string + IngressHost string + ServiceAnnotations map[string]string + PodAnnotations map[string]string + LoadBalancerIp string + DisableMutualTLS bool +} + +type LinkStatus struct { + Name string + Url string + Cost int + Connected bool + Configured bool + Description string + Created string +} diff --git a/internal/router/router.go b/internal/router/router.go index 4e18fee..7e1251c 100644 --- a/internal/router/router.go +++ b/internal/router/router.go @@ -14,161 +14,250 @@ package router import ( + "encoding/json" "fmt" + "log" + "os" + "path/filepath" + "time" + "github.com/datasance/router/internal/config" "github.com/datasance/router/internal/exec" + "github.com/datasance/router/internal/qdr" ) -type Listener struct { - Role string `json:"role"` - Host string `json:"host"` - Port int `json:"port"` -} - -type Connector struct { - Name string `json:"name"` - Role string `json:"role"` - Host string `json:"host"` - Port int `json:"port"` -} - type Config struct { - Mode string `json:"mode"` - Name string `json:"id"` - Listeners []Listener `json:"listeners"` - Connectors []Connector `json:"connectors"` + Metadata qdr.RouterMetadata + SslProfiles map[string]qdr.SslProfile + Listeners map[string]qdr.Listener + Connectors map[string]qdr.Connector + Addresses map[string]qdr.Address + LogConfig map[string]qdr.LogConfig + SiteConfig *qdr.SiteConfig + Bridges qdr.BridgeConfig } type Router struct { - listeners map[string]Listener - connectors map[string]Connector - Config *Config + Config *Config } -func qdmanage(args []string) { - exitChannel := make(chan error) - go exec.Run(exitChannel, "qdmanage", args, []string{}) - for { - select { - case <-exitChannel: - return - } +func (router *Router) UpdateRouter(newConfig *Config) error { + log.Printf("DEBUG: Starting router configuration update") + + // Create agent pool and get client + log.Printf("DEBUG: Creating agent pool") + agentPool := qdr.NewAgentPool("amqp://localhost:5672", nil) + client, err := agentPool.Get() + if err != nil { + log.Printf("ERROR: Failed to get client from pool: %v", err) + return fmt.Errorf("failed to get client from pool: %v", err) } -} -func listenerName(listener Listener) string { - return fmt.Sprintf("listener-%s-%s-%d", listener.Role, listener.Host, listener.Port) -} + // Get current bridge configuration + log.Printf("DEBUG: Getting current bridge configuration") + currentBridgeConfig, err := client.GetLocalBridgeConfig() + if err != nil { + log.Printf("ERROR: Failed to get current bridge config: %v", err) + return fmt.Errorf("failed to get current bridge config: %v", err) + } -func connectorName(connector Connector) string { - return fmt.Sprintf("connector-%s-%s-%s-%d", connector.Name, connector.Role, connector.Host, connector.Port) -} + // Calculate differences using qdr's built-in Difference method + log.Printf("DEBUG: Calculating bridge configuration differences") + changes := currentBridgeConfig.Difference(&newConfig.Bridges) + log.Printf("DEBUG: Bridge config changes: %+v", changes) -func deleteEntity(name string) { - args := []string{ - "delete", - fmt.Sprintf("--name=%s", name), + // Update via AMQP management using qdr's built-in function + log.Printf("DEBUG: Updating bridge configuration") + if err := client.UpdateLocalBridgeConfig(changes); err != nil { + log.Printf("ERROR: Failed to update bridge config: %v", err) + return fmt.Errorf("failed to update bridge config: %v", err) } - qdmanage(args) -} -func (router *Router) createListener(listener Listener) { - args := []string{ - "create", - "--type=listener", - fmt.Sprintf("port=%d", listener.Port), - fmt.Sprintf("role=%s", listener.Role), - fmt.Sprintf("host=%s", listener.Host), - fmt.Sprintf("name=%s", listenerName(listener)), - fmt.Sprintf("saslMechanisms=ANONYMOUS"), - fmt.Sprintf("authenticatePeer=no"), - } - qdmanage(args) - router.listeners[listenerName(listener)] = listener -} + // Update the configuration file (skip on Kubernetes; config is read-only from ConfigMap) + if !config.IsKubernetesRouterMode() { + log.Printf("DEBUG: Updating router configuration file") + configJSON := router.GetRouterConfig() + configPath := config.GetConfigPath() + if err := os.WriteFile(configPath, []byte(configJSON), 0644); err != nil { + log.Printf("ERROR: Failed to write router configuration: %v", err) + return fmt.Errorf("failed to write router configuration: %v", err) + } + } -func (router *Router) createConnector(connector Connector) { - args := []string{ - "create", - "--type=connector", - fmt.Sprintf("port=%d", connector.Port), - fmt.Sprintf("role=%s", connector.Role), - fmt.Sprintf("host=%s", connector.Host), - fmt.Sprintf("name=%s", connectorName(connector)), - } - qdmanage(args) - router.connectors[connectorName(connector)] = connector -} + // Update the in-memory configuration + router.Config = newConfig + + // Return client to the pool instead of closing it + if client != nil { + agentPool.Put(client) + } -func (router *Router) deleteListener(listener Listener) { - deleteEntity(listenerName(listener)) - delete(router.listeners, listenerName(listener)) + log.Printf("DEBUG: Router configuration update completed successfully") + return nil } -func (router *Router) deleteConnector(connector Connector) { - deleteEntity(connectorName(connector)) - delete(router.connectors, connectorName(connector)) +// OnSSLProfilesFromDisk merges profiles (from SSL_PROFILE_PATH scan) into Config.SslProfiles, +// writes the router config file, and calls qdr ReloadSslProfile for each profile so the +// running router picks up cert rotation without restart. +func (r *Router) OnSSLProfilesFromDisk(profiles map[string]qdr.SslProfile) { + if r.Config == nil || r.Config.SslProfiles == nil { + return + } + for name, profile := range profiles { + r.Config.SslProfiles[name] = profile + } + // Write config file only on Pot; on Kubernetes config is read-only from ConfigMap + if !config.IsKubernetesRouterMode() { + configPath := config.GetConfigPath() + configJSON := r.GetRouterConfig() + if err := os.WriteFile(configPath, []byte(configJSON), 0644); err != nil { + log.Printf("ERROR: Failed to write router config after SSL profile update: %v", err) + return + } + } + agentPool := qdr.NewAgentPool("amqp://localhost:5672", nil) + client, err := agentPool.Get() + if err != nil { + log.Printf("ERROR: Failed to get qdr client for SSL profile reload: %v", err) + return + } + defer agentPool.Put(client) + for name := range profiles { + if err := client.ReloadSslProfile(name); err != nil { + log.Printf("ERROR: Failed to reload SSL profile %s: %v", name, err) + } + } } -func (router *Router) UpdateRouter(newConfig *Config) { - newListeners := make(map[string]Listener) - newConnectors := make(map[string]Connector) +func (router *Router) GetRouterConfig() string { + config := router.Config + configElements := [][]interface{}{} - for _, listener := range newConfig.Listeners { - newListeners[listenerName(listener)] = listener - if _, ok := router.listeners[listenerName(listener)]; !ok { - router.createListener(listener) - } + // Add router metadata + configElements = append(configElements, []interface{}{ + "router", + config.Metadata, + }) + + // Add SSL profiles (file paths are already absolute) + for _, profile := range config.SslProfiles { + configElements = append(configElements, []interface{}{ + "sslProfile", + profile, + }) } - for _, connector := range newConfig.Connectors { - newConnectors[connectorName(connector)] = connector - if _, ok := router.connectors[connectorName(connector)]; !ok { - router.createConnector(connector) - } + // Add listeners + for _, listener := range config.Listeners { + configElements = append(configElements, []interface{}{ + "listener", + listener, + }) } - for _, listener := range router.listeners { - if _, ok := newListeners[listenerName(listener)]; !ok { - router.deleteListener(listener) - } + // Add connectors + for _, connector := range config.Connectors { + configElements = append(configElements, []interface{}{ + "connector", + connector, + }) } - for _, connector := range router.connectors { - if _, ok := newConnectors[connectorName(connector)]; !ok { - router.deleteConnector(connector) - } + // Add TCP listeners + for _, listener := range config.Bridges.TcpListeners { + configElements = append(configElements, []interface{}{ + "tcpListener", + listener, + }) } - router.Config = newConfig -} + // Add TCP connectors + for _, connector := range config.Bridges.TcpConnectors { + configElements = append(configElements, []interface{}{ + "tcpConnector", + connector, + }) + } -func (router *Router) GetRouterConfig() string { - listenersConfig := "" - for _, listener := range router.listeners { - listenersConfig += fmt.Sprintf("\\nlistener {\\n name: %s\\n role: %s\\n host: %s\\n port: %d\\n saslMechanisms: ANONYMOUS\\n authenticatePeer: no\\n}", listenerName(listener), listener.Role, listener.Host, listener.Port) + // Add addresses + for _, address := range config.Addresses { + configElements = append(configElements, []interface{}{ + "address", + address, + }) } - connectorsConfig := "" - for _, connector := range router.connectors { - connectorsConfig += fmt.Sprintf("\\nconnector {\\n name: %s\\n host: %s\\n port: %d\\n role: %s\\n saslMechanisms: ANONYMOUS\\n}", connectorName(connector), connector.Host, connector.Port, connector.Role) + // Add log configs + for _, logConfig := range config.LogConfig { + configElements = append(configElements, []interface{}{ + "log", + logConfig, + }) } - return fmt.Sprintf("router {\\n mode: %s\\n id: %s\\n}%s%s", router.Config.Mode, router.Config.Name, listenersConfig, connectorsConfig) + // Add site config if present + if config.SiteConfig != nil { + configElements = append(configElements, []interface{}{ + "site", + *config.SiteConfig, + }) + } + + // Marshal to JSON + data, err := json.MarshalIndent(configElements, "", " ") + if err != nil { + log.Printf("Error marshaling router config: %v", err) + return "" + } + + return string(data) } func (router *Router) StartRouter(ch chan<- error) { - router.listeners = make(map[string]Listener) - router.connectors = make(map[string]Connector) + log.Printf("DEBUG: Starting router with configuration") + + configPath := config.GetConfigPath() + // On Pot we create and write initial config; on Kubernetes config is already mounted at QDROUTERD_CONF + if !config.IsKubernetesRouterMode() { + log.Printf("DEBUG: Creating initial router configuration") + configJSON := router.GetRouterConfig() + + log.Printf("DEBUG: Ensuring configuration directory exists") + if err := os.MkdirAll(filepath.Dir(configPath), 0755); err != nil { + log.Printf("ERROR: Failed to create configuration directory: %v", err) + ch <- fmt.Errorf("failed to create configuration directory: %v", err) + return + } - for _, listener := range router.Config.Listeners { - router.listeners[listenerName(listener)] = listener + log.Printf("DEBUG: Writing initial configuration to %s", configPath) + if err := os.WriteFile(configPath, []byte(configJSON), 0644); err != nil { + log.Printf("ERROR: Failed to write initial configuration: %v", err) + ch <- fmt.Errorf("failed to write initial configuration: %v", err) + return + } } - for _, connector := range router.Config.Connectors { - router.connectors[connectorName(connector)] = connector + // Start router with QDROUTERD_CONF and QDROUTERD_CONF_TYPE so launch script uses our config file + env := []string{ + fmt.Sprintf("QDROUTERD_CONF=%s", configPath), + "QDROUTERD_CONF_TYPE=json", } + exitChannel := make(chan error) + log.Printf("DEBUG: Starting router process") + go exec.Run(ch, "/home/skrouterd/bin/launch.sh", []string{}, env) - routerConfig := router.GetRouterConfig() - exec.Run(ch, "/qpid-dispatch/launch.sh", []string{}, []string{"QDROUTERD_CONF=" + routerConfig}) + // Monitor for configuration updates + go func() { + for { + select { + case err := <-exitChannel: + log.Printf("ERROR: Router process exited with error: %v", err) + ch <- fmt.Errorf("router process exited with error: %v", err) + return + default: + // Check for configuration updates from ioFog-agent + time.Sleep(5 * time.Second) + } + } + }() } diff --git a/internal/utils/command.go b/internal/utils/command.go new file mode 100644 index 0000000..8f5e3e9 --- /dev/null +++ b/internal/utils/command.go @@ -0,0 +1,29 @@ +package utils + +import ( + "bytes" +) + +const ( + maxLineLength = 80 + indent = " " + newLinePrefix = " \\\n" + indent +) + +func PrettyPrintCommand(command string, args []string) string { + var lineLength int + buf := new(bytes.Buffer) + buf.WriteString(command) + lineLength = len(command) + for i, arg := range args { + buf.WriteString(" ") + buf.WriteString(arg) + lineLength += len(arg) + 1 + if lineLength > maxLineLength && i < len(args)-1 { + buf.WriteString(newLinePrefix) + lineLength = len(indent) + } + } + buf.WriteString("\n") + return buf.String() +} diff --git a/internal/utils/command_test.go b/internal/utils/command_test.go new file mode 100644 index 0000000..78ef1bd --- /dev/null +++ b/internal/utils/command_test.go @@ -0,0 +1,32 @@ +package utils + +import ( + "testing" + + "gotest.tools/v3/assert" +) + +const ( + expectedOutput = `sample_command argument1 argument2 argument3 argument4 argument5 argument6 argument7 \ + argument8 argument9 argument10 argument11 argument12 argument13 argument14 argument15 \ + argument16 argument17 argument18 argument19 argument20 argument21 argument22 argument23 \ + argument24 argument25 argument26 argument27 argument28 argument29 +` +) + +var ( + commandArgs = []string{ + "sample_command", "argument1", "argument2", "argument3", "argument4", "argument5", + "argument6", "argument7", "argument8", "argument9", "argument10", "argument11", "argument12", + "argument13", "argument14", "argument15", "argument16", "argument17", "argument18", + "argument19", "argument20", "argument21", "argument22", "argument23", "argument24", + "argument25", "argument26", "argument27", "argument28", "argument29", + } +) + +func TestPrettyPrintCommand(t *testing.T) { + output := PrettyPrintCommand(commandArgs[0], commandArgs[1:]) + assert.Equal(t, expectedOutput, output) + shortCommand := PrettyPrintCommand("command", []string{"arg1", "arg2", "arg3"}) + assert.Equal(t, "command arg1 arg2 arg3\n", shortCommand) +} diff --git a/internal/utils/files.go b/internal/utils/files.go new file mode 100644 index 0000000..0be97bb --- /dev/null +++ b/internal/utils/files.go @@ -0,0 +1,43 @@ +package utils + +import ( + "fmt" + "os" + "path" +) + +type FilenameFilter func(string) bool +type DirectoryReader struct{} + +func (f *DirectoryReader) ReadDir(dirname string, filter FilenameFilter) ([]string, error) { + dir, err := os.Open(dirname) + if err != nil { + return nil, err + } + dirInfo, err := dir.Stat() + if err != nil { + return nil, err + } + if !dirInfo.IsDir() { + return nil, fmt.Errorf("%s is not a directory", dirname) + } + files, err := dir.ReadDir(0) + if err != nil { + return nil, err + } + var fileNames []string + for _, file := range files { + if file.IsDir() { + recursiveFiles, err := f.ReadDir(path.Join(dirname, file.Name()), filter) + if err != nil { + return nil, err + } + fileNames = append(fileNames, recursiveFiles...) + } else { + if filter == nil || filter(file.Name()) { + fileNames = append(fileNames, path.Join(dirname, file.Name())) + } + } + } + return fileNames, nil +} diff --git a/internal/utils/files_test.go b/internal/utils/files_test.go new file mode 100644 index 0000000..e25be98 --- /dev/null +++ b/internal/utils/files_test.go @@ -0,0 +1,108 @@ +package utils + +import ( + "os" + "path" + "slices" + "strings" + "testing" + + "gotest.tools/v3/assert" +) + +func TestDirectoryReader(t *testing.T) { + for _, test := range []struct { + description string + files int + directories int + levels int + filter func(string) bool + expectedFiles []string + }{ + { + description: "empty-directory", + files: 0, + directories: 0, + levels: 0, + expectedFiles: []string{}, + }, + { + description: "empty-directory-tree", + files: 0, + directories: 3, + levels: 3, + }, + { + description: "full-directory", + files: 3, + directories: 0, + levels: 1, + expectedFiles: []string{ + "file.1", + "file.2", + "file.3", + }, + }, + { + description: "full-directory-tree", + files: 3, + directories: 3, + levels: 1, + expectedFiles: []string{ + "file.1", + "file.2", + "file.3", + "dir1/file.1", + "dir1/file.2", + "dir1/file.3", + "dir2/file.1", + "dir2/file.2", + "dir2/file.3", + "dir3/file.1", + "dir3/file.2", + "dir3/file.3", + }, + }, + { + description: "full-directory-tree-filtered", + files: 3, + directories: 3, + levels: 1, + filter: func(name string) bool { + return strings.HasSuffix(name, ".3") + }, + expectedFiles: []string{ + "file.3", + "dir1/file.3", + "dir2/file.3", + "dir3/file.3", + }, + }, + } { + t.Run(test.description, func(t *testing.T) { + baseDir, err := os.MkdirTemp("", "testdirreader.*") + assert.Assert(t, err) + defer func() { + assert.Assert(t, os.RemoveAll(baseDir)) + }() + // Generating files and asserting generation was successful + tree := generateDirectoryTree(test.directories, test.levels) + err = createFiles(baseDir, test.files, []byte("sample data"), tree) + assert.Assert(t, err, "unable to create files") + + r := new(DirectoryReader) + files, err := r.ReadDir(baseDir, test.filter) + assert.NilError(t, err, "error reading directory") + if test.filter == nil { + assert.Equal(t, len(files), expectedCreatedFiles(test.directories, test.levels, test.files)) + } else { + if len(test.expectedFiles) > 0 { + assert.Equal(t, len(files), len(test.expectedFiles)) + } + } + for _, expectedFile := range test.expectedFiles { + assert.Assert(t, slices.Contains(files, path.Join(baseDir, expectedFile))) + } + }) + } +} diff --git a/internal/utils/retry.go b/internal/utils/retry.go new file mode 100644 index 0000000..ba24718 --- /dev/null +++ b/internal/utils/retry.go @@ -0,0 +1,141 @@ +/* +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 + + http://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 utils + +import ( + "context" + "fmt" + "time" +) + +type ConditionFunc func() (bool, error) + +type CheckedFunc func() error + +// Retry retries f every interval until after maxRetries. +// +// The interval won't be affected by how long f takes. +// For example, if interval is 3s, f takes 1s, another f will be called 2s later. +// However, if f takes longer than interval, it will be delayed. +// +// If an error is received from f, fail immediately and return that error (no +// further retries). +// +// Keep in mind that the second argument is for max _retries_. So, with a value +// of 1, f() will run at most 2 times (one try and one _retry_). +func Retry(interval time.Duration, maxRetries int, f ConditionFunc) error { + if maxRetries <= 0 { + return fmt.Errorf("maxRetries (%d) should be > 0", maxRetries) + } + tick := time.NewTicker(interval) + defer tick.Stop() + + for i := 0; ; i++ { + ok, err := f() + if err != nil { + return err + } + if ok { + return nil + } + if i == maxRetries { + return fmt.Errorf("still failing after %d retries", i) + } + <-tick.C + } +} + +// This is similar to Retry(), but it will not fail immediately on errors, and +// if the retries are exhausted and f() still failing, it will return f()'s error +func RetryError(interval time.Duration, maxRetries int, f CheckedFunc) error { + if maxRetries <= 0 { + return fmt.Errorf("maxRetries (%d) should be > 0", maxRetries) + } + tick := time.NewTicker(interval) + defer tick.Stop() + + for i := 0; ; i++ { + err := f() + if err == nil { + return nil + } + if i == maxRetries { + return err + } + <-tick.C + } +} + +type Result struct { + Value interface{} + Error error +} + +type ResultFunc func() Result + +func TryUntil(maxWindowTime time.Duration, f ResultFunc) (interface{}, error) { + + result := make(chan Result, 1) + + go func() { + result <- f() + }() + select { + case <-time.After(maxWindowTime): + return nil, fmt.Errorf("timed out") + case result := <-result: + return result.Value, result.Error + } +} + +// RetryWithContext retries f every interval until the specified context times out. +func RetryWithContext(ctx context.Context, interval time.Duration, f ConditionFunc) error { + tick := time.NewTicker(interval) + defer tick.Stop() + + for { + select { + case <-ctx.Done(): + return context.DeadlineExceeded + case <-tick.C: + r, err := f() + if err != nil { + return err + } + if r { + return nil + } + } + } +} + +// RetryErrorWithContext will retry as long the checked function is returning an error and the context does not time out +func RetryErrorWithContext(ctx context.Context, interval time.Duration, f CheckedFunc) error { + tick := time.NewTicker(interval) + defer tick.Stop() + + for { + select { + case <-ctx.Done(): + return context.DeadlineExceeded + + case <-tick.C: + err := f() + if err == nil { + return nil + } + } + } +} diff --git a/internal/utils/retry_test.go b/internal/utils/retry_test.go new file mode 100644 index 0000000..e4cc08c --- /dev/null +++ b/internal/utils/retry_test.go @@ -0,0 +1,407 @@ +package utils + +import ( + "context" + "fmt" + "testing" + "time" + + "gotest.tools/v3/assert" +) + +// f() return: Retry() +// +// n ok err maxRetries return (error) +// -- ----- ----- ----------- -------------- +// 1 true, nil no nil +// 2 true, !nil no err from f() +// 3 false, nil no retry +// 4 false, !nil no err from f() +// +// 5 true, nil yes nil +// 6 true, !nil yes err from f() +// 7 false, nil yes RetryError +// 8 false, !nil yes err from f() +// +// Or: +// +// - If function produces an error, fail immediately with that error +// - Else, if ok is true, return nil and succeed +// - Otherwise: +// - if before maximum retry: retry +// - if on maximum retry: return a Retry error and fail + +type RetryTestItem struct { + // These configure what the f() function will respond + err error + okOnTry int // OkOnTry = 1 make it ok right away; OkOnTry = 0 will never be ok + errorOnTry int + nilOnTry int + // This configures Retry itself + maxRetries int + // And those are what we're expecting the actual result to look like + expectedTries int + expectedResponse error + + // these change the normal response of f() until a specific try +} + +func TestRetry(t *testing.T) { + + testTable := []RetryTestItem{ + { // #1 + okOnTry: 1, + err: nil, + maxRetries: 3, + expectedTries: 1, + expectedResponse: nil, + }, { // #2 + okOnTry: 1, + err: fmt.Errorf("app error"), + maxRetries: 3, + expectedTries: 1, + expectedResponse: fmt.Errorf("app error"), + }, { // #3, #7 + okOnTry: 0, + err: nil, + maxRetries: 3, + expectedTries: 4, + expectedResponse: fmt.Errorf("still failing after 3 retries"), + }, { // #4 + okOnTry: 0, + err: fmt.Errorf("app error"), + maxRetries: 3, + expectedTries: 1, + expectedResponse: fmt.Errorf("app error"), + }, { // #3, #1 + okOnTry: 2, + err: nil, + maxRetries: 3, + expectedTries: 2, + expectedResponse: nil, + }, { // #3, #2 + okOnTry: 2, + err: fmt.Errorf("app error"), + maxRetries: 3, + expectedTries: 2, + expectedResponse: fmt.Errorf("app error"), + errorOnTry: 2, + }, { // #3, #4 + okOnTry: 0, + err: fmt.Errorf("app error"), + maxRetries: 3, + expectedTries: 2, + expectedResponse: fmt.Errorf("app error"), + errorOnTry: 2, + }, { // #3, #5 + okOnTry: 4, + err: nil, + maxRetries: 3, + expectedTries: 4, + expectedResponse: nil, + }, { // #3, #6 + okOnTry: 4, + err: fmt.Errorf("app error"), + maxRetries: 3, + expectedTries: 4, + expectedResponse: fmt.Errorf("app error"), + errorOnTry: 4, + }, { // #3, #8 + okOnTry: 0, + err: fmt.Errorf("app error"), + maxRetries: 3, + expectedTries: 4, + expectedResponse: fmt.Errorf("app error"), + errorOnTry: 4, + }, { + okOnTry: 1, + err: nil, + maxRetries: -1, + expectedTries: 0, + expectedResponse: fmt.Errorf("maxRetries (%d) should be > 0", -1), + }, { + okOnTry: 1, + err: nil, + maxRetries: 0, + expectedTries: 0, + expectedResponse: fmt.Errorf("maxRetries (%d) should be > 0", 0), + }, + } + + for _, item := range testTable { + name := fmt.Sprintf("okOnTry:%v err:%v expectedTries:%v maxRetries:%v errorOnTry:%v nilOnTry: %v", + item.okOnTry, item.err, item.expectedTries, item.maxRetries, item.errorOnTry, item.nilOnTry) + + var currentTry int + t.Run(name, func(t *testing.T) { + + retryErr := Retry(time.Microsecond, item.maxRetries, func() (ok bool, err error) { + currentTry++ + if currentTry > item.maxRetries+1 { + // This is a protection for infinite loops + t.Fatalf("Retry %v > maxRetries %v + 1", currentTry, item.maxRetries) + } + + ok = item.okOnTry > 0 && currentTry >= item.okOnTry + + if item.errorOnTry > 0 { + if currentTry >= item.errorOnTry { + err = item.err + } else { + err = nil + } + } else { + err = item.err + } + + if item.nilOnTry > 0 && currentTry >= item.nilOnTry { + err = nil + } + + return + + }) + + if item.expectedResponse != nil { + if retryErr != nil { + if retryErr.Error() != item.expectedResponse.Error() { + t.Error("Received error:", retryErr) + } + } else { + t.Error("Received error:", retryErr) + } + } else { + if retryErr != nil { + t.Error("Received error:", retryErr) + } + } + + if currentTry != item.expectedTries { + t.Errorf("%v != %v", currentTry, item.expectedTries) + } + + }) + } + +} + +type TestRetryErrorItem struct { + workOnTry int + expectedTries int + maxRetries int + expectSuccess bool +} + +func TestRetryError(t *testing.T) { + testTable := []TestRetryErrorItem{ + { + workOnTry: 1, + expectedTries: 1, + maxRetries: 3, + expectSuccess: true, + }, { + workOnTry: 2, + expectedTries: 2, + maxRetries: 3, + expectSuccess: true, + }, { + workOnTry: 4, + expectedTries: 4, + maxRetries: 3, + expectSuccess: true, + }, { + workOnTry: 5, + expectedTries: 4, + maxRetries: 3, + expectSuccess: false, + }, + } + + for _, item := range testTable { + name := fmt.Sprintf("workOnTry: %v expectedTries: %v maxRetries: %v expectSuccess: %v", + item.workOnTry, item.expectedTries, item.maxRetries, item.expectSuccess) + t.Run(name, func(t *testing.T) { + var currentTry int + + resp := RetryError(time.Microsecond, item.maxRetries, func() (err error) { + currentTry++ + if currentTry >= item.workOnTry { + return nil + } + return fmt.Errorf("Still not working") + }) + + if item.expectSuccess != (resp == nil) { + t.Errorf("Received error: %v", resp) + } + + if item.expectedTries != currentTry { + t.Errorf("Returned in %d tries", currentTry) + } + + }) + } + +} + +type TestTryUntilItem struct { + workOnSecond time.Duration + funcError error + funcValue interface{} + maxDuration time.Duration + expectTimeout bool +} + +func TestTryUntil(t *testing.T) { + testTable := []TestTryUntilItem{ + { + workOnSecond: 100 * time.Millisecond, + funcError: nil, + funcValue: []string{"first", "second", "third"}, + maxDuration: 500 * time.Millisecond, + expectTimeout: false, + }, + { + workOnSecond: 400 * time.Millisecond, + funcError: nil, + funcValue: 5, + maxDuration: 1000 * time.Millisecond, + expectTimeout: false, + }, + { + workOnSecond: 100 * time.Millisecond, + funcError: fmt.Errorf("function is not working"), + funcValue: nil, + maxDuration: 5 * time.Second, + expectTimeout: false, + }, + { + workOnSecond: 30 * time.Second, + funcError: nil, + funcValue: nil, + maxDuration: 500 * time.Millisecond, + expectTimeout: true, + }, + } + + for _, item := range testTable { + name := fmt.Sprintf("workOnSecond: %v maxDuration: %v expectTimeout: %v", + item.workOnSecond, item.maxDuration, item.expectTimeout) + item := item + t.Run(name, func(t *testing.T) { + t.Parallel() + resp, err := TryUntil(item.maxDuration, func() Result { + time.Sleep(item.workOnSecond) + return Result{ + Value: item.funcValue, + Error: item.funcError, + } + }) + + fmt.Printf("result: %v", resp) + fmt.Println() + + if item.expectTimeout && err.Error() != "timed out" { + t.Errorf("It was expected a timeout but it did not happen") + } + + if item.funcValue != nil && resp == nil { + t.Errorf("It was expected to receive a value") + } + + if !item.expectTimeout && item.funcError != err { + t.Errorf("Received wrong error: %s", err) + } + + }) + } + +} + +type TestRetryErrorWithContextItem struct { + doc string + timeout time.Duration + workOnTry int + expectedTries int + expectSuccess bool + expectedError string +} + +func TestRetryErrorWithContext(t *testing.T) { + testTable := []TestRetryErrorWithContextItem{ + { + doc: "The execution should work at the first try", + timeout: time.Millisecond * 200, + workOnTry: 1, + expectedTries: 1, + expectSuccess: true, + }, { + doc: "The execution should work at the second try", + timeout: time.Millisecond * 300, + workOnTry: 2, + expectedTries: 2, + expectSuccess: true, + }, { + doc: "The execution should work after many tries", + timeout: time.Millisecond * 500, + workOnTry: 4, + expectedTries: 4, + expectSuccess: true, + }, { + doc: "The execution should time out after many retries due the context", + timeout: time.Millisecond * 400, + workOnTry: 5, + expectedTries: 4, + expectSuccess: false, + expectedError: "context deadline exceeded", + }, + } + + for _, item := range testTable { + item := item + + t.Run(item.doc, func(t *testing.T) { + t.Parallel() + var currentTry int + + ctx, cancel := context.WithTimeout(context.Background(), item.timeout) + defer cancel() + + start := time.Now() + + resp := RetryErrorWithContext(ctx, 100*time.Millisecond, func() (err error) { + currentTry++ + if currentTry == item.workOnTry { + return nil + } + return fmt.Errorf("Still not working") + }) + + elapsed := time.Since(start) + + if item.expectSuccess { + // Expecting success: check that the function completed successfully + if resp != nil { + t.Errorf("Expected success, but got error: %v", resp) + } + if elapsed > item.timeout { + t.Errorf("Expected to complete before timeout, but took %v", elapsed) + } + } else { + assert.Assert(t, resp != nil) + if item.expectedError != "" { + assert.Equal(t, item.expectedError, resp.Error()) + } + if elapsed <= item.timeout { + t.Logf("The execution should have timed out, but it did not. Elapsed %d ms, timeout %d ms.", elapsed/time.Millisecond, item.timeout/time.Millisecond) + } else if elapsed > item.timeout+20*time.Millisecond { + t.Logf("The execution should have timed out, but it took too long. Elapsed %d ms, timeout %d ms.", elapsed/time.Millisecond, item.timeout/time.Millisecond) + } + } + if item.expectedTries != currentTry { + t.Errorf("Returned in %d tries (expected %d)", currentTry, item.expectedTries) + } + }) + } + +} diff --git a/internal/utils/tarball.go b/internal/utils/tarball.go new file mode 100644 index 0000000..b9efd96 --- /dev/null +++ b/internal/utils/tarball.go @@ -0,0 +1,255 @@ +package utils + +import ( + "archive/tar" + "bytes" + "compress/gzip" + "fmt" + "io" + "os" + "path" + "strings" + "sync" + "time" +) + +type Tarball struct { + buf *bytes.Buffer + gz *gzip.Writer + tw *tar.Writer + lastAdded time.Time + basePath string + mutex *sync.Mutex +} + +// NewTarball returns an initialized Tarball +func NewTarball() *Tarball { + tb := &Tarball{} + tb.buf = new(bytes.Buffer) + tb.gz = gzip.NewWriter(tb.buf) + tb.tw = tar.NewWriter(tb.gz) + tb.mutex = &sync.Mutex{} + return tb +} + +// Save saves tarball based on added directories. +// The provided filename will be created or truncated +// if it already exists. +// Once Save method is executed, this instance cannot +// be used anymore. +func (t *Tarball) Save(filename string) error { + var err error + err = t.close() + if err != nil { + return err + } + err = os.WriteFile(filename, t.buf.Bytes(), 0644) + if err != nil { + return err + } + return nil +} + +// SaveData saves written files and returns the tarball data. +// Once SaveData method is executed, this instance cannot +// be used anymore. +func (t *Tarball) SaveData() ([]byte, error) { + err := t.close() + if err != nil { + return nil, err + } + return t.buf.Bytes(), nil +} + +func (t *Tarball) close() error { + t.mutex.Lock() + defer t.mutex.Unlock() + var err error + err = t.tw.Flush() + if err != nil { + return err + } + err = t.tw.Close() + if err != nil { + return err + } + err = t.gz.Close() + if err != nil { + return err + } + return nil +} + +// AddFiles adds all files (recursively) based on the +// provided directory. +func (t *Tarball) AddFiles(dir string, includesOnly ...string) error { + t.mutex.Lock() + defer t.mutex.Unlock() + t.lastAdded = time.Now() + if !strings.HasSuffix(dir, "/") { + dir = dir + "/" + } + t.basePath = dir + var err error + if len(includesOnly) > 0 { + for _, inc := range includesOnly { + err = t.addFiles(path.Join(dir, inc)) + } + } else { + err = t.addFiles(dir) + } + t.lastAdded = time.Time{} + t.basePath = "" + return err +} + +func (t *Tarball) addFiles(dir string) error { + entries, err := os.ReadDir(dir) + if err != nil { + return err + } + innerDir := dir[len(t.basePath):] + for _, entry := range entries { + fileStat, err := os.Stat(path.Join(dir, entry.Name())) + if err != nil { + return err + } + if entry.IsDir() { + t.tw.WriteHeader(&tar.Header{ + Name: path.Join(innerDir, entry.Name()) + "/", + Mode: int64(fileStat.Mode()), + Typeflag: tar.TypeDir, + ModTime: fileStat.ModTime(), + }) + err = t.addFiles(path.Join(dir, entry.Name())) + if err != nil { + return err + } + } else { + fileName := path.Join(innerDir, entry.Name()) + err = t.tw.WriteHeader(&tar.Header{ + Name: fileName, + Mode: int64(fileStat.Mode()), + Size: fileStat.Size(), + ModTime: fileStat.ModTime(), + }) + if err != nil { + return err + } + data, err := os.ReadFile(path.Join(dir, entry.Name())) + if err != nil { + return err + } + _, err = t.tw.Write(data) + if err != nil { + return err + } + err = t.tw.Flush() + if err != nil { + return err + } + } + } + return nil +} + +func (t *Tarball) AddFileData(fileName string, mode int64, mod time.Time, data []byte) error { + var err error + err = t.tw.WriteHeader(&tar.Header{ + Name: fileName, + Mode: mode, + Size: int64(len(data)), + ModTime: mod, + }) + if err != nil { + return err + } + _, err = t.tw.Write(data) + if err != nil { + return err + } + err = t.tw.Flush() + if err != nil { + return err + } + return nil +} + +func (t *Tarball) validateOutputPathoutputPath(outputPath string) error { + // Validating outputPath + if outputPath == "" { + return fmt.Errorf("outputPath is empty") + } + outputPathStat, err := os.Stat(outputPath) + if err != nil { + err = os.MkdirAll(outputPath, 0755) + if err != nil { + return err + } + } else if !outputPathStat.Mode().IsDir() { + return fmt.Errorf("outputPath is not a directory") + } + return nil +} + +func (t *Tarball) ExtractData(data []byte, outputPath string) error { + err := t.validateOutputPathoutputPath(outputPath) + if err != nil { + return err + } + reader := bytes.NewReader(data) + return t.extract(reader, outputPath) +} + +// Extract extracts the given tar.gz filename into the provided outputPath +func (t *Tarball) Extract(fileName, outputPath string) error { + err := t.validateOutputPathoutputPath(outputPath) + if err != nil { + return err + } + tgzFile, err := os.Open(fileName) + if err != nil { + return err + } + return t.extract(tgzFile, outputPath) +} + +func (t *Tarball) extract(tgzReader io.Reader, outputPath string) error { + gzipReader, err := gzip.NewReader(tgzReader) + if err != nil { + return err + } + tarReader := tar.NewReader(gzipReader) + for { + header, err := tarReader.Next() + switch { + case err == io.EOF: + return nil + case err != nil: + return err + case header == nil: + continue + } + targetFilePath := path.Join(outputPath, header.Name) + switch header.Typeflag { + case tar.TypeDir: + if _, err := os.Stat(targetFilePath); err != nil { + if err := os.MkdirAll(targetFilePath, 0755); err != nil { + return err + } + } + case tar.TypeReg: + file, err := os.OpenFile(targetFilePath, os.O_CREATE|os.O_RDWR, os.FileMode(header.Mode)) + if err != nil { + return err + } + if _, err := io.Copy(file, tarReader); err != nil { + return err + } + err = file.Close() + if err != nil { + return err + } + } + } +} diff --git a/internal/utils/tarball_test.go b/internal/utils/tarball_test.go new file mode 100644 index 0000000..f90f720 --- /dev/null +++ b/internal/utils/tarball_test.go @@ -0,0 +1,230 @@ +package utils + +import ( + "fmt" + "math" + "os" + "path" + "strings" + "testing" + "time" + + "gotest.tools/v3/assert" +) + +func TestTarball(t *testing.T) { + const testFileContent = "test data" + + for _, tc := range []struct { + description string + files int + directories int + levels int + }{ + { + description: "only-files", + files: 10, + directories: 0, + levels: 1, + }, + { + description: "files-and-directories", + files: 10, + directories: 3, + levels: 1, + }, + { + description: "files-and-directories-multiple-levels", + files: 10, + directories: 3, + levels: 3, + }, + } { + t.Run(tc.description, func(t *testing.T) { + var cleanupList []string + tree := generateDirectoryTree(tc.directories, tc.levels) + baseDir, err := os.MkdirTemp("", "testtarball.*") + assert.Assert(t, err) + defer func() { + assert.Assert(t, os.RemoveAll(baseDir)) + for _, fileOrDir := range cleanupList { + assert.Assert(t, os.RemoveAll(fileOrDir)) + } + }() + now := time.Now() + // Generating files and asserting generation was successful + err = createFiles(baseDir, tc.files, []byte(testFileContent), tree) + assert.Assert(t, err, "unable to create files") + generatedFilesExpected := tc.files * (len(tree) + 1) + dirReader := new(DirectoryReader) + filesFound, err := dirReader.ReadDir(baseDir, nil) + assert.Assert(t, err) + assert.Equal(t, generatedFilesExpected, len(filesFound)) + for _, file := range filesFound { + data, err := os.ReadFile(file) + assert.Assert(t, err) + assert.Equal(t, string(data), testFileContent) + } + var savedData, savedDataExtra []byte + var savedFile = baseDir + ".tar.gz" + var savedFileExtra = baseDir + "-extra.tar.gz" + t.Run(tc.description+"-SaveData", func(t *testing.T) { + // Compressing generated files + tb := NewTarball() + assert.Assert(t, tb != nil) + assert.Assert(t, tb.AddFiles(baseDir)) + savedData, err = tb.SaveData() + assert.Assert(t, err) + assert.Assert(t, len(savedData) > 0) + }) + t.Run(tc.description+"-Save", func(t *testing.T) { + // Compressing generated files + tb := NewTarball() + assert.Assert(t, tb != nil) + assert.Assert(t, tb.AddFiles(baseDir)) + err = tb.Save(savedFile) + assert.Assert(t, err) + cleanupList = append(cleanupList, savedFile) + savedFileStat, err := os.Stat(savedFile) + assert.Assert(t, err) + assert.Assert(t, savedFileStat.Size() == int64(len(savedData))) + }) + t.Run(tc.description+"-AddFileData-SaveData", func(t *testing.T) { + // Compressing generated files adding an extra file + tb := NewTarball() + assert.Assert(t, tb != nil) + assert.Assert(t, tb.AddFiles(baseDir)) + assert.Assert(t, tb.AddFileData("sample.file", 0755, now, []byte(testFileContent))) + savedDataExtra, err = tb.SaveData() + assert.Assert(t, err) + assert.Assert(t, len(savedDataExtra) > 0) + }) + t.Run(tc.description+"-AddFileData-Save", func(t *testing.T) { + // Compressing generated files adding an extra file + tb := NewTarball() + assert.Assert(t, tb != nil) + assert.Assert(t, tb.AddFiles(baseDir)) + assert.Assert(t, tb.AddFileData("sample.file", 0755, now, []byte(testFileContent))) + err = tb.Save(savedFileExtra) + assert.Assert(t, err) + cleanupList = append(cleanupList, savedFileExtra) + savedFileData, err := os.ReadFile(savedFileExtra) + assert.Assert(t, err) + assert.DeepEqual(t, savedFileData, savedDataExtra) + assert.Assert(t, len(savedDataExtra) > len(savedData)) + }) + t.Run(tc.description+"-Uncompress", func(t *testing.T) { + baseDirCopy := baseDir + ".copy" + tb := NewTarball() + err = tb.Extract(savedFile, baseDirCopy) + assert.Assert(t, err) + cleanupList = append(cleanupList, baseDirCopy) + filesFoundCopy, err := dirReader.ReadDir(baseDirCopy, nil) + assert.Assert(t, err) + assert.Equal(t, generatedFilesExpected, len(filesFoundCopy)) + for _, file := range filesFoundCopy { + data, err := os.ReadFile(file) + assert.Assert(t, err) + assert.Equal(t, string(data), testFileContent) + } + }) + t.Run(tc.description+"-UncompressData", func(t *testing.T) { + baseDirCopy := baseDir + ".data" + tb := NewTarball() + err = tb.ExtractData(savedData, baseDirCopy) + assert.Assert(t, err) + cleanupList = append(cleanupList, baseDirCopy) + filesFoundCopy, err := dirReader.ReadDir(baseDirCopy, nil) + assert.Assert(t, err) + assert.Equal(t, generatedFilesExpected, len(filesFoundCopy)) + for _, file := range filesFoundCopy { + data, err := os.ReadFile(file) + assert.Assert(t, err) + assert.Equal(t, string(data), testFileContent) + } + }) + t.Run(tc.description+"-UncompressExtra", func(t *testing.T) { + baseDirExtra := baseDir + ".extra" + tb := NewTarball() + err = tb.Extract(savedFileExtra, baseDirExtra) + assert.Assert(t, err) + cleanupList = append(cleanupList, baseDirExtra) + filesFoundExtra, err := dirReader.ReadDir(baseDirExtra, nil) + assert.Assert(t, err) + assert.Equal(t, generatedFilesExpected+1, len(filesFoundExtra)) + for _, file := range filesFoundExtra { + data, err := os.ReadFile(file) + assert.Assert(t, err) + assert.Equal(t, string(data), testFileContent) + if strings.HasSuffix(file, "sample.file") { + extraFileStat, err := os.Stat(file) + assert.Assert(t, err) + assert.Assert(t, extraFileStat.Mode() == os.FileMode(0755)) + } + } + }) + }) + } +} + +// createFiles iterates through the directory "tree" list, +// creating the given amount of "files" using the provided +// "content" into the "baseDir". +func createFiles(baseDir string, files int, content []byte, tree []string) error { + tree = append(tree, "") + for _, dir := range tree { + err := os.MkdirAll(path.Join(baseDir, dir), 0755) + if err != nil { + return err + } + for i := 1; i <= files; i++ { + filename := path.Join(baseDir, dir, fmt.Sprintf("file.%d", i)) + err = os.WriteFile(filename, content, 0644) + if err != nil { + return err + } + } + } + return nil +} + +// expectedCreatedFiles returns the amount of tiles expected +// to be created based on the provided arguments. +func expectedCreatedFiles(dirs, levels, files int) int { + /* + total of files is: (sum(dirs^!levels))*files + i.e: dir=3,levels=4,files=10 + (3^4 + 3^3 + 3^2 + 3^1) * 10 + */ + sum := 0 + for level := 1; level <= levels; level++ { + sum += int(math.Pow(float64(dirs), float64(level))) + } + sum *= files + return sum + files +} + +func generateDirectoryTree(dirs, levels int) []string { + var tree []string + indexSum := func(level int) int { + sum := 0 + for l := level; l >= 1; l-- { + sum += int(math.Pow(float64(dirs), float64(l))) + } + return sum + } + for level := 1; level <= levels; level++ { + var baseDirs = []string{""} + if level > 1 { + initialIdx := indexSum(level - 2) + finalIdx := indexSum(level - 1) + baseDirs = tree[initialIdx:finalIdx] + } + for _, baseDir := range baseDirs { + for dir := 1; dir <= dirs; dir++ { + tree = append(tree, path.Join(baseDir, fmt.Sprintf("dir%d", dir))) + } + } + } + return tree +} diff --git a/internal/utils/tcp.go b/internal/utils/tcp.go new file mode 100644 index 0000000..7ecd768 --- /dev/null +++ b/internal/utils/tcp.go @@ -0,0 +1,28 @@ +package utils + +import ( + "fmt" + "net" + "strconv" +) + +func TcpPortInUse(host string, port int) bool { + address := net.JoinHostPort(host, strconv.Itoa(port)) + listener, err := net.Listen("tcp", address) + if err != nil { + return true + } + if listener != nil { + _ = listener.Close() + } + return false +} + +func TcpPortNextFree(startPort int) (int, error) { + for port := startPort; port <= 65535; port++ { + if !TcpPortInUse("", port) { + return port, nil + } + } + return 0, fmt.Errorf("no available ports found") +} diff --git a/internal/utils/tcp_test.go b/internal/utils/tcp_test.go new file mode 100644 index 0000000..2fb0db8 --- /dev/null +++ b/internal/utils/tcp_test.go @@ -0,0 +1,63 @@ +package utils + +import ( + "context" + "fmt" + "net" + "sync" + "testing" + + "gotest.tools/v3/assert" +) + +func TestTcpPortNextFree(t *testing.T) { + minPort, err := TcpPortNextFree(1024) + assert.Assert(t, err, "no available tcp ports found") + + ctx, cancel := context.WithCancel(context.Background()) + + // listening on minPort to validate if it reports as in use + wg := listenTcpPort(ctx, minPort) + // waiting on port to be bound + wg.Wait() + + // assert TcpPortNextFree shows a different port + newMinPort, err := TcpPortNextFree(minPort) + assert.Assert(t, err, "no more available tcp ports found") + assert.Assert(t, newMinPort > minPort, "expected next free port available to be higher than %d but got %d", minPort, newMinPort) + cancel() +} + +func TestTcpPortInUse(t *testing.T) { + minPort, err := TcpPortNextFree(1024) + assert.Assert(t, err, "no available tcp ports found") + + ctx := context.Background() + + // listening on minPort to validate if it reports as in use + wg := listenTcpPort(ctx, minPort) + // waiting on port to be bound + wg.Wait() + + // assert TcpPortInUse reports port as being used + assert.Assert(t, TcpPortInUse("", minPort), "%d expected to be in use", minPort) + + // getting an extra port + nextMinPort, err := TcpPortNextFree(minPort) + assert.Assert(t, err, "no more available tcp ports found") + assert.Assert(t, !TcpPortInUse("", nextMinPort), "tcp port %d expected to be available", nextMinPort) +} + +func listenTcpPort(ctx context.Context, port int) *sync.WaitGroup { + wg := new(sync.WaitGroup) + wg.Add(1) + go func() { + listener, err := net.Listen("tcp", fmt.Sprintf(":%d", port)) + wg.Done() + if err != nil { + <-ctx.Done() + _ = listener.Close() + } + }() + return wg +} diff --git a/internal/utils/tlscfg/tls.go b/internal/utils/tlscfg/tls.go new file mode 100644 index 0000000..44d2ec5 --- /dev/null +++ b/internal/utils/tlscfg/tls.go @@ -0,0 +1,32 @@ +package tlscfg + +import "crypto/tls" + +var ( + tlsCiphers []uint16 +) + +func init() { + tlsCiphers = make([]uint16, len(tls.CipherSuites())) + for i, suite := range tls.CipherSuites() { + tlsCiphers[i] = suite.ID + } +} + +// Modern TLS Configuration for when TLSv1.3 can be assumed (e.g. when only +// internal clients are expected.) +func Modern() *tls.Config { + return &tls.Config{ + MinVersion: tls.VersionTLS13, + } +} + +// Default TLS Configuration excludes cipher suites implemented in crypto/tls +// that have been marked insecure. +func Default() *tls.Config { + suites := make([]uint16, len(tlsCiphers)) + copy(suites, tlsCiphers) + return &tls.Config{ + CipherSuites: suites, + } +} diff --git a/internal/utils/utils.go b/internal/utils/utils.go new file mode 100644 index 0000000..bc7658f --- /dev/null +++ b/internal/utils/utils.go @@ -0,0 +1,173 @@ +/* +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 + + http://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 utils + +import ( + "crypto/rand" + "io" + "os" + "os/user" + "regexp" + "strings" +) + +const alphanumerics = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" + +func RandomId(length int) string { + buffer := make([]byte, length) + rand.Read(buffer) + max := len(alphanumerics) + for i := range buffer { + buffer[i] = alphanumerics[int(buffer[i])%max] + } + return string(buffer) +} + +func StringifySelector(labels map[string]string) string { + result := "" + for k, v := range labels { + if result != "" { + result += "," + } + result += k + result += "=" + result += v + } + return result +} + +// LabelToMap expects label string to be a comma separated +// list of key and value pairs delimited by equals. +func LabelToMap(label string) map[string]string { + m := map[string]string{} + labels := strings.Split(label, ",") + for _, l := range labels { + if !strings.Contains(l, "=") { + continue + } + entry := strings.Split(l, "=") + m[entry[0]] = entry[1] + } + return m +} + +func StringSliceContains(s []string, e string) bool { + for _, a := range s { + if a == e { + return true + } + } + return false +} + +func StringSliceEndsWith(s []string, e string) bool { + for _, a := range s { + if strings.HasSuffix(a, e) { + return true + } + } + return false +} + +func RegexpStringSliceContains(s []string, e string) bool { + for _, re := range s { + match, err := regexp.Match(re, []byte(e)) + if err == nil && match { + return true + } + } + return false +} + +func IntSliceContains(s []int, e int) bool { + for _, a := range s { + if a == e { + return true + } + } + return false +} + +func IsDirEmpty(name string) (bool, error) { + file, err := os.Open(name) + + if err != nil { + return false, err + } + defer file.Close() + + _, err = file.Readdir(1) + + if err == io.EOF { + return true, nil + } + + return false, err +} + +func StringSlicesEqual(a, b []string) bool { + if len(a) != len(b) { + return false + } + for _, v := range a { + if !StringSliceContains(b, v) { + return false + } + } + return true +} + +// DefaultStr returns the first non-empty string +func DefaultStr(values ...string) string { + if len(values) == 1 { + return values[0] + } + if values[0] != "" { + return values[0] + } + return DefaultStr(values[1:]...) +} + +func GetOrDefault(str string, defaultStr string) string { + var result string + if len(str) > 0 { + result = str + } else { + result = defaultStr + } + return result +} + +type Number interface { + int | int32 | int64 | float32 | float64 +} + +func DefaultNumber[T Number](values ...T) T { + if len(values) == 1 { + return values[0] + } + if values[0] > 0 { + return values[0] + } + return DefaultNumber(values[1:]...) +} + +func ReadUsername() string { + u, err := user.Current() + if err != nil { + return DefaultStr(os.Getenv("USER"), os.Getenv("USERNAME")) + } + return strings.Join(strings.Fields(u.Username), "") +} diff --git a/internal/utils/utils_test.go b/internal/utils/utils_test.go new file mode 100644 index 0000000..610af60 --- /dev/null +++ b/internal/utils/utils_test.go @@ -0,0 +1,79 @@ +package utils + +import ( + "gotest.tools/v3/assert" + "reflect" + "testing" +) + +func TestStringifySelector(t *testing.T) { + type test struct { + name string + labels map[string]string + result string + } + + testTable := []test{ + {name: "empty-map", labels: map[string]string{}, result: ""}, + {name: "one-label-map", labels: map[string]string{"label1": "value1"}, result: "label1=value1"}, + {name: "three-label-map", labels: map[string]string{"label1": "value1", "label2": "value2", "label3": "value3"}, result: "label1=value1,label2=value2,label3=value3"}, + } + + for _, test := range testTable { + t.Run(test.name, func(t *testing.T) { + // getting result into a map as labels ordering cannot be guaranteed + expectedResMap := LabelToMap(test.result) + actualResMap := LabelToMap(StringifySelector(test.labels)) + assert.Assert(t, reflect.DeepEqual(expectedResMap, actualResMap)) + }) + } +} + +func TestSliceEquals(t *testing.T) { + type test struct { + name string + sliceA []string + sliceB []string + result bool + } + + testTable := []test{ + {name: "not equals", sliceA: []string{"one", "two"}, sliceB: []string{"two", "three"}, result: false}, + {name: "not equals, one is empty", sliceA: []string{}, sliceB: []string{"two", "three"}, result: false}, + {name: "equals", sliceA: []string{"one", "two"}, sliceB: []string{"one", "two"}, result: true}, + {name: "equals but different order", sliceA: []string{"one", "two"}, sliceB: []string{"two", "one"}, result: true}, + } + + for _, test := range testTable { + t.Run(test.name, func(t *testing.T) { + + expectedResult := test.result + actualResult := StringSlicesEqual(test.sliceA, test.sliceB) + assert.Assert(t, reflect.DeepEqual(actualResult, expectedResult)) + }) + } +} + +func TestGetOrDefault(t *testing.T) { + type test struct { + name string + value string + defaultValue string + result string + } + + testTable := []test{ + {name: "empty string", value: "", defaultValue: "default-value", result: "default-value"}, + {name: "valid value", value: "provided-value", defaultValue: "default-value", result: "provided-value"}, + {name: "both empty", value: "", defaultValue: "", result: ""}, + } + + for _, test := range testTable { + t.Run(test.name, func(t *testing.T) { + + expectedResult := test.result + actualResult := GetOrDefault(test.value, test.defaultValue) + assert.Assert(t, reflect.DeepEqual(actualResult, expectedResult)) + }) + } +} diff --git a/internal/utils/validator/simple_validator.go b/internal/utils/validator/simple_validator.go new file mode 100644 index 0000000..d4acbfe --- /dev/null +++ b/internal/utils/validator/simple_validator.go @@ -0,0 +1,207 @@ +package validator + +import ( + "fmt" + "regexp" + "strings" + "time" +) + +type Validator interface { + Evaluate(value interface{}) (bool, error) +} + +// + +type stringValidator struct { + Expression *regexp.Regexp +} + +func NewStringValidator() *stringValidator { + return &stringValidator{ + Expression: regexp.MustCompile(`^\S*$`), + } +} + +func NewHostStringValidator() *stringValidator { + return &stringValidator{ + Expression: regexp.MustCompile(`^[a-z0-9]+([-.]{1}[a-z0-9]+)*$`), + } +} + +func NewResourceStringValidator() *stringValidator { + return &stringValidator{ + Expression: regexp.MustCompile(`^[a-z0-9]([-a-z0-9]*[a-z0-9])*(\.[a-z0-9]([-a-z0-9]*[a-z0-9])*)*$`), + } +} + +// TBD what are valid characters for selector field +func NewSelectorStringValidator() *stringValidator { + return &stringValidator{ + Expression: regexp.MustCompile(`^[A-Za-z0-9=:./-]+$`), + } +} + +func NewFilePathStringValidator() *stringValidator { + return &stringValidator{ + Expression: regexp.MustCompile(`^[A-Za-z0-9./~-]+$`), + } +} + +func (s stringValidator) Evaluate(value interface{}) (bool, error) { + v, ok := value.(string) + + if !ok { + return false, fmt.Errorf("value is not a string") + } + + if s.Expression.MatchString(v) { + return true, nil + } + + return false, fmt.Errorf("value does not match this regular expression: %s", s.Expression) +} + +// + +type NumberValidator struct { + PositiveInt bool + IncludeZero bool +} + +func NewNumberValidator() *NumberValidator { + return &NumberValidator{ + PositiveInt: true, + IncludeZero: true, + } +} + +func (i NumberValidator) Evaluate(value interface{}) (bool, error) { + + v, ok := value.(int) + + if !ok { + return false, fmt.Errorf("value is not an integer") + } + + if i.PositiveInt { + if v < 0 { + return false, fmt.Errorf("value is not positive") + } + if v > 0 { + return true, nil + } + if v == 0 { + if i.IncludeZero { + return true, nil + } + return false, fmt.Errorf("value 0 is not allowed") + } + } + return true, nil +} + +/// + +type OptionValidator struct { + AllowedOptions []string +} + +func NewOptionValidator(validOptions []string) *OptionValidator { + return &OptionValidator{ + AllowedOptions: validOptions, + } +} + +func (i OptionValidator) Evaluate(value interface{}) (bool, error) { + + v, ok := value.(string) + + if !ok { + return false, fmt.Errorf("value is not a string") + } + + if v == "" { + return false, fmt.Errorf("value must not be empty") + } + + valueFound := false + for _, option := range i.AllowedOptions { + if option == v { + valueFound = true + } + } + + if !valueFound { + return false, fmt.Errorf("value %s not allowed. It should be one of this options: %v", v, i.AllowedOptions) + } + return true, nil +} + +type DurationValidator struct { + MinDuration time.Duration +} + +func NewTimeoutInSecondsValidator() *DurationValidator { + return &DurationValidator{ + MinDuration: time.Second * 10, + } +} + +func NewExpirationInSecondsValidator() *DurationValidator { + return &DurationValidator{ + MinDuration: time.Minute * 1, + } +} + +func (i DurationValidator) Evaluate(value time.Duration) (bool, error) { + + if value < i.MinDuration { + return false, fmt.Errorf("duration must not be less than %v; got %v", i.MinDuration, value) + } + + return true, nil +} + +type WorkloadValidator struct { + Expression *regexp.Regexp + AllowedOptions []string +} + +func NewWorkloadStringValidator(validOptions []string) *WorkloadValidator { + re, err := regexp.Compile("^[A-Za-z0-9._-]+$") + if err != nil { + fmt.Printf("Error compiling regex: %v", err) + return nil + } + return &WorkloadValidator{ + Expression: re, + AllowedOptions: validOptions, + } +} + +func (s WorkloadValidator) Evaluate(value interface{}) (string, string, bool, error) { + + v, ok := value.(string) + + if !ok { + return "", "", false, fmt.Errorf("value is not a string") + } + + // workload has two parts / + resource := strings.Split(v, "/") + if len(resource) != 2 { + return "", "", false, fmt.Errorf("workload must include /") + } + + if s.Expression.MatchString(resource[1]) { + resourceType := strings.ToLower(resource[0]) + for _, option := range s.AllowedOptions { + if option == resourceType { + return option, resource[1], true, nil + } + } + return "", "", false, fmt.Errorf("resource-type does not match expected value: deployment/service/daemonset/statefulset") + } + return "", "", false, fmt.Errorf("value does not match this regular expression: %s", s.Expression) +} diff --git a/internal/utils/validator/simple_validator_test.go b/internal/utils/validator/simple_validator_test.go new file mode 100644 index 0000000..f7c35e2 --- /dev/null +++ b/internal/utils/validator/simple_validator_test.go @@ -0,0 +1,310 @@ +package validator + +import ( + "reflect" + "regexp" + "testing" + "time" + + "gotest.tools/v3/assert" +) + +func TestNewStringValidator(t *testing.T) { + + t.Run("Test String Validator constructor", func(t *testing.T) { + + validRegexp := regexp.MustCompile(`^\S*$`) + expectedResult := &stringValidator{validRegexp} + actualResult := NewStringValidator() + assert.Assert(t, reflect.DeepEqual(actualResult, expectedResult)) + }) +} + +func TestStringValidator_Evaluate(t *testing.T) { + type test struct { + name string + value interface{} + result bool + } + + testTable := []test{ + {name: "empty string", value: "", result: true}, + {name: "valid value", value: "provided-value", result: true}, + {name: "string with spaces", value: "provided value", result: false}, + {name: "string with numbers", value: "site123", result: true}, + {name: "number", value: 123, result: false}, + {name: "nil value", value: nil, result: false}, + } + + for _, test := range testTable { + t.Run(test.name, func(t *testing.T) { + + stringValidator := NewStringValidator() + expectedResult := test.result + actualResult, _ := stringValidator.Evaluate(test.value) + assert.Assert(t, reflect.DeepEqual(actualResult, expectedResult)) + }) + } +} + +func TestNewNumberValidator(t *testing.T) { + + t.Run("Test Positive Int Validator constructor", func(t *testing.T) { + + expectedResult := &NumberValidator{PositiveInt: true, IncludeZero: true} + actualResult := NewNumberValidator() + assert.Assert(t, reflect.DeepEqual(actualResult, expectedResult)) + }) +} + +func TestIntegerValidator_Evaluate(t *testing.T) { + type test struct { + name string + value interface{} + result bool + } + + testTable := []test{ + {name: "empty string", value: "", result: false}, + {name: "value greater than zero", value: 235, result: true}, + {name: "zero value", value: 0, result: true}, + {name: "negative number", value: -2, result: false}, + {name: "not valid characters", value: "abc", result: false}, + {name: "nil value", value: nil, result: false}, + } + + for _, test := range testTable { + t.Run(test.name, func(t *testing.T) { + + numberValidator := NewNumberValidator() + + expectedResult := test.result + actualResult, _ := numberValidator.Evaluate(test.value) + assert.Assert(t, reflect.DeepEqual(actualResult, expectedResult)) + }) + } +} + +func TestTimeoutInSecondsValidator_Evaluate(t *testing.T) { + type test struct { + name string + value time.Duration + result bool + } + + testTable := []test{ + {name: "value less than minimum", value: time.Second * 1, result: false}, + {name: "zero value", value: time.Second * 0, result: false}, + } + + for _, test := range testTable { + t.Run(test.name, func(t *testing.T) { + + numberValidator := NewTimeoutInSecondsValidator() + + expectedResult := test.result + actualResult, _ := numberValidator.Evaluate(test.value) + assert.Assert(t, reflect.DeepEqual(actualResult, expectedResult)) + }) + } +} + +func TestNewOptionValidator(t *testing.T) { + + t.Run("Test Option Validator constructor", func(t *testing.T) { + + expectedResult := &OptionValidator{ + AllowedOptions: []string{"a", "b"}, + } + actualResult := NewOptionValidator([]string{"a", "b"}) + assert.Assert(t, reflect.DeepEqual(actualResult, expectedResult)) + }) +} + +func TestOptionValidator_Evaluate(t *testing.T) { + type test struct { + name string + value interface{} + result bool + } + + testTable := []test{ + {name: "empty string", value: "", result: false}, + {name: "value not included", value: "c", result: false}, + {name: "nil value", value: nil, result: false}, + } + + for _, test := range testTable { + t.Run(test.name, func(t *testing.T) { + + optionValidator := NewOptionValidator([]string{"a", "b"}) + expectedResult := test.result + actualResult, _ := optionValidator.Evaluate(test.value) + assert.Assert(t, reflect.DeepEqual(actualResult, expectedResult)) + }) + } +} + +func TestNewResourceStringValidator(t *testing.T) { + + t.Run("Test New Resource String Validator constructor", func(t *testing.T) { + + validRegexp := regexp.MustCompile(`^[a-z0-9]([-a-z0-9]*[a-z0-9])*(\.[a-z0-9]([-a-z0-9]*[a-z0-9])*)*$`) + expectedResult := &stringValidator{validRegexp} + actualResult := NewResourceStringValidator() + assert.Assert(t, reflect.DeepEqual(actualResult, expectedResult)) + }) +} + +func TestNewResourceStringValidator_Evaluate(t *testing.T) { + type test struct { + name string + value interface{} + result bool + } + + testTable := []test{ + {name: "empty string", value: "", result: false}, + {name: "valid value", value: "provided-value", result: true}, + {name: "string with spaces", value: "provided value", result: false}, + {name: "string with numbers", value: "site123", result: true}, + {name: "number", value: 123, result: false}, + {name: "nil value", value: nil, result: false}, + {name: "string with underscore", value: "abc_def", result: false}, + } + + for _, test := range testTable { + t.Run(test.name, func(t *testing.T) { + + stringValidator := NewResourceStringValidator() + expectedResult := test.result + actualResult, _ := stringValidator.Evaluate(test.value) + assert.Assert(t, reflect.DeepEqual(actualResult, expectedResult)) + }) + } +} + +func TestNewSelectorStringValidator(t *testing.T) { + + t.Run("Test New Selector String Validator constructor", func(t *testing.T) { + + validRegexp := regexp.MustCompile("^[A-Za-z0-9=:./-]+$") + expectedResult := &stringValidator{validRegexp} + actualResult := NewSelectorStringValidator() + assert.Assert(t, reflect.DeepEqual(actualResult, expectedResult)) + }) +} + +func TestNewSelectorStringValidator_Evaluate(t *testing.T) { + type test struct { + name string + value interface{} + result bool + } + + testTable := []test{ + {name: "empty string", value: "", result: false}, + {name: "string with spaces", value: "provided value", result: false}, + {name: "string with numbers", value: "site123", result: true}, + {name: "number", value: 123, result: false}, + {name: "nil value", value: nil, result: false}, + {name: "string with underscore", value: "abc_def", result: false}, + {name: "string with equal", value: "abc=def", result: true}, + {name: "string with slash", value: "abc/def", result: true}, + {name: "string with dash", value: "abc-def", result: true}, + {name: "string with dot", value: "provided.value", result: true}, + } + + for _, test := range testTable { + t.Run(test.name, func(t *testing.T) { + stringValidator := NewSelectorStringValidator() + expectedResult := test.result + actualResult, _ := stringValidator.Evaluate(test.value) + assert.Assert(t, reflect.DeepEqual(actualResult, expectedResult)) + }) + } +} + +func TestNewFilePathStringValidator(t *testing.T) { + + t.Run("Test New File Path String Validator constructor", func(t *testing.T) { + + validRegexp := regexp.MustCompile("^[A-Za-z0-9./~-]+$") + expectedResult := &stringValidator{validRegexp} + actualResult := NewFilePathStringValidator() + assert.Assert(t, reflect.DeepEqual(actualResult, expectedResult)) + }) +} + +func TestNewFilePathStringValidator_Evaluate(t *testing.T) { + type test struct { + name string + value interface{} + result bool + } + + testTable := []test{ + {name: "empty string", value: "", result: false}, + {name: "string with spaces", value: "provided value", result: false}, + {name: "string with numbers", value: "site123", result: true}, + {name: "number", value: 123, result: false}, + {name: "nil value", value: nil, result: false}, + {name: "string with underscore", value: "abc_def", result: false}, + {name: "string with equal", value: "abc=def", result: false}, + {name: "string with slash", value: "abc/def", result: true}, + {name: "string with dash", value: "abc-def", result: true}, + {name: "string with dot", value: "provided.value", result: true}, + {name: "valid path", value: "~/tmp/test.yaml", result: true}, + } + + for _, test := range testTable { + t.Run(test.name, func(t *testing.T) { + stringValidator := NewFilePathStringValidator() + expectedResult := test.result + actualResult, _ := stringValidator.Evaluate(test.value) + assert.Assert(t, reflect.DeepEqual(actualResult, expectedResult)) + }) + } +} + +func TestNewWorkloadStringValidator(t *testing.T) { + + t.Run("Test New Workload String Validator constructor", func(t *testing.T) { + + validRegexp := regexp.MustCompile("^[A-Za-z0-9._-]+$") + expectedResult := &WorkloadValidator{validRegexp, []string{"a", "b"}} + actualResult := NewWorkloadStringValidator([]string{"a", "b"}) + assert.Assert(t, reflect.DeepEqual(actualResult, expectedResult)) + }) +} +func TestWorkloadStringValidator_Evaluate(t *testing.T) { + type test struct { + name string + value interface{} + result bool + } + + testTable := []test{ + {name: "empty string", value: "", result: false}, + {name: "valid value", value: "a/name", result: true}, + {name: "string without /", value: "aname", result: false}, + {name: "string with numbers", value: "b/name123", result: true}, + {name: "number", value: 123, result: false}, + {name: "nil value", value: nil, result: false}, + {name: "string without name", value: "a/", result: false}, + {name: "string without type", value: "/name", result: false}, + {name: "string non matching type", value: "c/name", result: false}, + {name: "bad value", value: "a/name@#", result: false}, + {name: "string with dashes", value: "a/workload-with-dashes", result: true}, + } + + for _, test := range testTable { + t.Run(test.name, func(t *testing.T) { + + stringValidator := NewWorkloadStringValidator([]string{"a", "b"}) + expectedResult := test.result + _, _, actualResult, _ := stringValidator.Evaluate(test.value) + assert.Assert(t, reflect.DeepEqual(actualResult, expectedResult)) + }) + } +} diff --git a/internal/utils/version.go b/internal/utils/version.go new file mode 100644 index 0000000..d4a8186 --- /dev/null +++ b/internal/utils/version.go @@ -0,0 +1,115 @@ +package utils + +import ( + "regexp" + "strconv" + "strings" +) + +type Version struct { + Major int + Minor int + Patch int + Qualifier string +} + +func ParseVersion(version string) Version { + var result Version + re := regexp.MustCompile(`^v?(\d+)[\.\+\-](\d+)?(\.(\d+))?\W?(.+)?`) + parts := re.FindStringSubmatch(version) + if len(parts) > 1 { + result.Major, _ = strconv.Atoi(parts[1]) + } + if len(parts) > 2 { + result.Minor, _ = strconv.Atoi(parts[2]) + } + if len(parts) > 4 { + result.Patch, _ = strconv.Atoi(parts[4]) + } + if len(parts) > 5 { + result.Qualifier = parts[5] + } + return result +} + +func (a *Version) MoreRecentThan(b Version) bool { + if a.Major > b.Major { + return true + } else if a.Major < b.Major { + return false + } + // a.Major == b.Major, so look at Minor + if a.Minor > b.Minor { + return true + } else if a.Minor < b.Minor { + return false + } + //a.Minor == b.Minor, so look at Patch + return a.Patch > b.Patch +} + +func (a *Version) LessRecentThan(b Version) bool { + if a.Major < b.Major { + return true + } else if a.Major > b.Major { + return false + } + // a.Major == b.Major, so look at Minor + if a.Minor < b.Minor { + return true + } else if a.Minor > b.Minor { + return false + } + //a.Minor == b.Minor, so look at Patch + return a.Patch < b.Patch +} + +func (a *Version) Equivalent(b Version) bool { + return a.Major == b.Major && a.Minor == b.Minor && a.Patch == b.Patch +} + +func (v *Version) IsUndefined() bool { + return v.Major == 0 && v.Minor == 0 && v.Patch == 0 && v.Qualifier == "" +} + +func EquivalentVersion(a string, b string) bool { + va := ParseVersion(a) + vb := ParseVersion(b) + return va.Equivalent(vb) +} + +func LessRecentThanVersion(a string, b string) bool { + va := ParseVersion(a) + vb := ParseVersion(b) + return va.LessRecentThan(vb) +} + +func MoreRecentThanVersion(a string, b string) bool { + va := ParseVersion(a) + vb := ParseVersion(b) + return va.MoreRecentThan(vb) +} + +func IsValidFor(actual string, minimum string) bool { + if actual == "" { //assume pre 0.5 + return false + } + va := ParseVersion(actual) + vb := ParseVersion(minimum) + return va.IsUndefined() || !va.LessRecentThan(vb) +} + +func GetVersionTag(imageDescriptor string) string { + versionTag := "" + imageDescriptorSlices := strings.Split(imageDescriptor, " ") + + if len(imageDescriptorSlices) > 0 { + imageSlices := strings.Split(imageDescriptorSlices[0], ":") + + if len(imageSlices) > 1 { + versionTag = imageSlices[1] + } + } + + return versionTag +} diff --git a/internal/utils/version_test.go b/internal/utils/version_test.go new file mode 100644 index 0000000..e3f0258 --- /dev/null +++ b/internal/utils/version_test.go @@ -0,0 +1,192 @@ +package utils + +import ( + "reflect" + "testing" +) + +func TestParseVersion(t *testing.T) { + var tests = []struct { + input string + expected Version + }{ + {"1.2.3", Version{1, 2, 3, ""}}, + {"v1.2.3", Version{1, 2, 3, ""}}, + {"v1.2.3-foo", Version{1, 2, 3, "foo"}}, + {"0.22.9993@bar-xyz", Version{0, 22, 9993, "bar-xyz"}}, + {"0e8beee", Version{}}, + {"1231667", Version{}}, + {"3littlepigs", Version{}}, + {"x0.22.9993@bar-xyz", Version{}}, + {"10.22+whatever", Version{10, 22, 0, "whatever"}}, + {"10+whatever", Version{10, 0, 0, "whatever"}}, + {"10+", Version{10, 0, 0, ""}}, + {"10.", Version{10, 0, 0, ""}}, + {"whatever-10-nonsense", Version{}}, + } + for _, test := range tests { + if actual := ParseVersion(test.input); !reflect.DeepEqual(actual, test.expected) { + t.Errorf("Expected %q for %s, got %q", test.expected, test.input, actual) + } + } +} + +func TestIsUndefined(t *testing.T) { + var tests = []struct { + input string + expected bool + }{ + {"1.2.3", false}, + {"v1.2.3", false}, + {"0.22.9993@bar-xyz", false}, + {"x0.22.9993@bar-xyz", true}, + {"10.22+whatever", false}, + {"10+whatever", false}, + {"whatever-10-nonsense", true}, + } + for _, test := range tests { + v := ParseVersion(test.input) + if actual := v.IsUndefined(); actual != test.expected { + t.Errorf("Expected IsUndefined() for %s to be %v, got %v", test.input, test.expected, actual) + } + } +} + +func TestEquivalent(t *testing.T) { + var tests = []struct { + a string + b string + expected bool + }{ + {"1.2.3", "1.2.3", true}, + {"1.2.3", "v1.2.3", true}, + {"v1.2.3", "v1.2.3", true}, + {"v1.2.3", "1.2.3", true}, + {"v1.2.3", "x1.2.3", false}, + {"1.2.3", "0.2.3", false}, + {"1.2.3", "1.2.4", false}, + {"1.2.3", "1.3.2", false}, + {"0.22.9993@bar-xyz", "0.22.9993", true}, + {"0.22.9993@bar-xyz", "0.22.9993+xyz", true}, + {"0.22.9993@bar-xyz", "0.22.999@bar-xyz", false}, + {"10.22+whatever", "10.22", true}, + {"10.22+whatever", "10.22_ignoreme", true}, + {"10.22+whatever", "10.32_ignoreme", false}, + {"10+whatever", "10+", true}, + {"10+whatever", "10-rrr", true}, + {"cat", "dog", true}, + } + for _, test := range tests { + if actual := EquivalentVersion(test.a, test.b); actual != test.expected { + if test.expected { + t.Errorf("Expected %s to be equivalent to %s", test.a, test.b) + } else { + t.Errorf("Expected %s to not be equivalent to %s", test.a, test.b) + } + } + } +} + +func TestMoreRecentThan(t *testing.T) { + var tests = []struct { + a string + b string + expected bool + }{ + {"1.2.3", "1.2.3", false}, + {"1.2.3", "1.2.2", true}, + {"1.2.3", "0.2.3", true}, + {"1.2.3", "0.3.4", true}, + {"1.2.3", "v1.2.3", false}, + {"1.2.3", "1.1.3", true}, + {"1.2.3", "1.1.9", true}, + {"v1.2.3", "1.2.3", false}, + {"v1.2.3", "x1.2.3", true}, + {"v1.2.3", "frog", true}, + {"frog", "v1.2.3", false}, + {"1.2.3", "1.2.4", false}, + {"1.2.3", "1.3.3", false}, + {"1.2.3", "2.1.2", false}, + } + for _, test := range tests { + if actual := MoreRecentThanVersion(test.a, test.b); actual != test.expected { + if test.expected { + t.Errorf("Expected %s to be MoreRecentThan %s", test.a, test.b) + } else { + t.Errorf("Expected %s to not be MoreRecentThan %s", test.a, test.b) + } + } + } +} + +func TestLessRecentThan(t *testing.T) { + var tests = []struct { + a string + b string + expected bool + }{ + {"1.2.3", "1.2.3", false}, + {"1.2.3", "1.2.2", false}, + {"1.2.3", "0.2.3", false}, + {"1.2.3", "0.3.4", false}, + {"1.2.3", "v1.2.3", false}, + {"1.2.3", "1.1.3", false}, + {"1.2.3", "1.1.9", false}, + {"v1.2.3", "1.2.3", false}, + {"v1.2.3", "frog", false}, + {"frog", "v1.2.3", true}, + {"1.2.3", "1.2.4", true}, + {"1.2.3", "1.3.3", true}, + {"1.2.3", "2.1.2", true}, + } + for _, test := range tests { + if actual := LessRecentThanVersion(test.a, test.b); actual != test.expected { + if test.expected { + t.Errorf("Expected %s to be LessRecentThan %s", test.a, test.b) + } else { + t.Errorf("Expected %s to not be LessRecentThan %s", test.a, test.b) + } + } + } +} + +func TestIsValidFor(t *testing.T) { + var tests = []struct { + actual string + minimum string + expected bool + }{ + {"", "0.7.0", false}, + {"0.5.3", "0.7.0", false}, + {"34145a5-modified", "0.7.0", true}, + {"0e8beee", "0.7.0", true}, + {"0.7.0", "0.7.0", true}, + {"0.7.1", "0.7.0", true}, + {"0.8.6", "0.7.5", true}, + {"1.0.0", "0.7.0", true}, + } + for _, test := range tests { + if actual := IsValidFor(test.actual, test.minimum); actual != test.expected { + t.Errorf("Expected IsValidFor(%s, %s) to be %v, got %v", test.actual, test.minimum, test.expected, actual) + } + } +} + +func TestGetVersionFromImageTag(t *testing.T) { + var tests = []struct { + imageTag string + expected string + }{ + {"quay.io/skupper/config-sync:1.4.4 (sha256:3b7e81fc45bd)", "1.4.4"}, + {"quay.io/skupper/config-sync:1.4.4", "1.4.4"}, + {"quay.io/skupper/config-sync (sha256:3b7e81fc45bd)", ""}, + {"", ""}, + {"quay.io/skupper/config-sync:1.4.4-prerelease", "1.4.4-prerelease"}, + {"1.5.1", ""}, + } + for _, test := range tests { + if actual := GetVersionTag(test.imageTag); actual != test.expected { + t.Errorf("Expected GetVersionTag(%s) to be %s, got %s", test.imageTag, test.expected, actual) + } + } +} diff --git a/internal/watch/config.go b/internal/watch/config.go new file mode 100644 index 0000000..41724d4 --- /dev/null +++ b/internal/watch/config.go @@ -0,0 +1,86 @@ +package watch + +import ( + "context" + "log" + "os" + "path/filepath" + "sync" + "time" + + "github.com/fsnotify/fsnotify" +) + +const configDebounceDuration = 500 * time.Millisecond + +// WatchConfigFile watches the config file at configPath for changes. On write/create +// (after debounce), it reads the file and calls onUpdate with the content. Loop +// prevention is the caller's responsibility: compare content with last applied and +// skip calling UpdateRouter if unchanged. Runs until ctx is cancelled. +func WatchConfigFile(ctx context.Context, configPath string, onUpdate func(configJSON string) error) { + watcher, err := fsnotify.NewWatcher() + if err != nil { + log.Printf("ERROR: Failed to create fsnotify watcher for config file: %v", err) + return + } + defer watcher.Close() + + dir := filepath.Dir(configPath) + if err := os.MkdirAll(dir, 0755); err != nil { + log.Printf("ERROR: Failed to create config dir %s: %v", dir, err) + return + } + if err := watcher.Add(dir); err != nil { + log.Printf("ERROR: Failed to add watch on %s: %v", dir, err) + return + } + + var debounceTimer *time.Timer + var debounceMu sync.Mutex + scheduleRead := func() { + debounceMu.Lock() + if debounceTimer != nil { + debounceTimer.Stop() + } + debounceTimer = time.AfterFunc(configDebounceDuration, func() { + data, err := os.ReadFile(configPath) + if err != nil { + if !os.IsNotExist(err) { + log.Printf("ERROR: Failed to read config file %s: %v", configPath, err) + } + return + } + if len(data) == 0 { + return + } + if onUpdate(string(data)) != nil { + // Caller logs the error + return + } + }) + debounceMu.Unlock() + } + + for { + select { + case <-ctx.Done(): + return + case event, ok := <-watcher.Events: + if !ok { + return + } + // We watch the directory; only react to changes to our config file + if filepath.Clean(event.Name) != filepath.Clean(configPath) { + continue + } + if event.Op&(fsnotify.Create|fsnotify.Write) != 0 { + scheduleRead() + } + case err, ok := <-watcher.Errors: + if !ok { + return + } + log.Printf("ERROR: Config file watcher error: %v", err) + } + } +} diff --git a/internal/watch/ssl.go b/internal/watch/ssl.go new file mode 100644 index 0000000..8ba3209 --- /dev/null +++ b/internal/watch/ssl.go @@ -0,0 +1,141 @@ +package watch + +import ( + "context" + "log" + "os" + "path/filepath" + "strings" + "sync" + "time" + + "github.com/fsnotify/fsnotify" + + "github.com/datasance/router/internal/qdr" +) + +const debounceDuration = 500 * time.Millisecond + +// ScanSSLProfileDir scans basePath for profile subdirs (each with ca.crt, and optionally tls.crt/tls.key) +// and returns a map of profile name to qdr.SslProfile with absolute paths. +func ScanSSLProfileDir(basePath string) (map[string]qdr.SslProfile, error) { + entries, err := os.ReadDir(basePath) + if err != nil { + if os.IsNotExist(err) { + return nil, nil + } + return nil, err + } + profiles := make(map[string]qdr.SslProfile) + for _, e := range entries { + if !e.IsDir() { + continue + } + name := e.Name() + dir := filepath.Join(basePath, name) + caPath := filepath.Join(dir, "ca.crt") + certPath := filepath.Join(dir, "tls.crt") + keyPath := filepath.Join(dir, "tls.key") + if _, err := os.Stat(caPath); err != nil { + continue + } + profile := qdr.SslProfile{ + Name: name, + CaCertFile: caPath, + } + if _, err := os.Stat(certPath); err == nil { + profile.CertFile = certPath + } + if _, err := os.Stat(keyPath); err == nil { + profile.PrivateKeyFile = keyPath + } + profiles[name] = profile + } + return profiles, nil +} + +// WatchSSLProfileDir watches basePath (and subdirs) for changes, debounces events, +// then rescans and calls onUpdate with the new profiles map. Runs until ctx is cancelled. +func WatchSSLProfileDir(ctx context.Context, basePath string, onUpdate func(profiles map[string]qdr.SslProfile)) { + watcher, err := fsnotify.NewWatcher() + if err != nil { + log.Printf("ERROR: Failed to create fsnotify watcher for SSL profile path: %v", err) + return + } + defer watcher.Close() + if err := watcher.Add(basePath); err != nil { + if !os.IsNotExist(err) { + log.Printf("ERROR: Failed to add watch on %s: %v", basePath, err) + } + return + } + // Watch new subdirs when they appear + subdirs := make(map[string]struct{}) + var mu sync.Mutex + addSubdir := func(path string) { + if path == basePath { + return + } + rel, err := filepath.Rel(basePath, path) + if err != nil || len(rel) == 0 || rel == ".." || strings.HasPrefix(rel, "..") { + return + } + if filepath.Dir(rel) != "." { + return + } + mu.Lock() + if _, ok := subdirs[path]; !ok { + subdirs[path] = struct{}{} + _ = watcher.Add(path) + } + mu.Unlock() + } + // Initial scan of subdirs + if entries, err := os.ReadDir(basePath); err == nil { + for _, e := range entries { + if e.IsDir() { + addSubdir(filepath.Join(basePath, e.Name())) + } + } + } + var debounceTimer *time.Timer + var debounceMu sync.Mutex + scheduleRescan := func() { + debounceMu.Lock() + if debounceTimer != nil { + debounceTimer.Stop() + } + debounceTimer = time.AfterFunc(debounceDuration, func() { + profiles, err := ScanSSLProfileDir(basePath) + if err != nil { + log.Printf("ERROR: Failed to rescan SSL profile dir: %v", err) + return + } + if len(profiles) > 0 { + onUpdate(profiles) + } + }) + debounceMu.Unlock() + } + for { + select { + case <-ctx.Done(): + return + case event, ok := <-watcher.Events: + if !ok { + return + } + if event.Op&(fsnotify.Create|fsnotify.Write|fsnotify.Remove) != 0 { + if info, err := os.Stat(event.Name); err == nil && info.IsDir() && event.Op == fsnotify.Create { + addSubdir(event.Name) + } + scheduleRescan() + } + case err, ok := <-watcher.Errors: + if !ok { + return + } + log.Printf("ERROR: SSL profile watcher error: %v", err) + } + } +} diff --git a/internal/watch/ssl_test.go b/internal/watch/ssl_test.go new file mode 100644 index 0000000..24fa533 --- /dev/null +++ b/internal/watch/ssl_test.go @@ -0,0 +1,112 @@ +package watch + +import ( + "os" + "path/filepath" + "testing" + + "github.com/datasance/router/internal/qdr" +) + +func TestScanSSLProfileDir(t *testing.T) { + dir := t.TempDir() + + // Empty dir returns empty map + profiles, err := ScanSSLProfileDir(dir) + if err != nil { + t.Fatal(err) + } + if len(profiles) != 0 { + t.Errorf("empty dir: got %d profiles, want 0", len(profiles)) + } + + // Subdir with ca.crt only + profile1 := filepath.Join(dir, "profile1") + if err := os.MkdirAll(profile1, 0755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(profile1, "ca.crt"), []byte("ca"), 0644); err != nil { + t.Fatal(err) + } + profiles, err = ScanSSLProfileDir(dir) + if err != nil { + t.Fatal(err) + } + if len(profiles) != 1 { + t.Fatalf("got %d profiles, want 1", len(profiles)) + } + p, ok := profiles["profile1"] + if !ok { + t.Fatal("profile1 not found") + } + if p.Name != "profile1" { + t.Errorf("profile name = %q, want profile1", p.Name) + } + absCa := filepath.Join(dir, "profile1", "ca.crt") + if p.CaCertFile != absCa { + t.Errorf("CaCertFile = %q, want %q", p.CaCertFile, absCa) + } + if p.CertFile != "" || p.PrivateKeyFile != "" { + t.Errorf("expected no cert/key when only ca.crt present") + } + + // Subdir with ca.crt, tls.crt, tls.key + profile2 := filepath.Join(dir, "profile2") + if err := os.MkdirAll(profile2, 0755); err != nil { + t.Fatal(err) + } + for _, f := range []string{"ca.crt", "tls.crt", "tls.key"} { + if err := os.WriteFile(filepath.Join(profile2, f), []byte(f), 0644); err != nil { + t.Fatal(err) + } + } + profiles, err = ScanSSLProfileDir(dir) + if err != nil { + t.Fatal(err) + } + if len(profiles) != 2 { + t.Fatalf("got %d profiles, want 2", len(profiles)) + } + p2, ok := profiles["profile2"] + if !ok { + t.Fatal("profile2 not found") + } + if p2.CaCertFile != filepath.Join(dir, "profile2", "ca.crt") { + t.Errorf("profile2 CaCertFile = %q", p2.CaCertFile) + } + if p2.CertFile != filepath.Join(dir, "profile2", "tls.crt") { + t.Errorf("profile2 CertFile = %q", p2.CertFile) + } + if p2.PrivateKeyFile != filepath.Join(dir, "profile2", "tls.key") { + t.Errorf("profile2 PrivateKeyFile = %q", p2.PrivateKeyFile) + } +} + +func TestScanSSLProfileDir_Nonexistent(t *testing.T) { + profiles, err := ScanSSLProfileDir(filepath.Join(t.TempDir(), "nonexistent")) + if err != nil { + t.Fatal(err) + } + if profiles != nil { + t.Errorf("nonexistent dir: got %v, want nil", profiles) + } +} + +func TestScanSSLProfileDir_ProfilesAreQdrSslProfile(t *testing.T) { + dir := t.TempDir() + profileDir := filepath.Join(dir, "myprofile") + if err := os.MkdirAll(profileDir, 0755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(profileDir, "ca.crt"), []byte("x"), 0644); err != nil { + t.Fatal(err) + } + profiles, err := ScanSSLProfileDir(dir) + if err != nil { + t.Fatal(err) + } + var _ map[string]qdr.SslProfile = profiles + if len(profiles) != 1 { + t.Fatalf("got %d profiles", len(profiles)) + } +} diff --git a/main.go b/main.go index 90f5802..2162854 100644 --- a/main.go +++ b/main.go @@ -14,13 +14,18 @@ package main import ( + "context" "errors" "log" "os" + "sync" + "time" + sdk "github.com/datasance/iofog-go-sdk/v3/pkg/microservices" + "github.com/datasance/router/internal/config" + qdr "github.com/datasance/router/internal/qdr" rt "github.com/datasance/router/internal/router" - - sdk "github.com/eclipse-iofog/iofog-go-sdk/v3/pkg/microservices" + "github.com/datasance/router/internal/watch" ) var ( @@ -29,34 +34,133 @@ var ( func init() { router = new(rt.Router) - router.Config = new(rt.Config) + router.Config = &rt.Config{ + SslProfiles: make(map[string]qdr.SslProfile), + Listeners: make(map[string]qdr.Listener), + Connectors: make(map[string]qdr.Connector), + Addresses: make(map[string]qdr.Address), + LogConfig: make(map[string]qdr.LogConfig), + Bridges: qdr.BridgeConfig{ + TcpListeners: make(map[string]qdr.TcpEndpoint), + TcpConnectors: make(map[string]qdr.TcpEndpoint), + }, + } } func main() { + if config.IsKubernetesRouterMode() { + runKubernetesMode() + return + } + runPotMode() +} + +func runKubernetesMode() { + configPath := config.GetConfigPath() + // Config file is volume-mounted by the operator at QDROUTERD_CONF; retry briefly if not yet present. + var data []byte + var err error + for i := 0; i < 30; i++ { + data, err = os.ReadFile(configPath) + if err == nil { + break + } + if os.IsNotExist(err) && i < 29 { + time.Sleep(time.Second) + continue + } + log.Fatalf("Failed to read router config from %s: %v", configPath, err) + } + qdrConfig, err := qdr.UnmarshalRouterConfig(string(data)) + if err != nil { + log.Fatalf("Failed to unmarshal router config: %v", err) + } + router.Config = &rt.Config{ + Metadata: qdrConfig.Metadata, + SslProfiles: qdrConfig.SslProfiles, + Listeners: qdrConfig.Listeners, + Connectors: qdrConfig.Connectors, + Addresses: qdrConfig.Addresses, + LogConfig: qdrConfig.LogConfig, + SiteConfig: qdrConfig.SiteConfig, + Bridges: qdrConfig.Bridges, + } + exitChannel := make(chan error) + go router.StartRouter(exitChannel) + ctx := context.Background() + var lastAppliedMu sync.Mutex + lastApplied := string(data) + go watch.WatchConfigFile(ctx, configPath, func(configJSON string) error { + lastAppliedMu.Lock() + same := lastApplied == configJSON + lastAppliedMu.Unlock() + if same { + return nil + } + qdrConfig, err := qdr.UnmarshalRouterConfig(configJSON) + if err != nil { + log.Printf("ERROR: Failed to unmarshal router config from file: %v", err) + return err + } + newConfig := &rt.Config{ + Metadata: qdrConfig.Metadata, + SslProfiles: qdrConfig.SslProfiles, + Listeners: qdrConfig.Listeners, + Connectors: qdrConfig.Connectors, + Addresses: qdrConfig.Addresses, + LogConfig: qdrConfig.LogConfig, + SiteConfig: qdrConfig.SiteConfig, + Bridges: qdrConfig.Bridges, + } + if err := router.UpdateRouter(newConfig); err != nil { + log.Printf("ERROR: Failed to update router from config file: %v", err) + return err + } + lastAppliedMu.Lock() + lastApplied = configJSON + lastAppliedMu.Unlock() + return nil + }) + go watch.WatchSSLProfileDir(ctx, config.GetSSLProfilePath(), router.OnSSLProfilesFromDisk) + <-exitChannel + os.Exit(0) +} + +func runPotMode() { ioFogClient, clientError := sdk.NewDefaultIoFogClient() if clientError != nil { log.Fatalln(clientError.Error()) } - if err := updateConfig(ioFogClient, router.Config); err != nil { log.Fatalln(err.Error()) } - confChannel := ioFogClient.EstablishControlWsConnection(0) - exitChannel := make(chan error) go router.StartRouter(exitChannel) - + ctx := context.Background() + go watch.WatchSSLProfileDir(ctx, config.GetSSLProfilePath(), router.OnSSLProfilesFromDisk) for { select { case <-exitChannel: os.Exit(0) case <-confChannel: - newConfig := new(rt.Config) + newConfig := &rt.Config{ + SslProfiles: make(map[string]qdr.SslProfile), + Listeners: make(map[string]qdr.Listener), + Connectors: make(map[string]qdr.Connector), + Addresses: make(map[string]qdr.Address), + LogConfig: make(map[string]qdr.LogConfig), + Bridges: qdr.BridgeConfig{ + TcpListeners: make(map[string]qdr.TcpEndpoint), + TcpConnectors: make(map[string]qdr.TcpEndpoint), + }, + } if err := updateConfig(ioFogClient, newConfig); err != nil { log.Fatal(err) } else { - router.UpdateRouter(newConfig) + if err := router.UpdateRouter(newConfig); err != nil { + log.Printf("Error updating router: %v", err) + } } } } diff --git a/scripts/launch.sh b/scripts/launch.sh index 113c85b..8e51a1c 100755 --- a/scripts/launch.sh +++ b/scripts/launch.sh @@ -1,13 +1,12 @@ -#!/bin/sh +#!/bin/bash -QDROUTERD_HOME=/qpid-dispatch -CONFIG_FILE=/tmp/qdrouterd.conf +export HOSTNAME_IP_ADDRESS=$(hostname -i) -rm -f $CONFIG_FILE -echo "${QDROUTERD_CONF}" | awk '{gsub(/\\n/,"\n")}1' >> $CONFIG_FILE +EXT=${QDROUTERD_CONF_TYPE:-conf} +CONFIG_FILE=/tmp/skrouterd.${EXT} -echo "--------------------------------------------------------------" -cat $CONFIG_FILE -echo "--------------------------------------------------------------" +if [ -f $CONFIG_FILE ]; then + ARGS="-c $CONFIG_FILE" +fi -exec qdrouterd -c $CONFIG_FILE \ No newline at end of file +exec skrouterd $ARGS \ No newline at end of file