From 7c05ce2bcfa38163728a25199e2d5876e0bc024f Mon Sep 17 00:00:00 2001 From: Kyle Jackson <58360154+wizedkyle@users.noreply.github.com> Date: Mon, 10 Jan 2022 21:43:54 +1000 Subject: [PATCH] Build pipeline update (#99) --- .github/workflows/config.json | 18 - .github/workflows/macos_amd64_config.json | 18 + .github/workflows/macos_arm64_config.json | 18 + .github/workflows/release.yml | 396 ++++++++++++++++++ .github/workflows/sumocli-build.yml | 267 ------------ .github/workflows/sumocli-tests.yml | 9 +- .goreleaser.yml | 62 +++ Dockerfile | 14 +- README.md | 36 +- config/config.go | 9 + internal/authentication/authentication.go | 10 +- internal/authorizers/authorizers.go | 76 ---- internal/az/az.go | 94 ----- internal/build/build.go | 8 +- internal/clients/clients.go | 119 ------ internal/config/config.go | 89 ---- .../create-subdomain/create-subdomain.go | 2 + .../delete-subdomain/delete-subdomain.go | 2 + pkg/cmd/account/get-owner/get-owner.go | 2 + .../account/get-subdomain/get-subdomain.go | 2 + .../recover-subdomain/recover-subdomain.go | 2 + .../update-subdomain/update-subdomain.go | 2 + pkg/cmd/apps/get/get.go | 2 + pkg/cmd/apps/install/install.go | 2 + pkg/cmd/apps/install_status/install_status.go | 2 + pkg/cmd/apps/list/list.go | 2 + pkg/cmd/collectors/create/create.go | 2 + pkg/cmd/collectors/delete/delete.go | 2 + pkg/cmd/collectors/get/get.go | 2 + pkg/cmd/collectors/list/list.go | 2 + pkg/cmd/collectors/update/update.go | 2 + .../get_upgradable_collectors.go | 2 + pkg/cmd/collectors/upgrade/start/start.go | 2 + pkg/cmd/collectors/upgrade/status/status.go | 2 + pkg/cmd/content/get/get.go | 2 + .../get_copy_status/get_copy_status.go | 2 + .../get_deletion_status.go | 2 + .../get_export_result/get_export_result.go | 2 + .../get_export_status/get_export_status.go | 2 + .../get_import_status/get_import_status.go | 2 + pkg/cmd/content/move/move.go | 2 + pkg/cmd/content/start_copy/start_copy.go | 2 + .../content/start_deletion/start_deletion.go | 2 + pkg/cmd/content/start_export/start_export.go | 2 + pkg/cmd/content/start_import/start_import.go | 2 + pkg/cmd/dashboards/create/create.go | 2 + pkg/cmd/dashboards/delete/delete.go | 2 + pkg/cmd/factory/http.go | 2 +- pkg/cmd/folders/create/create.go | 2 + pkg/cmd/folders/get/get.go | 2 + .../get_admin_recommended_folder.go | 2 + .../get_admin_recommended_folder_result.go | 2 + .../get_admin_recommended_folder_status.go | 2 + .../get_global_folder/get_global_folder.go | 2 + .../get_global_folder_result.go | 2 + .../get_global_folder_status.go | 2 + .../get_personal_folder.go | 2 + pkg/cmd/folders/update/update.go | 2 + .../get_audit_policy/get_audit_policy.go | 2 + .../get_data_access_level_policy.go | 2 + .../get_max_user_session_timeout_policy.go | 2 + .../get_search_audit_policy.go | 2 + ..._dashboards_outside_organization_policy.go | 2 + ...t_user_concurrent_sessions_limit_policy.go | 2 + .../set_audit_policy/set_audit_policy.go | 2 + .../set_data_access_level_policy.go | 2 + .../set_max_user_session_timeout_policy.go | 2 + .../set_search_audit_policy.go | 2 + ..._dashboards_outside_organization_policy.go | 2 + ...t_user_concurrent_sessions_limit_policy.go | 2 + pkg/cmd/roles/assign/assign.go | 3 + pkg/cmd/roles/create/create.go | 2 + pkg/cmd/roles/delete/delete.go | 2 + pkg/cmd/roles/get/get.go | 2 + pkg/cmd/roles/list/list.go | 4 + pkg/cmd/roles/remove/remove.go | 2 + pkg/cmd/roles/update/update.go | 2 + .../sources/azure_event_hub/create/create.go | 2 + pkg/cmd/sources/azure_event_hub/get/get.go | 2 + .../sources/azure_event_hub/update/update.go | 2 + pkg/cmd/tokens/create/create.go | 2 + pkg/cmd/tokens/delete/delete.go | 2 + pkg/cmd/tokens/get/get.go | 2 + pkg/cmd/tokens/list/list.go | 2 + pkg/cmd/tokens/update/update.go | 2 + pkg/cmd/users/change_email/change_email.go | 2 + pkg/cmd/users/create/create.go | 2 + pkg/cmd/users/delete/delete.go | 2 + pkg/cmd/users/disable_mfa/disable_mfa.go | 2 + pkg/cmd/users/get/get.go | 2 + pkg/cmd/users/list/list.go | 2 + .../users/reset_password/reset_password.go | 2 + pkg/cmd/users/unlock/unlock.go | 2 + pkg/cmd/users/update/update.go | 2 + pkg/cmd/version/version.go | 3 +- scripts/build-debianpackage.sh | 40 ++ scripts/build.ps1 | 138 ------ scripts/create-brewformula.sh | 71 ++++ scripts/create-debianrelease.ps1 | 27 -- scripts/docker-build.sh | 29 -- scripts/invalidate-cloudfront.sh | 17 + scripts/release-debianpackage.sh | 121 ++++++ scripts/release-macos.sh | 0 103 files changed, 953 insertions(+), 895 deletions(-) delete mode 100644 .github/workflows/config.json create mode 100644 .github/workflows/macos_amd64_config.json create mode 100644 .github/workflows/macos_arm64_config.json create mode 100644 .github/workflows/release.yml delete mode 100644 .github/workflows/sumocli-build.yml create mode 100644 .goreleaser.yml delete mode 100644 internal/authorizers/authorizers.go delete mode 100644 internal/az/az.go delete mode 100644 internal/clients/clients.go delete mode 100644 internal/config/config.go create mode 100644 scripts/build-debianpackage.sh delete mode 100644 scripts/build.ps1 create mode 100644 scripts/create-brewformula.sh delete mode 100644 scripts/create-debianrelease.ps1 delete mode 100644 scripts/docker-build.sh create mode 100644 scripts/invalidate-cloudfront.sh create mode 100755 scripts/release-debianpackage.sh delete mode 100644 scripts/release-macos.sh diff --git a/.github/workflows/config.json b/.github/workflows/config.json deleted file mode 100644 index 356adc9d..00000000 --- a/.github/workflows/config.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "source" : ["./sumocli"], - "bundle_id" : "com.thepublicclouds.sumocli", - "apple_id": { - "username" : "kyle.jackson733@gmail.com", - "password": "@env:AC_PASSWORD" - }, - "sign" :{ - "application_identity" : "08C9A4B04024CDEF2C5D93593710C60591FB4614" - }, - "dmg" :{ - "output_path": "sumocli.dmg", - "volume_name": "sumocli" - }, - "zip" :{ - "output_path" : "sumocli.zip" - } -} diff --git a/.github/workflows/macos_amd64_config.json b/.github/workflows/macos_amd64_config.json new file mode 100644 index 00000000..e49c4c0d --- /dev/null +++ b/.github/workflows/macos_amd64_config.json @@ -0,0 +1,18 @@ +{ + "source": ["./dist/sumocli_darwin_amd64/sumocli"], + "bundle_id": "com.thepublicclouds.sumocli", + "apple_id": { + "username": "kyle.jackson733@gmail.com", + "password": "@env:AC_PASSWORD" + }, + "sign": { + "application_identity": "08C9A4B04024CDEF2C5D93593710C60591FB4614" + }, + "dmg": { + "output_path": "sumocli_darwin_amd64.dmg", + "volume_name": "sumocli" + }, + "zip": { + "output_path": "sumocli_darwin_amd64.zip" + } +} diff --git a/.github/workflows/macos_arm64_config.json b/.github/workflows/macos_arm64_config.json new file mode 100644 index 00000000..4599f4c1 --- /dev/null +++ b/.github/workflows/macos_arm64_config.json @@ -0,0 +1,18 @@ +{ + "source": ["./dist/sumocli_darwin_arm64/sumocli"], + "bundle_id": "com.thepublicclouds.sumocli", + "apple_id": { + "username": "kyle.jackson733@gmail.com", + "password": "@env:AC_PASSWORD" + }, + "sign": { + "application_identity": "08C9A4B04024CDEF2C5D93593710C60591FB4614" + }, + "dmg": { + "output_path": "sumocli_darwin_arm64.dmg", + "volume_name": "sumocli" + }, + "zip": { + "output_path": "sumocli_darwin_arm64.zip" + } +} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..73af3e9d --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,396 @@ +name: release + +on: + push: + tags: + - '*.*.*' + +permissions: + contents: write + packages: write + +env: + GOVERSION: '1.17.6' + +jobs: + build: + name: Build + runs-on: macos-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Setup Go + uses: actions/setup-go@v2 + with: + go-version: ${{ env.GOVERSION }} + - name: Setup Podman + run: | + brew install podman + podman machine init + podman machine start + podman info + - name: Container Registry Login + run: | + podman login -u ${{ github.repository_owner }} -p ${{ secrets.GITHUB_TOKEN }} ghcr.io + - name: Install GoReleaser Pro + run: | + brew install goreleaser/tap/goreleaser-pro + - name: Run GoReleaser Pro + run: | + goreleaser release -f .goreleaser.yml --rm-dist + env: + AC_PASSWORD: ${{ secrets.AC_PASSWORD }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} + - name: Upload Darwin amd64 + uses: actions/upload-artifact@v2 + with: + name: sumocli_darwin_amd64 + path: ./dist/sumocli_darwin_amd64/sumocli + - name: Upload Darwin arm64 + uses: actions/upload-artifact@v2 + with: + name: sumocli_darwin_arm64 + path: ./dist/sumocli_darwin_arm64/sumocli + - name: Upload linux amd64 + uses: actions/upload-artifact@v2 + with: + name: sumocli_linux_amd64 + path: ./dist/sumocli_linux_amd64/sumocli + - name: Upload linux arm64 + uses: actions/upload-artifact@v2 + with: + name: sumocli_linux_arm64 + path: ./dist/sumocli_linux_arm64/sumocli + - name: Upload Windows amd64 + uses: actions/upload-artifact@v2 + with: + name: sumocli_windows_amd64 + path: ./dist/sumocli_windows_amd64/sumocli.exe + + create_debian_package: + name: Create debian package + needs: build + runs-on: ubuntu-latest + steps: + - name: Set Version Variable + run: | + echo "TAG=${GITHUB_REF/refs\/tags\/}" >> $GITHUB_ENV + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Download linux amd64 artifact + uses: actions/download-artifact@v2 + with: + name: sumocli_linux_amd64 + path: ./sumocli_linux_amd64/sumocli + - name: Download linux arm64 artifact + uses: actions/download-artifact@v2 + with: + name: sumocli_linux_arm64 + path: ./sumocli_linux_arm64/sumocli + - name: Run debian package script + shell: bash + run: | + chmod +x ./scripts/build-debianpackage.sh + ./scripts/build-debianpackage.sh -a amd64 -v ${{ env.TAG }} + ./scripts/build-debianpackage.sh -a arm64 -v ${{ env.TAG }} + - name: Upload debian amd package asset + uses: actions/upload-artifact@v2 + with: + name: sumocli_linux_amd64_deb + path: ./deb/sumocli_${{ env.TAG }}-1_amd64.deb + - name: Upload debian arm64 package asset + uses: actions/upload-artifact@v2 + with: + name: sumocli_linux_arm64_deb + path: ./deb/sumocli_${{ env.TAG }}-1_arm64.deb + + sign_macos_binaries: + name: Signing macOS binaries + needs: build + runs-on: macos-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Download darwin amd64 artifact + uses: actions/download-artifact@v2 + with: + name: sumocli_darwin_amd64 + path: ./dist/sumocli_darwin_amd64 + - name: Download darwin arm64 artifact + uses: actions/download-artifact@v2 + with: + name: sumocli_darwin_arm64 + path: ./dist/sumocli_darwin_arm64 + - name: Install Gon + shell: bash + run: | + brew tap mitchellh/gon + brew install mitchellh/gon/gon + - name: Configuring signing certificate + shell: bash + run: | + CERTIFICATE_PATH=$RUNNER_TEMP/build_certificate.p12 + KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db + echo -n "$APPLE_DEV_CERT" | base64 --decode --output $CERTIFICATE_PATH + security create-keychain -p $KEYCHAIN_PASSWORD $KEYCHAIN_PATH + security set-keychain-settings -lut 21600 $KEYCHAIN_PATH + security unlock-keychain -p $KEYCHAIN_PASSWORD $KEYCHAIN_PATH + security import $CERTIFICATE_PATH -P $APPLE_DEV_CERT_PASSWORD -A -t cert -f pkcs12 -k $KEYCHAIN_PATH + security list-keychain -d user -s $KEYCHAIN_PATH + env: + APPLE_DEV_CERT: ${{ secrets.APPLE_DEV_CERT }} + APPLE_DEV_CERT_PASSWORD: ${{ secrets.APPLE_DEV_CERT_PASSWORD }} + KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }} + - name: Sign macOS amd64 binary + shell: bash + run: | + gon --log-level=info --log-json .github/workflows/macos_amd64_config.json + gon --log-level=info --log-json .github/workflows/macos_arm64_config.json + env: + AC_PASSWORD: ${{ secrets.AC_PASSWORD }} + - name: Upload signed macOS amd64 dmg + uses: actions/upload-artifact@v2 + with: + name: sumocli_darwin_amd64_signed_dmg + path: ./sumocli_darwin_amd64.dmg + - name: Upload signed macOS amd64 zip + uses: actions/upload-artifact@v2 + with: + name: sumocli_darwin_amd64_signed_zip + path: ./sumocli_darwin_amd64.zip + - name: Upload signed macOS arm64 dmg + uses: actions/upload-artifact@v2 + with: + name: sumocli_darwin_arm64_signed_dmg + path: ./sumocli_darwin_arm64.dmg + - name: Upload signed macOS arm64 zip + uses: actions/upload-artifact@v2 + with: + name: sumocli_darwin_arm64_signed_zip + path: ./sumocli_darwin_arm64.zip + + sign_windows_binaries: + name: Sign and Timestamp Windows Binary + needs: build + runs-on: windows-latest + steps: + - name: Setup Dotnet + uses: actions/setup-dotnet@v1 + with: + dotnet-version: '3.x.x' + - name: Install AzureSignTool + shell: pwsh + run: | + dotnet tool install --global AzureSignTool --version 3.0.0 + - name: Download Windows amd64 binary + uses: actions/download-artifact@v2 + with: + name: sumocli_windows_amd64 + path: ./dist/sumocli_windows_amd64/sumocli.exe + - name: Sign Windows binaries + shell: pwsh + run: | + $amd64 = Get-ChildItem ./dist/sumocli_windows_amd64/sumocli.exe | % { $_.FullName } + azuresigntool sign --description-url "https://github.com/SumoLogic-Labs/sumocli" --file-digest sha256 ` + --azure-key-vault-url ${{ secrets.AZURE_KEY_VAULT_URL }} ` + --azure-key-vault-client-id ${{ secrets.AZURE_KEY_VAULT_CLIENT_ID }} ` + --azure-key-vault-client-secret ${{ secrets.AZURE_KEY_VAULT_CLIENT_SECRET }} ` + --azure-key-vault-certificate ${{ secrets.AZURE_KEY_VAULT_CERTIFICATE }} ` + --azure-key-vault-tenant-id ${{ secrets.AZURE_KEY_VAULT_TENANT_ID }} ` + --timestamp-rfc3161 http://timestamp.sectigo.com ` + --timestamp-digest sha256 ` + $amd64 + - name: Upload Signed Windows amd64 binary + uses: actions/upload-artifact@v2 + with: + name: sumocli_windows_amd64_signed + path: ./dist/sumocli_windows_amd64/sumocli.exe + + upload_assets_to_release: + name: Upload Assets to Release + needs: [build, create_debian_package, sign_macos_binaries, sign_windows_binaries] + runs-on: ubuntu-latest + steps: + - name: Set Version Variable + run: | + echo "TAG=${GITHUB_REF/refs\/tags\/}" >> $GITHUB_ENV + - name: Download darwin amd64 signed asset + uses: actions/download-artifact@v2 + with: + name: sumocli_darwin_amd64_signed_zip + path: sumocli_darwin_amd64/sumocli + - name: Download darwin arm64 signed asset + uses: actions/download-artifact@v2 + with: + name: sumocli_darwin_arm64_signed_zip + path: sumocli_darwin_arm64/sumocli + - name: Download linux amd64 asset + uses: actions/download-artifact@v2 + with: + name: sumocli_linux_amd64 + path: sumocli_linux_amd64/sumocli + - name: Download linux arm64 asset + uses: actions/download-artifact@v2 + with: + name: sumocli_linux_arm64 + path: sumocli_linux_arm64/sumocli + - name: Download windows amd64 signed asset + uses: actions/download-artifact@v2 + with: + name: sumocli_windows_amd64_signed + path: sumocli_windows_amd64/sumocli.exe + - name: Create installer archives + shell: bash + run: | + mkdir archives + unzip ./sumocli_darwin_amd64/sumocli/sumocli_darwin_amd64.zip -d ./sumocli_darwin_amd64/sumocli + unzip ./sumocli_darwin_arm64/sumocli/sumocli_darwin_arm64.zip -d ./sumocli_darwin_arm64/sumocli + rm ./sumocli_darwin_amd64/sumocli/sumocli_darwin_amd64.zip + rm ./sumocli_darwin_arm64/sumocli/sumocli_darwin_arm64.zip + tar -czf ./archives/sumocli_${{ env.TAG }}_darwin_amd64.tar.gz -C sumocli_darwin_amd64/sumocli . + tar -czf ./archives/sumocli_${{ env.TAG }}_darwin_arm64.tar.gz -C sumocli_darwin_arm64/sumocli . + tar -czf ./archives/sumocli_${{ env.TAG }}_linux_amd64.tar.gz -C sumocli_linux_amd64/sumocli . + tar -czf ./archives/sumocli_${{ env.TAG }}_linux_arm64.tar.gz -C sumocli_linux_arm64/sumocli . + zip ./archives/sumocli_${{ env.TAG }}_windows_amd64.zip sumocli_windows_amd64/sumocli.exe/sumocli.exe + find ./archives -type f -exec sha256sum {} \; > checksums.txt + cat checksums.txt + - name: Create Release + uses: softprops/action-gh-release@v1 + with: + files: | + ./archives/sumocli_${{ env.TAG }}_darwin_amd64.tar.gz + ./archives/sumocli_${{ env.TAG }}_darwin_arm64.tar.gz + ./archives/sumocli_${{ env.TAG }}_linux_amd64.tar.gz + ./archives/sumocli_${{ env.TAG }}_linux_arm64.tar.gz + ./archives/sumocli_${{ env.TAG }}_windows_amd64.zip + checksums.txt + + release_debian_packages: + name: Release Debian Packages + needs: [build, create_debian_package] + runs-on: ubuntu-latest + steps: + - name: Set Version Variable + run: | + echo "TAG=${GITHUB_REF/refs\/tags\/}" >> $GITHUB_ENV + - name: Import GPG Key + uses: crazy-max/ghaction-import-gpg@v4 + with: + gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} + passphrase: ${{ secrets.GPG_PRIVATE_KEY_PASSPHRASE }} + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Download debian amd64 package + uses: actions/download-artifact@v2 + with: + name: sumocli_linux_amd64_deb + - name: Download debian arm64 package + uses: actions/download-artifact@v2 + with: + name: sumocli_linux_arm64_deb + - name: Installing release prerequsities + shell: bash + run: | + sudo apt-get install dpkg-dev + - name: Run debian release + shell: bash + run: | + chmod +x ./scripts/release-debianpackage.sh + ./scripts/release-debianpackage.sh -a amd64 -a arm64 -v ${{ env.TAG }} + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }} + - name: Invalidate Cloudfront Cache + shell: bash + run: | + chmod +x ./scripts/invalidate-cloudfront.sh + ./scripts/invalidate-cloudfront.sh + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }} + DISTRIBUTIONID: ${{ secrets.DISTRIBUTIONID }} + + update_homebrew_formula: + name: Update Hombrew Formula + needs: [build, upload_assets_to_release] + runs-on: ubuntu-latest + steps: + - name: Set Version Variable + run: | + echo "TAG=${GITHUB_REF/refs\/tags\/}" >> $GITHUB_ENV + - name: Set SSH Key + uses: webfactory/ssh-agent@v0.5.4 + with: + ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Download Darwin AMD asset + uses: dsaltares/fetch-gh-release-asset@master + with: + token: ${{ secrets.GITHUB_TOKEN }} + file: sumocli_${{ env.TAG }}_darwin_amd64.tar.gz + version: tags/${{ env.TAG }} + target: sumocli_${{ env.TAG }}_darwin_amd64.tar.gz + - name: Download Darwin ARM asset + uses: dsaltares/fetch-gh-release-asset@master + with: + token: ${{ secrets.GITHUB_TOKEN }} + file: sumocli_${{ env.TAG }}_darwin_arm64.tar.gz + version: tags/${{ env.TAG }} + target: sumocli_${{ env.TAG }}_darwin_arm64.tar.gz + - name: Download Linux AMD asset + uses: dsaltares/fetch-gh-release-asset@master + with: + token: ${{ secrets.GITHUB_TOKEN }} + file: sumocli_${{ env.TAG }}_linux_amd64.tar.gz + version: tags/${{ env.TAG }} + target: sumocli_${{ env.TAG }}_linux_amd64.tar.gz + - name: Download Linux ARM asset + uses: dsaltares/fetch-gh-release-asset@master + with: + token: ${{ secrets.GITHUB_TOKEN }} + file: sumocli_${{ env.TAG }}_linux_arm64.tar.gz + version: tags/${{ env.TAG }} + target: sumocli_${{ env.TAG }}_linux_arm64.tar.gz + - name: Generate homebrew formula + shell: bash + run: | + chmod +x ./scripts/create-brewformula.sh + ./scripts/create-brewformula.sh -v ${{ env.TAG }} + - name: Check homebrew formula + shell: bash + run: | + ls -la + cat sumocli.rb + - name: Update homebrew formula + shell: bash + run: | + git clone git@github.com:SumoLogic-Labs/homebrew-tap.git + git config --global user.email ${{ secrets.EMAIL }} + git config --global user.name ${{ secrets.NAME }} + cd homebrew-tap + git checkout -b "${{ env.TAG }}-update" + cd .. + rm ./homebrew-tap/Formula/sumocli.rb + mv ./sumocli.rb ./homebrew-tap/Formula/sumocli.rb + cd homebrew-tap + git add ./Formula/sumocli.rb + git commit -m "Updating sumocli formula to ${{ env.TAG }}" + git push --set-upstream origin "${{ env.TAG }}-update" + URL=$(gh pr create --title "Update sumocli formula to ${{ env.TAG }}" --body "Updates sumocli homebrew formula to version ${{ env.TAG }}" --repo SumoLogic-Labs/homebrew-tap) + gh pr merge "$URL" --squash --delete-branch --repo SumoLogic-Labs/homebrew-tap + env: + GITHUB_TOKEN: ${{ secrets.REPO_KEY }} diff --git a/.github/workflows/sumocli-build.yml b/.github/workflows/sumocli-build.yml deleted file mode 100644 index add8e466..00000000 --- a/.github/workflows/sumocli-build.yml +++ /dev/null @@ -1,267 +0,0 @@ -name: Sumocli Build and Release - -on: - push: - tags: - - v*.*.* - -jobs: - create_github_release: - name: Create GitHub Release - runs-on: ubuntu-latest - steps: - - name: Set Version Variable - run: | - echo "TAG=${GITHUB_REF/refs\/tags\/}" >> $GITHUB_ENV - - name: Create Release - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ env.TAG }} - release_name: Release ${{ env.TAG }} - draft: false - prerelease: false - outputs: - releaseurl: ${{ steps.create_release.outputs.upload_url }} - - build_docker_image: - name: Build Docker Image - runs-on: ubuntu-latest - steps: - - name: Run Docker Build - run: | - docker build --build-arg buildnumber=00001 --build-arg version=0.0.1 --tag sumocli-test . - - build_windows: - name: Build Windows Binary - needs: create_github_release - runs-on: windows-latest - steps: - - name: Setup Go - uses: actions/setup-go@v2 - with: - go-version: '1.17' - - name: Setup Dotnet - uses: actions/setup-dotnet@v1 - with: - dotnet-version: '2.1.x' - - name: Set Version Variable - run: | - echo "TAG=${GITHUB_REF/refs\/tags\/}" >> $GITHUB_ENV - - name: Checkout Repo - uses: actions/checkout@v2 - - name: Download Dependencies - run: go mod download - - name: Run Tests - run: go test ./... - - name: Build Binary - run: ./scripts/build.sh -b "" -v "" -w - - name: Upload Windows Release Asset - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ needs.create_github_release.outputs.releaseurl }} - asset_path: ./sumocli-windows-amd64.zip - asset_name: sumocli-windows-amd64.zip - asset_content_type: application/zip - - name: Upload Artifact - uses: actions/upload-artifact@v2 - with: - name: sumocli-windows-amd64 - path: ./sumocli.exe - - build_linux: - name: Build Linux Binary - needs: create_github_release - runs-on: ubuntu-latest - steps: - - name: Setup Go - uses: actions/setup-go@v2 - with: - go-version: '1.17' - - name: Set Version Variable - run: | - echo "TAG=${GITHUB_REF/refs\/tags\/}" >> $GITHUB_ENV - - name: Checkout Repo - uses: actions/checkout@v2 - - name: Download Dependencies - run: go mod download - - name: Run Tests - run: go test ./... - - name: Build Sumocli - shell: pwsh - run: | - $build = $Env:GITHUB_RUN_NUMBER - $time = Get-Date - go build -ldflags ` - "-X 'github.com/SumoLogic-Labs/sumocli/internal/build.Version=${{ env.TAG }}' ` - -X 'github.com/SumoLogic-Labs/sumocli/internal/build.Build=$build' ` - -X 'github.com/SumoLogic-Labs/sumocli/internal/build.Date=$time'" ` - ./cmd/sumocli - - name: Zip Releases - run: | - zip -r sumocli-linux-amd64.zip sumocli - - name: Upload Linux Release Asset - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ needs.create_github_release.outputs.releaseurl }} - asset_path: ./sumocli-linux-amd64.zip - asset_name: sumocli-linux-amd64.zip - asset_content_type: application/zip - - name: Upload Artifact - uses: actions/upload-artifact@v2 - with: - name: sumocli-linux-amd64 - path: ./sumocli - - build_macos_intel: - name: Build macOS Binary (Intel) - needs: create_github_release - runs-on: macos-latest - steps: - - name: Setup Go - uses: actions/setup-go@v2 - with: - go-version: '1.17' - - name: Set Version Variable - run: | - echo "TAG=${GITHUB_REF/refs\/tags\/}" >> $GITHUB_ENV - - name: Checkout Repo - uses: actions/checkout@v2 - - name: Download Dependencies - run: go mod download - - name: Run Tests - run: go test ./... - - name: Build Sumocli - shell: pwsh - run: | - $build = $Env:GITHUB_RUN_NUMBER - $time = Get-Date - go build -ldflags ` - "-X 'github.com/SumoLogic-Labs/sumocli/internal/build.Version=${{ env.TAG }}' ` - -X 'github.com/SumoLogic-Labs/sumocli/internal/build.Build=$build' ` - -X 'github.com/SumoLogic-Labs/sumocli/internal/build.Date=$time'" ` - ./cmd/sumocli - env: - GOOS: darwin - GOARCH: amd64 - - name: Install gon - shell: bash - run: | - brew tap mitchellh/gon - brew install mitchellh/gon/gon - - name: Sign and Notarize Binary - shell: bash - run: | - # Install signing certificate - CERTIFICATE_PATH=$RUNNER_TEMP/build_certificate.p12 - KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db - echo -n "$APPLE_DEV_CERT" | base64 --decode --output $CERTIFICATE_PATH - security create-keychain -p $KEYCHAIN_PASSWORD $KEYCHAIN_PATH - security set-keychain-settings -lut 21600 $KEYCHAIN_PATH - security unlock-keychain -p $KEYCHAIN_PASSWORD $KEYCHAIN_PATH - security import $CERTIFICATE_PATH -P $APPLE_DEV_CERT_PASSWORD -A -t cert -f pkcs12 -k $KEYCHAIN_PATH - security list-keychain -d user -s $KEYCHAIN_PATH - - # Sign macOS build - gon -log-level=info -log-json .github/workflows/config.json - env: - APPLE_DEV_CERT: ${{ secrets.APPLE_DEV_CERT }} - APPLE_DEV_CERT_PASSWORD: ${{ secrets.APPLE_DEV_CERT_PASSWORD }} - KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }} - AC_USERNAME: ${{ secrets.AC_USERNAME }} - AC_PASSWORD: ${{ secrets.AC_PASSWORD }} - - name: Zip Releases - run: | - zip -r sumocli-macos-amd64.zip sumocli - - name: Upload macOS Release Asset - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ needs.create_github_release.outputs.releaseurl }} - asset_path: ./sumocli.zip - asset_name: sumocli-macos-amd64.zip - asset_content_type: application/zip - - name: Upload Artifact - uses: actions/upload-artifact@v2 - with: - name: sumocli-macos-amd64 - path: ./sumocli - - - build_macos_apple_silicon: - name: Build macOS Binary (Apple Silicon) - needs: create_github_release - runs-on: macos-latest - steps: - - name: Setup Go - uses: actions/setup-go@v2 - with: - go-version: '1.17' - - name: Set Version Variable - run: | - echo "TAG=${GITHUB_REF/refs\/tags\/}" >> $GITHUB_ENV - - name: Checkout Repo - uses: actions/checkout@v2 - - name: Download Dependencies - run: go mod download - - name: Run Tests - run: go test ./... - - name: Build Sumocli - shell: bash - run: | - time=$(date) - go build -ldflags \ - "-X 'github.com/SumoLogic-Labs/sumocli/internal/build.Version=${{ env.TAG }}' \ - -X 'github.com/SumoLogic-Labs/sumocli/internal/build.Build=$GITHUB_RUN_NUMBER' \ - -X 'github.com/SumoLogic-Labs/sumocli/internal/build.Date=$time'" \ - ./cmd/sumocli - env: - GOOS: darwin - GOARCH: arm64 - - name: Install gon - shell: bash - run: | - brew tap mitchellh/gon - brew install mitchellh/gon/gon - - name: Sign and Notarize Binary - shell: bash - run: | - # Install signing certificate - CERTIFICATE_PATH=$RUNNER_TEMP/build_certificate.p12 - KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db - echo -n "$APPLE_DEV_CERT" | base64 --decode --output $CERTIFICATE_PATH - security create-keychain -p $KEYCHAIN_PASSWORD $KEYCHAIN_PATH - security set-keychain-settings -lut 21600 $KEYCHAIN_PATH - security unlock-keychain -p $KEYCHAIN_PASSWORD $KEYCHAIN_PATH - security import $CERTIFICATE_PATH -P $APPLE_DEV_CERT_PASSWORD -A -t cert -f pkcs12 -k $KEYCHAIN_PATH - security list-keychain -d user -s $KEYCHAIN_PATH - - # Sign macOS build - gon -log-level=info -log-json .github/workflows/config.json - env: - APPLE_DEV_CERT: ${{ secrets.APPLE_DEV_CERT }} - APPLE_DEV_CERT_PASSWORD: ${{ secrets.APPLE_DEV_CERT_PASSWORD }} - KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }} - AC_USERNAME: ${{ secrets.AC_USERNAME }} - AC_PASSWORD: ${{ secrets.AC_PASSWORD }} - - name: Upload macOS Release Asset - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ needs.create_github_release.outputs.releaseurl }} - asset_path: ./sumocli.zip - asset_name: sumocli-macos-arm64.zip - asset_content_type: application/zip - - name: Upload Artifact - uses: actions/upload-artifact@v2 - with: - name: sumocli-macos-arm64 - path: ./sumocli diff --git a/.github/workflows/sumocli-tests.yml b/.github/workflows/sumocli-tests.yml index 2e9e3f60..fd9fa0a4 100644 --- a/.github/workflows/sumocli-tests.yml +++ b/.github/workflows/sumocli-tests.yml @@ -2,6 +2,9 @@ name: Sumocli Tests on: [pull_request, push] +env: + GOVERSION: '1.17.6' + jobs: compile_linux_binary: name: Test and Compile Linux Binary @@ -10,7 +13,7 @@ jobs: - name: Setup Go Environment uses: actions/setup-go@v2 with: - go-version: '1.16.5' + go-version: ${{ env.GOVERSION }} - name: Checkout Code uses: actions/checkout@v2 - name: Build Sumocli @@ -25,7 +28,7 @@ jobs: - name: Setup Go Environment uses: actions/setup-go@v2 with: - go-version: '1.16.5' + go-version: ${{ env.GOVERSION }} - name: Checkout Code uses: actions/checkout@v2 - name: Build Sumocli @@ -40,7 +43,7 @@ jobs: - name: Setup Go Environment uses: actions/setup-go@v2 with: - go-version: '1.16.5' + go-version: ${{ env.GOVERSION }} - name: Checkout Code uses: actions/checkout@v2 - name: Build Sumocli diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 00000000..7877c9eb --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,62 @@ +builds: + - goos: + - darwin + - linux + - windows + goarch: + - amd64 + - arm64 + main: ./cmd/sumocli + ldflags: + - -X 'github.com/SumoLogic-Labs/sumocli/internal/build.Build={{.Commit}}' + - -X 'github.com/SumoLogic-Labs/sumocli/internal/build.Date={{.Date}}' + - -X 'github.com/SumoLogic-Labs/sumocli/internal/build.Version={{.Version}}' + ignore: + - goos: windows + goarch: arm64 +dockers: + - image_templates: + - "ghcr.io/sumologic-labs/sumocli:{{.Version}}-amd64" + goos: linux + goarch: amd64 + build_flag_templates: + - --label=org.opencontainers.image.title={{.ProjectName}} + - --label=org.opencontainers.image.source=https://github.com/SumoLogic-Labs/sumocli + - --label=org.opencontainers.image.version={{.Version}} + - --label=org.opencontainers.image.revision={{.FullCommit}} + skip_push: false + use: podman + - image_templates: + - "ghcr.io/sumologic-labs/sumocli:{{.Version}}-arm64" + goos: linux + goarch: arm64 + build_flag_templates: + - --label=org.opencontainers.image.title={{.ProjectName}} + - --label=org.opencontainers.image.source=https://github.com/SumoLogic-Labs/sumocli + - --label=org.opencontainers.image.version={{.Version}} + - --label=org.opencontainers.image.revision={{.FullCommit}} + skip_push: false + use: podman +archives: + - replacements: + darwin: Darwin + linux: Linux + windows: Windows + 386: i386 + amd64: x86_64 + + format_overrides: + - goos: windows + format: zip +release: + disable: true +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ incpatch .Version }}-next" +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' diff --git a/Dockerfile b/Dockerfile index 83e1554b..6bb54c4b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,3 @@ -FROM golang:1.17.1-alpine -ARG buildnumber=DEV -ARG version=DEV -LABEL maintainer="Kyle Jackson " - -WORKDIR $GOPATH/src/github.com/SumoLogic-Labs/sumocli -COPY . . -RUN chmod +x ./scripts/docker-build.sh -RUN ./scripts/docker-build.sh -b $buildnumber -v $version -d - -ENTRYPOINT ["/go/bin/sumocli"] +FROM scratch +ENTRYPOINT ["/sumocli"] +COPY sumocli / diff --git a/README.md b/README.md index 05b7bb0b..ff57136a 100644 --- a/README.md +++ b/README.md @@ -5,32 +5,34 @@ Sumocli is currently in development so there could be bugs/incomplete functional GA will be v1.0.0 which I am expecting to be ready for release in Q1 2022. ## Installation -### Linux -You can install sumocli via apt on debian based linux distributions by running the following commands: +### Container Image + +Container images for `sumocli` are hosted in GitHub Packages and can be pulled with the following command: +```shell +docker pull ghcr.io/sumologic-labs/sumocli:$VERSION-$ARCHITECTURE ``` +### Linux +You can install `sumocli` via apt on debian based linux distributions by running the following commands: + +```shell +apt-key adv --fetch-keys https://apt.sumocli.app/public.key +add-apt-repository "deb https://apt.sumocli.app/ stable main" apt-get update +apt-get install sumocli ``` - ### macOS +You can install `sumocli` via homebrew on macOS by running the following commands: +```shell +brew tap sumologic-labs/homebrew-tap +brew install sumologic-labs/tap/sumocli +``` ### Windows - - -### Docker - -Each version of Sumocli is published on [Docker Hub](https://hub.docker.com/r/wizedkyle/sumocli). - -Pull the latest image: - -`docker pull wiedkyle/sumocli:latest` - -Pull a specific version image: - -`docker pull wizedkyle/sumocli:v0.11.0` +You can download a signed binary file from the specific release you want. ### Build Yourself You can build the sumocli application for your platform by performing the following steps: @@ -54,7 +56,7 @@ The sections below explain the requirements for each authentication type. ### Environment Variables -Environment variable authentication is useful when running sumocli in a CI/CD pipeline. The following environment variables need to be set to allow for proper authentication. +Environment variable authentication is useful when running sumocli in a CI/CD pipeline or when using the Docker image. The following environment variables need to be set to allow for proper authentication. ``` SUMO_ACCESS_ID: abcefghi diff --git a/config/config.go b/config/config.go index a4a3fd86..f491e42a 100644 --- a/config/config.go +++ b/config/config.go @@ -2,11 +2,16 @@ package config import ( "github.com/SumoLogic-Labs/sumocli/internal/authentication" + "github.com/SumoLogic-Labs/sumocli/internal/build" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "net/http" "time" ) +var ( + userAgent = "Sumocli " + build.Version +) + func GetSumoLogicSDKConfig() *cip.APIClient { accessId, accessKey, endpoint := authentication.ReadAuthCredentials() client := cip.APIClient{ @@ -24,3 +29,7 @@ func GetSumoLogicSDKConfig() *cip.APIClient { } return &client } + +func GetUserAgent() string { + return userAgent +} diff --git a/internal/authentication/authentication.go b/internal/authentication/authentication.go index 1818e7dc..74165f83 100644 --- a/internal/authentication/authentication.go +++ b/internal/authentication/authentication.go @@ -4,11 +4,19 @@ import ( "encoding/base64" "fmt" "github.com/SumoLogic-Labs/sumocli/internal/encryption" + "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/spf13/viper" "os" "path/filepath" ) +func ConfirmCredentialsSet(client *cip.APIClient) { + if client.Cfg.Authentication.AccessId == "" || client.Cfg.Authentication.AccessKey == "" || client.Cfg.BasePath == "" { + fmt.Println("No authentication credentials set, please run sumocli configure or set environment variables.") + os.Exit(1) + } +} + func ConfigPath() string { var filePath = ".sumocli/credentials/creds.json" homeDirectory, _ := os.UserHomeDir() @@ -22,7 +30,7 @@ func ReadAccessId() string { viper.AutomaticEnv() err := viper.ReadInConfig() if err != nil { - fmt.Println("No authentication credentials, please run sumocli login") + fmt.Println("No authentication credentials, please run sumocli configure") return "" } else { version := viper.GetString("version") diff --git a/internal/authorizers/authorizers.go b/internal/authorizers/authorizers.go deleted file mode 100644 index f42bef2f..00000000 --- a/internal/authorizers/authorizers.go +++ /dev/null @@ -1,76 +0,0 @@ -package authorizers - -import ( - "fmt" - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/adal" - "github.com/Azure/go-autorest/autorest/azure/auth" - "github.com/SumoLogic-Labs/sumocli/internal/config" -) - -type OAuthGrantType int - -var armAuthorizer autorest.Authorizer - -const ( - OAuthGrantTypeServicePrincipal OAuthGrantType = iota - OAuthGrantTypeDeviceFlow -) - -func GetARMAuthorizer() (autorest.Authorizer, error) { - if armAuthorizer != nil { - return armAuthorizer, nil - } - - var a autorest.Authorizer - var err error - - a, err = getAuthorizerForResource(grantType(), config.Environment().ResourceManagerEndpoint) - if err == nil { - armAuthorizer = a - } else { - armAuthorizer = nil - } - return armAuthorizer, err -} - -func getAuthorizerForResource(grantType OAuthGrantType, resource string) (autorest.Authorizer, error) { - var a autorest.Authorizer - var err error - - switch grantType { - case OAuthGrantTypeServicePrincipal: - oauthConfig, err := adal.NewOAuthConfig( - config.Environment().ActiveDirectoryEndpoint, config.GetTenantId()) - if err != nil { - return nil, err - } - - token, err := adal.NewServicePrincipalToken( - *oauthConfig, config.GetClientId(), config.GetClientSecret(), resource) - if err != nil { - return nil, err - } - a = autorest.NewBearerAuthorizer(token) - - case OAuthGrantTypeDeviceFlow: - deviceConfig := auth.NewDeviceFlowConfig(config.GetClientId(), config.GetTenantId()) - deviceConfig.Resource = resource - a, err = deviceConfig.Authorizer() - if err != nil { - return nil, err - } - - default: - return a, fmt.Errorf("invalid grant type specified") - } - - return a, err -} - -func grantType() OAuthGrantType { - if config.GetUseDeviceFlow() { - return OAuthGrantTypeDeviceFlow - } - return OAuthGrantTypeServicePrincipal -} diff --git a/internal/az/az.go b/internal/az/az.go deleted file mode 100644 index f113bed3..00000000 --- a/internal/az/az.go +++ /dev/null @@ -1,94 +0,0 @@ -package az - -import ( - "github.com/Azure/azure-sdk-for-go/services/web/mgmt/2020-06-01/web" - "github.com/Azure/go-autorest/autorest/to" -) - -func ReaderAppSettings(storageAccountName string, storageAccountConnection string, instrumentationKey *string, eventHubKey *string, - serviceBusKey *string) []web.NameValuePair { - readerAppSettings := []web.NameValuePair{ - {Name: to.StringPtr("FUNCTIONS_EXTENSION_VERSION"), Value: to.StringPtr("~1")}, - {Name: to.StringPtr("Project"), Value: to.StringPtr("BlockBlobReader/target/producer_build/")}, - {Name: to.StringPtr("AzureWebJobsDashboard"), Value: to.StringPtr(storageAccountConnection)}, - {Name: to.StringPtr("AzureWebJobsStorage"), Value: to.StringPtr(storageAccountConnection)}, - {Name: to.StringPtr("APPINSIGHTS_INSTRUMENTATIONKEY"), Value: instrumentationKey}, - {Name: to.StringPtr("TABLE_NAME"), Value: to.StringPtr("FileOffsetMap")}, - {Name: to.StringPtr("AzureEventHubConnectionString"), Value: eventHubKey}, - {Name: to.StringPtr("TaskQueueConnectionString"), Value: serviceBusKey}, - {Name: to.StringPtr("WEBSITE_NODE_DEFAULT_VERSION"), Value: to.StringPtr("6.5.0")}, - {Name: to.StringPtr("FUNCTION_APP_EDIT_MODE"), Value: to.StringPtr("readwrite")}, - {Name: to.StringPtr("WEBSITE_CONTENTAZUREFILECONNECTIONSTRING"), Value: to.StringPtr(storageAccountConnection)}, - {Name: to.StringPtr("WEBSITE_CONTENTSHARE"), Value: to.StringPtr(storageAccountName)}, - } - return readerAppSettings -} - -func ConsumerAppSettings(storageAccountName string, storageAccountConnection string, instrumentationKey *string, - serviceBusKey *string, sumoLogicSource string) []web.NameValuePair { - consumerAppSettings := []web.NameValuePair{ - {Name: to.StringPtr("FUNCTIONS_EXTENSION_VERSION"), Value: to.StringPtr("~1")}, - {Name: to.StringPtr("Project"), Value: to.StringPtr("BlockBlobReader/target/consumer_build/")}, - {Name: to.StringPtr("AzureWebJobsDashboard"), Value: to.StringPtr(storageAccountConnection)}, - {Name: to.StringPtr("AzureWebJobsStorage"), Value: to.StringPtr(storageAccountConnection)}, - {Name: to.StringPtr("APPINSIGHTS_INSTRUMENTATIONKEY"), Value: instrumentationKey}, - {Name: to.StringPtr("SumoLogEndpoint"), Value: to.StringPtr(sumoLogicSource)}, - {Name: to.StringPtr("TaskQueueConnectionString"), Value: serviceBusKey}, - {Name: to.StringPtr("WEBSITE_NODE_DEFAULT_VERSION"), Value: to.StringPtr("6.5.0")}, - {Name: to.StringPtr("FUNCTION_APP_EDIT_MODE"), Value: to.StringPtr("readwrite")}, - {Name: to.StringPtr("WEBSITE_CONTENTAZUREFILECONNECTIONSTRING"), Value: to.StringPtr(storageAccountConnection)}, - {Name: to.StringPtr("WEBSITE_CONTENTSHARE"), Value: to.StringPtr(storageAccountName)}, - } - return consumerAppSettings -} - -func DlqAppSettings(storageAccountName string, storageAccountConnection string, instrumentationKey *string, - serviceBusKey *string, queueName string, sumoLogicSource string) []web.NameValuePair { - dlqAppSettings := []web.NameValuePair{ - {Name: to.StringPtr("FUNCTIONS_EXTENSION_VERSION"), Value: to.StringPtr("~1")}, - {Name: to.StringPtr("Project"), Value: to.StringPtr("BlockBlobReader/target/dlqprocessor_build/")}, - {Name: to.StringPtr("AzureWebJobsDashboard"), Value: to.StringPtr(storageAccountConnection)}, - {Name: to.StringPtr("AzureWebJobsStorage"), Value: to.StringPtr(storageAccountConnection)}, - {Name: to.StringPtr("APPINSIGHTS_INSTRUMENTATIONKEY"), Value: instrumentationKey}, - {Name: to.StringPtr("SumoLogEndpoint"), Value: to.StringPtr(sumoLogicSource)}, - {Name: to.StringPtr("TaskQueueConnectionString"), Value: serviceBusKey}, - {Name: to.StringPtr("TASKQUEUE_NAME"), Value: to.StringPtr(queueName)}, - {Name: to.StringPtr("WEBSITE_NODE_DEFAULT_VERSION"), Value: to.StringPtr("6.5.0")}, - {Name: to.StringPtr("FUNCTION_APP_EDIT_MODE"), Value: to.StringPtr("readwrite")}, - {Name: to.StringPtr("WEBSITE_CONTENTAZUREFILECONNECTIONSTRING"), Value: to.StringPtr(storageAccountConnection)}, - {Name: to.StringPtr("WEBSITE_CONTENTSHARE"), Value: to.StringPtr(storageAccountName)}, - } - return dlqAppSettings -} - -func DiagnosticLogsAppSettings(logsStorageAccountName string, logsStorageAccountConnection string, failedStorageAccountConnection string, - eventHubKey *string, sumoLogicSource string) []web.NameValuePair { - diagnosticAppSettings := []web.NameValuePair{ - {Name: to.StringPtr("FUNCTIONS_EXTENSION_VERSION"), Value: to.StringPtr("~1")}, - {Name: to.StringPtr("Project"), Value: to.StringPtr("EventHubs/target/logs_build/")}, - {Name: to.StringPtr("AzureWebJobsDashboard"), Value: to.StringPtr(logsStorageAccountConnection)}, - {Name: to.StringPtr("AzureWebJobsStorage"), Value: to.StringPtr(logsStorageAccountConnection)}, - {Name: to.StringPtr("SumoLogsEndpoint"), Value: to.StringPtr(sumoLogicSource)}, - {Name: to.StringPtr("AzureEventHubConnectionString"), Value: eventHubKey}, - {Name: to.StringPtr("StorageConnectionString"), Value: to.StringPtr(failedStorageAccountConnection)}, - {Name: to.StringPtr("WEBSITE_CONTENTAZUREFILECONNECTIONSTRING"), Value: to.StringPtr(logsStorageAccountConnection)}, - {Name: to.StringPtr("WEBSITE_CONTENTSHARE"), Value: to.StringPtr(logsStorageAccountName)}, - } - return diagnosticAppSettings -} - -func MetricsAppSettings(logsStorageAccountName string, logsStorageAccountConnection string, failedStorageAccountConnection string, - eventHubKey *string, sumoLogicSource string) []web.NameValuePair { - metricsAppSettings := []web.NameValuePair{ - {Name: to.StringPtr("FUNCTIONS_EXTENSION_VERSION"), Value: to.StringPtr("~1")}, - {Name: to.StringPtr("Project"), Value: to.StringPtr("EventHubs/target/metrics_build/")}, - {Name: to.StringPtr("AzureWebJobsDashboard"), Value: to.StringPtr(logsStorageAccountConnection)}, - {Name: to.StringPtr("AzureWebJobsStorage"), Value: to.StringPtr(logsStorageAccountConnection)}, - {Name: to.StringPtr("SumoLabsMetricEndpoint"), Value: to.StringPtr(sumoLogicSource)}, - {Name: to.StringPtr("AzureEventHubConnectionString"), Value: eventHubKey}, - {Name: to.StringPtr("StorageConnectionString"), Value: to.StringPtr(failedStorageAccountConnection)}, - {Name: to.StringPtr("WEBSITE_CONTENTAZUREFILECONNECTIONSTRING"), Value: to.StringPtr(logsStorageAccountConnection)}, - {Name: to.StringPtr("WEBSITE_CONTENTSHARE"), Value: to.StringPtr(logsStorageAccountName)}, - } - return metricsAppSettings -} diff --git a/internal/build/build.go b/internal/build/build.go index 581287f1..1cfcb298 100644 --- a/internal/build/build.go +++ b/internal/build/build.go @@ -1,5 +1,7 @@ package build -var Version = "Dev" - -var Build = "Dev" +var ( + Build = "Dev" + Date = "Dev" + Version = "Dev" +) diff --git a/internal/clients/clients.go b/internal/clients/clients.go deleted file mode 100644 index a6f46737..00000000 --- a/internal/clients/clients.go +++ /dev/null @@ -1,119 +0,0 @@ -package clients - -import ( - "fmt" - "github.com/Azure/azure-sdk-for-go/profiles/latest/resources/mgmt/features" - "github.com/Azure/azure-sdk-for-go/profiles/latest/storage/mgmt/storage" - "github.com/Azure/azure-sdk-for-go/services/appinsights/mgmt/2015-05-01/insights" - "github.com/Azure/azure-sdk-for-go/services/eventgrid/mgmt/2020-06-01/eventgrid" - "github.com/Azure/azure-sdk-for-go/services/eventhub/mgmt/2017-04-01/eventhub" - "github.com/Azure/azure-sdk-for-go/services/servicebus/mgmt/2017-04-01/servicebus" - "github.com/Azure/azure-sdk-for-go/services/web/mgmt/2020-06-01/web" - "github.com/SumoLogic-Labs/sumocli/internal/authorizers" - "github.com/SumoLogic-Labs/sumocli/internal/config" -) - -func GetAppServiceClient() web.AppsClient { - appClient := web.NewAppsClient(config.GetSubscriptionId()) - auth, _ := authorizers.GetARMAuthorizer() - appClient.Authorizer = auth - appClient.AddToUserAgent(config.GetUserAgent()) - return appClient -} - -func GetAppServicePlanClient() web.AppServicePlansClient { - appClient := web.NewAppServicePlansClient(config.GetSubscriptionId()) - auth, _ := authorizers.GetARMAuthorizer() - appClient.Authorizer = auth - appClient.AddToUserAgent(config.GetUserAgent()) - return appClient -} - -func GetConsumerGroupsClient() eventhub.ConsumerGroupsClient { - csClient := eventhub.NewConsumerGroupsClient(config.GetSubscriptionId()) - auth, _ := authorizers.GetARMAuthorizer() - csClient.Authorizer = auth - csClient.AddToUserAgent(config.GetUserAgent()) - return csClient -} - -func GetEventGridSubscriptionClient() eventgrid.EventSubscriptionsClient { - egSubClient := eventgrid.NewEventSubscriptionsClient(config.GetSubscriptionId()) - auth, _ := authorizers.GetARMAuthorizer() - egSubClient.Authorizer = auth - egSubClient.AddToUserAgent(config.GetUserAgent()) - return egSubClient -} - -func GetEventGridTopicClient() eventgrid.TopicsClient { - egClient := eventgrid.NewTopicsClient(config.GetSubscriptionId()) - auth, _ := authorizers.GetARMAuthorizer() - egClient.Authorizer = auth - egClient.AddToUserAgent(config.GetUserAgent()) - return egClient -} - -func GetEventHubClient() eventhub.EventHubsClient { - ehClient := eventhub.NewEventHubsClient(config.GetSubscriptionId()) - auth, _ := authorizers.GetARMAuthorizer() - ehClient.Authorizer = auth - ehClient.AddToUserAgent(config.GetUserAgent()) - return ehClient -} - -func GetEventHubNamespaceClient() eventhub.NamespacesClient { - ehClient := eventhub.NewNamespacesClient(config.GetSubscriptionId()) - auth, _ := authorizers.GetARMAuthorizer() - ehClient.Authorizer = auth - ehClient.AddToUserAgent(config.GetUserAgent()) - return ehClient -} - -func GetInsightsClient() insights.ComponentsClient { - insightsClient := insights.NewComponentsClient(config.GetSubscriptionId()) - auth, _ := authorizers.GetARMAuthorizer() - insightsClient.Authorizer = auth - insightsClient.AddToUserAgent(config.GetUserAgent()) - return insightsClient -} - -func GetNamespaceClient() servicebus.NamespacesClient { - nsClient := servicebus.NewNamespacesClient(config.GetSubscriptionId()) - auth, _ := authorizers.GetARMAuthorizer() - nsClient.Authorizer = auth - nsClient.AddToUserAgent(config.GetUserAgent()) - return nsClient -} - -func GetQueueClient() servicebus.QueuesClient { - queueClient := servicebus.NewQueuesClient(config.GetSubscriptionId()) - auth, _ := authorizers.GetARMAuthorizer() - queueClient.Authorizer = auth - queueClient.AddToUserAgent(config.GetUserAgent()) - return queueClient -} - -func GetResourceGroupClient() features.ResourceGroupsClient { - rgClient := features.NewResourceGroupsClient(config.GetSubscriptionId()) - auth, _ := authorizers.GetARMAuthorizer() - fmt.Println(auth) - rgClient.Authorizer = auth - rgClient.AddToUserAgent(config.GetUserAgent()) - return rgClient -} - -func GetStorageClient() storage.AccountsClient { - sgClient := storage.NewAccountsClient(config.GetSubscriptionId()) - auth, _ := authorizers.GetARMAuthorizer() - sgClient.Authorizer = auth - sgClient.AddToUserAgent(config.GetUserAgent()) - return sgClient -} - -func GetStorageTableClient() storage.TableClient { - sgTableClient := storage.NewTableClient(config.GetSubscriptionId()) - auth, _ := authorizers.GetARMAuthorizer() - sgTableClient.Authorizer = auth - sgTableClient.AddToUserAgent(config.GetUserAgent()) - return sgTableClient -} diff --git a/internal/config/config.go b/internal/config/config.go deleted file mode 100644 index a0883bd3..00000000 --- a/internal/config/config.go +++ /dev/null @@ -1,89 +0,0 @@ -package config - -import ( - "github.com/Azure/go-autorest/autorest/azure" - "github.com/Azure/go-autorest/autorest/to" - "github.com/SumoLogic-Labs/sumocli/internal/build" - "github.com/SumoLogic-Labs/sumocli/pkg/logging" - "github.com/spf13/cobra" -) - -var ( - clientId string - clientSecret string - tenantId string - subscriptionId string - defaultLocation string - cloudName = "AzurePublicCloud" - useDeviceFlow bool - userAgent = "Sumocli " + build.Version - environment *azure.Environment -) - -func AddAzureFlags(cmd *cobra.Command) { - cmd.PersistentFlags().StringVar(&clientId, "clientId", "", "Specify the client ID of the Azure AD Application") - cmd.PersistentFlags().StringVar(&clientSecret, "clientSecret", "", "Specify the client secret of the Azure AD Application") - cmd.PersistentFlags().StringVar(&tenantId, "tenantId", "", "Specify the tenant ID of the Azure AD tenant") - cmd.PersistentFlags().StringVar(&subscriptionId, "subscriptionId", "", "Specify the subscription ID of the Azure subscription you want to deploy to") - cmd.PersistentFlags().StringVar(&defaultLocation, "location", "", "Specify the Azure location to deploy resources to") - cmd.PersistentFlags().BoolVar(&useDeviceFlow, "useDeviceFlow", false, "Uses device flow authentication, requires clientId and tenantId") -} - -func GetClientId() string { - return clientId -} - -func GetClientSecret() string { - return clientSecret -} - -func GetTenantId() string { - return tenantId -} - -func GetSubscriptionId() string { - return subscriptionId -} - -func GetDefaultLocation() string { - return defaultLocation -} - -func GetUseDeviceFlow() bool { - return useDeviceFlow -} - -func GetUserAgent() string { - return userAgent -} - -func Environment() *azure.Environment { - log := logging.GetConsoleLogger() - if environment != nil { - return environment - } - env, err := azure.EnvironmentFromName(cloudName) - if err != nil { - log.Error().Err(err).Msg("unable to retrieve Azure environment name") - } - environment = &env - return environment -} - -func GetAzureLogTags() map[string]*string { - logTags := map[string]*string{ - "CollectionType": to.StringPtr("Logs"), - "CreatedBy": to.StringPtr("Sumocli"), - "Version": to.StringPtr(build.Version), - } - return logTags -} - -func AzureMetricTags() map[string]*string { - metricTags := map[string]*string{ - "CollectionType": to.StringPtr("Metrics"), - "CreatedBy": to.StringPtr("Sumocli"), - "Version": to.StringPtr(build.Version), - } - return metricTags -} diff --git a/pkg/cmd/account/create-subdomain/create-subdomain.go b/pkg/cmd/account/create-subdomain/create-subdomain.go index f283bd09..dbbe33b4 100644 --- a/pkg/cmd/account/create-subdomain/create-subdomain.go +++ b/pkg/cmd/account/create-subdomain/create-subdomain.go @@ -1,6 +1,7 @@ package create_subdomain import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -13,6 +14,7 @@ func NewCmdAccountCreateSubdomain(client *cip.APIClient) *cobra.Command { Use: "create-subdomain", Short: "Create a subdomain. Only the Account Owner can create a subdomain.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) createSubdomain(subdomain, client) }, } diff --git a/pkg/cmd/account/delete-subdomain/delete-subdomain.go b/pkg/cmd/account/delete-subdomain/delete-subdomain.go index 78c48cbf..629742f2 100644 --- a/pkg/cmd/account/delete-subdomain/delete-subdomain.go +++ b/pkg/cmd/account/delete-subdomain/delete-subdomain.go @@ -1,6 +1,7 @@ package delete_subdomain import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/spf13/cobra" @@ -11,6 +12,7 @@ func NewCmdAccountDeleteSubdomain(client *cip.APIClient) *cobra.Command { Use: "delete-subdomain", Short: "Delete the configured subdomain.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) deleteSubdomain(client) }, } diff --git a/pkg/cmd/account/get-owner/get-owner.go b/pkg/cmd/account/get-owner/get-owner.go index 26d4b685..07ade7c4 100644 --- a/pkg/cmd/account/get-owner/get-owner.go +++ b/pkg/cmd/account/get-owner/get-owner.go @@ -1,6 +1,7 @@ package get_owner import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/spf13/cobra" @@ -11,6 +12,7 @@ func NewCmdAccountGetOwner(client *cip.APIClient) *cobra.Command { Use: "get-owner", Short: "Returns the user identifier as the account owner.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) getOwner(client) }, } diff --git a/pkg/cmd/account/get-subdomain/get-subdomain.go b/pkg/cmd/account/get-subdomain/get-subdomain.go index b964e1cd..84472e4e 100644 --- a/pkg/cmd/account/get-subdomain/get-subdomain.go +++ b/pkg/cmd/account/get-subdomain/get-subdomain.go @@ -1,6 +1,7 @@ package get_subdomain import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/spf13/cobra" @@ -11,6 +12,7 @@ func NewCmdAccountGetSubdomain(client *cip.APIClient) *cobra.Command { Use: "get-subdomain", Short: "Get the configured subdomain.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) getSubdomain(client) }, } diff --git a/pkg/cmd/account/recover-subdomain/recover-subdomain.go b/pkg/cmd/account/recover-subdomain/recover-subdomain.go index 78b5ce70..6abd01ac 100644 --- a/pkg/cmd/account/recover-subdomain/recover-subdomain.go +++ b/pkg/cmd/account/recover-subdomain/recover-subdomain.go @@ -1,6 +1,7 @@ package recover_subdomain import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/spf13/cobra" @@ -12,6 +13,7 @@ func NewCmdAccountRecoverSubdomain(client *cip.APIClient) *cobra.Command { Use: "recover-subdomain", Short: "Send an email with the subdomain information for a user with the given email address.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) recoverSubdomain(email, client) }, } diff --git a/pkg/cmd/account/update-subdomain/update-subdomain.go b/pkg/cmd/account/update-subdomain/update-subdomain.go index d53dade0..c54d0567 100644 --- a/pkg/cmd/account/update-subdomain/update-subdomain.go +++ b/pkg/cmd/account/update-subdomain/update-subdomain.go @@ -1,6 +1,7 @@ package update_subdomain import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -13,6 +14,7 @@ func NewCmdAccountUpdateSubdomain(client *cip.APIClient) *cobra.Command { Use: "update-subdomain", Short: "Update a subdomain. Only the Account Owner can update the subdomain.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) updateSubdomain(subdomain, client) }, } diff --git a/pkg/cmd/apps/get/get.go b/pkg/cmd/apps/get/get.go index a21916eb..2d51e0e4 100644 --- a/pkg/cmd/apps/get/get.go +++ b/pkg/cmd/apps/get/get.go @@ -1,6 +1,7 @@ package get import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/spf13/cobra" @@ -12,6 +13,7 @@ func NewCmdAppsGet(client *cip.APIClient) *cobra.Command { Use: "get", Short: "Gets the app with the given universally unique identifier (UUID).", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) getApp(uuid, client) }, } diff --git a/pkg/cmd/apps/install/install.go b/pkg/cmd/apps/install/install.go index 94766267..5845b4ac 100644 --- a/pkg/cmd/apps/install/install.go +++ b/pkg/cmd/apps/install/install.go @@ -1,6 +1,7 @@ package install import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -19,6 +20,7 @@ func NewCmdAppsInstall(client *cip.APIClient) *cobra.Command { Use: "install", Short: "Installs the app with given UUID in the folder specified.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) installApp(destinationFolderId, description, logSource, name, uuid, client) }, } diff --git a/pkg/cmd/apps/install_status/install_status.go b/pkg/cmd/apps/install_status/install_status.go index e62ecaa2..53a04e82 100644 --- a/pkg/cmd/apps/install_status/install_status.go +++ b/pkg/cmd/apps/install_status/install_status.go @@ -1,6 +1,7 @@ package install_status import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/spf13/cobra" @@ -12,6 +13,7 @@ func NewCmdAppsInstallStatus(client *cip.APIClient) *cobra.Command { Use: "install-status", Short: "Get the status of an asynchronous app install request for the given job identifier.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) getAppInstallStatus(jobId, client) }, } diff --git a/pkg/cmd/apps/list/list.go b/pkg/cmd/apps/list/list.go index b941c4db..d625ffd9 100644 --- a/pkg/cmd/apps/list/list.go +++ b/pkg/cmd/apps/list/list.go @@ -1,6 +1,7 @@ package list import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/spf13/cobra" @@ -11,6 +12,7 @@ func NewCmdAppsList(client *cip.APIClient) *cobra.Command { Use: "list", Short: "Lists all available apps from the App Catalog.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) listAvailableApps(client) }, } diff --git a/pkg/cmd/collectors/create/create.go b/pkg/cmd/collectors/create/create.go index b9926fff..7bbd341f 100644 --- a/pkg/cmd/collectors/create/create.go +++ b/pkg/cmd/collectors/create/create.go @@ -1,6 +1,7 @@ package create import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -19,6 +20,7 @@ func NewCmdCollectorCreate(client *cip.APIClient) *cobra.Command { Use: "create", Short: "Creates a Sumo Logic Hosted Collector", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) Collector(name, description, category, fieldNames, fieldValues, client) }, } diff --git a/pkg/cmd/collectors/delete/delete.go b/pkg/cmd/collectors/delete/delete.go index d59d2c5a..2733d38d 100644 --- a/pkg/cmd/collectors/delete/delete.go +++ b/pkg/cmd/collectors/delete/delete.go @@ -1,6 +1,7 @@ package delete import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -18,6 +19,7 @@ func NewCmdCollectorDelete(client *cip.APIClient) *cobra.Command { Use: "delete", Short: "Deletes a Sumo Logic collector", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) deleteCollector(aliveBeforeDays, id, offline, client) }, } diff --git a/pkg/cmd/collectors/get/get.go b/pkg/cmd/collectors/get/get.go index a1dc9c6c..5099f8ce 100644 --- a/pkg/cmd/collectors/get/get.go +++ b/pkg/cmd/collectors/get/get.go @@ -2,6 +2,7 @@ package get import ( "fmt" + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/spf13/cobra" @@ -17,6 +18,7 @@ func NewCmdCollectorGet(client *cip.APIClient) *cobra.Command { Short: "Gets a Sumo Logic collector information", Long: "You can use either the id or the name of the collector to specify the collector to return", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) getCollector(id, name, client) }, } diff --git a/pkg/cmd/collectors/list/list.go b/pkg/cmd/collectors/list/list.go index 90fb115d..4bd488aa 100644 --- a/pkg/cmd/collectors/list/list.go +++ b/pkg/cmd/collectors/list/list.go @@ -1,6 +1,7 @@ package list import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -20,6 +21,7 @@ func NewCmdCollectorList(client *cip.APIClient) *cobra.Command { Use: "list", Short: "Lists Sumo Logic collectors", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) listCollectors(aliveBeforeDays, filter, limit, offset, offline, client) }, } diff --git a/pkg/cmd/collectors/update/update.go b/pkg/cmd/collectors/update/update.go index eec64032..7e4c83a4 100644 --- a/pkg/cmd/collectors/update/update.go +++ b/pkg/cmd/collectors/update/update.go @@ -1,6 +1,7 @@ package update import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -27,6 +28,7 @@ func NewCmdCollectorUpdate(client *cip.APIClient) *cobra.Command { Use: "update", Short: "updates a Sumo Logic collector settings", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) updateCollector(category, id, cutoffTimestamp, description, ephemeral, fieldNames, fieldValues, hostName, installedCollector, name, sourceSyncMode, timeZone, targetCPU, client) }, diff --git a/pkg/cmd/collectors/upgrade/get_upgradable_collectors/get_upgradable_collectors.go b/pkg/cmd/collectors/upgrade/get_upgradable_collectors/get_upgradable_collectors.go index 7e71c8c0..c05da2b0 100644 --- a/pkg/cmd/collectors/upgrade/get_upgradable_collectors/get_upgradable_collectors.go +++ b/pkg/cmd/collectors/upgrade/get_upgradable_collectors/get_upgradable_collectors.go @@ -1,6 +1,7 @@ package get_upgradable_collectors import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -18,6 +19,7 @@ func NewCmdGetUpgradableCollectors(client *cip.APIClient) *cobra.Command { Use: "get-upgradable-collectors", Short: "Gets collectors in Sumo Logic that are upgradable", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) getUpgradableCollectors(toVersion, offset, limit, client) }, } diff --git a/pkg/cmd/collectors/upgrade/start/start.go b/pkg/cmd/collectors/upgrade/start/start.go index a8e30f6b..3bd4c1ea 100644 --- a/pkg/cmd/collectors/upgrade/start/start.go +++ b/pkg/cmd/collectors/upgrade/start/start.go @@ -2,6 +2,7 @@ package start import ( "fmt" + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -18,6 +19,7 @@ func NewCmdUpgradeStart(client *cip.APIClient) *cobra.Command { Use: "start", Short: "Starts an upgrade or downgrade of an existing installed collector", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) upgradeStart(id, toVersion, client) }, } diff --git a/pkg/cmd/collectors/upgrade/status/status.go b/pkg/cmd/collectors/upgrade/status/status.go index 534e246d..de78ed08 100644 --- a/pkg/cmd/collectors/upgrade/status/status.go +++ b/pkg/cmd/collectors/upgrade/status/status.go @@ -1,6 +1,7 @@ package status import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/spf13/cobra" @@ -18,6 +19,7 @@ The status of the upgrade can be one of the following 3 - failed 6 - progressing, the upgrade is running on the Collector`, Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) upgradableCollectorStatus(upgradeTaskId, client) }, } diff --git a/pkg/cmd/content/get/get.go b/pkg/cmd/content/get/get.go index 5568babc..baa18546 100644 --- a/pkg/cmd/content/get/get.go +++ b/pkg/cmd/content/get/get.go @@ -2,6 +2,7 @@ package get import ( "fmt" + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/spf13/cobra" @@ -16,6 +17,7 @@ func NewCmdGet(client *cip.APIClient) *cobra.Command { Use: "get", Short: "Gets a content item corresponding to the provided path or via the identifier of the content.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) getContent(contentId, path, client) }, } diff --git a/pkg/cmd/content/get_copy_status/get_copy_status.go b/pkg/cmd/content/get_copy_status/get_copy_status.go index 5eeb669f..263e3b29 100644 --- a/pkg/cmd/content/get_copy_status/get_copy_status.go +++ b/pkg/cmd/content/get_copy_status/get_copy_status.go @@ -1,6 +1,7 @@ package get_copy_status import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -18,6 +19,7 @@ func NewCmdGetCopyStatus(client *cip.APIClient) *cobra.Command { Use: "get-copy-status", Short: "Get the status of the copy request with the given job identifier. On success, field statusMessage will contain identifier of the newly copied content.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) copyStatus(id, jobId, isAdminMode, client) }, } diff --git a/pkg/cmd/content/get_deletion_status/get_deletion_status.go b/pkg/cmd/content/get_deletion_status/get_deletion_status.go index 95cbbdd6..88d576d3 100644 --- a/pkg/cmd/content/get_deletion_status/get_deletion_status.go +++ b/pkg/cmd/content/get_deletion_status/get_deletion_status.go @@ -1,6 +1,7 @@ package get_deletion_status import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -18,6 +19,7 @@ func NewCmdGetDeletionStatus(client *cip.APIClient) *cobra.Command { Use: "get-deletion-status", Short: "Get the status of an asynchronous content deletion job request for the given job identifier.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) deletionStatus(id, jobId, isAdminMode, client) }, } diff --git a/pkg/cmd/content/get_export_result/get_export_result.go b/pkg/cmd/content/get_export_result/get_export_result.go index 4c378594..5009e828 100644 --- a/pkg/cmd/content/get_export_result/get_export_result.go +++ b/pkg/cmd/content/get_export_result/get_export_result.go @@ -3,6 +3,7 @@ package get_export_result import ( "encoding/json" "fmt" + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -27,6 +28,7 @@ func NewCmdGetExportResult(client *cip.APIClient) *cobra.Command { Use: "get-export-result", Short: "Gets results from content export job for the given job identifier", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) exportResult(contentId, jobId, isAdminMode, saveToFile, filePath, fileName, client) }, } diff --git a/pkg/cmd/content/get_export_status/get_export_status.go b/pkg/cmd/content/get_export_status/get_export_status.go index 9d493bac..c02a1917 100644 --- a/pkg/cmd/content/get_export_status/get_export_status.go +++ b/pkg/cmd/content/get_export_status/get_export_status.go @@ -1,6 +1,7 @@ package get_export_status import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -18,6 +19,7 @@ func NewCmdExportStatus(client *cip.APIClient) *cobra.Command { Use: "get-export-status", Short: "Get the status of an asynchronous content export request for the given job identifier", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) exportStatus(contentId, jobId, isAdminMode, client) }, } diff --git a/pkg/cmd/content/get_import_status/get_import_status.go b/pkg/cmd/content/get_import_status/get_import_status.go index 2fa70eb1..9e478c8f 100644 --- a/pkg/cmd/content/get_import_status/get_import_status.go +++ b/pkg/cmd/content/get_import_status/get_import_status.go @@ -1,6 +1,7 @@ package get_import_status import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -18,6 +19,7 @@ func NewCmdGetImportStatus(client *cip.APIClient) *cobra.Command { Use: "import-status", Short: "Get the status of an asynchronous content import request for the given job identifier", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) importStatus(folderId, jobId, isAdminMode, client) }, } diff --git a/pkg/cmd/content/move/move.go b/pkg/cmd/content/move/move.go index 347c887b..c82eb9ac 100644 --- a/pkg/cmd/content/move/move.go +++ b/pkg/cmd/content/move/move.go @@ -1,6 +1,7 @@ package move import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -18,6 +19,7 @@ func NewCmdMove(client *cip.APIClient) *cobra.Command { Use: "move", Short: "Moves an item from its current location to another folder.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) move(id, destinationFolderId, isAdminMode, client) }, } diff --git a/pkg/cmd/content/start_copy/start_copy.go b/pkg/cmd/content/start_copy/start_copy.go index 9a7badca..0e7291ef 100644 --- a/pkg/cmd/content/start_copy/start_copy.go +++ b/pkg/cmd/content/start_copy/start_copy.go @@ -1,6 +1,7 @@ package start_copy import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -18,6 +19,7 @@ func NewCmdStartCopy(client *cip.APIClient) *cobra.Command { Use: "start-copy", Short: "Start an asynchronous content copy job with the given identifier to the destination folder. If the content item is a folder, everything under the folder is copied recursively.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) startCopy(id, destinationFolder, isAdminMode, client) }, } diff --git a/pkg/cmd/content/start_deletion/start_deletion.go b/pkg/cmd/content/start_deletion/start_deletion.go index 2a0c8f69..ee0bceb1 100644 --- a/pkg/cmd/content/start_deletion/start_deletion.go +++ b/pkg/cmd/content/start_deletion/start_deletion.go @@ -1,6 +1,7 @@ package start_deletion import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -17,6 +18,7 @@ func NewCmdStartDeletion(client *cip.APIClient) *cobra.Command { Use: "start-deletion", Short: "Start an asynchronous content deletion job with the given identifier.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) startDeletion(id, isAdminMode, client) }, } diff --git a/pkg/cmd/content/start_export/start_export.go b/pkg/cmd/content/start_export/start_export.go index 633df1f4..e58169c6 100644 --- a/pkg/cmd/content/start_export/start_export.go +++ b/pkg/cmd/content/start_export/start_export.go @@ -1,6 +1,7 @@ package start_export import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -19,6 +20,7 @@ func NewCmdStartExport(client *cip.APIClient) *cobra.Command { "which can be used with the sumocli content export-status command." + "If the content is a folder everything under that folder is exported recursively.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) startExport(id, isAdminMode, client) }, } diff --git a/pkg/cmd/content/start_import/start_import.go b/pkg/cmd/content/start_import/start_import.go index ac017891..89f5f93c 100644 --- a/pkg/cmd/content/start_import/start_import.go +++ b/pkg/cmd/content/start_import/start_import.go @@ -2,6 +2,7 @@ package start_import import ( "encoding/json" + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -22,6 +23,7 @@ func NewCmdStartImport(client *cip.APIClient) *cobra.Command { Use: "start-import", Short: "Schedule an asynchronous import of content inside an existing folder with the given identifier. The start-import command can be used to create or update content within a folder.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) startImport(file, folderId, isAdminMode, overwrite, client) }, } diff --git a/pkg/cmd/dashboards/create/create.go b/pkg/cmd/dashboards/create/create.go index 9a004368..0c39d43f 100644 --- a/pkg/cmd/dashboards/create/create.go +++ b/pkg/cmd/dashboards/create/create.go @@ -2,6 +2,7 @@ package create import ( "encoding/json" + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -19,6 +20,7 @@ func NewCmdDashboardsCreate(client *cip.APIClient) *cobra.Command { Long: "Note: When exporting a dashboard spec from the Sumo Logic portal ensure that you have the timeRange.to object set as well as the " + "timeRange.from set otherwise you will get errors when trying to create.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) createDashboard(file, client) }, } diff --git a/pkg/cmd/dashboards/delete/delete.go b/pkg/cmd/dashboards/delete/delete.go index 630f27f4..74d340fb 100644 --- a/pkg/cmd/dashboards/delete/delete.go +++ b/pkg/cmd/dashboards/delete/delete.go @@ -1,6 +1,7 @@ package delete import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/spf13/cobra" @@ -12,6 +13,7 @@ func NewCmdDashboardsDelete(client *cip.APIClient) *cobra.Command { Use: "delete", Short: "Delete a dashboard by the given identifier.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) deleteDashboards(id, client) }, } diff --git a/pkg/cmd/factory/http.go b/pkg/cmd/factory/http.go index 1a4b4ebf..337abcb4 100644 --- a/pkg/cmd/factory/http.go +++ b/pkg/cmd/factory/http.go @@ -5,8 +5,8 @@ import ( "encoding/json" "fmt" "github.com/SumoLogic-Labs/sumocli/api" + "github.com/SumoLogic-Labs/sumocli/config" "github.com/SumoLogic-Labs/sumocli/internal/authentication" - "github.com/SumoLogic-Labs/sumocli/internal/config" "github.com/SumoLogic-Labs/sumocli/pkg/logging" "github.com/rs/zerolog" "net/http" diff --git a/pkg/cmd/folders/create/create.go b/pkg/cmd/folders/create/create.go index 644f91e2..1b9d0495 100644 --- a/pkg/cmd/folders/create/create.go +++ b/pkg/cmd/folders/create/create.go @@ -1,6 +1,7 @@ package create import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -19,6 +20,7 @@ func NewCmdCreate(client *cip.APIClient) *cobra.Command { Use: "create", Short: "Creates a new folder under the given parent folder.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) create(name, description, parentId, isAdminMode, client) }, } diff --git a/pkg/cmd/folders/get/get.go b/pkg/cmd/folders/get/get.go index 46a7a873..fd7fd030 100644 --- a/pkg/cmd/folders/get/get.go +++ b/pkg/cmd/folders/get/get.go @@ -1,6 +1,7 @@ package get import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -17,6 +18,7 @@ func NewCmdGet(client *cip.APIClient) *cobra.Command { Use: "get", Short: "Get a folder with the given identifier.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) get(id, isAdminMode, client) }, } diff --git a/pkg/cmd/folders/get_admin_recommended_folder/get_admin_recommended_folder.go b/pkg/cmd/folders/get_admin_recommended_folder/get_admin_recommended_folder.go index 96bb7df6..cda5051f 100644 --- a/pkg/cmd/folders/get_admin_recommended_folder/get_admin_recommended_folder.go +++ b/pkg/cmd/folders/get_admin_recommended_folder/get_admin_recommended_folder.go @@ -1,6 +1,7 @@ package get_admin_recommended_folder import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -15,6 +16,7 @@ func NewCmdGetAdminRecommendedFolder(client *cip.APIClient) *cobra.Command { Use: "get-admin-recommended-folder", Short: "Schedule an asynchronous job to get the top-level Admin Recommended content items.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) getAdminRecommendedFolder(isAdminMode, client) }, } diff --git a/pkg/cmd/folders/get_admin_recommended_folder_result/get_admin_recommended_folder_result.go b/pkg/cmd/folders/get_admin_recommended_folder_result/get_admin_recommended_folder_result.go index a8d326fc..048b387e 100644 --- a/pkg/cmd/folders/get_admin_recommended_folder_result/get_admin_recommended_folder_result.go +++ b/pkg/cmd/folders/get_admin_recommended_folder_result/get_admin_recommended_folder_result.go @@ -1,6 +1,7 @@ package get_admin_recommended_folder_result import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/spf13/cobra" @@ -13,6 +14,7 @@ func NewCmdGetAdminRecommendedFolderResult(client *cip.APIClient) *cobra.Command Use: "get-admin-recommended-folder-result", Short: "Get results from Admin Recommended job for the given job identifier.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) getAdminRecommendedFolderResult(jobId, client) }, } diff --git a/pkg/cmd/folders/get_admin_recommended_folder_status/get_admin_recommended_folder_status.go b/pkg/cmd/folders/get_admin_recommended_folder_status/get_admin_recommended_folder_status.go index 2fdf9c10..9cc46991 100644 --- a/pkg/cmd/folders/get_admin_recommended_folder_status/get_admin_recommended_folder_status.go +++ b/pkg/cmd/folders/get_admin_recommended_folder_status/get_admin_recommended_folder_status.go @@ -1,6 +1,7 @@ package get_admin_recommended_folder_status import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/spf13/cobra" @@ -13,6 +14,7 @@ func NewCmdGetAdminRecommendedFolderStatus(client *cip.APIClient) *cobra.Command Use: "get-admin-recommended-folder-status", Short: "Get the status of an asynchronous Admin Recommended folder job for the given job identifier.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) getAdminRecommendedFolderStatus(jobId, client) }, } diff --git a/pkg/cmd/folders/get_global_folder/get_global_folder.go b/pkg/cmd/folders/get_global_folder/get_global_folder.go index 87032e38..4e05c8f0 100644 --- a/pkg/cmd/folders/get_global_folder/get_global_folder.go +++ b/pkg/cmd/folders/get_global_folder/get_global_folder.go @@ -1,6 +1,7 @@ package get_global_folder import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -16,6 +17,7 @@ func NewCmdGetGlobalFolder(client *cip.APIClient) *cobra.Command { Short: "Schedule an asynchronous job to get global folder. " + "Global folder contains all content items that a user has permissions to view in the organization.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) getGlobalFolder(isAdminMode, client) }, } diff --git a/pkg/cmd/folders/get_global_folder_result/get_global_folder_result.go b/pkg/cmd/folders/get_global_folder_result/get_global_folder_result.go index bf79de39..6884ae67 100644 --- a/pkg/cmd/folders/get_global_folder_result/get_global_folder_result.go +++ b/pkg/cmd/folders/get_global_folder_result/get_global_folder_result.go @@ -1,6 +1,7 @@ package get_global_folder_result import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/spf13/cobra" @@ -13,6 +14,7 @@ func NewCmdGetGlobalFolderResult(client *cip.APIClient) *cobra.Command { Use: "get-global-folder-result", Short: "Get results from global folder job for the given job identifier.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) getGlobalFolderResult(jobId, client) }, } diff --git a/pkg/cmd/folders/get_global_folder_status/get_global_folder_status.go b/pkg/cmd/folders/get_global_folder_status/get_global_folder_status.go index d2f44547..65c87ddb 100644 --- a/pkg/cmd/folders/get_global_folder_status/get_global_folder_status.go +++ b/pkg/cmd/folders/get_global_folder_status/get_global_folder_status.go @@ -1,6 +1,7 @@ package get_global_folder_status import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/spf13/cobra" @@ -13,6 +14,7 @@ func NewCmdGetGlobalFolderStatus(client *cip.APIClient) *cobra.Command { Use: "get-global-folder-status", Short: "Get the status of an asynchronous global folder job for the given job identifier.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) getGlobalFolderStatus(jobId, client) }, } diff --git a/pkg/cmd/folders/get_personal_folder/get_personal_folder.go b/pkg/cmd/folders/get_personal_folder/get_personal_folder.go index d34c71be..38bbc286 100644 --- a/pkg/cmd/folders/get_personal_folder/get_personal_folder.go +++ b/pkg/cmd/folders/get_personal_folder/get_personal_folder.go @@ -1,6 +1,7 @@ package get_personal_folder import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/spf13/cobra" @@ -11,6 +12,7 @@ func NewCmdGetPersonalFolder(client *cip.APIClient) *cobra.Command { Use: "get-personal-folder", Short: "Get the personal folder of the current user.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) getPersonalFolder(client) }, } diff --git a/pkg/cmd/folders/update/update.go b/pkg/cmd/folders/update/update.go index 131503ab..4ffb7f6e 100644 --- a/pkg/cmd/folders/update/update.go +++ b/pkg/cmd/folders/update/update.go @@ -1,6 +1,7 @@ package update import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -19,6 +20,7 @@ func NewCmdUpdate(client *cip.APIClient) *cobra.Command { Use: "update", Short: "Update an existing folder with the given identifier.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) update(name, description, id, isAdminMode, client) }, } diff --git a/pkg/cmd/policies/get_audit_policy/get_audit_policy.go b/pkg/cmd/policies/get_audit_policy/get_audit_policy.go index 127900e7..4b2e5a24 100644 --- a/pkg/cmd/policies/get_audit_policy/get_audit_policy.go +++ b/pkg/cmd/policies/get_audit_policy/get_audit_policy.go @@ -1,6 +1,7 @@ package get_audit_policy import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/spf13/cobra" @@ -12,6 +13,7 @@ func NewCmdGetAuditPolicy(client *cip.APIClient) *cobra.Command { Short: "Get the Audit policy.", Long: "Get the Audit policy. This policy specifies whether audit records for your account are enabled. You can access details about reported account events in the Sumo Logic Audit Index.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) getAuditPolicy(client) }, } diff --git a/pkg/cmd/policies/get_data_access_level_policy/get_data_access_level_policy.go b/pkg/cmd/policies/get_data_access_level_policy/get_data_access_level_policy.go index 24a6aca3..4113cf7d 100644 --- a/pkg/cmd/policies/get_data_access_level_policy/get_data_access_level_policy.go +++ b/pkg/cmd/policies/get_data_access_level_policy/get_data_access_level_policy.go @@ -1,6 +1,7 @@ package get_data_access_level_policy import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/spf13/cobra" @@ -13,6 +14,7 @@ func NewCmdGetDataAccessLevelPolicy(client *cip.APIClient) *cobra.Command { Long: "Get the Data Access Level policy. When enabled, this policy sets the default data access level for all newly created dashboards to the viewer’s role access filter. " + "Otherwise, newly created dashboards will default to the sharer’s role access filter and might display data that viewers’ roles don’t allow them to view.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) getDataAccessLevelPolicy(client) }, } diff --git a/pkg/cmd/policies/get_max_user_session_timeout_policy/get_max_user_session_timeout_policy.go b/pkg/cmd/policies/get_max_user_session_timeout_policy/get_max_user_session_timeout_policy.go index b4f0c7d9..ccd67a4f 100644 --- a/pkg/cmd/policies/get_max_user_session_timeout_policy/get_max_user_session_timeout_policy.go +++ b/pkg/cmd/policies/get_max_user_session_timeout_policy/get_max_user_session_timeout_policy.go @@ -1,6 +1,7 @@ package get_max_user_session_timeout_policy import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/spf13/cobra" @@ -13,6 +14,7 @@ func NewCmdGetMaxUserSessionTimeoutPolicy(client *cip.APIClient) *cobra.Command Long: "Get the Max User Session Timeout policy. When enabled, this policy sets the maximum web session timeout users are able to configure within their user preferences. " + "Users preferences will be updated to match this value only if their current preference is set to a higher value.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) getMaxUserSessionTimeoutPolicy(client) }, } diff --git a/pkg/cmd/policies/get_search_audit_policy/get_search_audit_policy.go b/pkg/cmd/policies/get_search_audit_policy/get_search_audit_policy.go index 9f096c57..18f7e222 100644 --- a/pkg/cmd/policies/get_search_audit_policy/get_search_audit_policy.go +++ b/pkg/cmd/policies/get_search_audit_policy/get_search_audit_policy.go @@ -1,6 +1,7 @@ package get_search_audit_policy import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/spf13/cobra" @@ -13,6 +14,7 @@ func NewCmdGetSearchAuditPolicy(client *cip.APIClient) *cobra.Command { Long: "Get the Search Audit policy. This policy specifies whether search records for your account are enabled. " + "You can access details about your account's search capacity, queries run by users from the Sumo Search Audit Index.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) getSearchAuditPolicy(client) }, } diff --git a/pkg/cmd/policies/get_share_dashboards_outside_organization_policy/get_share_dashboards_outside_organization_policy.go b/pkg/cmd/policies/get_share_dashboards_outside_organization_policy/get_share_dashboards_outside_organization_policy.go index 3d28e558..abfcca5c 100644 --- a/pkg/cmd/policies/get_share_dashboards_outside_organization_policy/get_share_dashboards_outside_organization_policy.go +++ b/pkg/cmd/policies/get_share_dashboards_outside_organization_policy/get_share_dashboards_outside_organization_policy.go @@ -1,6 +1,7 @@ package get_share_dashboards_outside_organization_policy import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/spf13/cobra" @@ -13,6 +14,7 @@ func NewCmdGetShareDashboardsOutsideOrganizationPolicy(client *cip.APIClient) *c Long: "Get the Share Dashboards Outside Organization policy. This policy allows users to share the dashboard with view only privileges outside of the organization (capability must be enabled from the Roles page). " + "Disabling this policy will disable all dashboards that have been shared outside of the organization.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) getShareDashboardsOutsideOrganizationPolicy(client) }, } diff --git a/pkg/cmd/policies/get_user_concurrent_sessions_limit_policy/get_user_concurrent_sessions_limit_policy.go b/pkg/cmd/policies/get_user_concurrent_sessions_limit_policy/get_user_concurrent_sessions_limit_policy.go index bf496107..b3c6ebe7 100644 --- a/pkg/cmd/policies/get_user_concurrent_sessions_limit_policy/get_user_concurrent_sessions_limit_policy.go +++ b/pkg/cmd/policies/get_user_concurrent_sessions_limit_policy/get_user_concurrent_sessions_limit_policy.go @@ -1,6 +1,7 @@ package get_user_concurrent_sessions_limit_policy import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/spf13/cobra" @@ -13,6 +14,7 @@ func NewCmdGetUserConcurrentSessionsLimitPolicy(client *cip.APIClient) *cobra.Co Long: "Get the User Concurrent Sessions Limit policy. When enabled, the number of concurrent sessions a user may have is limited to the value entered. " + "If a user exceeds the allowed number of sessions, the user's oldest session will be logged out to accommodate the new one. Disabling this policy means a user may have an unlimited number of concurrent sessions.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) getUserConcurrentSessionsLimitPolicy(client) }, } diff --git a/pkg/cmd/policies/set_audit_policy/set_audit_policy.go b/pkg/cmd/policies/set_audit_policy/set_audit_policy.go index b797b911..fbbabb03 100644 --- a/pkg/cmd/policies/set_audit_policy/set_audit_policy.go +++ b/pkg/cmd/policies/set_audit_policy/set_audit_policy.go @@ -1,6 +1,7 @@ package set_audit_policy import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -15,6 +16,7 @@ func NewCmdSetAuditPolicy(client *cip.APIClient) *cobra.Command { Long: "Set the Audit policy. This policy specifies whether audit records for your account are enabled. " + "You can access details about reported account events in the Sumo Logic Audit Index.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) setAuditPolicy(client, enabled) }, } diff --git a/pkg/cmd/policies/set_data_access_level_policy/set_data_access_level_policy.go b/pkg/cmd/policies/set_data_access_level_policy/set_data_access_level_policy.go index 45b98ed8..196f83c5 100644 --- a/pkg/cmd/policies/set_data_access_level_policy/set_data_access_level_policy.go +++ b/pkg/cmd/policies/set_data_access_level_policy/set_data_access_level_policy.go @@ -1,6 +1,7 @@ package set_data_access_level_policy import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -15,6 +16,7 @@ func NewCmdSetDataAccessLevelPolicy(client *cip.APIClient) *cobra.Command { Long: "Set the Data Access Level policy. When enabled, this policy sets the default data access level for all newly created dashboards to the viewer’s role access filter. " + "Otherwise, newly created dashboards will default to the sharer’s role access filter and might display data that viewers’ roles don’t allow them to view.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) setDataAccessLevelPolicy(client, enabled) }, } diff --git a/pkg/cmd/policies/set_max_user_session_timeout_policy/set_max_user_session_timeout_policy.go b/pkg/cmd/policies/set_max_user_session_timeout_policy/set_max_user_session_timeout_policy.go index 3930017f..8ceba206 100644 --- a/pkg/cmd/policies/set_max_user_session_timeout_policy/set_max_user_session_timeout_policy.go +++ b/pkg/cmd/policies/set_max_user_session_timeout_policy/set_max_user_session_timeout_policy.go @@ -1,6 +1,7 @@ package set_max_user_session_timeout_policy import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -15,6 +16,7 @@ func NewCmdSetMaxUserSessionTimeoutPolicy(client *cip.APIClient) *cobra.Command Long: "Set the Max User Session Timeout policy. When enabled, this policy sets the maximum web session timeout users are able to configure within their user preferences. " + "Users preferences will be updated to match this value only if their current preference is set to a higher value.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) setMaxUserSessionTimeoutPolicy(client, maxUserSessionTimeout) }, } diff --git a/pkg/cmd/policies/set_search_audit_policy/set_search_audit_policy.go b/pkg/cmd/policies/set_search_audit_policy/set_search_audit_policy.go index e50b18e5..00dd6d74 100644 --- a/pkg/cmd/policies/set_search_audit_policy/set_search_audit_policy.go +++ b/pkg/cmd/policies/set_search_audit_policy/set_search_audit_policy.go @@ -1,6 +1,7 @@ package set_search_audit_policy import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -15,6 +16,7 @@ func NewCmdSetSearchAuditPolicy(client *cip.APIClient) *cobra.Command { Long: "Set the Search Audit policy. This policy specifies whether search records for your account are enabled. " + "You can access details about your account's search capacity, queries run by users from the Sumo Search Audit Index.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) setSearchAuditPolicy(client, enabled) }, } diff --git a/pkg/cmd/policies/set_share_dashboards_outside_organizaton_policy/set_share_dashboards_outside_organization_policy.go b/pkg/cmd/policies/set_share_dashboards_outside_organizaton_policy/set_share_dashboards_outside_organization_policy.go index d09d397b..3d967ef7 100644 --- a/pkg/cmd/policies/set_share_dashboards_outside_organizaton_policy/set_share_dashboards_outside_organization_policy.go +++ b/pkg/cmd/policies/set_share_dashboards_outside_organizaton_policy/set_share_dashboards_outside_organization_policy.go @@ -1,6 +1,7 @@ package set_share_dashboards_outside_organizaton_policy import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -15,6 +16,7 @@ func NewCmdSetShareDashboardsOutsideOrganizationPolicy(client *cip.APIClient) *c Long: "Set the Share Dashboards Outside Organization policy. This policy allows users to share the dashboard with view only privileges outside of the organization (capability must be enabled from the Roles page). " + "Disabling this policy will disable all dashboards that have been shared outside of the organization.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) setShareDashboardsOutsideOrganizationPolicy(client, enabled) }, } diff --git a/pkg/cmd/policies/set_user_concurrent_sessions_limit_policy/set_user_concurrent_sessions_limit_policy.go b/pkg/cmd/policies/set_user_concurrent_sessions_limit_policy/set_user_concurrent_sessions_limit_policy.go index 8269e5c4..40c13a1b 100644 --- a/pkg/cmd/policies/set_user_concurrent_sessions_limit_policy/set_user_concurrent_sessions_limit_policy.go +++ b/pkg/cmd/policies/set_user_concurrent_sessions_limit_policy/set_user_concurrent_sessions_limit_policy.go @@ -1,6 +1,7 @@ package set_user_concurrent_sessions_limit_policy import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -18,6 +19,7 @@ func NewCmdSetUserConcurrentSessionsLimitPolicy(client *cip.APIClient) *cobra.Co Long: "Set the User Concurrent Sessions Limit policy. When enabled, the number of concurrent sessions a user may have is limited to the value entered. If a user exceeds the allowed number of sessions, the user's oldest session will be logged out to accommodate the new one. " + "Disabling this policy means a user may have an unlimited number of concurrent sessions.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) setUserConcurrentSessionsLimitPolicy(client, enabled, maxConcurrentSessions) }, } diff --git a/pkg/cmd/roles/assign/assign.go b/pkg/cmd/roles/assign/assign.go index 20609116..ecacc8fd 100644 --- a/pkg/cmd/roles/assign/assign.go +++ b/pkg/cmd/roles/assign/assign.go @@ -1,6 +1,7 @@ package assign import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/spf13/cobra" @@ -15,6 +16,7 @@ func NewCmdRoleAssign(client *cip.APIClient) *cobra.Command { Use: "assign", Short: "Assigns the specified Sumo Logic user to the role.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) assignRoleToUser(client, roleId, userId) }, } @@ -26,6 +28,7 @@ func NewCmdRoleAssign(client *cip.APIClient) *cobra.Command { } func assignRoleToUser(client *cip.APIClient, roleId string, userId string) { + authentication.ConfirmCredentialsSet(client) data, response, err := client.AssignRoleToUser(roleId, userId) if err != nil { cmdutils.OutputError(response, err) diff --git a/pkg/cmd/roles/create/create.go b/pkg/cmd/roles/create/create.go index 90f1c7a9..e9868015 100644 --- a/pkg/cmd/roles/create/create.go +++ b/pkg/cmd/roles/create/create.go @@ -1,6 +1,7 @@ package create import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -21,6 +22,7 @@ func NewCmdRoleCreate(client *cip.APIClient) *cobra.Command { Use: "create", Short: "Creates a Sumo Logic role", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) createRole(client, name, description, filter, users, capabilities, autofill) }, } diff --git a/pkg/cmd/roles/delete/delete.go b/pkg/cmd/roles/delete/delete.go index 36cac2a8..e466f30c 100644 --- a/pkg/cmd/roles/delete/delete.go +++ b/pkg/cmd/roles/delete/delete.go @@ -1,6 +1,7 @@ package delete import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/spf13/cobra" @@ -12,6 +13,7 @@ func NewCmdRoleDelete(client *cip.APIClient) *cobra.Command { Use: "delete", Short: "Deletes a Sumo Logic role", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) deleteRole(client, id) }, } diff --git a/pkg/cmd/roles/get/get.go b/pkg/cmd/roles/get/get.go index af06fa3b..10059cd0 100644 --- a/pkg/cmd/roles/get/get.go +++ b/pkg/cmd/roles/get/get.go @@ -1,6 +1,7 @@ package get import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/spf13/cobra" @@ -12,6 +13,7 @@ func NewCmdRoleGet(client *cip.APIClient) *cobra.Command { Use: "get", Short: "Gets a Sumo Logic role information", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) getRole(client, id) }, } diff --git a/pkg/cmd/roles/list/list.go b/pkg/cmd/roles/list/list.go index c5a81887..d34c265e 100644 --- a/pkg/cmd/roles/list/list.go +++ b/pkg/cmd/roles/list/list.go @@ -1,6 +1,8 @@ package list import ( + "fmt" + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -18,6 +20,7 @@ func NewCmdRoleList(client *cip.APIClient) *cobra.Command { Use: "list", Short: "Lists Sumo Logic roles", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) listRoles(client, limit, name, sortBy) }, } @@ -40,6 +43,7 @@ func listRoles(client *cip.APIClient, limit int32, name string, sortBy bool) { options.Name = optional.NewString(name) } data, response, err := client.ListRoles(&options) + fmt.Println(err) if err != nil { cmdutils.OutputError(response, err) } else { diff --git a/pkg/cmd/roles/remove/remove.go b/pkg/cmd/roles/remove/remove.go index b5540519..491ac0f5 100644 --- a/pkg/cmd/roles/remove/remove.go +++ b/pkg/cmd/roles/remove/remove.go @@ -1,6 +1,7 @@ package remove import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/spf13/cobra" @@ -15,6 +16,7 @@ func NewCmdRoleRemoveUser(client *cip.APIClient) *cobra.Command { Use: "remove user", Short: "Removes the specified Sumo Logic user from the role.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) removeRoleFromUser(client, roleId, userId) }, } diff --git a/pkg/cmd/roles/update/update.go b/pkg/cmd/roles/update/update.go index a336d73a..2a065389 100644 --- a/pkg/cmd/roles/update/update.go +++ b/pkg/cmd/roles/update/update.go @@ -1,6 +1,7 @@ package update import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -22,6 +23,7 @@ func NewCmdRoleUpdate(client *cip.APIClient) *cobra.Command { Use: "update", Short: "Updates a Sumo Logic role.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) updateRole(client, id, name, description, filter, users, capabilities, autofill) }, } diff --git a/pkg/cmd/sources/azure_event_hub/create/create.go b/pkg/cmd/sources/azure_event_hub/create/create.go index 46f989dd..173e1bdc 100644 --- a/pkg/cmd/sources/azure_event_hub/create/create.go +++ b/pkg/cmd/sources/azure_event_hub/create/create.go @@ -1,6 +1,7 @@ package create import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -25,6 +26,7 @@ func NewCmdAzureEventHubSourceCreate(client *cip.APIClient) *cobra.Command { Use: "create", Short: "Creates an Azure Event Hub source", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) createEventHubSource(authorizationRuleName, category, collectorId, consumerGroup, description, eventHubKey, eventHubName, fieldNames, fieldValues, name, namespace, client) }, diff --git a/pkg/cmd/sources/azure_event_hub/get/get.go b/pkg/cmd/sources/azure_event_hub/get/get.go index a7831d87..1203b054 100644 --- a/pkg/cmd/sources/azure_event_hub/get/get.go +++ b/pkg/cmd/sources/azure_event_hub/get/get.go @@ -1,6 +1,7 @@ package get import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/spf13/cobra" @@ -15,6 +16,7 @@ func NewCmdAzureEventHubSourceGet(client *cip.APIClient) *cobra.Command { Use: "get", Short: "Gets information about an Azure Event Hub source", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) getEventHubSource(collectorId, sourceId, client) }, } diff --git a/pkg/cmd/sources/azure_event_hub/update/update.go b/pkg/cmd/sources/azure_event_hub/update/update.go index af77c4bc..8ad78404 100644 --- a/pkg/cmd/sources/azure_event_hub/update/update.go +++ b/pkg/cmd/sources/azure_event_hub/update/update.go @@ -1,6 +1,7 @@ package update import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -28,6 +29,7 @@ func NewCmdAzureEventHubSourceUpdate(client *cip.APIClient) *cobra.Command { Use: "update", Short: "Updates an Azure Event Hub source", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) updateEventHubSource(authorizationRuleName, category, collectorId, consumerGroup, description, eventHubKey, eventHubName, fieldNames, fieldValues, name, namespace, sourceId, client) }, diff --git a/pkg/cmd/tokens/create/create.go b/pkg/cmd/tokens/create/create.go index 69f821b3..1a5be376 100644 --- a/pkg/cmd/tokens/create/create.go +++ b/pkg/cmd/tokens/create/create.go @@ -1,6 +1,7 @@ package create import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -17,6 +18,7 @@ func NewCmdTokensCreate(client *cip.APIClient) *cobra.Command { Use: "create", Short: "Create a token in the token library.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) createToken(description, inactive, name, client) }, } diff --git a/pkg/cmd/tokens/delete/delete.go b/pkg/cmd/tokens/delete/delete.go index 12c84f6b..dc950c09 100644 --- a/pkg/cmd/tokens/delete/delete.go +++ b/pkg/cmd/tokens/delete/delete.go @@ -1,6 +1,7 @@ package delete import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/spf13/cobra" @@ -12,6 +13,7 @@ func NewCmdTokensDelete(client *cip.APIClient) *cobra.Command { Use: "delete", Short: "Delete a token with the given identifier in the token library.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) deleteToken(id, client) }, } diff --git a/pkg/cmd/tokens/get/get.go b/pkg/cmd/tokens/get/get.go index 5d650dd0..c2a353a9 100644 --- a/pkg/cmd/tokens/get/get.go +++ b/pkg/cmd/tokens/get/get.go @@ -1,6 +1,7 @@ package get import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/spf13/cobra" @@ -12,6 +13,7 @@ func NewCmdTokensGet(client *cip.APIClient) *cobra.Command { Use: "get", Short: "Get a token with the given identifier in the token library.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) getToken(id, client) }, } diff --git a/pkg/cmd/tokens/list/list.go b/pkg/cmd/tokens/list/list.go index e989ce5a..f62ef5dd 100644 --- a/pkg/cmd/tokens/list/list.go +++ b/pkg/cmd/tokens/list/list.go @@ -1,6 +1,7 @@ package list import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/spf13/cobra" @@ -11,6 +12,7 @@ func NewCmdTokensList(client *cip.APIClient) *cobra.Command { Use: "list", Short: "Get a list of all tokens in the token library.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) listTokens(client) }, } diff --git a/pkg/cmd/tokens/update/update.go b/pkg/cmd/tokens/update/update.go index af26cdfb..5233fac2 100644 --- a/pkg/cmd/tokens/update/update.go +++ b/pkg/cmd/tokens/update/update.go @@ -1,6 +1,7 @@ package update import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -19,6 +20,7 @@ func NewCmdTokensUpdate(client *cip.APIClient) *cobra.Command { Use: "update", Short: "Update a token with the given identifier in the token library.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) updateToken(description, id, inactive, name, version, client) }, } diff --git a/pkg/cmd/users/change_email/change_email.go b/pkg/cmd/users/change_email/change_email.go index 7cfa7bce..8ba39f0b 100644 --- a/pkg/cmd/users/change_email/change_email.go +++ b/pkg/cmd/users/change_email/change_email.go @@ -1,6 +1,7 @@ package change_email import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -16,6 +17,7 @@ func NewCmdUserChangeEmail(client *cip.APIClient) *cobra.Command { Use: "change-email", Short: "Changes the email address of a Sumo Logic user.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) userChangeEmail(id, email, client) }, } diff --git a/pkg/cmd/users/create/create.go b/pkg/cmd/users/create/create.go index b8c2be59..0309ce51 100644 --- a/pkg/cmd/users/create/create.go +++ b/pkg/cmd/users/create/create.go @@ -1,6 +1,7 @@ package create import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -18,6 +19,7 @@ func NewCmdUserCreate(client *cip.APIClient) *cobra.Command { Use: "create", Short: "Creates a Sumo Logic user account", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) user(firstName, lastName, emailAddress, roleIds, client) }, } diff --git a/pkg/cmd/users/delete/delete.go b/pkg/cmd/users/delete/delete.go index d09e7ee3..b857a389 100644 --- a/pkg/cmd/users/delete/delete.go +++ b/pkg/cmd/users/delete/delete.go @@ -1,6 +1,7 @@ package delete import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -17,6 +18,7 @@ func NewCmdUserDelete(client *cip.APIClient) *cobra.Command { Use: "delete", Short: "Deletes a Sumo Logic user", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) deleteUser(id, transferTo, client) }, } diff --git a/pkg/cmd/users/disable_mfa/disable_mfa.go b/pkg/cmd/users/disable_mfa/disable_mfa.go index 4d8e4979..b22493ad 100644 --- a/pkg/cmd/users/disable_mfa/disable_mfa.go +++ b/pkg/cmd/users/disable_mfa/disable_mfa.go @@ -2,6 +2,7 @@ package disable_mfa import ( "errors" + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -15,6 +16,7 @@ func NewCmdUserDisableMFA(client *cip.APIClient) *cobra.Command { Use: "disable-mfa", Short: "Disables MFA for a Sumo Logic user (this command only works interactively).", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) userDisableMFA(client) }, } diff --git a/pkg/cmd/users/get/get.go b/pkg/cmd/users/get/get.go index ed948f0c..e00a740b 100644 --- a/pkg/cmd/users/get/get.go +++ b/pkg/cmd/users/get/get.go @@ -1,6 +1,7 @@ package get import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/spf13/cobra" @@ -12,6 +13,7 @@ func NewCmdGetUser(client *cip.APIClient) *cobra.Command { Use: "get", Short: "Gets a Sumo Logic user", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) getUser(id, client) }, } diff --git a/pkg/cmd/users/list/list.go b/pkg/cmd/users/list/list.go index 7f5e96fe..d6070e4a 100644 --- a/pkg/cmd/users/list/list.go +++ b/pkg/cmd/users/list/list.go @@ -1,6 +1,7 @@ package list import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -18,6 +19,7 @@ func NewCmdUserList(client *cip.APIClient) *cobra.Command { Use: "list", Short: "Lists Sumo Logic users", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) listUsers(email, limit, sortBy, client) }, } diff --git a/pkg/cmd/users/reset_password/reset_password.go b/pkg/cmd/users/reset_password/reset_password.go index fb365187..4e20ff11 100644 --- a/pkg/cmd/users/reset_password/reset_password.go +++ b/pkg/cmd/users/reset_password/reset_password.go @@ -1,6 +1,7 @@ package reset_password import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/spf13/cobra" @@ -12,6 +13,7 @@ func NewCmdUserResetPassword(client *cip.APIClient) *cobra.Command { Use: "reset-password", Short: "Initiates a password reset for a Sumo Logic user.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) userResetPassword(id, client) }, } diff --git a/pkg/cmd/users/unlock/unlock.go b/pkg/cmd/users/unlock/unlock.go index d1fae097..e6577326 100644 --- a/pkg/cmd/users/unlock/unlock.go +++ b/pkg/cmd/users/unlock/unlock.go @@ -1,6 +1,7 @@ package unlock import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/spf13/cobra" @@ -12,6 +13,7 @@ func NewCmdUnlockUser(client *cip.APIClient) *cobra.Command { Use: "unlock", Short: "Unlocks a Sumo Logic user account", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) unlockUser(id, client) }, } diff --git a/pkg/cmd/users/update/update.go b/pkg/cmd/users/update/update.go index 152f07a7..6ad3c4f8 100644 --- a/pkg/cmd/users/update/update.go +++ b/pkg/cmd/users/update/update.go @@ -1,6 +1,7 @@ package update import ( + "github.com/SumoLogic-Labs/sumocli/internal/authentication" "github.com/SumoLogic-Labs/sumocli/pkg/cmdutils" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip" "github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip/types" @@ -19,6 +20,7 @@ func NewCmdUserUpdate(client *cip.APIClient) *cobra.Command { Use: "update", Short: "Updates a Sumo Logic user.", Run: func(cmd *cobra.Command, args []string) { + authentication.ConfirmCredentialsSet(client) updateUser(id, firstName, lastName, isActive, roleIds, client) }, } diff --git a/pkg/cmd/version/version.go b/pkg/cmd/version/version.go index b469267c..37419f5b 100644 --- a/pkg/cmd/version/version.go +++ b/pkg/cmd/version/version.go @@ -12,9 +12,8 @@ func NewCmdVersion() *cobra.Command { Short: "Displays sumocli version", Long: "Displays the version and build number of sumocli.", Run: func(cmd *cobra.Command, args []string) { - fmt.Println("Sumocli " + build.Version + " " + build.Build) + fmt.Println("Sumocli " + build.Version + " " + build.Build + " " + build.Date) }, } - return cmd } diff --git a/scripts/build-debianpackage.sh b/scripts/build-debianpackage.sh new file mode 100644 index 00000000..f37c7409 --- /dev/null +++ b/scripts/build-debianpackage.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +architecture="" +version="" + +while getopts ":a:v:" options; do + case "${options}" in + a) + architecture=${OPTARG} + ;; + v) + version=${OPTARG} + ;; + :) + echo "Error: -${OPTARG} requires an argument" + exit 1 + ;; + *) + exit 1 + ;; + esac +done + +echo "=> Creating debian package folder structure" +mkdir -p "./deb/sumocli_$version-1_$architecture/usr/bin" +echo "=> Copying sumocli binary" +chmod +x "./sumocli_linux_$architecture/sumocli/sumocli" +cp "./sumocli_linux_$architecture/sumocli/sumocli" "./deb/sumocli_$version-1_$architecture/usr/bin" +echo "=> Creating debian control file" +mkdir -p "./deb/sumocli_$version-1_$architecture/DEBIAN" +cat > "./deb/sumocli_$version-1_$architecture/DEBIAN/control" << EOF +Package: sumocli +Version: $version +Maintainer: kyle@thepublicclouds.com +Architecture: $architecture +Homepage: https://github.com/SumoLogic-Labs/sumocli +Description: Sumocli is a CLI application written in Go that allows you to manage your Sumo Logic tenancy from the command line. +EOF +echo "=> Building debian package" +dpkg --build "./deb/sumocli_$version-1_$architecture" diff --git a/scripts/build.ps1 b/scripts/build.ps1 deleted file mode 100644 index f04400d6..00000000 --- a/scripts/build.ps1 +++ /dev/null @@ -1,138 +0,0 @@ - -param ( - [switch]$arm = $false, - [string]$build = "DEV", - [string]$keyVaultCertificate = "", - [string]$keyVaultClientId = "", - [string]$keyVaultClientSecret = "", - [string]$keyvaulttenantId = "", - [string]$keyVaultUrl = "", - [switch]$linux = $false, - [switch]$macos = $false, - [string]$maintainer = "kyle@thepublicclouds.com", - [switch]$release = $false, - [string]$version = "DEV", - [switch]$windows = $false -) - -$goarchitecture="amd64" - -# Add goarchitecture if statement - -if ($linux -eq $true) { - Write-Host "Compiling Linux $goarchitecture binary" - $env:GOOS="linux"; $env:GOARCH=$goarchitecture; go build -ldflags ` - "-X 'github.com/SumoLogic-Labs/sumocli/internal/build.Version=$version' - -X 'github.com/SumoLogic-Labs/sumocli/internal/build.Build=$build'" ` - ./cmd/sumocli - if ($version -ne "DEV" -and $build -ne "DEV") { - Write-Host "=> Creating deb package" - mkdir -p ~/deb/sumocli_$version-1_amd64/usr/bin - cp sumocli ~/deb/sumocli_$version-1_amd64/usr/bin - Write-Host "=> Creating DEBIAN control file" - mkdir -p ~/deb/sumocli_$version-1_amd64/DEBIAN - $controlFile = @" -Package: sumocli -Version: $version -Maintainer: $maintainer -Architecture: amd64 -Homepage: https://github.com/SumoLogic-Labs/sumocli -Description: Sumocli is a CLI application written in Go that allows you to manage your Sumo Logic tenancy from the command line. -"@ - Set-Content -Path ~/deb/sumocli_$version-1_amd64/DEBIAN/control -Value $controlFile - Write-Host "=> Building deb package" - dpkg --build ~/deb/sumocli_$version-1_$goarchitecture - if ($release -eq $true) { - Write-Host "=> Deleteing local apt repo cache" - rm -r ~/aptsumocli - Write-Host "=> Creating apt repo folder" - mkdir ~/aptsumocli/ - Write-Host "=> Syncing aptsumocli S3 bucket locally" - aws s3 sync s3://aptsumocli ~/aptsumocli/ - Write-Host "=> Creating pools directory" - mkdir -p ~/aptsumocli/pool/main - Write-Host "=> Moving deb package to local apt repo" - mv ~/deb/sumocli_$version-1_$goarchitecture.deb ~/aptsumocli/pool/main/sumocli_$version-1_$goarchitecture.deb - Write-Host "=> Creating packages directory" - mkdir -p ~/aptsumocli/dists/stable/main/binary-$goarchitecture - Write-Host "=> Removing old packages file" - rm ~/aptsumocli/dists/stable/main/binary-$goarchitecture/Packages - rm ~/aptsumocli/dists/stable/main/binary-$goarchitecture/Packages.gz - Write-Host "=> Generating new packages file" - cd ~/aptsumocli - dpkg-scanpackages --arch $goarchitecture pool/ > ~/aptsumocli/dists/stable/main/binary-$goarchitecture/Packages - Write-Host "=> Compressing packages file" - gzip -k ~/aptsumocli/dists/stable/main/binary-$goarchitecture/Packages - Write-Host "=> Removing old release files" - rm ~/aptsumocli/dists/stable/Release - rm ~/aptsumocli/dists/stable/Release.gpg - rm ~/aptsumocli/dists/stable/InRelease - Write-Host "=> Creating release file" - $date = Get-Date -UFormat "%a, %d %b %Y %T %Z" -AsUTC - $releaseFile = @" -Origin: apt.sumocli.app -Suite: stable -Codename: stable -Version: $version -Architectures: amd64 -Components: main -Description: Sumocli is a CLI application written in Go that allows you to manage your Sumo Logic tenancy from the command line. -Date: $date -$(pwsh "$PSScriptRoot/create-debianrelease.ps1" | Out-String) -"@ - $releaseFile | Out-File -FilePath ~/aptsumocli/dists/stable/Release - Write-Host "=> Signing release file" - Get-Content -Path ~/aptsumocli/dists/stable/Release | gpg --default-key "Kyle Jackson" -abs > ~/aptsumocli/dists/stable/Release.gpg - Write-Host "=> Creating InRelease file" - cat ~/aptsumocli/dists/stable/Release | gpg --default-key "Kyle Jackson" -abs --clearsign > ~/aptsumocli/dists/stable/InRelease - Write-Host "Syncing local aptsumocli repo to S3" - aws s3 sync ~/aptsumocli/ s3://aptsumocli - } - } -} - -if ($windows -eq $true) { - Write-Host "=> Compiling Windows $goarchitecture binary" - $env:GOOS="windows"; $env:GOARCH=$goarchitecture; go build -ldflags ` - "-X 'github.com/SumoLogic-Labs/sumocli/internal/build.Version=$version' - -X 'github.com/SumoLogic-Labs/sumocli/internal/build.Build=$build'" ` - ./cmd/sumocli - if ($version -ne "DEV" -and $build -ne "DEV") { - Write-Host "=> preparing to sign code" - Write-Host "=> Installing azuresigntool" - dotnet tool install --global AzureSignTool --version 3.0.0 - Write-Host "=> Signing Windows binary with Azure Key Vault" - azuresigntool sign --description-url "https://github.com/SumoLogic-Labs/sumocli" --file-digest sha256 ` - --azure-key-vault-url $keyVaultUrl ` - --azure-key-vault-client-id $keyVaultClientId ` - --azure-key-vault-client-secret $keyVaultClientSecret ` - --azure-key-vault-certificate $keyVaultCertificate ` - --azure-key-vault-tenant-id $keyvaulttenantId ` - --timestamp-rfc3161 http://timestamp.sectigo.com ` - --timestamp-digest sha256 ` - sumocli.exe - if ($release -eq $true) { - mkdir tools - mv sumocli.exe tools/sumocli.exe - Write-Host "=> Generating choco nuspec file" - $nuspecFile = @" - - - - sumocli - $version - Kyle Jackson - https://github.com/SumoLogic-Labs/sumocli - - - - - - -"@ - $nuspecFile | Out-File -FilePath sumocli.nuspec - choco pack - - } - } -} diff --git a/scripts/create-brewformula.sh b/scripts/create-brewformula.sh new file mode 100644 index 00000000..dbcd752e --- /dev/null +++ b/scripts/create-brewformula.sh @@ -0,0 +1,71 @@ +#!/bin/bash + +version="" + +generate_hash() { + file=$1 + sha256sum "$file" | cut -d" " -f1 +} + +while getopts ":v:" options; do + case "${options}" in + v) + version=${OPTARG} + ;; + :) + echo "Error: -${OPTARG} requires an argument" + exit 1 + ;; + *) + exit 1 + ;; + esac +done + +cat << EOF > sumocli.rb +class Sumocli < Formula + desc "sumocli" + homepage "https://github.com/SumoLogic-Labs/sumocli" + version "$version" + + on_macos do + if Hardware::CPU.intel? + url "https://github.com/SumoLogic-Labs/sumocli/releases/download/$version/sumocli_${version}_darwin_amd64.tar.gz" + sha256 "$(generate_hash "sumocli_${version}_darwin_amd64.tar.gz")" + + def install + bin.install "sumocli" + end + end + + if Hardware::CPU.arm? + url "https://github.com/SumoLogic-Labs/sumocli/releases/download/$version/sumocli_${version}_darwin_arm64.tar.gz" + sha256 "$(generate_hash "sumocli_${version}_darwin_arm64.tar.gz")" + + def install + bin.install "sumocli" + end + end + end + + on_linux do + if Hardware::CPU.intel? + url "https://github.com/SumoLogic-Labs/sumocli/releases/download/$version/sumocli_${version}_linux_amd64.tar.gz" + sha256 "$(generate_hash "sumocli_${version}_linux_amd64.tar.gz")" + + def install + bin.install "sumocli" + end + end + + if Hardware::CPU.arm? + url "https://github.com/SumoLogic-Labs/sumocli/releases/download/0.1.0/sumocli_${version}_linux_amd64.tar.gz" + sha256 "$(generate_hash "sumocli_${version}_linux_arm64.tar.gz")" + + def install + bin.install "sumocli" + end + end + end +end +EOF diff --git a/scripts/create-debianrelease.ps1 b/scripts/create-debianrelease.ps1 deleted file mode 100644 index 8cd3d008..00000000 --- a/scripts/create-debianrelease.ps1 +++ /dev/null @@ -1,27 +0,0 @@ -$algorithms = @( - "MD5", - "SHA1", - "SHA256", - "SHA512" -) -$hashContent = @() - -foreach ($i in $algorithms) { - if ($i -eq "MD5") { - $hashContent = $hashContent + "MD5Sum:" - } else { - $algorithm = $i + ":" - $hashContent = $hashContent + $algorithm - } - Get-ChildItem -Path ~/aptsumocli/dists/stable/main -recurse -File | ForEach-Object { - $hash = Get-FileHash $_.FullName -Algorithm $i - $relativePath = Resolve-Path -Path ~/aptsumocli/dists/stable/ | Select-Object -ExpandProperty Path - $fileName = $_.FullName.Replace($relativePath, "") - $data = " " + $hash.Hash.ToLower() + " " + $_.Length + " " + $fileName - $hashContent = $hashContent + $data - } -} - -foreach ($i in $hashContent) { - Write-Host $i -} diff --git a/scripts/docker-build.sh b/scripts/docker-build.sh deleted file mode 100644 index 251994fb..00000000 --- a/scripts/docker-build.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/sh - -build="DEV" -version="DEV" - -while getopts "bdv" opt; do - case $opt in - b) - build=$OPTARG - ;; - d) - echo "$build" - echo "$version" - echo "=> Compiling linux AMD64 binary for Docker image" >&2 - GOOS=linux GOARCH=amd64 go build -ldflags \ - "-X 'github.com/SumoLogic-Labs/sumocli/internal/build.Version=$version' - -X 'github.com/SumoLogic-Labs/sumocli/internal/build.Build=$build'" \ - ./cmd/sumocli - echo "=> Moving sumocli binary to $GOPATH/bin/" - mv "$GOPATH/src/github.com/SumoLogic-Labs/sumocli/sumocli" "$GOPATH/bin/sumocli" - ;; - v) - version=$OPTARG - ;; - \?) - echo "Invalid option!" >&2 - ;; - esac -done diff --git a/scripts/invalidate-cloudfront.sh b/scripts/invalidate-cloudfront.sh new file mode 100644 index 00000000..6dc707af --- /dev/null +++ b/scripts/invalidate-cloudfront.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +invalidationid=$(aws cloudfront create-invalidation --distribution-id "$DISTRIBUTIONID" --paths "/*" | jq -r .Invalidation.Id) +invalidationstatus=$(aws cloudfront get-invalidation --id "$invalidationid" --distribution-id "$DISTRIBUTIONID" | jq -r .Invalidation.Status) +echo "invalidating cloudfront cache (invalidation id: $invalidationid" +while [ "$invalidationstatus" == "InProgress" ] +do + echo "checking cloudfront invalidation status" + if [ "$invalidationstatus" == "InProgress" ]; then + echo "cloudfront invalidation status still in progress checking again in 30 seconds" + sleep 30 + invalidationstatus=$(aws cloudfront get-invalidation --id "$invalidationid" --distribution-id "$DISTRIBUTIONID" | jq -r .Invalidation.Status) + fi +done +if [ "$invalidationstatus" == "Completed" ]; then + echo "cloudfront invalidation complete!" +fi diff --git a/scripts/release-debianpackage.sh b/scripts/release-debianpackage.sh new file mode 100755 index 00000000..49b9ab35 --- /dev/null +++ b/scripts/release-debianpackage.sh @@ -0,0 +1,121 @@ +#!/bin/bash + +releaseArchitectures="" +version="" + +generate_hash() { + hashname=$1 + hashcmd=$2 + echo "$hashname:" + for file in $(find -type f); do + file=$(echo "$file" | cut -c3-) + if [ "$file" = "Release" ]; then + continue + fi + echo " $(${hashcmd} "$file" | cut -d" " -f1) $(wc -c "$file")" + done +} + +while getopts ":a:v:" options; do + case "${options}" in + a) + architectures+=("$OPTARG") + ;; + v) + version=${OPTARG} + ;; + :) + echo "Error: -${OPTARG} requires an argument" + exit 1 + ;; + *) + exit 1 + ;; + esac +done + +echo "=> Creating apt repo folder" +mkdir ./aptsumocli +echo "=> Syncing S3 bucket locally" +aws s3 sync s3://aptsumocli ./aptsumocli +echo "=> Checking pools directory" +if [ -d "./aptsumocli/pool/main" ]; then + echo "=> ./aptsumocli/pool/main already exists" +else + echo "=> Creating pools directory" + mkdir -p ./aptsumocli/pool/main +fi +for architecture in "${architectures[@]}"; do + releaseArchitectures+=$architecture + releaseArchitectures+=" " + echo "=> Moving $architecture debian package to local apt repo" + mv "./sumocli_$version-1_$architecture.deb" "./aptsumocli/pool/main/sumocli_$version-1_$architecture.deb" + echo "=> Checking for $architecture packages directory" + if [ -d "./aptsumocli/dists/stable/main/binary-$architecture" ]; then + echo "=> ./aptsumocli/dists/stable/main/binary-$architecture already exists" + else + mkdir -p "./aptsumocli/dists/stable/main/binary-$architecture" + fi + echo "=> Checking for old $architecture package files" + if [ -f "./aptsumocli/dists/stable/main/binary-$architecture/Packages" ]; then + echo "=> Removing ./aptsumocli/dists/stable/main/binary-$architecture/Packages" + rm "./aptsumocli/dists/stable/main/binary-$architecture/Packages" + else + echo "=> ./aptsumocli/dists/stable/main/binary-$architecture/Packages does not exist" + fi + if [ -f "./aptsumocli/dists/stable/main/binary-$architecture/Packages.gz" ]; then + echo "=> Removing ./aptsumocli/dists/stable/main/binary-$architecture/Packages.gz" + rm "./aptsumocli/dists/stable/main/binary-$architecture/Packages.gz" + else + echo "=> ./aptsumocli/dists/stable/main/binary-$architecture/Packages.gz does not exist" + fi + echo "=> Generate new $architecture package file" + cd ./aptsumocli || exit + dpkg-scanpackages --arch "$architecture" pool/ > "Packages" + cd .. + mv -f "./aptsumocli/Packages" "./aptsumocli/dists/stable/main/binary-$architecture/Packages" + echo "=> Compressing $architecture package file" + gzip -k "./aptsumocli/dists/stable/main/binary-$architecture/Packages" +done +echo "=> Checking for old release files" +if [ -f "./aptsumocli/dists/stable/Release" ]; then + echo "=> Removing ./aptsumocli/dists/stable/Release" + rm ./aptsumocli/dists/stable/Release +else + echo "=> ./aptsumocli/dists/stable/Release does not exist" +fi +if [ -f "./aptsumocli/dists/stable/Release.gpg" ]; then + echo "=> Removing ./aptsumocli/dists/stable/Release.gpg" + rm ./aptsumocli/dists/stable/Release.gpg +else + echo "=> ./aptsumocli/dists/stable/Release.gpg does not exist" +fi +if [ -f "./aptsumocli/dists/stable/InRelease" ]; then + echo "=> Removing ./aptsumocli/dists/stable/InRelease" + rm ./aptsumocli/dists/stable/InRelease +else + echo "=> ./aptsumocli/dists/stable/InRelease does not exist" +fi +echo "=> Moving directories to ./aptsumocli/dists/stable" +cd ./aptsumocli/dists/stable || exit +cat << EOF > Release +Origin: apt.sumocli.app +Suite: stable +Codename: stable +Version: $version +Architectures: $releaseArchitectures +Components: main +Description: Sumocli is a CLI application written in Go that allows you to manage your Sumo Logic tenancy from the command line. +Date: $(date -Ru) +$(generate_hash "MD5Sum" "md5sum") +$(generate_hash "SHA1" "sha1sum") +$(generate_hash "SHA256" "sha256sum") +EOF +echo "=> Signing release file" +cat ./Release | gpg --default-key "Kyle Jackson" -abs > Release.gpg +echo "=> Creating InRelease file" +cat ./Release | gpg --default-key "Kyle Jackson" -abs --clearsign > InRelease +echo "=> Moving back to root directory" +cd - +echo "=> Syncing local apt repo to S3" +aws s3 sync ./aptsumocli/ s3://aptsumocli diff --git a/scripts/release-macos.sh b/scripts/release-macos.sh deleted file mode 100644 index e69de29b..00000000