From 9ca45bd6947884a2b58e1f7a837ad45a73960c86 Mon Sep 17 00:00:00 2001 From: Nick Schuch Date: Thu, 23 Nov 2023 14:28:30 +1000 Subject: [PATCH 1/5] Adds Github Actions --- .github/workflows/lint.yml | 22 ++++++++++++++++++ .github/workflows/publish.yml | 42 +++++++++++++++++++++++++++++++++++ .github/workflows/test.yml | 20 +++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/publish.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..371ee57 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,22 @@ +name: Lint + +on: + push + +jobs: + lint: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install Go + uses: actions/setup-go@v3 + with: + go-version: '1.21' + + - name: Lint + uses: golangci/golangci-lint-action@v3 + with: + args: --timeout=5m diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..eb223fe --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,42 @@ +name: Create and Publish a Docker Image + +on: + push: + branches: ['main'] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Log in to the Container registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..24aaf1d --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,20 @@ +name: Test + +on: + push + +jobs: + lint: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install Go + uses: actions/setup-go@v3 + with: + go-version: '1.21' + + - name: Lint + run: go test ./... From 891878abc53495aa802ffb139f7a25b62901a181 Mon Sep 17 00:00:00 2001 From: Nick Schuch Date: Thu, 23 Nov 2023 14:31:40 +1000 Subject: [PATCH 2/5] Adds fmt and vet --- .github/workflows/fmt.yml | 19 +++++++++++++++++++ .github/workflows/vet.yml | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 .github/workflows/fmt.yml create mode 100644 .github/workflows/vet.yml diff --git a/.github/workflows/fmt.yml b/.github/workflows/fmt.yml new file mode 100644 index 0000000..31426ff --- /dev/null +++ b/.github/workflows/fmt.yml @@ -0,0 +1,19 @@ +name: 📋 Format + +on: + push + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: ⬇️ Git clone the repository + uses: actions/checkout@v3 + + - name: 📦 Install Go + uses: actions/setup-go@v3 + with: + go-version: '1.21' + + - name: 📋 Gofmt + run: go fmt ./... diff --git a/.github/workflows/vet.yml b/.github/workflows/vet.yml new file mode 100644 index 0000000..dae51c7 --- /dev/null +++ b/.github/workflows/vet.yml @@ -0,0 +1,19 @@ +name: 📋 Vet + +on: + push + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: ⬇️ Git clone the repository + uses: actions/checkout@v3 + + - name: 📦 Install Go + uses: actions/setup-go@v3 + with: + go-version: '1.21' + + - name: 📋 Vet + run: go vet ./... From 202c7f0ff4d5a5f3059c9e7d3fcc0c8f57d0b43d Mon Sep 17 00:00:00 2001 From: Nick Schuch Date: Thu, 23 Nov 2023 14:34:27 +1000 Subject: [PATCH 3/5] Update emojis --- .github/workflows/lint.yml | 4 ++-- .github/workflows/publish.yml | 8 ++++---- .github/workflows/test.yml | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 371ee57..cb97a08 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -8,10 +8,10 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout repository + - name: ⬇️ Git clone the repository uses: actions/checkout@v3 - - name: Install Go + - name: 📦 Install Go uses: actions/setup-go@v3 with: go-version: '1.21' diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index eb223fe..83998e8 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -17,23 +17,23 @@ jobs: packages: write steps: - - name: Checkout repository + - name: ⬇️ Git clone the repository uses: actions/checkout@v3 - - name: Log in to the Container registry + - name: 🔐 Log in to the Container registry uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Extract metadata (tags, labels) for Docker + - name: 📋 Extract metadata (tags, labels) for Docker id: meta uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - - name: Build and push Docker image + - name: ☁️ Build and push Docker image uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 with: context: . diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 24aaf1d..ddcbdac 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,13 +8,13 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout repository + - name: ⬇️ Git clone the repository uses: actions/checkout@v3 - - name: Install Go + - name: 📦 Install Go uses: actions/setup-go@v3 with: go-version: '1.21' - - name: Lint + - name: 📋 Lint run: go test ./... From 6588369bfde4acb359cf08ec20a32da957c2e950 Mon Sep 17 00:00:00 2001 From: Nick Schuch Date: Thu, 23 Nov 2023 14:38:13 +1000 Subject: [PATCH 4/5] Fix linting --- internal/aws/federation/federation.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/internal/aws/federation/federation.go b/internal/aws/federation/federation.go index 4358f41..2d30e3e 100644 --- a/internal/aws/federation/federation.go +++ b/internal/aws/federation/federation.go @@ -3,7 +3,8 @@ package federation import ( "encoding/json" "fmt" - "io/ioutil" + "io" + "log" "net/http" "net/url" "strconv" @@ -40,9 +41,14 @@ func GetSignInLink(credentials aws.Credentials, issuer, dashboardURL string, dur if err != nil { return "", fmt.Errorf("failed getting federation URL: %w", err) } - defer response.Body.Close() + defer func() { + err := response.Body.Close() + if err != nil { + log.Print(err) + } + }() - bodyBytes, err := ioutil.ReadAll(response.Body) + bodyBytes, err := io.ReadAll(response.Body) if err != nil { return "", fmt.Errorf("failed reading response body: %w", err) } From 8d8af6c7de1aeb96553cbdef24db05edf36b30c3 Mon Sep 17 00:00:00 2001 From: Nick Schuch Date: Thu, 23 Nov 2023 14:40:11 +1000 Subject: [PATCH 5/5] Fix linting --- internal/server/callback.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/server/callback.go b/internal/server/callback.go index 55d5c3f..096b8e0 100644 --- a/internal/server/callback.go +++ b/internal/server/callback.go @@ -64,6 +64,10 @@ func (s *DashboardServer) Callback(c *gin.Context) { IdentityPool: s.config.IdentityPool, IdentityProvider: s.config.IdentityProvider, }) + if err != nil { + c.String(http.StatusInternalServerError, err.Error()) + return + } dashboardURL := cloudwatchdashboard.GetURI(s.config.Region, dashboardName)