diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..68334cf3 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,7 @@ +version: 2 + +updates: + - package-ecosystem: "gomod" + directory: "/" + schedule: + interval: "daily" \ No newline at end of file diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml deleted file mode 100644 index 64693002..00000000 --- a/.github/workflows/e2e-test.yml +++ /dev/null @@ -1,23 +0,0 @@ -# Go e2e integration workflow -name: e2e-test - -on: - push: - branches: [ "master", "development" ] - pull_request: - branches: [ "master", "development" ] - -jobs: - - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.19 - - - name: Run E2E Integration Tests - run: make e2e-test diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml deleted file mode 100644 index 0760c575..00000000 --- a/.github/workflows/go-test.yml +++ /dev/null @@ -1,23 +0,0 @@ -# Go test workflow -name: go-test - -on: - push: - branches: [ "master", "development" ] - pull_request: - branches: [ "master", "development" ] - -jobs: - - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.19 - - - name: Run Unit Tests - run: make test diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml deleted file mode 100644 index 4576482d..00000000 --- a/.github/workflows/golangci-lint.yml +++ /dev/null @@ -1,20 +0,0 @@ -# Linting with golangci-lint -name: golangci-lint -on: - - push: - branches: [ "master", "development" ] - pull_request: - branches: [ "master", "development" ] - -jobs: - golangci: - name: lint - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: golangci-lint - uses: golangci/golangci-lint-action@v3 - with: - # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version - version: v1.52.1 diff --git a/.github/workflows/hygeine.yml b/.github/workflows/hygeine.yml new file mode 100644 index 00000000..84d76d0b --- /dev/null +++ b/.github/workflows/hygeine.yml @@ -0,0 +1,39 @@ +name: hygeiene + +on: + push: + branches: [ "master", "development" ] + pull_request: + branches: [ "master", "development" ] + +jobs: + ensure-mock-gen: + # Generation assurance test workflow + # (e.g. no uncovered diffs in go-mocks) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.19 + + - name: Install mockgen + run: go install github.com/golang/mock/mockgen@v1.6.0 + + - name: Mock diff check + run: make go-gen-mocks && git diff --exit-code + + golangci: + # Linting job + # https://github.com/golangci/golangci-lint-action + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version + version: v1.52.1 diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml new file mode 100644 index 00000000..fc912e2c --- /dev/null +++ b/.github/workflows/security.yml @@ -0,0 +1,22 @@ +name: security + +on: + push: + branches: [ "master", "development" ] + pull_request: + branches: [ "master", "development" ] + +jobs: + # Static security scan using gosec + # https://github.com/securego/gosec + gosec: + runs-on: ubuntu-latest + env: + GO111MODULE: on + steps: + - name: Checkout Source + uses: actions/checkout@v3 + - name: Run Gosec Security Scanner + uses: securego/gosec@master + with: + args: ./... diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..38efb4ae --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,48 @@ +# Go test workflow +name: test + +on: + push: + branches: [ "master", "development" ] + pull_request: + branches: [ "master", "development" ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.19 + + - name: Build App + run: make build-app + + go-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.19 + + - name: Run Unit Tests + run: make test + + e2e-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.19 + + - name: Run E2E Integration Tests + run: make e2e-test diff --git a/Makefile b/Makefile index 5c9f4c2e..44a001cb 100644 --- a/Makefile +++ b/Makefile @@ -46,6 +46,10 @@ lint: @golangci-lint run +gosec: + @echo "$(GREEN) Running security scan with gosec...$(COLOR_END)" + gosec ./... + .PHONY: metric-docs metric-docs: build-app @echo "$(GREEN) Generating metric documentation...$(COLOR_END)" @@ -59,4 +63,4 @@ docker-build: .PHONY: docker-run docker-run: @echo "$(GREEN) Running docker image...$(COLOR_END)" - @docker run -p 8080:8080 -p 7300:7300 -e config.env $(APP_NAME) \ No newline at end of file + @docker run -p 8080:8080 -p 7300:7300 -e config.env $(APP_NAME) diff --git a/cmd/main.go b/cmd/main.go index a04139f1..b93a084e 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "os" + "path/filepath" "strings" "github.com/base-org/pessimism/cmd/doc" @@ -117,7 +118,7 @@ func fetchBootSessions(path string) ([]app.BootSession, error) { return nil, fmt.Errorf("invalid bootstrap file format; expected %s", extJSON) } - file, err := os.ReadFile(path) + file, err := os.ReadFile(filepath.Clean(path)) if err != nil { return nil, err } diff --git a/internal/api/server/server.go b/internal/api/server/server.go index 1bbf6ec7..bd43ebf5 100644 --- a/internal/api/server/server.go +++ b/internal/api/server/server.go @@ -66,11 +66,12 @@ func initializeServer(config *Config, handler http.Handler) *Server { return &Server{ Cfg: config, serverHTTP: &http.Server{ - Addr: fmt.Sprintf("%s:%d", config.Host, config.Port), - Handler: handler, - IdleTimeout: time.Duration(config.KeepAlive) * time.Second, - ReadTimeout: time.Duration(config.ReadTimeout) * time.Second, - WriteTimeout: time.Duration(config.WriteTimeout) * time.Second, + Addr: fmt.Sprintf("%s:%d", config.Host, config.Port), + Handler: handler, + IdleTimeout: time.Duration(config.KeepAlive) * time.Second, + ReadHeaderTimeout: time.Duration(config.ReadTimeout) * time.Second, + ReadTimeout: time.Duration(config.ReadTimeout) * time.Second, + WriteTimeout: time.Duration(config.WriteTimeout) * time.Second, }, } } diff --git a/internal/client/slack_client.go b/internal/client/slack_client.go index aee7c9da..e440fe33 100644 --- a/internal/client/slack_client.go +++ b/internal/client/slack_client.go @@ -13,6 +13,7 @@ import ( "net/http" "github.com/base-org/pessimism/internal/logging" + "go.uber.org/zap" ) // SlackClient ... Interface for slack client @@ -86,7 +87,13 @@ func (sc slackClient) PostData(ctx context.Context, str string) (*SlackAPIRespon if err != nil { return nil, err } - defer resp.Body.Close() + defer func() { + err := resp.Body.Close() + if err != nil { + logging.WithContext(ctx).Warn("Could not close slack response body", + zap.Error(err)) + } + }() // read response bytes, err := io.ReadAll(resp.Body)