Skip to content

Commit

Permalink
Merge pull request #98 from SumoLogic/addGithubAuthentication
Browse files Browse the repository at this point in the history
Add GitHub authentication
  • Loading branch information
harshshahsumo authored Jul 11, 2024
2 parents f6e1234 + 7fb6c35 commit 7d31881
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/_reusable_build_package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ on:
required: false
microsoft_description:
required: false
gh_ci_token:
required: true

defaults:
run:
Expand Down Expand Up @@ -81,6 +83,7 @@ jobs:
if: runner.os == 'macOS'
env:
PRODUCTBUILD_IDENTITY_NAME: ${{ secrets.productbuild_identity_name }}
GH_CI_TOKEN: ${{ secrets.GH_CI_TOKEN }}
run: |
if [ -n "${PRODUCTBUILD_IDENTITY_NAME}" ]; then
echo "MACOS_SIGNING_ENABLED=true" >> $GITHUB_ENV
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build_packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ jobs:
microsoft_certhash: ${{ secrets.MICROSOFT_CERTHASH }}
microsoft_certname: ${{ secrets.MICROSOFT_CERTNAME }}
microsoft_description: ${{ secrets.MICROSOFT_DESCRIPTION }}
gh_ci_token: ${{ secrets.GH_CI_TOKEN }}

strategy:
matrix:
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/test-install-script.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ jobs:
install-script/**/*
.github/**
- name: Set up environment variables
env:
GITHUB_TOKEN: ${{ secrets.GH_CI_TOKEN }}

- name: Setup go
if: steps.changed-files.outputs.any_changed == 'true'
uses: WillAbides/setup-go-faster@v1
Expand All @@ -40,4 +44,4 @@ jobs:
- name: Run install script tests
if: steps.changed-files.outputs.any_changed == 'true'
working-directory: install-script/test
run: make test
run: make test --token $GITHUB_TOKEN
33 changes: 26 additions & 7 deletions install-script/test/consts_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sumologic_scripts_tests
import (
"encoding/json"
"fmt"
"log"
"net/http"
"net/url"
"os"
Expand All @@ -18,18 +19,36 @@ var (
latestAppVersion string
)

func authenticateGithub() string {
githubToken := os.Getenv("GH_CI_TOKEN")
if githubToken == "" {
log.Fatal("GITHUB_TOKEN environment variable not set")

}
return githubToken
}

func getLatestAppReleaseVersion() (string, error) {
githubApiBaseUrl, err := url.Parse(GithubApiBaseUrl)
if err != nil {
return "", err
}
githubApiLatestReleaseUrl := githubApiBaseUrl.JoinPath(
"repos",
GithubOrg,
GithubAppRepository,
"releases",
"latest")
response, err := http.Get(githubApiLatestReleaseUrl.String()) //nolint:noctx
githubToken := authenticateGithub()

githubApiLatestReleaseUrl := fmt.Sprintf("%s/repos/%s/%s/releases/latest", githubApiBaseUrl, GithubOrg, GithubAppRepository)

req, err := http.NewRequest("GET", githubApiLatestReleaseUrl, nil)
if err != nil {
return "", err
}

// Set Authorization header with GitHub token
req.Header.Set("Authorization", "token "+githubToken)
req.Header.Set("Accept", "application/vnd.github.v3+json")

// Send request
client := http.Client{}
response, err := client.Do(req)
if err != nil {
return "", err
}
Expand Down

0 comments on commit 7d31881

Please sign in to comment.