diff --git a/.github/workflows/config.json b/.github/workflows/config.json deleted file mode 100644 index 356adc9..0000000 --- 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 0000000..e49c4c0 --- /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 0000000..4599f4c --- /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 0000000..73af3e9 --- /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 add8e46..0000000 --- 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 2e9e3f6..fd9fa0a 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 0000000..7877c9e --- /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 83e1554..6bb54c4 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 05b7bb0..ff57136 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 a4a3fd8..f491e42 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 1818e7d..74165f8 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 f42bef2..0000000 --- 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 f113bed..0000000 --- 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 581287f..1cfcb29 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 a6f4673..0000000 --- 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 a0883bd..0000000 --- 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 f283bd0..dbbe33b 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 78c48cb..629742f 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 26d4b68..07ade7c 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 b964e1c..84472e4 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 78b5ce7..6abd01a 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 d53dade..c54d056 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 a21916e..2d51e0e 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 9476626..5845b4a 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 e62ecaa..53a04e8 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 b941c4d..d625ffd 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 b9926ff..7bbd341 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 d59d2c5..2733d38 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 a1dc9c6..5099f8c 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 90fb115..4bd488a 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 eec6403..7e4c83a 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 7e71c8c..c05da2b 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 a8e30f6..3bd4c1e 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 534e246..de78ed0 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 5568bab..baa1854 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 5eeb669..263e3b2 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 95cbbdd..88d576d 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 4c37859..5009e82 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 9d493ba..c02a191 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 2fa70eb..9e478c8 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 347c887..c82eb9a 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 9a7badc..0e7291e 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 2a0c8f6..ee0bceb 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 633df1f..e58169c 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 ac01789..89f5f93 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 9a00436..0c39d43 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 630f27f..74d340f 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 1a4b4eb..337abcb 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 644f91e..1b9d049 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 46a7a87..fd7fd03 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 96bb7df..cda5051 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 a8d326f..048b387 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 2fdf9c1..9cc4699 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 87032e3..4e05c8f 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 bf79de3..6884ae6 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 d2f4454..65c87dd 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 d34c71b..38bbc28 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 131503a..4ffb7f6 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 127900e..4b2e5a2 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 24a6aca..4113cf7 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 b4f0c7d..ccd67a4 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 9f096c5..18f7e22 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 3d28e55..abfcca5 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 bf49610..b3c6ebe 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 b797b91..fbbabb0 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 45b98ed..196f83c 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 3930017..8ceba20 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 e50b18e..00dd6d7 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 d09d397..3d967ef 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 8269e5c..40c13a1 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 2060911..ecacc8f 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 90f1c7a..e986801 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 36cac2a..e466f30 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 af06fa3..10059cd 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 c5a8188..d34c265 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 b554051..491ac0f 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 a336d73..2a06538 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 46f989d..173e1bd 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 a7831d8..1203b05 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 af77c4b..8ad7840 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 69f821b..1a5be37 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 12c84f6..dc950c0 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 5d650dd..c2a353a 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 e989ce5..f62ef5d 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 af26cdf..5233fac 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 7cfa7bc..8ba39f0 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 b8c2be5..0309ce5 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 d09e7ee..b857a38 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 4d8e497..b22493a 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 ed948f0..e00a740 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 7f5e96f..d6070e4 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 fb36518..4e20ff1 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 d1fae09..e657732 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 152f07a..6ad3c4f 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 b469267..37419f5 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 0000000..f37c740 --- /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 f04400d..0000000 --- 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 0000000..dbcd752 --- /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 8cd3d00..0000000 --- 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 251994f..0000000 --- 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 0000000..6dc707a --- /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 0000000..49b9ab3 --- /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 e69de29..0000000