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/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..cb97a08 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,22 @@ +name: Lint + +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: 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..83998e8 --- /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: ⬇️ Git clone the 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..ddcbdac --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,20 @@ +name: Test + +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: 📋 Lint + run: go test ./... 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 ./... 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) } 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)