diff --git a/.env.example b/.env.example index fdffdf154..bec7cae60 100644 --- a/.env.example +++ b/.env.example @@ -36,6 +36,11 @@ VELA_API=http://localhost:8080 # default: 30 # VELA_MAX_BUILD_LIMIT= +# customize the set of repos that are allowed to use schedules +# +# default: * +# VELA_SCHEDULE_ALLOWLIST= + ############################################################ # _______ _______ ______ __ __ _______ ______ # # | || || _ | | | | || || _ | # diff --git a/.github/README.md b/.github/README.md index 30a9fd391..e668cecb4 100644 --- a/.github/README.md +++ b/.github/README.md @@ -34,7 +34,7 @@ Please see our [support](SUPPORT.md) documentation for further instructions. ## Copyright and License ``` -Copyright (c) 2022 Target Brands, Inc. +Copyright 2019 Target Brands, Inc. ``` -[Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) +[Apache License, Version 2.0](../LICENSE) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bdbb9a8ca..18f2131d2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,10 +13,10 @@ jobs: steps: - name: clone - uses: actions/checkout@v3 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 - name: install go - uses: actions/setup-go@v4 + uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4 with: # use version from go.mod file go-version-file: 'go.mod' diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index ecc65e90c..7fedee4a2 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -35,11 +35,11 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v2 + uses: github/codeql-action/init@74483a38d39275f33fcff5f35b679b5ca4a26a99 # v2 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -50,7 +50,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@v2 + uses: github/codeql-action/autobuild@74483a38d39275f33fcff5f35b679b5ca4a26a99 # v2 # ℹī¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -64,4 +64,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 + uses: github/codeql-action/analyze@74483a38d39275f33fcff5f35b679b5ca4a26a99 # v2 diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index d339d45f6..6c6606aeb 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -15,7 +15,7 @@ jobs: services: postgres: - image: postgres:15-alpine@sha256:8bc3c893342c766481df5fde58fab6f1a1115b94eb56778126163305243e9709 + image: postgres:15-alpine@sha256:35ce2187f2f7fb75e8e79493e13743596c21eb3789ff41ece145ae04d06e93a5 env: POSTGRES_DB: vela POSTGRES_PASSWORD: notARealPassword12345 @@ -34,10 +34,10 @@ jobs: steps: - name: clone - uses: actions/checkout@v3 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 - name: install go - uses: actions/setup-go@v4 + uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4 with: # use version from go.mod file go-version-file: 'go.mod' diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml index fc792032f..0cdd28972 100644 --- a/.github/workflows/prerelease.yml +++ b/.github/workflows/prerelease.yml @@ -14,13 +14,13 @@ jobs: steps: - name: clone - uses: actions/checkout@v3 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 with: # ensures we fetch tag history for the repository fetch-depth: 0 - name: install go - uses: actions/setup-go@v4 + uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4 with: # use version from go.mod file go-version-file: 'go.mod' @@ -40,7 +40,7 @@ jobs: make build-static-ci - name: publish - uses: elgohr/Publish-Docker-Github-Action@v5 + uses: elgohr/Publish-Docker-Github-Action@eb53b3ec07136a6ebaed78d8135806da64f7c7e2 # v5 with: name: target/vela-server cache: true @@ -49,7 +49,7 @@ jobs: password: ${{ secrets.DOCKER_PASSWORD }} - name: publish-alpine - uses: elgohr/Publish-Docker-Github-Action@v5 + uses: elgohr/Publish-Docker-Github-Action@eb53b3ec07136a6ebaed78d8135806da64f7c7e2 # v5 with: name: target/vela-server cache: true diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index f90fb83b0..aec7f16ff 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -13,13 +13,13 @@ jobs: steps: - name: clone - uses: actions/checkout@v3 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 with: # ensures we fetch tag history for the repository fetch-depth: 0 - name: install go - uses: actions/setup-go@v4 + uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4 with: # use version from go.mod file go-version-file: 'go.mod' @@ -34,7 +34,7 @@ jobs: make build-static-ci - name: publish - uses: elgohr/Publish-Docker-Github-Action@v5 + uses: elgohr/Publish-Docker-Github-Action@eb53b3ec07136a6ebaed78d8135806da64f7c7e2 # v5 with: name: target/vela-server cache: true @@ -42,7 +42,7 @@ jobs: password: ${{ secrets.DOCKER_PASSWORD }} - name: publish-alpine - uses: elgohr/Publish-Docker-Github-Action@v5 + uses: elgohr/Publish-Docker-Github-Action@eb53b3ec07136a6ebaed78d8135806da64f7c7e2 # v5 with: name: target/vela-server cache: true diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/reviewdog.yml index 0a0027c70..c143ffcb1 100644 --- a/.github/workflows/reviewdog.yml +++ b/.github/workflows/reviewdog.yml @@ -12,10 +12,10 @@ jobs: steps: - name: clone - uses: actions/checkout@v3 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 - name: install go - uses: actions/setup-go@v4 + uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4 with: # use version from go.mod file go-version-file: 'go.mod' @@ -23,7 +23,7 @@ jobs: check-latest: true - name: golangci-lint - uses: reviewdog/action-golangci-lint@v2 + uses: reviewdog/action-golangci-lint@94d61e3205b61acf4ddabfeb13c5f8a13eb4167b # v2 with: github_token: ${{ secrets.github_token }} golangci_lint_flags: "--config=.golangci.yml" @@ -36,10 +36,10 @@ jobs: steps: - name: clone - uses: actions/checkout@v3 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 - name: install go - uses: actions/setup-go@v4 + uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4 with: # use version from go.mod file go-version-file: 'go.mod' @@ -47,7 +47,7 @@ jobs: check-latest: true - name: golangci-lint - uses: reviewdog/action-golangci-lint@v2 + uses: reviewdog/action-golangci-lint@94d61e3205b61acf4ddabfeb13c5f8a13eb4167b # v2 with: github_token: ${{ secrets.github_token }} golangci_lint_flags: "--config=.golangci.yml" diff --git a/.github/workflows/spec.yml b/.github/workflows/spec.yml index 32a3211be..edf87886f 100644 --- a/.github/workflows/spec.yml +++ b/.github/workflows/spec.yml @@ -13,10 +13,10 @@ jobs: steps: - name: clone - uses: actions/checkout@v3 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 - name: install go - uses: actions/setup-go@v4 + uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4 with: # use version from go.mod file go-version-file: 'go.mod' diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cdc0c6aa3..a21198941 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,10 +13,10 @@ jobs: steps: - name: clone - uses: actions/checkout@v3 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 - name: install go - uses: actions/setup-go@v4 + uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4 with: # use version from go.mod file go-version-file: 'go.mod' @@ -28,7 +28,7 @@ jobs: make test - name: coverage - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3 with: token: ${{ secrets.CODECOV_TOKEN }} file: coverage.out \ No newline at end of file diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index b2dec4a9d..15f2c7245 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -13,10 +13,10 @@ jobs: steps: - name: clone - uses: actions/checkout@v3 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 - name: install go - uses: actions/setup-go@v4 + uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4 with: # use version from go.mod file go-version-file: 'go.mod' diff --git a/.golangci.yml b/.golangci.yml index 00c50154f..48151b3e9 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -35,9 +35,7 @@ linters-settings: # https://github.com/denis-tingaikin/go-header goheader: template: |- - Copyright (c) {{ YEAR }} Target Brands, Inc. All rights reserved. - - Use of this source code is governed by the LICENSE file in this repository. + SPDX-License-Identifier: Apache-2.0 # https://github.com/client9/misspell misspell: diff --git a/Dockerfile b/Dockerfile index 8f86431d8..72b794ed1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,6 @@ -# Copyright (c) 2022 Target Brands, Inc. All rights reserved. -# -# Use of this source code is governed by the LICENSE file in this repository. +# SPDX-License-Identifier: Apache-2.0 -FROM alpine:3.18.3@sha256:c5c5fda71656f28e49ac9c5416b3643eaa6a108a8093151d6d1afc9463be8e33 as certs +FROM alpine:3.18.4@sha256:eece025e432126ce23f223450a0326fbebde39cdf496a85d8c016293fc851978 as certs RUN apk add --update --no-cache ca-certificates diff --git a/Dockerfile-alpine b/Dockerfile-alpine index 894752491..0e6d47c3f 100644 --- a/Dockerfile-alpine +++ b/Dockerfile-alpine @@ -1,8 +1,6 @@ -# Copyright (c) 2022 Target Brands, Inc. All rights reserved. -# -# Use of this source code is governed by the LICENSE file in this repository. +# SPDX-License-Identifier: Apache-2.0 -FROM alpine:3.18.3@sha256:c5c5fda71656f28e49ac9c5416b3643eaa6a108a8093151d6d1afc9463be8e33 +FROM alpine:3.18.4@sha256:eece025e432126ce23f223450a0326fbebde39cdf496a85d8c016293fc851978 RUN apk add --update --no-cache ca-certificates diff --git a/LICENSE b/LICENSE index 3abdb0366..1decd39ed 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright (c) 2022 Target Brands, Inc. + Copyright 2019 Target Brands, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/Makefile b/Makefile index f46e05a3f..811c60296 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,4 @@ -# Copyright (c) 2022 Target Brands, Inc. All rights reserved. -# -# Use of this source code is governed by the LICENSE file in this repository. +# SPDX-License-Identifier: Apache-2.0 # capture the current date we build the application from BUILD_DATE = $(shell date +%Y-%m-%dT%H:%M:%SZ) diff --git a/api/admin/build.go b/api/admin/build.go index 2be805ef2..a56cdbd16 100644 --- a/api/admin/build.go +++ b/api/admin/build.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore similar code package admin diff --git a/api/admin/clean.go b/api/admin/clean.go index 6ee9e7056..efe3819c6 100644 --- a/api/admin/clean.go +++ b/api/admin/clean.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package admin @@ -110,10 +108,20 @@ func CleanResources(c *gin.Context) { logrus.Infof("platform admin %s: cleaned %d builds in database", u.GetName(), builds) + // clean executables + executables, err := database.FromContext(c).CleanBuildExecutables(ctx) + if err != nil { + retErr := fmt.Errorf("%d builds cleaned. unable to clean build executables: %w", builds, err) + + util.HandleError(c, http.StatusInternalServerError, retErr) + + return + } + // clean services services, err := database.FromContext(c).CleanServices(ctx, msg, before) if err != nil { - retErr := fmt.Errorf("%d builds cleaned. unable to update services: %w", builds, err) + retErr := fmt.Errorf("%d builds cleaned. %d executables cleaned. unable to update services: %w", builds, executables, err) util.HandleError(c, http.StatusInternalServerError, retErr) @@ -125,7 +133,7 @@ func CleanResources(c *gin.Context) { // clean steps steps, err := database.FromContext(c).CleanSteps(msg, before) if err != nil { - retErr := fmt.Errorf("%d builds cleaned. %d services cleaned. unable to update steps: %w", builds, services, err) + retErr := fmt.Errorf("%d builds cleaned. %d executables cleaned. %d services cleaned. unable to update steps: %w", builds, executables, services, err) util.HandleError(c, http.StatusInternalServerError, retErr) @@ -134,5 +142,5 @@ func CleanResources(c *gin.Context) { logrus.Infof("platform admin %s: cleaned %d steps in database", u.GetName(), steps) - c.JSON(http.StatusOK, fmt.Sprintf("%d builds cleaned. %d services cleaned. %d steps cleaned.", builds, services, steps)) + c.JSON(http.StatusOK, fmt.Sprintf("%d builds cleaned. %d executables cleaned. %d services cleaned. %d steps cleaned.", builds, executables, services, steps)) } diff --git a/api/admin/deployment.go b/api/admin/deployment.go index 063407b6d..deeac0045 100644 --- a/api/admin/deployment.go +++ b/api/admin/deployment.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package admin diff --git a/api/admin/doc.go b/api/admin/doc.go index 565520dbf..31152b484 100644 --- a/api/admin/doc.go +++ b/api/admin/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package admin provides the admin handlers for the Vela API. // diff --git a/api/admin/hook.go b/api/admin/hook.go index 7cdf2c5e4..4336a0744 100644 --- a/api/admin/hook.go +++ b/api/admin/hook.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore similar code package admin diff --git a/api/admin/repo.go b/api/admin/repo.go index b24fb7013..11814a8a0 100644 --- a/api/admin/repo.go +++ b/api/admin/repo.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore similar code package admin diff --git a/api/admin/secret.go b/api/admin/secret.go index b2f6d4a52..9c00c830c 100644 --- a/api/admin/secret.go +++ b/api/admin/secret.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore similar code package admin diff --git a/api/admin/service.go b/api/admin/service.go index b80c71a80..190d4f902 100644 --- a/api/admin/service.go +++ b/api/admin/service.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore similar code package admin diff --git a/api/admin/step.go b/api/admin/step.go index 2da12ece1..88204ca45 100644 --- a/api/admin/step.go +++ b/api/admin/step.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore similar code package admin diff --git a/api/admin/user.go b/api/admin/user.go index 9893c0250..416cd2e09 100644 --- a/api/admin/user.go +++ b/api/admin/user.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore similar code package admin diff --git a/api/admin/worker.go b/api/admin/worker.go index 8c0f9978a..1966d7d25 100644 --- a/api/admin/worker.go +++ b/api/admin/worker.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package admin diff --git a/api/auth/doc.go b/api/auth/doc.go index c200b5faf..365c84f57 100644 --- a/api/auth/doc.go +++ b/api/auth/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package auth provides the auth handlers (authenticate, login, ...) for the Vela API. // diff --git a/api/auth/get_token.go b/api/auth/get_token.go index 81f632f4d..16b4334ae 100644 --- a/api/auth/get_token.go +++ b/api/auth/get_token.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package auth @@ -72,7 +70,7 @@ func GetAuthToken(c *gin.Context) { code := c.Request.FormValue("code") if len(code) == 0 { // start the initial OAuth workflow - oAuthState, err = scm.FromContext(c).Login(c.Writer, c.Request) + oAuthState, err = scm.FromContext(c).Login(ctx, c.Writer, c.Request) if err != nil { retErr := fmt.Errorf("unable to login user: %w", err) @@ -83,7 +81,7 @@ func GetAuthToken(c *gin.Context) { } // complete the OAuth workflow and authenticates the user - newUser, err := scm.FromContext(c).Authenticate(c.Writer, c.Request, oAuthState) + newUser, err := scm.FromContext(c).Authenticate(ctx, c.Writer, c.Request, oAuthState) if err != nil { retErr := fmt.Errorf("unable to authenticate user: %w", err) diff --git a/api/auth/login.go b/api/auth/login.go index 36b977009..041d844f3 100644 --- a/api/auth/login.go +++ b/api/auth/login.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package auth diff --git a/api/auth/logout.go b/api/auth/logout.go index a496f15cd..454d2b9ed 100644 --- a/api/auth/logout.go +++ b/api/auth/logout.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package auth diff --git a/api/auth/post_token.go b/api/auth/post_token.go index 55fe47fdf..2f68af691 100644 --- a/api/auth/post_token.go +++ b/api/auth/post_token.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package auth @@ -53,7 +51,7 @@ func PostAuthToken(c *gin.Context) { ctx := c.Request.Context() // attempt to get user from source - u, err := scm.FromContext(c).AuthenticateToken(c.Request) + u, err := scm.FromContext(c).AuthenticateToken(ctx, c.Request) if err != nil { retErr := fmt.Errorf("unable to authenticate user: %w", err) diff --git a/api/auth/redirect.go b/api/auth/redirect.go index 32b486393..473c7a612 100644 --- a/api/auth/redirect.go +++ b/api/auth/redirect.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package auth diff --git a/api/auth/refresh.go b/api/auth/refresh.go index 0c12425cc..65a7626b7 100644 --- a/api/auth/refresh.go +++ b/api/auth/refresh.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package auth diff --git a/api/auth/validate.go b/api/auth/validate.go index d78057193..6485fe9f9 100644 --- a/api/auth/validate.go +++ b/api/auth/validate.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package auth diff --git a/api/auth/validate_oauth.go b/api/auth/validate_oauth.go new file mode 100644 index 000000000..5a31c0069 --- /dev/null +++ b/api/auth/validate_oauth.go @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: Apache-2.0 + +package auth + +import ( + "fmt" + "net/http" + + "github.com/gin-gonic/gin" + "github.com/go-vela/server/scm" + "github.com/go-vela/server/util" +) + +// swagger:operation GET /validate-oauth authenticate ValidateOAuthToken +// +// Validate that a user oauth token was created by Vela +// +// --- +// produces: +// - application/json +// parameters: +// - in: header +// name: Token +// type: string +// required: true +// description: > +// OAuth integration user access token +// responses: +// '200': +// description: Successfully validated +// schema: +// "$ref": "#/definitions/Token" +// '401': +// description: Unable to validate +// schema: +// "$ref": "#/definitions/Error" + +// ValidateOAuthToken represents the API handler to +// validate that a user oauth token was created by Vela. +func ValidateOAuthToken(c *gin.Context) { + // capture middleware values + ctx := c.Request.Context() + + token := c.Request.Header.Get("Token") + if len(token) == 0 { + retErr := fmt.Errorf("unable to validate oauth token: no token provided in header") + + util.HandleError(c, http.StatusUnauthorized, retErr) + + return + } + + // attempt to validate access token from source OAuth app + ok, err := scm.FromContext(c).ValidateOAuthToken(ctx, token) + if err != nil { + retErr := fmt.Errorf("unable to validate oauth token: %w", err) + + util.HandleError(c, http.StatusUnauthorized, retErr) + + return + } + + if !ok { + retErr := fmt.Errorf("oauth token was not created by vela") + + util.HandleError(c, http.StatusUnauthorized, retErr) + + return + } + + // return a 200 indicating token is valid and created by the server's OAuth app + c.JSON(http.StatusOK, "oauth token was created by vela") +} diff --git a/api/badge.go b/api/badge.go index bb84d2c48..df4fcd97a 100644 --- a/api/badge.go +++ b/api/badge.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package api diff --git a/api/build/auto_cancel.go b/api/build/auto_cancel.go new file mode 100644 index 000000000..9ffb32b26 --- /dev/null +++ b/api/build/auto_cancel.go @@ -0,0 +1,187 @@ +// SPDX-License-Identifier: Apache-2.0 + +package build + +import ( + "context" + "encoding/json" + "fmt" + "io" + "net/http" + "strings" + "time" + + "github.com/gin-gonic/gin" + "github.com/go-vela/server/database" + "github.com/go-vela/server/internal/token" + "github.com/go-vela/types/constants" + "github.com/go-vela/types/library" + "github.com/go-vela/types/pipeline" +) + +// AutoCancel is a helper function that checks to see if any pending or running +// builds for the repo can be replaced by the current build. +func AutoCancel(c *gin.Context, b *library.Build, rB *library.Build, r *library.Repo, cancelOpts *pipeline.CancelOptions) (bool, error) { + // if build is the current build, continue + if rB.GetID() == b.GetID() { + return false, nil + } + + // ensure criteria is met before auto canceling (push to same branch, or pull with same action from same head_ref) + if (strings.EqualFold(rB.GetEvent(), constants.EventPush) && + strings.EqualFold(b.GetEvent(), constants.EventPush) && + strings.EqualFold(b.GetBranch(), rB.GetBranch())) || + (strings.EqualFold(rB.GetEvent(), constants.EventPull) && + strings.EqualFold(b.GetEventAction(), rB.GetEventAction()) && + strings.EqualFold(b.GetHeadRef(), rB.GetHeadRef())) { + switch { + case strings.EqualFold(rB.GetStatus(), constants.StatusPending) && cancelOpts.Pending: + // pending build will be handled gracefully by worker once pulled off queue + rB.SetStatus(constants.StatusCanceled) + + _, err := database.FromContext(c).UpdateBuild(c, rB) + if err != nil { + return false, err + } + + // remove executable from table + _, err = database.FromContext(c).PopBuildExecutable(c, rB.GetID()) + if err != nil { + return true, err + } + case strings.EqualFold(rB.GetStatus(), constants.StatusRunning) && cancelOpts.Running: + // call cancelRunning routine for builds already running on worker + err := cancelRunning(c, rB, r) + if err != nil { + return false, err + } + default: + return false, nil + } + + // set error message that references current build + rB.SetError(fmt.Sprintf("build was auto canceled in favor of build %d", b.GetNumber())) + + _, err := database.FromContext(c).UpdateBuild(c, rB) + if err != nil { + // if this call fails, we still canceled the build, so return true + return true, err + } + } + + return true, nil +} + +// cancelRunning is a helper function that determines the executor currently running a build and sends an API call +// to that executor's worker to cancel the build. +func cancelRunning(c *gin.Context, b *library.Build, r *library.Repo) error { + e := new([]library.Executor) + // retrieve the worker + w, err := database.FromContext(c).GetWorkerForHostname(c, b.GetHost()) + if err != nil { + return err + } + + // prepare the request to the worker to retrieve executors + client := http.DefaultClient + client.Timeout = 30 * time.Second + endpoint := fmt.Sprintf("%s/api/v1/executors", w.GetAddress()) + + req, err := http.NewRequestWithContext(context.Background(), "GET", endpoint, nil) + if err != nil { + return err + } + + tm := c.MustGet("token-manager").(*token.Manager) + + // set mint token options + mto := &token.MintTokenOpts{ + Hostname: "vela-server", + TokenType: constants.WorkerAuthTokenType, + TokenDuration: time.Minute * 1, + } + + // mint token + tkn, err := tm.MintToken(mto) + if err != nil { + return err + } + + // add the token to authenticate to the worker + req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", tkn)) + + // make the request to the worker and check the response + resp, err := client.Do(req) + if err != nil { + return err + } + + defer resp.Body.Close() + + // Read Response Body + respBody, err := io.ReadAll(resp.Body) + if err != nil { + return err + } + + // parse response and validate at least one item was returned + err = json.Unmarshal(respBody, e) + if err != nil { + return err + } + + for _, executor := range *e { + // check each executor on the worker running the build to see if it's running the build we want to cancel + if strings.EqualFold(executor.Repo.GetFullName(), r.GetFullName()) && *executor.GetBuild().Number == b.GetNumber() { + // prepare the request to the worker + client := http.DefaultClient + client.Timeout = 30 * time.Second + + // set the API endpoint path we send the request to + u := fmt.Sprintf("%s/api/v1/executors/%d/build/cancel", w.GetAddress(), executor.GetID()) + + req, err := http.NewRequestWithContext(context.Background(), "DELETE", u, nil) + if err != nil { + return err + } + + tm := c.MustGet("token-manager").(*token.Manager) + + // set mint token options + mto := &token.MintTokenOpts{ + Hostname: "vela-server", + TokenType: constants.WorkerAuthTokenType, + TokenDuration: time.Minute * 1, + } + + // mint token + tkn, err := tm.MintToken(mto) + if err != nil { + return err + } + + // add the token to authenticate to the worker + req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", tkn)) + + // perform the request to the worker + resp, err := client.Do(req) + if err != nil { + return err + } + defer resp.Body.Close() + + // Read Response Body + respBody, err := io.ReadAll(resp.Body) + if err != nil { + return err + } + + err = json.Unmarshal(respBody, b) + if err != nil { + return err + } + } + } + + return nil +} diff --git a/api/build/cancel.go b/api/build/cancel.go index 7d5bff144..e8cd19264 100644 --- a/api/build/cancel.go +++ b/api/build/cancel.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build @@ -79,7 +77,7 @@ func CancelBuild(c *gin.Context) { e := executors.Retrieve(c) o := org.Retrieve(c) r := repo.Retrieve(c) - u := user.Retrieve(c) + user := user.Retrieve(c) ctx := c.Request.Context() entry := fmt.Sprintf("%s/%d", r.GetFullName(), b.GetNumber()) @@ -91,7 +89,7 @@ func CancelBuild(c *gin.Context) { "build": b.GetNumber(), "org": o, "repo": r.GetName(), - "user": u.GetName(), + "user": user.GetName(), }).Infof("canceling build %s", entry) switch b.GetStatus() { @@ -171,6 +169,16 @@ func CancelBuild(c *gin.Context) { return } + b.SetError(fmt.Sprintf("build was canceled by %s", user.GetName())) + + b, err = database.FromContext(c).UpdateBuild(ctx, b) + if err != nil { + retErr := fmt.Errorf("unable to update status for build %s: %w", entry, err) + util.HandleError(c, http.StatusInternalServerError, retErr) + + return + } + c.JSON(resp.StatusCode, b) return @@ -199,6 +207,15 @@ func CancelBuild(c *gin.Context) { return } + // remove build executable for clean up + _, err = database.FromContext(c).PopBuildExecutable(ctx, b.GetID()) + if err != nil { + retErr := fmt.Errorf("unable to pop build %s from executables table: %w", entry, err) + util.HandleError(c, http.StatusInternalServerError, retErr) + + return + } + // retrieve the steps for the build from the step table steps := []*library.Step{} page := 1 diff --git a/api/build/clean.go b/api/build/clean.go index 475525f98..e830c48a9 100644 --- a/api/build/clean.go +++ b/api/build/clean.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/api/build/create.go b/api/build/create.go index 9d75a4ef0..a90ca549a 100644 --- a/api/build/create.go +++ b/api/build/create.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build @@ -184,7 +182,7 @@ func CreateBuild(c *gin.Context) { if !strings.EqualFold(input.GetEvent(), constants.EventComment) && !strings.EqualFold(input.GetEvent(), constants.EventPull) { // send API call to capture list of files changed for the commit - files, err = scm.FromContext(c).Changeset(u, r, input.GetCommit()) + files, err = scm.FromContext(c).Changeset(ctx, u, r, input.GetCommit()) if err != nil { retErr := fmt.Errorf("unable to create new build: failed to get changeset for %s: %w", r.GetFullName(), err) @@ -207,7 +205,7 @@ func CreateBuild(c *gin.Context) { } // send API call to capture list of files changed for the pull request - files, err = scm.FromContext(c).ChangesetPR(u, r, number) + files, err = scm.FromContext(c).ChangesetPR(ctx, u, r, number) if err != nil { retErr := fmt.Errorf("unable to create new build: failed to get changeset for %s: %w", r.GetFullName(), err) @@ -232,7 +230,7 @@ func CreateBuild(c *gin.Context) { pipeline, err = database.FromContext(c).GetPipelineForRepo(ctx, input.GetCommit(), r) if err != nil { // assume the pipeline doesn't exist in the database yet // send API call to capture the pipeline configuration file - config, err = scm.FromContext(c).ConfigBackoff(u, r, input.GetCommit()) + config, err = scm.FromContext(c).ConfigBackoff(ctx, u, r, input.GetCommit()) if err != nil { retErr := fmt.Errorf("unable to create new build: failed to get pipeline configuration for %s: %w", r.GetFullName(), err) @@ -286,7 +284,7 @@ func CreateBuild(c *gin.Context) { input.SetStatus(constants.StatusSuccess) // send API call to set the status on the commit - err = scm.FromContext(c).Status(u, input, r.GetOrg(), r.GetName()) + err = scm.FromContext(c).Status(ctx, u, input, r.GetOrg(), r.GetName()) if err != nil { logger.Errorf("unable to set commit status for %s/%d: %v", r.GetFullName(), input.GetNumber(), err) } @@ -342,7 +340,7 @@ func CreateBuild(c *gin.Context) { c.JSON(http.StatusCreated, input) // send API call to set the status on the commit - err = scm.FromContext(c).Status(u, input, r.GetOrg(), r.GetName()) + err = scm.FromContext(c).Status(ctx, u, input, r.GetOrg(), r.GetName()) if err != nil { logger.Errorf("unable to set commit status for build %s/%d: %v", r.GetFullName(), input.GetNumber(), err) } diff --git a/api/build/delete.go b/api/build/delete.go index ffc9a7ac4..c1ce1de82 100644 --- a/api/build/delete.go +++ b/api/build/delete.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/api/build/doc.go b/api/build/doc.go index 94b6571e3..5fc6778e6 100644 --- a/api/build/doc.go +++ b/api/build/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package build provides the build handlers for the Vela API. // diff --git a/api/build/executable.go b/api/build/executable.go index 17ca1c082..e7cd2c291 100644 --- a/api/build/executable.go +++ b/api/build/executable.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/api/build/get.go b/api/build/get.go index 7e476441e..135ca1bb4 100644 --- a/api/build/get.go +++ b/api/build/get.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/api/build/get_id.go b/api/build/get_id.go index 439cd9b81..90237c420 100644 --- a/api/build/get_id.go +++ b/api/build/get_id.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build @@ -101,7 +99,7 @@ func GetBuildByID(c *gin.Context) { // Capture user access from SCM. We do this in order to ensure user has access and is not // just retrieving any build using a random id number. - perm, err := scm.FromContext(c).RepoAccess(u, u.GetToken(), r.GetOrg(), r.GetName()) + perm, err := scm.FromContext(c).RepoAccess(ctx, u, u.GetToken(), r.GetOrg(), r.GetName()) if err != nil { logrus.Errorf("unable to get user %s access level for repo %s", u.GetName(), r.GetFullName()) } diff --git a/api/build/graph.go b/api/build/graph.go new file mode 100644 index 000000000..bc1c26319 --- /dev/null +++ b/api/build/graph.go @@ -0,0 +1,616 @@ +// SPDX-License-Identifier: Apache-2.0 + +package build + +import ( + "fmt" + "net/http" + "strings" + + "github.com/gin-gonic/gin" + "github.com/go-vela/server/compiler" + "github.com/go-vela/server/database" + "github.com/go-vela/server/router/middleware/build" + "github.com/go-vela/server/router/middleware/org" + "github.com/go-vela/server/router/middleware/repo" + "github.com/go-vela/server/router/middleware/user" + "github.com/go-vela/server/scm" + "github.com/go-vela/server/util" + "github.com/go-vela/types" + "github.com/go-vela/types/constants" + "github.com/go-vela/types/library" + "github.com/go-vela/types/pipeline" + "github.com/sirupsen/logrus" +) + +// Graph contains nodes, and relationships between nodes, or edges. +// +// a node is a pipeline stage and its relevant steps. +// an edge is a relationship between nodes, defined by the 'needs' tag. +// +// swagger:model Graph +type Graph struct { + BuildID int64 `json:"build_id"` + BuildNumber int `json:"build_number"` + Org string `json:"org"` + Repo string `json:"repo"` + Nodes map[int]*node `json:"nodes"` + Edges []*edge `json:"edges"` +} + +// node represents a pipeline stage and its relevant steps. +type node struct { + ID int `json:"id"` + Cluster int `json:"cluster"` + Name string `json:"name"` + + // vela metadata + Status string `json:"status"` + StartedAt int `json:"started_at"` + FinishedAt int `json:"finished_at"` + Steps []*library.Step `json:"steps"` + + // unexported data used for building edges + Stage *pipeline.Stage `json:"-"` +} + +// edge represents a relationship between nodes, primarily defined by a stage 'needs' tag. +type edge struct { + Cluster int `json:"cluster"` + Source int `json:"source"` + Destination int `json:"destination"` + + // vela metadata + Status string `json:"status"` +} + +// stg represents a stage's steps and some metadata for producing node/edge information. +type stg struct { + steps []*library.Step + // used for tracking stage status + success int + running int + failure int + killed int + canceled int + skipped int + errored int + startedAt int + finishedAt int +} + +const ( + // clusters determine graph orientation. + BuiltInCluster = 2 + PipelineCluster = 1 + ServiceCluster = 0 + GraphComplexityLimit = 1000 // arbitrary value to limit render complexity. +) + +// swagger:operation GET /api/v1/repos/{org}/{repo}/builds/{build}/graph builds GetBuildGraph +// +// Get directed a-cyclical graph for a build in the configured backend +// +// --- +// produces: +// - application/json +// parameters: +// - in: path +// name: org +// description: Name of the org +// required: true +// type: string +// - in: path +// name: repo +// description: Name of the repo +// required: true +// type: string +// - in: path +// name: build +// description: Build number +// required: true +// type: integer +// security: +// - ApiKeyAuth: [] +// responses: +// '200': +// description: Successfully retrieved graph for the build +// type: json +// schema: +// "$ref": "#/definitions/Graph" +// '401': +// description: Unable to retrieve graph for the build — unauthorized +// schema: +// "$ref": "#/definitions/Error" +// '404': +// description: Unable to retrieve graph for the build — not found +// schema: +// "$ref": "#/definitions/Error" +// '500': +// description: Unable to retrieve graph for the build +// schema: +// "$ref": "#/definitions/Error" + +// GetBuildGraph represents the API handler to capture a +// directed a-cyclical graph for a build from the configured backend. +// +//nolint:funlen,goconst,gocyclo // ignore function length and constants +func GetBuildGraph(c *gin.Context) { + // capture middleware values + b := build.Retrieve(c) + o := org.Retrieve(c) + r := repo.Retrieve(c) + u := user.Retrieve(c) + m := c.MustGet("metadata").(*types.Metadata) + ctx := c.Request.Context() + + // update engine logger with API metadata + // + // https://pkg.go.dev/github.com/sirupsen/logrus?tab=doc#Entry.WithFields + entry := fmt.Sprintf("%s/%d", r.GetFullName(), b.GetNumber()) + logger := logrus.WithFields(logrus.Fields{ + "build": b.GetNumber(), + "org": o, + "repo": r.GetName(), + "user": u.GetName(), + }) + + baseErr := "unable to retrieve graph" + + logger.Infof("constructing graph for build %s", entry) + + logger.Info("retrieving pipeline configuration") + + var config []byte + + lp, err := database.FromContext(c).GetPipelineForRepo(ctx, b.GetCommit(), r) + if err != nil { // assume the pipeline doesn't exist in the database yet (before pipeline support was added) + // send API call to capture the pipeline configuration file + config, err = scm.FromContext(c).ConfigBackoff(ctx, u, r, b.GetCommit()) + if err != nil { + retErr := fmt.Errorf("unable to get pipeline configuration for %s: %w", r.GetFullName(), err) + + util.HandleError(c, http.StatusNotFound, retErr) + + return + } + } else { + config = lp.GetData() + } + + if config == nil { + retErr := fmt.Errorf("unable to get pipeline configuration for %s: config is nil", r.GetFullName()) + + util.HandleError(c, http.StatusNotFound, retErr) + + return + } + + // variable to store changeset files + var files []string + // check if the build event is not issue_comment + if !strings.EqualFold(b.GetEvent(), constants.EventComment) { + // check if the build event is not pull_request + if !strings.EqualFold(b.GetEvent(), constants.EventPull) { + // send API call to capture list of files changed for the commit + files, err = scm.FromContext(c).Changeset(ctx, u, r, b.GetCommit()) + if err != nil { + retErr := fmt.Errorf("%s: failed to get changeset for %s: %w", baseErr, r.GetFullName(), err) + + util.HandleError(c, http.StatusInternalServerError, retErr) + + return + } + } + } + + logger.Info("compiling pipeline configuration") + + // parse and compile the pipeline configuration file + p, _, err := compiler.FromContext(c). + Duplicate(). + WithBuild(b). + WithFiles(files). + WithCommit(b.GetCommit()). + WithMetadata(m). + WithRepo(r). + WithUser(u). + Compile(config) + if err != nil { + // format the error message with extra information + err = fmt.Errorf("unable to compile pipeline configuration for %s: %w", r.GetFullName(), err) + + logger.Error(err.Error()) + + retErr := fmt.Errorf("%s: %w", baseErr, err) + + util.HandleError(c, http.StatusInternalServerError, retErr) + + return + } + + // skip the build if only the init or clone steps are found + skip := SkipEmptyBuild(p) + if skip != "" { + c.JSON(http.StatusOK, skip) + return + } + + // retrieve the steps for the build from the step table + steps := []*library.Step{} + page := 1 + perPage := 100 + + // only fetch steps when necessary + if len(p.Stages) > 0 || len(p.Steps) > 0 { + for page > 0 { + // retrieve build steps (per page) from the database + stepsPart, stepsCount, err := database.FromContext(c).ListStepsForBuild(b, nil, page, perPage) + if err != nil { + retErr := fmt.Errorf("unable to retrieve steps for build %s: %w", entry, err) + + util.HandleError(c, http.StatusNotFound, retErr) + + return + } + + // add page of steps to list steps + steps = append(steps, stepsPart...) + + // assume no more pages exist if under 100 results are returned + if int(stepsCount) < perPage { + page = 0 + } else { + page++ + } + } + } + + if len(steps) == 0 { + retErr := fmt.Errorf("no steps found for build %s", entry) + + util.HandleError(c, http.StatusNotFound, retErr) + + return + } + + // retrieve the services for the build from the service table + services := []*library.Service{} + page = 1 + perPage = 100 + + // only fetch services when necessary + if len(p.Services) > 0 { + for page > 0 { + // retrieve build services (per page) from the database + servicesPart, servicesCount, err := database.FromContext(c).ListServicesForBuild(ctx, b, nil, page, perPage) + if err != nil { + retErr := fmt.Errorf("unable to retrieve services for build %s: %w", entry, err) + + util.HandleError(c, http.StatusNotFound, retErr) + + return + } + + // add page of services to list services + services = append(services, servicesPart...) + + // assume no more pages exist if under 100 results are returned + if int(servicesCount) < perPage { + page = 0 + } else { + page++ + } + } + } + + // this is a simple check + // but it will save on processing a massive build that should not be rendered + complexity := len(steps) + len(p.Stages) + len(services) + if complexity > GraphComplexityLimit { + c.JSON(http.StatusInternalServerError, "build is too complex, too many resources") + return + } + + logger.Info("generating build graph") + + // create nodes from pipeline stages + nodes := make(map[int]*node) + + // create edges from nodes + // an edge is as a relationship between two nodes + // that is defined by the 'needs' tag + edges := []*edge{} + + // initialize a map for grouping steps by stage name + // and tracking stage information + stageMap := map[string]*stg{} + + // build a map for step_id to pipeline step + stepMap := map[int]*pipeline.Container{} + + for _, pStep := range p.Steps { + stepMap[pStep.Number] = pStep + } + + for _, pStage := range p.Stages { + for _, pStep := range pStage.Steps { + stepMap[pStep.Number] = pStep + } + } + + for _, step := range steps { + name := step.GetStage() + if len(name) == 0 { + name = step.GetName() + } + + // initialize a stage tracker + if _, ok := stageMap[name]; !ok { + stageMap[name] = &stg{ + steps: []*library.Step{}, + } + } + + // retrieve the stage to update + s := stageMap[name] + + // count each step status + switch step.GetStatus() { + case constants.StatusRunning: + s.running++ + case constants.StatusSuccess: + s.success++ + case constants.StatusFailure: + stp, ok := stepMap[step.GetNumber()] + if ok && stp.Ruleset.Continue { + s.success++ + } else { + s.failure++ + } + case constants.StatusKilled: + s.killed++ + case constants.StatusCanceled: + s.canceled++ + case constants.StatusSkipped: + s.skipped++ + case constants.StatusError: + s.errored++ + default: + } + + // keep track of the widest time window possible + if s.finishedAt == 0 || s.finishedAt < int(step.GetFinished()) { + s.finishedAt = int(step.GetFinished()) + } + + if s.startedAt == 0 || s.startedAt > int(step.GetStarted()) { + s.startedAt = int(step.GetStarted()) + } + + s.steps = append(s.steps, step) + } + + // construct services nodes separately + // services are grouped via cluster and manually-constructed edges + for _, service := range services { + // create the node + nodeID := len(nodes) + node := nodeFromService(nodeID, service) + nodes[nodeID] = node + + // create a sequential edge for nodes after the first + if nodeID > 0 { + edge := &edge{ + Cluster: ServiceCluster, + Source: nodeID - 1, + Destination: nodeID, + Status: service.GetStatus(), + } + edges = append(edges, edge) + } + } + + // construct pipeline stages nodes when stages exist + for _, stage := range p.Stages { + // scrub the environment + for _, step := range stage.Steps { + step.Environment = nil + } + + // create the node + nodeID := len(nodes) + + cluster := PipelineCluster + + // override the cluster id for built-in nodes + // this allows for better layout control because all stages need 'clone' + if stage.Name == "init" { + cluster = BuiltInCluster + } + + if stage.Name == "clone" { + cluster = BuiltInCluster + } + + node := nodeFromStage(nodeID, cluster, stage, stageMap[stage.Name]) + nodes[nodeID] = node + } + + // create single-step stages when no stages exist + if len(p.Stages) == 0 { + for _, step := range p.Steps { + // scrub the environment + step.Environment = nil + + // mock stage for edge creation + stage := &pipeline.Stage{ + Name: step.Name, + Needs: []string{}, + } + + // create the node + nodeID := len(nodes) + + // no built-in step separation for graphs without stages + cluster := PipelineCluster + + node := nodeFromStage(nodeID, cluster, stage, stageMap[stage.Name]) + nodes[nodeID] = node + } + } + + // loop over all nodes and create edges based on 'needs' + for _, destinationNode := range nodes { + // if theres no stage, skip because the edge is already created + if destinationNode.Stage == nil { + continue + } + + // compare all nodes against all nodes + for _, sourceNode := range nodes { + if sourceNode.Stage == nil { + continue + } + + // create a sequential edge for built-in nodes + if sourceNode.Cluster == BuiltInCluster && + destinationNode.Cluster == BuiltInCluster && + sourceNode.ID < destinationNode.ID && + destinationNode.ID-sourceNode.ID == 1 { + edge := &edge{ + Cluster: sourceNode.Cluster, + Source: sourceNode.ID, + Destination: destinationNode.ID, + Status: sourceNode.Status, + } + edges = append(edges, edge) + } + + // skip normal processing for built-in nodes + if destinationNode.Cluster == BuiltInCluster || + sourceNode.Cluster == BuiltInCluster { + continue + } + + // dont compare the same node + if destinationNode.ID == sourceNode.ID { + continue + } + + // use needs to create an edge + if len((*destinationNode.Stage).Needs) > 0 { + // check destination node needs + for _, need := range (*destinationNode.Stage).Needs { + // all stages need "clone" + if need == "clone" { + continue + } + + // check destination needs source stage + if sourceNode.Stage.Name != need { + continue + } + + // create an edge for source->destination + edge := &edge{ + Cluster: sourceNode.Cluster, + Source: sourceNode.ID, + Destination: destinationNode.ID, + Status: sourceNode.Status, + } + edges = append(edges, edge) + } + } else { + // create an edge for source->next + edge := &edge{ + Cluster: sourceNode.Cluster, + Source: sourceNode.ID, + Destination: sourceNode.ID + 1, + Status: sourceNode.Status, + } + edges = append(edges, edge) + } + } + } + + // validate the generated graph's complexity is beneath the limit + if len(nodes)+len(edges) > GraphComplexityLimit { + c.JSON(http.StatusInternalServerError, "graph is too complex, too many nodes and edges") + return + } + + // construct the response + graph := Graph{ + BuildID: b.GetID(), + BuildNumber: b.GetNumber(), + Org: r.GetOrg(), + Repo: r.GetName(), + Nodes: nodes, + Edges: edges, + } + + c.JSON(http.StatusOK, graph) +} + +// nodeFromStage returns a new node from a stage. +func nodeFromStage(nodeID, cluster int, stage *pipeline.Stage, s *stg) *node { + return &node{ + ID: nodeID, + Cluster: cluster, + Name: stage.Name, + Stage: stage, + Steps: s.steps, + Status: s.GetOverallStatus(), + StartedAt: s.startedAt, + FinishedAt: s.finishedAt, + } +} + +// nodeFromService returns a new node from a service. +func nodeFromService(nodeID int, service *library.Service) *node { + return &node{ + ID: nodeID, + Cluster: ServiceCluster, + Name: service.GetName(), + Stage: nil, + Steps: []*library.Step{}, + Status: service.GetStatus(), + StartedAt: int(service.GetStarted()), + FinishedAt: int(service.GetFinished()), + } +} + +// GetOverallStatus determines the "status" for a stage based on the steps within it. +// this could potentially get complicated with ruleset logic (continue/detach). +func (s *stg) GetOverallStatus() string { + if s.running > 0 { + return constants.StatusRunning + } + + if s.failure > 0 { + return constants.StatusFailure + } + + if s.errored > 0 { + return constants.StatusError + } + + if s.killed >= len(s.steps) { + return constants.StatusKilled + } + + if s.skipped > 0 { + return constants.StatusSkipped + } + + if s.success > 0 { + return constants.StatusSuccess + } + + if s.canceled > 0 { + return constants.StatusCanceled + } + + return constants.StatusPending +} diff --git a/api/build/list_org.go b/api/build/list_org.go index 3ab3bf9d3..aa495087e 100644 --- a/api/build/list_org.go +++ b/api/build/list_org.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build @@ -190,7 +188,7 @@ func ListBuildsForOrg(c *gin.Context) { perPage = util.MaxInt(1, util.MinInt(100, perPage)) // See if the user is an org admin to bypass individual permission checks - perm, err := scm.FromContext(c).OrgAccess(u, o) + perm, err := scm.FromContext(c).OrgAccess(ctx, u, o) if err != nil { logrus.Errorf("unable to get user %s access level for org %s", u.GetName(), o) } diff --git a/api/build/list_repo.go b/api/build/list_repo.go index 1fb701dc5..e6b043afd 100644 --- a/api/build/list_repo.go +++ b/api/build/list_repo.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/api/build/plan.go b/api/build/plan.go index a6a812b2c..1c546e095 100644 --- a/api/build/plan.go +++ b/api/build/plan.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/api/build/publish.go b/api/build/publish.go index 3cf20ff02..1499fe540 100644 --- a/api/build/publish.go +++ b/api/build/publish.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/api/build/restart.go b/api/build/restart.go index 8fa21c0ca..9867a626f 100644 --- a/api/build/restart.go +++ b/api/build/restart.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build @@ -177,7 +175,7 @@ func RestartBuild(c *gin.Context) { if !strings.EqualFold(b.GetEvent(), constants.EventComment) && !strings.EqualFold(b.GetEvent(), constants.EventPull) { // send API call to capture list of files changed for the commit - files, err = scm.FromContext(c).Changeset(u, r, b.GetCommit()) + files, err = scm.FromContext(c).Changeset(ctx, u, r, b.GetCommit()) if err != nil { retErr := fmt.Errorf("unable to restart build: failed to get changeset for %s: %w", r.GetFullName(), err) @@ -200,7 +198,7 @@ func RestartBuild(c *gin.Context) { } // send API call to capture list of files changed for the pull request - files, err = scm.FromContext(c).ChangesetPR(u, r, number) + files, err = scm.FromContext(c).ChangesetPR(ctx, u, r, number) if err != nil { retErr := fmt.Errorf("unable to restart build: failed to get changeset for %s: %w", r.GetFullName(), err) @@ -226,7 +224,7 @@ func RestartBuild(c *gin.Context) { pipeline, err = database.FromContext(c).GetPipelineForRepo(ctx, b.GetCommit(), r) if err != nil { // assume the pipeline doesn't exist in the database yet (before pipeline support was added) // send API call to capture the pipeline configuration file - config, err = scm.FromContext(c).ConfigBackoff(u, r, b.GetCommit()) + config, err = scm.FromContext(c).ConfigBackoff(ctx, u, r, b.GetCommit()) if err != nil { retErr := fmt.Errorf("unable to get pipeline configuration for %s: %w", r.GetFullName(), err) @@ -281,7 +279,7 @@ func RestartBuild(c *gin.Context) { b.SetStatus(constants.StatusSkipped) // send API call to set the status on the commit - err = scm.FromContext(c).Status(u, b, r.GetOrg(), r.GetName()) + err = scm.FromContext(c).Status(ctx, u, b, r.GetOrg(), r.GetName()) if err != nil { logrus.Errorf("unable to set commit status for %s/%d: %v", r.GetFullName(), b.GetNumber(), err) } @@ -336,7 +334,7 @@ func RestartBuild(c *gin.Context) { c.JSON(http.StatusCreated, b) // send API call to set the status on the commit - err = scm.FromContext(c).Status(u, b, r.GetOrg(), r.GetName()) + err = scm.FromContext(c).Status(ctx, u, b, r.GetOrg(), r.GetName()) if err != nil { logger.Errorf("unable to set commit status for build %s: %v", entry, err) } diff --git a/api/build/skip.go b/api/build/skip.go index 4d5cf8af9..0987e99f6 100644 --- a/api/build/skip.go +++ b/api/build/skip.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build @@ -15,25 +13,25 @@ import ( func SkipEmptyBuild(p *pipeline.Build) string { if len(p.Stages) == 1 { if p.Stages[0].Name == "init" { - return "skipping build since only init stage found" + return "skipping build since only init stage found — it is likely no rulesets matched for the webhook payload" } } if len(p.Stages) == 2 { if p.Stages[0].Name == "init" && p.Stages[1].Name == "clone" { - return "skipping build since only init and clone stages found" + return "skipping build since only init and clone stages found — it is likely no rulesets matched for the webhook payload" } } if len(p.Steps) == 1 { if p.Steps[0].Name == "init" { - return "skipping build since only init step found" + return "skipping build since only init step found — it is likely no rulesets matched for the webhook payload" } } if len(p.Steps) == 2 { if p.Steps[0].Name == "init" && p.Steps[1].Name == "clone" { - return "skipping build since only init and clone steps found" + return "skipping build since only init and clone steps found — it is likely no rulesets matched for the webhook payload" } } diff --git a/api/build/skip_test.go b/api/build/skip_test.go index ca805a84e..f55163227 100644 --- a/api/build/skip_test.go +++ b/api/build/skip_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build @@ -24,7 +22,7 @@ func Test_SkipEmptyBuild(t *testing.T) { { Name: "init", }, - }}}, "skipping build since only init stage found"}, + }}}, "skipping build since only init stage found — it is likely no rulesets matched for the webhook payload"}, {"init and clone stages", args{p: &pipeline.Build{Stages: []*pipeline.Stage{ { Name: "init", @@ -32,7 +30,7 @@ func Test_SkipEmptyBuild(t *testing.T) { { Name: "clone", }, - }}}, "skipping build since only init and clone stages found"}, + }}}, "skipping build since only init and clone stages found — it is likely no rulesets matched for the webhook payload"}, {"three stages", args{p: &pipeline.Build{Stages: []*pipeline.Stage{ { Name: "init", @@ -48,7 +46,7 @@ func Test_SkipEmptyBuild(t *testing.T) { { Name: "init", }, - }}}, "skipping build since only init step found"}, + }}}, "skipping build since only init step found — it is likely no rulesets matched for the webhook payload"}, {"init and clone steps", args{p: &pipeline.Build{Steps: []*pipeline.Container{ { Name: "init", @@ -56,7 +54,7 @@ func Test_SkipEmptyBuild(t *testing.T) { { Name: "clone", }, - }}}, "skipping build since only init and clone steps found"}, + }}}, "skipping build since only init and clone steps found — it is likely no rulesets matched for the webhook payload"}, {"three steps", args{p: &pipeline.Build{Steps: []*pipeline.Container{ { Name: "init", diff --git a/api/build/token.go b/api/build/token.go index da18a0322..7365a72d4 100644 --- a/api/build/token.go +++ b/api/build/token.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/api/build/update.go b/api/build/update.go index 4a6ab2004..566a46360 100644 --- a/api/build/update.go +++ b/api/build/update.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build @@ -176,7 +174,7 @@ func UpdateBuild(c *gin.Context) { } // send API call to set the status on the commit - err = scm.FromContext(c).Status(u, b, r.GetOrg(), r.GetName()) + err = scm.FromContext(c).Status(ctx, u, b, r.GetOrg(), r.GetName()) if err != nil { logrus.Errorf("unable to set commit status for build %s: %v", entry, err) } diff --git a/api/deployment/create.go b/api/deployment/create.go index 2075e65da..0c7112069 100644 --- a/api/deployment/create.go +++ b/api/deployment/create.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package deployment @@ -59,6 +57,7 @@ func CreateDeployment(c *gin.Context) { o := org.Retrieve(c) r := repo.Retrieve(c) u := user.Retrieve(c) + ctx := c.Request.Context() // update engine logger with API metadata // @@ -99,7 +98,7 @@ func CreateDeployment(c *gin.Context) { } // send API call to create the deployment - err = scm.FromContext(c).CreateDeployment(u, r, input) + err = scm.FromContext(c).CreateDeployment(ctx, u, r, input) if err != nil { retErr := fmt.Errorf("unable to create new deployment for %s: %w", r.GetFullName(), err) diff --git a/api/deployment/doc.go b/api/deployment/doc.go index c6118b8f3..a63c8ade5 100644 --- a/api/deployment/doc.go +++ b/api/deployment/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package deployment provides the deployment handlers for the Vela API. // diff --git a/api/deployment/get.go b/api/deployment/get.go index ff6827d3a..1eef1c527 100644 --- a/api/deployment/get.go +++ b/api/deployment/get.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package deployment @@ -65,6 +63,7 @@ func GetDeployment(c *gin.Context) { r := repo.Retrieve(c) u := user.Retrieve(c) deployment := util.PathParameter(c, "deployment") + ctx := c.Request.Context() entry := fmt.Sprintf("%s/%s", r.GetFullName(), deployment) @@ -87,7 +86,7 @@ func GetDeployment(c *gin.Context) { } // send API call to capture the deployment - d, err := scm.FromContext(c).GetDeployment(u, r, int64(number)) + d, err := scm.FromContext(c).GetDeployment(ctx, u, r, int64(number)) if err != nil { retErr := fmt.Errorf("unable to get deployment %s: %w", entry, err) diff --git a/api/deployment/list.go b/api/deployment/list.go index cb2ec2010..384255136 100644 --- a/api/deployment/list.go +++ b/api/deployment/list.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package deployment @@ -117,7 +115,7 @@ func ListDeployments(c *gin.Context) { perPage = util.MaxInt(1, util.MinInt(100, perPage)) // send API call to capture the total number of deployments for the repo - t, err := scm.FromContext(c).GetDeploymentCount(u, r) + t, err := scm.FromContext(c).GetDeploymentCount(ctx, u, r) if err != nil { retErr := fmt.Errorf("unable to get deployment count for %s: %w", r.GetFullName(), err) @@ -127,7 +125,7 @@ func ListDeployments(c *gin.Context) { } // send API call to capture the list of deployments for the repo - d, err := scm.FromContext(c).GetDeploymentList(u, r, page, perPage) + d, err := scm.FromContext(c).GetDeploymentList(ctx, u, r, page, perPage) if err != nil { retErr := fmt.Errorf("unable to get deployments for %s: %w", r.GetFullName(), err) diff --git a/api/doc.go b/api/doc.go index 4f9d47c48..098d3c5c3 100644 --- a/api/doc.go +++ b/api/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package api provides the handlers for the Vela API. // diff --git a/api/health.go b/api/health.go index 8aa50d94a..71c8eacf4 100644 --- a/api/health.go +++ b/api/health.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package api diff --git a/api/hook/create.go b/api/hook/create.go index 234e32eae..569e43664 100644 --- a/api/hook/create.go +++ b/api/hook/create.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/api/hook/delete.go b/api/hook/delete.go index 3087e928a..86ef22312 100644 --- a/api/hook/delete.go +++ b/api/hook/delete.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/api/hook/get.go b/api/hook/get.go index 49ddca5de..d3ff18793 100644 --- a/api/hook/get.go +++ b/api/hook/get.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/api/hook/list.go b/api/hook/list.go index bd47e019e..902cd33cc 100644 --- a/api/hook/list.go +++ b/api/hook/list.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/api/hook/redeliver.go b/api/hook/redeliver.go index 63ab91a9a..50f68e6eb 100644 --- a/api/hook/redeliver.go +++ b/api/hook/redeliver.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/api/hook/update.go b/api/hook/update.go index ab2fb5955..74954dde1 100644 --- a/api/hook/update.go +++ b/api/hook/update.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/api/log/create_service.go b/api/log/create_service.go index 501dcfe89..fb188aead 100644 --- a/api/log/create_service.go +++ b/api/log/create_service.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore similar code to step package log diff --git a/api/log/create_step.go b/api/log/create_step.go index 5a3c07f97..19c8030ef 100644 --- a/api/log/create_step.go +++ b/api/log/create_step.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore similar code to service package log diff --git a/api/log/delete_service.go b/api/log/delete_service.go index d5d8d6655..788fe1f8d 100644 --- a/api/log/delete_service.go +++ b/api/log/delete_service.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore similar code with step package log diff --git a/api/log/delete_step.go b/api/log/delete_step.go index 8fe0818f5..7209637ff 100644 --- a/api/log/delete_step.go +++ b/api/log/delete_step.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore similar code with service package log diff --git a/api/log/doc.go b/api/log/doc.go index 9f619b01c..09fa858b9 100644 --- a/api/log/doc.go +++ b/api/log/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package log provides the log handlers for the Vela API. // diff --git a/api/log/get_service.go b/api/log/get_service.go index 6b73a2a07..62500eb3c 100644 --- a/api/log/get_service.go +++ b/api/log/get_service.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore similar code with step package log diff --git a/api/log/get_step.go b/api/log/get_step.go index 33f71974f..2e2798918 100644 --- a/api/log/get_step.go +++ b/api/log/get_step.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore similar code with service package log diff --git a/api/log/list_build.go b/api/log/list_build.go index ed89f3e20..6cb2e5130 100644 --- a/api/log/list_build.go +++ b/api/log/list_build.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package log diff --git a/api/log/update_service.go b/api/log/update_service.go index a396b0e76..7e1ca5a5b 100644 --- a/api/log/update_service.go +++ b/api/log/update_service.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore similar code with step package log diff --git a/api/log/update_step.go b/api/log/update_step.go index 8b17cc2f3..d6f0370ec 100644 --- a/api/log/update_step.go +++ b/api/log/update_step.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore similar code with service package log diff --git a/api/metrics.go b/api/metrics.go index 507753041..b3dbbeb9f 100644 --- a/api/metrics.go +++ b/api/metrics.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package api @@ -444,7 +442,6 @@ func recordGauges(c *gin.Context) { } // check if the worker checked in within the last worker_active_interval if worker.GetLastCheckedIn() >= before { - switch worker.GetStatus() { case constants.WorkerStatusIdle: idleWorkers++ diff --git a/api/pagination.go b/api/pagination.go index a63af8214..6abb3f3d9 100644 --- a/api/pagination.go +++ b/api/pagination.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package api diff --git a/api/pipeline/compile.go b/api/pipeline/compile.go index 8ac5fed93..072613c1b 100644 --- a/api/pipeline/compile.go +++ b/api/pipeline/compile.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore similar code with expand package pipeline diff --git a/api/pipeline/create.go b/api/pipeline/create.go index 87bfb6634..240b59c57 100644 --- a/api/pipeline/create.go +++ b/api/pipeline/create.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/api/pipeline/delete.go b/api/pipeline/delete.go index 1012b3094..d6ca9936e 100644 --- a/api/pipeline/delete.go +++ b/api/pipeline/delete.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/api/pipeline/doc.go b/api/pipeline/doc.go index 0b2c02901..fefe60102 100644 --- a/api/pipeline/doc.go +++ b/api/pipeline/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package pipeline provides the pipeline handlers for the Vela API. // diff --git a/api/pipeline/expand.go b/api/pipeline/expand.go index 17f782fee..a757551bc 100644 --- a/api/pipeline/expand.go +++ b/api/pipeline/expand.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore similar code with compile package pipeline diff --git a/api/pipeline/get.go b/api/pipeline/get.go index 45beb61dc..8e8b9cf16 100644 --- a/api/pipeline/get.go +++ b/api/pipeline/get.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/api/pipeline/list.go b/api/pipeline/list.go index a43f33788..ebb83ad54 100644 --- a/api/pipeline/list.go +++ b/api/pipeline/list.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/api/pipeline/output.go b/api/pipeline/output.go index 46fcace56..b7e260ed3 100644 --- a/api/pipeline/output.go +++ b/api/pipeline/output.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/api/pipeline/template.go b/api/pipeline/template.go index 7b00abb5d..9716b6328 100644 --- a/api/pipeline/template.go +++ b/api/pipeline/template.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline @@ -146,7 +144,7 @@ func GetTemplates(c *gin.Context) { } // retrieve link to template file from github - link, err := scm.FromContext(c).GetHTMLURL(user, src.Org, src.Repo, src.Name, src.Ref) + link, err := scm.FromContext(c).GetHTMLURL(ctx, user, src.Org, src.Repo, src.Name, src.Ref) if err != nil { util.HandleError(c, http.StatusBadRequest, fmt.Errorf("%s: unable to get html url for %s/%s/%s/@%s: %w", baseErr, src.Org, src.Repo, src.Name, src.Ref, err)) diff --git a/api/pipeline/update.go b/api/pipeline/update.go index 8c349f5bb..075d00265 100644 --- a/api/pipeline/update.go +++ b/api/pipeline/update.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/api/pipeline/validate.go b/api/pipeline/validate.go index 45aae1ff8..9c2a36a34 100644 --- a/api/pipeline/validate.go +++ b/api/pipeline/validate.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/api/queue/queue.go b/api/queue/queue.go new file mode 100644 index 000000000..78d4c170b --- /dev/null +++ b/api/queue/queue.go @@ -0,0 +1,54 @@ +// SPDX-License-Identifier: Apache-2.0 + +package queue + +import ( + "net/http" + + "github.com/gin-gonic/gin" + "github.com/go-vela/server/router/middleware/claims" + "github.com/go-vela/types/library" + "github.com/sirupsen/logrus" +) + +// swagger:operation POST /api/v1/queue/info queue Info +// +// Get queue credentials +// +// --- +// produces: +// - application/json +// security: +// - ApiKeyAuth: [] +// responses: +// '200': +// description: Successfully retrieved queue credentials +// schema: +// "$ref": "#/definitions/QueueInfo" +// '401': +// description: Unauthorized +// schema: +// "$ref": "#/definitions/Error" + +// Info represents the API handler to +// retrieve queue credentials as part of worker onboarding. +func Info(c *gin.Context) { + cl := claims.Retrieve(c) + + logrus.WithFields(logrus.Fields{ + "user": cl.Subject, + }).Info("requesting queue credentials with registration token") + + // extract the public key that was packed into gin context + k := c.MustGet("public-key").(string) + + // extract the queue-address that was packed into gin context + a := c.MustGet("queue-address").(string) + + wr := library.QueueInfo{ + QueuePublicKey: &k, + QueueAddress: &a, + } + + c.JSON(http.StatusOK, wr) +} diff --git a/api/repo/chown.go b/api/repo/chown.go index 93a4ec5fa..8061b2de6 100644 --- a/api/repo/chown.go +++ b/api/repo/chown.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo diff --git a/api/repo/create.go b/api/repo/create.go index cb63a15ca..91dda798b 100644 --- a/api/repo/create.go +++ b/api/repo/create.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo @@ -17,6 +15,7 @@ import ( "github.com/go-vela/server/util" "github.com/go-vela/types/constants" "github.com/go-vela/types/library" + "github.com/go-vela/types/library/actions" "github.com/google/uuid" "github.com/sirupsen/logrus" ) @@ -99,7 +98,7 @@ func CreateRepo(c *gin.Context) { }).Infof("creating new repo %s", input.GetFullName()) // get repo information from the source - r, err := scm.FromContext(c).GetRepo(u, input) + r, err := scm.FromContext(c).GetRepo(ctx, u, input) if err != nil { retErr := fmt.Errorf("unable to retrieve repo info for %s from source: %w", r.GetFullName(), err) @@ -157,10 +156,10 @@ func CreateRepo(c *gin.Context) { // set default events if no events are passed in if input.GetAllowEvents() == nil { events := new(library.Events) - pushActions := new(library.PushActions) - pullActions := new(library.PullActions) - deployActions := new(library.DeployActions) - commentActions := new(library.CommentActions) + pushActions := new(actions.Push) + pullActions := new(actions.Pull) + deployActions := new(actions.Deploy) + commentActions := new(actions.Comment) for _, event := range defaultRepoEvents { switch event { @@ -260,7 +259,7 @@ func CreateRepo(c *gin.Context) { // check if we should create the webhook if c.Value("webhookvalidation").(bool) { // send API call to create the webhook - h, _, err = scm.FromContext(c).Enable(u, r, h) + h, _, err = scm.FromContext(c).Enable(ctx, u, r, h) if err != nil { retErr := fmt.Errorf("unable to create webhook for %s: %w", r.GetFullName(), err) diff --git a/api/repo/delete.go b/api/repo/delete.go index 4ddaf11f7..445a9af92 100644 --- a/api/repo/delete.go +++ b/api/repo/delete.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo @@ -71,7 +69,7 @@ func DeleteRepo(c *gin.Context) { }).Infof("deleting repo %s", r.GetFullName()) // send API call to remove the webhook - err := scm.FromContext(c).Disable(u, r.GetOrg(), r.GetName()) + err := scm.FromContext(c).Disable(ctx, u, r.GetOrg(), r.GetName()) if err != nil { retErr := fmt.Errorf("unable to delete webhook for %s: %w", r.GetFullName(), err) diff --git a/api/repo/doc.go b/api/repo/doc.go index 82eb5304e..a2f856d05 100644 --- a/api/repo/doc.go +++ b/api/repo/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package repo provides the repo handlers for the Vela API. // diff --git a/api/repo/get.go b/api/repo/get.go index 65cbede1b..d8b1fdebb 100644 --- a/api/repo/get.go +++ b/api/repo/get.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo diff --git a/api/repo/list.go b/api/repo/list.go index 77c127b3c..7b7f788f6 100644 --- a/api/repo/list.go +++ b/api/repo/list.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo diff --git a/api/repo/list_org.go b/api/repo/list_org.go index 727b91b5d..22114e50c 100644 --- a/api/repo/list_org.go +++ b/api/repo/list_org.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo @@ -132,7 +130,7 @@ func ListReposForOrg(c *gin.Context) { } // See if the user is an org admin to bypass individual permission checks - perm, err := scm.FromContext(c).OrgAccess(u, o) + perm, err := scm.FromContext(c).OrgAccess(ctx, u, o) if err != nil { logrus.Errorf("unable to get user %s access level for org %s", u.GetName(), o) } diff --git a/api/repo/repair.go b/api/repo/repair.go index 1f8ffeea8..55274b158 100644 --- a/api/repo/repair.go +++ b/api/repo/repair.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo @@ -69,7 +67,7 @@ func RepairRepo(c *gin.Context) { // check if we should create the webhook if c.Value("webhookvalidation").(bool) { // send API call to remove the webhook - err := scm.FromContext(c).Disable(u, r.GetOrg(), r.GetName()) + err := scm.FromContext(c).Disable(ctx, u, r.GetOrg(), r.GetName()) if err != nil { retErr := fmt.Errorf("unable to delete webhook for %s: %w", r.GetFullName(), err) @@ -88,7 +86,7 @@ func RepairRepo(c *gin.Context) { } // send API call to create the webhook - hook, _, err = scm.FromContext(c).Enable(u, r, hook) + hook, _, err = scm.FromContext(c).Enable(ctx, u, r, hook) if err != nil { retErr := fmt.Errorf("unable to create webhook for %s: %w", r.GetFullName(), err) diff --git a/api/repo/update.go b/api/repo/update.go index b4a2b0fea..474e5d260 100644 --- a/api/repo/update.go +++ b/api/repo/update.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo @@ -249,7 +247,7 @@ func UpdateRepo(c *gin.Context) { }).Infof("platform admin %s updating repo webhook events for repo %s", admn, r.GetFullName()) } // update webhook with new events - _, err = scm.FromContext(c).Update(u, r, lastHook.GetWebhookID()) + _, err = scm.FromContext(c).Update(ctx, u, r, lastHook.GetWebhookID()) if err != nil { retErr := fmt.Errorf("unable to update repo webhook for %s: %w", r.GetFullName(), err) diff --git a/api/schedule/create.go b/api/schedule/create.go index 667eb3ca9..88df46a75 100644 --- a/api/schedule/create.go +++ b/api/schedule/create.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule @@ -106,6 +104,8 @@ func CreateSchedule(c *gin.Context) { // ensure schedule name is defined if input.GetName() == "" { util.HandleError(c, http.StatusBadRequest, fmt.Errorf("schedule name must be set")) + + return } // update engine logger with API metadata diff --git a/api/schedule/create_test.go b/api/schedule/create_test.go index a2956f6ca..41178f4b5 100644 --- a/api/schedule/create_test.go +++ b/api/schedule/create_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/api/schedule/delete.go b/api/schedule/delete.go index 9c6f1dda8..3e7eea10d 100644 --- a/api/schedule/delete.go +++ b/api/schedule/delete.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/api/schedule/get.go b/api/schedule/get.go index 727de5b84..902b06b21 100644 --- a/api/schedule/get.go +++ b/api/schedule/get.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/api/schedule/list.go b/api/schedule/list.go index a3d6d6e14..cd47a56e1 100644 --- a/api/schedule/list.go +++ b/api/schedule/list.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/api/schedule/update.go b/api/schedule/update.go index 6c2a8b9b6..fdf078d64 100644 --- a/api/schedule/update.go +++ b/api/schedule/update.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/api/scm/doc.go b/api/scm/doc.go index 5d66cafed..731d515ac 100644 --- a/api/scm/doc.go +++ b/api/scm/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package scm provides the scm handlers for the Vela API. // diff --git a/api/scm/sync.go b/api/scm/sync.go index db645f623..f268c9a92 100644 --- a/api/scm/sync.go +++ b/api/scm/sync.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package scm @@ -19,7 +17,7 @@ import ( "github.com/sirupsen/logrus" ) -// swagger:operation GET /api/v1/scm/repos/{org}/{repo}/sync scm SyncRepo +// swagger:operation PATCH /api/v1/scm/repos/{org}/{repo}/sync scm SyncRepo // // Sync up scm service and database in the context of a specific repo // @@ -73,7 +71,7 @@ func SyncRepo(c *gin.Context) { logger.Infof("syncing repo %s", r.GetFullName()) // retrieve repo from source code manager service - _, err := scm.FromContext(c).GetRepo(u, r) + _, err := scm.FromContext(c).GetRepo(ctx, u, r) // if there is an error retrieving repo, we know it is deleted: set to inactive if err != nil { @@ -98,7 +96,7 @@ func SyncRepo(c *gin.Context) { // verify the user is an admin of the repo // we cannot use our normal permissions check due to the possibility the repo was deleted - perm, err := scm.FromContext(c).RepoAccess(u, u.GetToken(), o, r.GetName()) + perm, err := scm.FromContext(c).RepoAccess(ctx, u, u.GetToken(), o, r.GetName()) if err != nil { logger.Errorf("unable to get user %s access level for org %s", u.GetName(), o) } @@ -125,13 +123,11 @@ func SyncRepo(c *gin.Context) { } // update webhook - webhookExists, err := scm.FromContext(c).Update(u, r, lastHook.GetWebhookID()) + webhookExists, err := scm.FromContext(c).Update(ctx, u, r, lastHook.GetWebhookID()) if err != nil { - // if webhook has been manually deleted from GitHub, // set to inactive in database if !webhookExists { - r.SetActive(false) _, err := database.FromContext(c).UpdateRepo(ctx, r) @@ -146,15 +142,13 @@ func SyncRepo(c *gin.Context) { c.JSON(http.StatusOK, fmt.Sprintf("webhook not found, repo %s deactivated", r.GetFullName())) return + } - } else { - - retErr := fmt.Errorf("unable to update repo webhook for %s: %w", r.GetFullName(), err) + retErr := fmt.Errorf("unable to update repo webhook for %s: %w", r.GetFullName(), err) - util.HandleError(c, http.StatusInternalServerError, retErr) + util.HandleError(c, http.StatusInternalServerError, retErr) - return - } + return } } diff --git a/api/scm/sync_org.go b/api/scm/sync_org.go index 6ae0b28df..bf7607533 100644 --- a/api/scm/sync_org.go +++ b/api/scm/sync_org.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package scm @@ -18,7 +16,7 @@ import ( "github.com/sirupsen/logrus" ) -// swagger:operation GET /api/v1/scm/orgs/{org}/sync scm SyncReposForOrg +// swagger:operation PATCH /api/v1/scm/orgs/{org}/sync scm SyncReposForOrg // // Sync up repos from scm service and database in a specified org // @@ -65,7 +63,7 @@ func SyncReposForOrg(c *gin.Context) { logger.Infof("syncing repos for org %s", o) // see if the user is an org admin - perm, err := scm.FromContext(c).OrgAccess(u, o) + perm, err := scm.FromContext(c).OrgAccess(ctx, u, o) if err != nil { logger.Errorf("unable to get user %s access level for org %s", u.GetName(), o) } @@ -109,7 +107,7 @@ func SyncReposForOrg(c *gin.Context) { // iterate through captured repos and check if they are in GitHub for _, repo := range repos { - _, err := scm.FromContext(c).GetRepo(u, repo) + _, err := scm.FromContext(c).GetRepo(ctx, u, repo) // if repo cannot be captured from GitHub, set to inactive in database if err != nil { repo.SetActive(false) @@ -138,13 +136,11 @@ func SyncReposForOrg(c *gin.Context) { } // update webhook - webhookExists, err := scm.FromContext(c).Update(u, repo, lastHook.GetWebhookID()) + webhookExists, err := scm.FromContext(c).Update(ctx, u, repo, lastHook.GetWebhookID()) if err != nil { - // if webhook has been manually deleted from GitHub, // set to inactive in database if !webhookExists { - repo.SetActive(false) _, err := database.FromContext(c).UpdateRepo(ctx, repo) @@ -157,15 +153,13 @@ func SyncReposForOrg(c *gin.Context) { } continue + } - } else { - - retErr := fmt.Errorf("unable to update repo webhook for %s: %w", repo.GetFullName(), err) + retErr := fmt.Errorf("unable to update repo webhook for %s: %w", repo.GetFullName(), err) - util.HandleError(c, http.StatusInternalServerError, retErr) + util.HandleError(c, http.StatusInternalServerError, retErr) - return - } + return } } } diff --git a/api/secret/create.go b/api/secret/create.go index fcfeac266..fc2dca67a 100644 --- a/api/secret/create.go +++ b/api/secret/create.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret @@ -118,7 +116,7 @@ func CreateSecret(c *gin.Context) { // but Org/Repo != org/repo in Vela. So this check ensures that // what a user inputs matches the casing we expect in Vela since // the SCM will have the source of truth for casing. - org, err := scm.FromContext(c).GetOrgName(u, o) + org, err := scm.FromContext(c).GetOrgName(ctx, u, o) if err != nil { retErr := fmt.Errorf("unable to retrieve organization %s", o) @@ -141,7 +139,7 @@ func CreateSecret(c *gin.Context) { // retrieve org and repo name from SCM // // same story as org secret. SCM has accurate casing. - scmOrg, scmRepo, err := scm.FromContext(c).GetOrgAndRepoName(u, o, n) + scmOrg, scmRepo, err := scm.FromContext(c).GetOrgAndRepoName(ctx, u, o, n) if err != nil { retErr := fmt.Errorf("unable to retrieve repository %s/%s", o, n) diff --git a/api/secret/delete.go b/api/secret/delete.go index 32d96df1c..5257b82a9 100644 --- a/api/secret/delete.go +++ b/api/secret/delete.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/api/secret/doc.go b/api/secret/doc.go index db89d7b55..d96644946 100644 --- a/api/secret/doc.go +++ b/api/secret/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package secret provides the secret handlers for the Vela API. // diff --git a/api/secret/get.go b/api/secret/get.go index e97781862..74cad449f 100644 --- a/api/secret/get.go +++ b/api/secret/get.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/api/secret/list.go b/api/secret/list.go index e69f4fdd5..a3870597f 100644 --- a/api/secret/list.go +++ b/api/secret/list.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret @@ -106,7 +104,7 @@ func ListSecrets(c *gin.Context) { if t == constants.SecretShared && n == "*" { var err error - teams, err = scm.FromContext(c).ListUsersTeamsForOrg(u, o) + teams, err = scm.FromContext(c).ListUsersTeamsForOrg(ctx, u, o) if err != nil { retErr := fmt.Errorf("unable to list users %s teams for org %s: %w", u.GetName(), o, err) diff --git a/api/secret/update.go b/api/secret/update.go index 795a8a5b4..86870d03d 100644 --- a/api/secret/update.go +++ b/api/secret/update.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/api/service/create.go b/api/service/create.go index b66e57c51..e43f66a0f 100644 --- a/api/service/create.go +++ b/api/service/create.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/api/service/delete.go b/api/service/delete.go index 24c0d7eb0..ff885e440 100644 --- a/api/service/delete.go +++ b/api/service/delete.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/api/service/doc.go b/api/service/doc.go index 53dc07284..083b50742 100644 --- a/api/service/doc.go +++ b/api/service/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package service provides the service handlers for the Vela API. // diff --git a/api/service/get.go b/api/service/get.go index b2165a69f..5ac4503b8 100644 --- a/api/service/get.go +++ b/api/service/get.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/api/service/list.go b/api/service/list.go index d91268092..d5e37cfef 100644 --- a/api/service/list.go +++ b/api/service/list.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/api/service/plan.go b/api/service/plan.go index 6ae3a9e86..790c9b538 100644 --- a/api/service/plan.go +++ b/api/service/plan.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/api/service/update.go b/api/service/update.go index fda5d9676..c391e6a86 100644 --- a/api/service/update.go +++ b/api/service/update.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/api/step/create.go b/api/step/create.go index 58e71a99e..06eeac4e9 100644 --- a/api/step/create.go +++ b/api/step/create.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/api/step/delete.go b/api/step/delete.go index 1a43c30b3..f9ee7c2ad 100644 --- a/api/step/delete.go +++ b/api/step/delete.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/api/step/doc.go b/api/step/doc.go index fad7dce79..0faed9f2d 100644 --- a/api/step/doc.go +++ b/api/step/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package step provides the step handlers for the Vela API. // diff --git a/api/step/get.go b/api/step/get.go index cf55c1bb5..51f1894c6 100644 --- a/api/step/get.go +++ b/api/step/get.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/api/step/list.go b/api/step/list.go index 5d76fb33c..1545e28ea 100644 --- a/api/step/list.go +++ b/api/step/list.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/api/step/plan.go b/api/step/plan.go index 96dccc283..103f38d6e 100644 --- a/api/step/plan.go +++ b/api/step/plan.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/api/step/update.go b/api/step/update.go index d0563d98d..e7b2402ee 100644 --- a/api/step/update.go +++ b/api/step/update.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/api/user/create.go b/api/user/create.go index 691f448ad..575e73c88 100644 --- a/api/user/create.go +++ b/api/user/create.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package user diff --git a/api/user/create_token.go b/api/user/create_token.go index f114f369a..9f57fde9a 100644 --- a/api/user/create_token.go +++ b/api/user/create_token.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore similar code with delete token package user diff --git a/api/user/delete.go b/api/user/delete.go index 29c63135a..36393d24a 100644 --- a/api/user/delete.go +++ b/api/user/delete.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package user diff --git a/api/user/delete_token.go b/api/user/delete_token.go index d24ae8bf0..adb554015 100644 --- a/api/user/delete_token.go +++ b/api/user/delete_token.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore similar code with create token package user diff --git a/api/user/doc.go b/api/user/doc.go index 7f1ce6bc5..70e2ee31a 100644 --- a/api/user/doc.go +++ b/api/user/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package user provides the user handlers for the Vela API. // diff --git a/api/user/get.go b/api/user/get.go index bf6e6f519..e888ff804 100644 --- a/api/user/get.go +++ b/api/user/get.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package user diff --git a/api/user/get_current.go b/api/user/get_current.go index b4b1ef4c3..641576df0 100644 --- a/api/user/get_current.go +++ b/api/user/get_current.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package user diff --git a/api/user/get_source.go b/api/user/get_source.go index 9892f319e..6390c00e7 100644 --- a/api/user/get_source.go +++ b/api/user/get_source.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package user @@ -55,7 +53,7 @@ func GetSourceRepos(c *gin.Context) { output := make(map[string][]library.Repo) // send API call to capture the list of repos for the user - srcRepos, err := scm.FromContext(c).ListUserRepos(u) + srcRepos, err := scm.FromContext(c).ListUserRepos(ctx, u) if err != nil { retErr := fmt.Errorf("unable to get SCM repos for user %s: %w", u.GetName(), err) diff --git a/api/user/list.go b/api/user/list.go index a1d0c487d..a62ae57aa 100644 --- a/api/user/list.go +++ b/api/user/list.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package user diff --git a/api/user/update.go b/api/user/update.go index f65335a0e..0535da1f5 100644 --- a/api/user/update.go +++ b/api/user/update.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package user diff --git a/api/user/update_current.go b/api/user/update_current.go index dd5051277..ab56023ad 100644 --- a/api/user/update_current.go +++ b/api/user/update_current.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package user diff --git a/api/version.go b/api/version.go index c5b956d37..349fd5ea4 100644 --- a/api/version.go +++ b/api/version.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package api diff --git a/api/webhook/doc.go b/api/webhook/doc.go index 0acc05476..dc6cc086e 100644 --- a/api/webhook/doc.go +++ b/api/webhook/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package webhook provides the webhook handlers for the Vela API. // diff --git a/api/webhook/post.go b/api/webhook/post.go index 749304029..264ad48d3 100644 --- a/api/webhook/post.go +++ b/api/webhook/post.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package webhook @@ -115,7 +113,7 @@ func PostWebhook(c *gin.Context) { // process the webhook from the source control provider // // populate build, hook, repo resources as well as PR Number / PR Comment if necessary - webhook, err := scm.FromContext(c).ProcessWebhook(c.Request) + webhook, err := scm.FromContext(c).ProcessWebhook(ctx, c.Request) if err != nil { retErr := fmt.Errorf("unable to parse webhook: %w", err) util.HandleError(c, http.StatusBadRequest, retErr) @@ -234,7 +232,7 @@ func PostWebhook(c *gin.Context) { // verify the webhook from the source control provider if c.Value("webhookvalidation").(bool) { - err = scm.FromContext(c).VerifyWebhook(dupRequest, repo) + err = scm.FromContext(c).VerifyWebhook(ctx, dupRequest, repo) if err != nil { retErr := fmt.Errorf("unable to verify webhook: %w", err) util.HandleError(c, http.StatusUnauthorized, retErr) @@ -294,7 +292,7 @@ func PostWebhook(c *gin.Context) { } // confirm current repo owner has at least write access to repo (needed for status update later) - _, err = scm.FromContext(c).RepoAccess(u, u.GetToken(), r.GetOrg(), r.GetName()) + _, err = scm.FromContext(c).RepoAccess(ctx, u, u.GetToken(), r.GetOrg(), r.GetName()) if err != nil { retErr := fmt.Errorf("unable to publish build to queue: repository owner %s no longer has write access to repository %s", u.GetName(), r.GetFullName()) util.HandleError(c, http.StatusUnauthorized, retErr) @@ -345,7 +343,7 @@ func PostWebhook(c *gin.Context) { // if the event is issue_comment and the issue is a pull request, // call SCM for more data not provided in webhook payload if strings.EqualFold(b.GetEvent(), constants.EventComment) && webhook.PRNumber > 0 { - commit, branch, baseref, headref, err := scm.FromContext(c).GetPullRequest(u, repo, webhook.PRNumber) + commit, branch, baseref, headref, err := scm.FromContext(c).GetPullRequest(ctx, u, repo, webhook.PRNumber) if err != nil { retErr := fmt.Errorf("%s: failed to get pull request info for %s: %w", baseErr, repo.GetFullName(), err) util.HandleError(c, http.StatusInternalServerError, retErr) @@ -369,7 +367,7 @@ func PostWebhook(c *gin.Context) { if !strings.EqualFold(b.GetEvent(), constants.EventComment) && !strings.EqualFold(b.GetEvent(), constants.EventPull) { // send API call to capture list of files changed for the commit - files, err = scm.FromContext(c).Changeset(u, repo, b.GetCommit()) + files, err = scm.FromContext(c).Changeset(ctx, u, repo, b.GetCommit()) if err != nil { retErr := fmt.Errorf("%s: failed to get changeset for %s: %w", baseErr, repo.GetFullName(), err) util.HandleError(c, http.StatusInternalServerError, retErr) @@ -384,7 +382,7 @@ func PostWebhook(c *gin.Context) { // check if the build event is a pull_request if strings.EqualFold(b.GetEvent(), constants.EventPull) && webhook.PRNumber > 0 { // send API call to capture list of files changed for the pull request - files, err = scm.FromContext(c).ChangesetPR(u, repo, webhook.PRNumber) + files, err = scm.FromContext(c).ChangesetPR(ctx, u, repo, webhook.PRNumber) if err != nil { retErr := fmt.Errorf("%s: failed to get changeset for %s: %w", baseErr, repo.GetFullName(), err) util.HandleError(c, http.StatusInternalServerError, retErr) @@ -426,7 +424,7 @@ func PostWebhook(c *gin.Context) { pipeline, err = database.FromContext(c).GetPipelineForRepo(ctx, b.GetCommit(), repo) if err != nil { // assume the pipeline doesn't exist in the database yet // send API call to capture the pipeline configuration file - config, err = scm.FromContext(c).ConfigBackoff(u, repo, b.GetCommit()) + config, err = scm.FromContext(c).ConfigBackoff(ctx, u, repo, b.GetCommit()) if err != nil { retErr := fmt.Errorf("%s: unable to get pipeline configuration for %s: %w", baseErr, repo.GetFullName(), err) @@ -530,8 +528,12 @@ func PostWebhook(c *gin.Context) { // set build to successful status b.SetStatus(constants.StatusSkipped) + // set hook status and message + h.SetStatus(constants.StatusSkipped) + h.SetError(skip) + // send API call to set the status on the commit - err = scm.FromContext(c).Status(u, b, repo.GetOrg(), repo.GetName()) + err = scm.FromContext(c).Status(ctx, u, b, repo.GetOrg(), repo.GetName()) if err != nil { logrus.Errorf("unable to set commit status for %s/%d: %v", repo.GetFullName(), b.GetNumber(), err) } @@ -660,7 +662,7 @@ func PostWebhook(c *gin.Context) { c.JSON(http.StatusOK, b) // send API call to set the status on the commit - err = scm.FromContext(c).Status(u, b, repo.GetOrg(), repo.GetName()) + err = scm.FromContext(c).Status(ctx, u, b, repo.GetOrg(), repo.GetName()) if err != nil { logrus.Errorf("unable to set commit status for %s/%d: %v", repo.GetFullName(), b.GetNumber(), err) } @@ -675,6 +677,40 @@ func PostWebhook(c *gin.Context) { repo, u, ) + + // if anything is provided in the auto_cancel metadata, then we start with true + runAutoCancel := p.Metadata.AutoCancel.Running || p.Metadata.AutoCancel.Pending || p.Metadata.AutoCancel.DefaultBranch + + // if the event is a push to the default branch and the AutoCancel.DefaultBranch value is false, bypass auto cancel + if strings.EqualFold(b.GetEvent(), constants.EventPush) && strings.EqualFold(b.GetBranch(), repo.GetBranch()) && !p.Metadata.AutoCancel.DefaultBranch { + runAutoCancel = false + } + + // if event is push or pull_request:synchronize, there is a chance this build could be superceding a stale build + // + // fetch pending and running builds for this repo in order to validate their merit to continue running. + if runAutoCancel && + ((strings.EqualFold(b.GetEvent(), constants.EventPull) && strings.EqualFold(b.GetEventAction(), constants.ActionSynchronize)) || + strings.EqualFold(b.GetEvent(), constants.EventPush)) { + // fetch pending and running builds + rBs, err := database.FromContext(c).ListPendingAndRunningBuildsForRepo(c, repo) + if err != nil { + logrus.Errorf("unable to fetch pending and running builds for %s: %v", repo.GetFullName(), err) + } + + for _, rB := range rBs { + // call auto cancel routine + canceled, err := build.AutoCancel(c, b, rB, repo, p.Metadata.AutoCancel) + if err != nil { + // continue cancel loop if error, but log based on type of error + if canceled { + logrus.Errorf("unable to update canceled build error message: %v", err) + } else { + logrus.Errorf("unable to cancel running build: %v", err) + } + } + } + } } // handleRepositoryEvent is a helper function that processes repository events from the SCM and updates diff --git a/api/worker/create.go b/api/worker/create.go index 09f802177..07edf3acc 100644 --- a/api/worker/create.go +++ b/api/worker/create.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package worker diff --git a/api/worker/delete.go b/api/worker/delete.go index 4857e119a..cde6c743a 100644 --- a/api/worker/delete.go +++ b/api/worker/delete.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package worker diff --git a/api/worker/doc.go b/api/worker/doc.go index 86da09ed7..8956f37ba 100644 --- a/api/worker/doc.go +++ b/api/worker/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package worker provides the worker handlers for the Vela API. // diff --git a/api/worker/get.go b/api/worker/get.go index b16cbb9cd..a8a4d6931 100644 --- a/api/worker/get.go +++ b/api/worker/get.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package worker diff --git a/api/worker/list.go b/api/worker/list.go index 07b6d136a..6b24484a6 100644 --- a/api/worker/list.go +++ b/api/worker/list.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package worker diff --git a/api/worker/refresh.go b/api/worker/refresh.go index 3ae1d09aa..15826f6d6 100644 --- a/api/worker/refresh.go +++ b/api/worker/refresh.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package worker diff --git a/api/worker/update.go b/api/worker/update.go index 0cec92224..d95ddf7af 100644 --- a/api/worker/update.go +++ b/api/worker/update.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package worker diff --git a/cmd/vela-server/compiler.go b/cmd/vela-server/compiler.go index 36878631c..4e85f046a 100644 --- a/cmd/vela-server/compiler.go +++ b/cmd/vela-server/compiler.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package main diff --git a/cmd/vela-server/main.go b/cmd/vela-server/main.go index 94fe7016b..81c8a79be 100644 --- a/cmd/vela-server/main.go +++ b/cmd/vela-server/main.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package main @@ -48,6 +46,12 @@ func main() { Usage: "set log level - options: (trace|debug|info|warn|error|fatal|panic)", Value: "info", }, + &cli.StringFlag{ + EnvVars: []string{"VELA_LOG_FORMATTER", "LOG_FORMATTER"}, + Name: "log-formatter", + Usage: "set log formatter - options: (json|ecs)", + Value: "json", + }, &cli.StringFlag{ EnvVars: []string{"VELA_ADDR", "VELA_HOST"}, Name: "server-addr", @@ -247,9 +251,6 @@ func main() { // Add Source Flags app.Flags = append(app.Flags, scm.Flags...) - // set logrus to log in JSON format - logrus.SetFormatter(&logrus.JSONFormatter{}) - if err = app.Run(os.Args); err != nil { logrus.Fatal(err) } diff --git a/cmd/vela-server/metadata.go b/cmd/vela-server/metadata.go index 4ce86ea31..88a29b23a 100644 --- a/cmd/vela-server/metadata.go +++ b/cmd/vela-server/metadata.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package main diff --git a/cmd/vela-server/queue.go b/cmd/vela-server/queue.go index edd703e69..8b8767e56 100644 --- a/cmd/vela-server/queue.go +++ b/cmd/vela-server/queue.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package main @@ -24,6 +22,7 @@ func setupQueue(c *cli.Context) (queue.Service, error) { Routes: c.StringSlice("queue.routes"), Timeout: c.Duration("queue.pop.timeout"), PrivateKey: c.String("queue.private-key"), + PublicKey: c.String("queue.public-key"), } // setup the queue diff --git a/cmd/vela-server/schedule.go b/cmd/vela-server/schedule.go index 9d6c77c7f..cceb70de8 100644 --- a/cmd/vela-server/schedule.go +++ b/cmd/vela-server/schedule.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package main @@ -16,6 +14,7 @@ import ( "github.com/go-vela/server/database" "github.com/go-vela/server/queue" "github.com/go-vela/server/scm" + "github.com/go-vela/server/util" "github.com/go-vela/types" "github.com/go-vela/types/constants" "github.com/go-vela/types/library" @@ -31,7 +30,7 @@ const ( scheduleWait = "waiting to trigger build for schedule" ) -func processSchedules(ctx context.Context, start time.Time, compiler compiler.Engine, database database.Interface, metadata *types.Metadata, queue queue.Service, scm scm.Service) error { +func processSchedules(ctx context.Context, start time.Time, compiler compiler.Engine, database database.Interface, metadata *types.Metadata, queue queue.Service, scm scm.Service, allowList []string) error { logrus.Infof("processing active schedules to create builds") // send API call to capture the list of active schedules @@ -124,7 +123,7 @@ func processSchedules(ctx context.Context, start time.Time, compiler compiler.En } // process the schedule and trigger a new build - err = processSchedule(ctx, schedule, compiler, database, metadata, queue, scm) + err = processSchedule(ctx, schedule, compiler, database, metadata, queue, scm, allowList) if err != nil { logrus.WithError(err).Warnf("%s %s", scheduleErr, schedule.GetName()) @@ -136,13 +135,18 @@ func processSchedules(ctx context.Context, start time.Time, compiler compiler.En } //nolint:funlen // ignore function length and number of statements -func processSchedule(ctx context.Context, s *library.Schedule, compiler compiler.Engine, database database.Interface, metadata *types.Metadata, queue queue.Service, scm scm.Service) error { +func processSchedule(ctx context.Context, s *library.Schedule, compiler compiler.Engine, database database.Interface, metadata *types.Metadata, queue queue.Service, scm scm.Service, allowList []string) error { // send API call to capture the repo for the schedule r, err := database.GetRepo(ctx, s.GetRepoID()) if err != nil { return fmt.Errorf("unable to fetch repo: %w", err) } + // ensure repo has not been removed from allow list + if !util.CheckAllowlist(r, allowList) { + return fmt.Errorf("skipping schedule: repo %s no longer on allow list", r.GetFullName()) + } + logrus.Tracef("processing schedule %s/%s", r.GetFullName(), s.GetName()) // check if the repo is active @@ -162,7 +166,7 @@ func processSchedule(ctx context.Context, s *library.Schedule, compiler compiler } // send API call to confirm repo owner has at least write access to repo - _, err = scm.RepoAccess(u, u.GetToken(), r.GetOrg(), r.GetName()) + _, err = scm.RepoAccess(ctx, u, u.GetToken(), r.GetOrg(), r.GetName()) if err != nil { return fmt.Errorf("%s does not have at least write access for repo %s", u.GetName(), r.GetFullName()) } @@ -173,7 +177,7 @@ func processSchedule(ctx context.Context, s *library.Schedule, compiler compiler } // send API call to capture the number of pending or running builds for the repo - builds, err := database.CountBuildsForRepo(context.TODO(), r, filters) + builds, err := database.CountBuildsForRepo(ctx, r, filters) if err != nil { return fmt.Errorf("unable to get count of builds for repo %s: %w", r.GetFullName(), err) } @@ -184,7 +188,7 @@ func processSchedule(ctx context.Context, s *library.Schedule, compiler compiler } // send API call to capture the commit sha for the branch - _, commit, err := scm.GetBranch(u, r, s.GetBranch()) + _, commit, err := scm.GetBranch(ctx, u, r, s.GetBranch()) if err != nil { return fmt.Errorf("failed to get commit for repo %s on %s branch: %w", r.GetFullName(), r.GetBranch(), err) } @@ -237,10 +241,10 @@ func processSchedule(ctx context.Context, s *library.Schedule, compiler compiler } // send API call to attempt to capture the pipeline - pipeline, err = database.GetPipelineForRepo(context.TODO(), b.GetCommit(), r) + pipeline, err = database.GetPipelineForRepo(ctx, b.GetCommit(), r) if err != nil { // assume the pipeline doesn't exist in the database yet // send API call to capture the pipeline configuration file - config, err = scm.ConfigBackoff(u, r, b.GetCommit()) + config, err = scm.ConfigBackoff(ctx, u, r, b.GetCommit()) if err != nil { return fmt.Errorf("unable to get pipeline config for %s/%s: %w", r.GetFullName(), b.GetCommit(), err) } @@ -326,7 +330,7 @@ func processSchedule(ctx context.Context, s *library.Schedule, compiler compiler pipeline.SetRef(b.GetRef()) // send API call to create the pipeline - pipeline, err = database.CreatePipeline(context.TODO(), pipeline) + pipeline, err = database.CreatePipeline(ctx, pipeline) if err != nil { err = fmt.Errorf("failed to create pipeline for %s: %w", r.GetFullName(), err) @@ -351,7 +355,7 @@ func processSchedule(ctx context.Context, s *library.Schedule, compiler compiler // using the same Number and thus create a constraint // conflict; consider deleting the partially created // build object in the database - err = build.PlanBuild(context.TODO(), database, p, b, r) + err = build.PlanBuild(ctx, database, p, b, r) if err != nil { // check if the retry limit has been exceeded if i < retryLimit-1 { @@ -380,14 +384,14 @@ func processSchedule(ctx context.Context, s *library.Schedule, compiler compiler } // send API call to capture the triggered build - b, err = database.GetBuildForRepo(context.TODO(), r, b.GetNumber()) + b, err = database.GetBuildForRepo(ctx, r, b.GetNumber()) if err != nil { return fmt.Errorf("unable to get new build %s/%d: %w", r.GetFullName(), b.GetNumber(), err) } // publish the build to the queue go build.PublishToQueue( - context.TODO(), + ctx, queue, database, p, diff --git a/cmd/vela-server/scm.go b/cmd/vela-server/scm.go index b50141d85..3a7e0ef73 100644 --- a/cmd/vela-server/scm.go +++ b/cmd/vela-server/scm.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package main diff --git a/cmd/vela-server/secret.go b/cmd/vela-server/secret.go index 56e6c0572..1b0e22ef8 100644 --- a/cmd/vela-server/secret.go +++ b/cmd/vela-server/secret.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package main diff --git a/cmd/vela-server/server.go b/cmd/vela-server/server.go index cb9f0edd1..8333a8921 100644 --- a/cmd/vela-server/server.go +++ b/cmd/vela-server/server.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package main @@ -26,6 +24,18 @@ import ( ) func server(c *cli.Context) error { + // set log formatter + switch c.String("log-formatter") { + case "json": + // set logrus to log in JSON format + logrus.SetFormatter(&logrus.JSONFormatter{}) + case "ecs": + // set logrus to log in Elasticsearch Common Schema (ecs) format + logrus.SetFormatter(&middleware.ECSFormatter{ + DataKey: "labels.vela", + }) + } + // validate all input err := validate(c) if err != nil { @@ -99,6 +109,8 @@ func server(c *cli.Context) error { middleware.Secrets(secrets), middleware.Scm(scm), middleware.QueueSigningPrivateKey(c.String("queue.private-key")), + middleware.QueueSigningPublicKey(c.String("queue.public-key")), + middleware.QueueAddress(c.String("queue.addr")), middleware.Allowlist(c.StringSlice("vela-repo-allowlist")), middleware.DefaultBuildLimit(c.Int64("default-build-limit")), middleware.DefaultTimeout(c.Int64("default-build-timeout")), @@ -200,7 +212,7 @@ func server(c *cli.Context) error { // sleep for a duration of time before processing schedules time.Sleep(jitter) - err = processSchedules(ctx, start, compiler, database, metadata, queue, scm) + err = processSchedules(ctx, start, compiler, database, metadata, queue, scm, c.StringSlice("vela-schedule-allowlist")) if err != nil { logrus.WithError(err).Warn("unable to process schedules") } else { diff --git a/cmd/vela-server/token.go b/cmd/vela-server/token.go index 298ef283a..39b1600a6 100644 --- a/cmd/vela-server/token.go +++ b/cmd/vela-server/token.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package main diff --git a/cmd/vela-server/validate.go b/cmd/vela-server/validate.go index cac3b0424..b05e012c6 100644 --- a/cmd/vela-server/validate.go +++ b/cmd/vela-server/validate.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package main diff --git a/compiler/context.go b/compiler/context.go index 2a5622628..c5977b45f 100644 --- a/compiler/context.go +++ b/compiler/context.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package compiler diff --git a/compiler/context_test.go b/compiler/context_test.go index e5b340de6..5c75acfb5 100644 --- a/compiler/context_test.go +++ b/compiler/context_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package compiler diff --git a/compiler/doc.go b/compiler/doc.go index 0e6e12e57..5a5bd0f10 100644 --- a/compiler/doc.go +++ b/compiler/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package compiler provides the ability for Vela to // reconstruct a yaml configuration into an executable diff --git a/compiler/engine.go b/compiler/engine.go index 0296c99d4..68304e910 100644 --- a/compiler/engine.go +++ b/compiler/engine.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package compiler diff --git a/compiler/native/clone.go b/compiler/native/clone.go index ffc14393a..9075292f7 100644 --- a/compiler/native/clone.go +++ b/compiler/native/clone.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native diff --git a/compiler/native/clone_test.go b/compiler/native/clone_test.go index f481ee4c3..662576d53 100644 --- a/compiler/native/clone_test.go +++ b/compiler/native/clone_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native diff --git a/compiler/native/compile.go b/compiler/native/compile.go index d106fa480..b0648ded0 100644 --- a/compiler/native/compile.go +++ b/compiler/native/compile.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native diff --git a/compiler/native/compile_test.go b/compiler/native/compile_test.go index e0d2fc59b..00a995bf8 100644 --- a/compiler/native/compile_test.go +++ b/compiler/native/compile_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native @@ -15,7 +13,7 @@ import ( "github.com/go-vela/types/constants" "github.com/go-vela/types/raw" - "github.com/google/go-github/v54/github" + "github.com/google/go-github/v56/github" "testing" "time" @@ -112,6 +110,7 @@ func TestNative_Compile_StagesPipeline(t *testing.T) { Clone: true, Template: false, Environment: []string{"steps", "services", "secrets"}, + AutoCancel: &pipeline.CancelOptions{}, }, Stages: pipeline.StageSlice{ &pipeline.Stage{ @@ -232,6 +231,7 @@ func TestNative_Compile_StagesPipeline(t *testing.T) { Engine: "native", Type: "repo", Origin: &pipeline.Container{}, + Pull: "build_start", }, &pipeline.Secret{ Name: "docker_password", @@ -239,6 +239,7 @@ func TestNative_Compile_StagesPipeline(t *testing.T) { Engine: "vault", Type: "repo", Origin: &pipeline.Container{}, + Pull: "build_start", }, }, } @@ -484,6 +485,10 @@ func TestNative_Compile_StepsPipeline(t *testing.T) { Clone: true, Template: false, Environment: []string{"steps", "services", "secrets"}, + AutoCancel: &pipeline.CancelOptions{ + Running: true, + Pending: true, + }, }, Steps: pipeline.ContainerSlice{ &pipeline.Container{ @@ -564,6 +569,7 @@ func TestNative_Compile_StepsPipeline(t *testing.T) { Engine: "native", Type: "repo", Origin: &pipeline.Container{}, + Pull: "build_start", }, &pipeline.Secret{ Name: "docker_password", @@ -571,6 +577,7 @@ func TestNative_Compile_StepsPipeline(t *testing.T) { Engine: "vault", Type: "repo", Origin: &pipeline.Container{}, + Pull: "build_start", }, }, } @@ -695,6 +702,7 @@ func TestNative_Compile_StagesPipelineTemplate(t *testing.T) { Clone: true, Template: false, Environment: []string{"steps", "services", "secrets"}, + AutoCancel: &pipeline.CancelOptions{}, }, Stages: pipeline.StageSlice{ &pipeline.Stage{ @@ -801,6 +809,7 @@ func TestNative_Compile_StagesPipelineTemplate(t *testing.T) { Engine: "native", Type: "repo", Origin: &pipeline.Container{}, + Pull: "build_start", }, &pipeline.Secret{ Name: "docker_password", @@ -808,6 +817,7 @@ func TestNative_Compile_StagesPipelineTemplate(t *testing.T) { Engine: "vault", Type: "repo", Origin: &pipeline.Container{}, + Pull: "build_start", }, &pipeline.Secret{ Name: "foo_password", @@ -815,6 +825,7 @@ func TestNative_Compile_StagesPipelineTemplate(t *testing.T) { Engine: "vault", Type: "repo", Origin: &pipeline.Container{}, + Pull: "build_start", }, }, Services: pipeline.ContainerSlice{ @@ -962,6 +973,7 @@ func TestNative_Compile_StepsPipelineTemplate(t *testing.T) { Clone: true, Template: false, Environment: []string{"steps", "services", "secrets"}, + AutoCancel: &pipeline.CancelOptions{}, }, Steps: pipeline.ContainerSlice{ &pipeline.Container{ @@ -1042,6 +1054,7 @@ func TestNative_Compile_StepsPipelineTemplate(t *testing.T) { Engine: "native", Type: "repo", Origin: &pipeline.Container{}, + Pull: "build_start", }, &pipeline.Secret{ Name: "docker_password", @@ -1049,6 +1062,7 @@ func TestNative_Compile_StepsPipelineTemplate(t *testing.T) { Engine: "vault", Type: "repo", Origin: &pipeline.Container{}, + Pull: "build_start", }, &pipeline.Secret{ Name: "foo_password", @@ -1056,6 +1070,7 @@ func TestNative_Compile_StepsPipelineTemplate(t *testing.T) { Engine: "vault", Type: "repo", Origin: &pipeline.Container{}, + Pull: "build_start", }, }, Services: pipeline.ContainerSlice{ @@ -1157,6 +1172,7 @@ func TestNative_Compile_StepsPipelineTemplate_VelaFunction_TemplateName(t *testi Clone: true, Template: false, Environment: []string{"steps", "services", "secrets"}, + AutoCancel: &pipeline.CancelOptions{}, }, Steps: pipeline.ContainerSlice{ &pipeline.Container{ @@ -1277,6 +1293,7 @@ func TestNative_Compile_StepsPipelineTemplate_VelaFunction_TemplateName_Inline(t Clone: true, Template: false, Environment: []string{"steps", "services", "secrets"}, + AutoCancel: &pipeline.CancelOptions{}, }, Steps: pipeline.ContainerSlice{ &pipeline.Container{ @@ -1451,6 +1468,7 @@ func TestNative_Compile_Clone(t *testing.T) { Clone: false, Template: false, Environment: []string{"steps", "services", "secrets"}, + AutoCancel: &pipeline.CancelOptions{}, }, Steps: pipeline.ContainerSlice{ &pipeline.Container{ @@ -1481,6 +1499,7 @@ func TestNative_Compile_Clone(t *testing.T) { Clone: true, Template: false, Environment: []string{"steps", "services", "secrets"}, + AutoCancel: &pipeline.CancelOptions{}, }, Steps: pipeline.ContainerSlice{ &pipeline.Container{ @@ -1520,6 +1539,7 @@ func TestNative_Compile_Clone(t *testing.T) { Clone: false, Template: false, Environment: []string{"steps", "services", "secrets"}, + AutoCancel: &pipeline.CancelOptions{}, }, Steps: pipeline.ContainerSlice{ &pipeline.Container{ @@ -1640,6 +1660,7 @@ func TestNative_Compile_Pipeline_Type(t *testing.T) { Clone: true, Template: false, Environment: []string{"steps", "services", "secrets"}, + AutoCancel: &pipeline.CancelOptions{}, }, Steps: pipeline.ContainerSlice{ &pipeline.Container{ @@ -1685,6 +1706,7 @@ func TestNative_Compile_Pipeline_Type(t *testing.T) { Clone: true, Template: false, Environment: []string{"steps", "services", "secrets"}, + AutoCancel: &pipeline.CancelOptions{}, }, Steps: pipeline.ContainerSlice{ &pipeline.Container{ @@ -1730,6 +1752,7 @@ func TestNative_Compile_Pipeline_Type(t *testing.T) { Clone: true, Template: false, Environment: []string{"steps", "services", "secrets"}, + AutoCancel: &pipeline.CancelOptions{}, }, Steps: pipeline.ContainerSlice{ &pipeline.Container{ @@ -2234,6 +2257,7 @@ func Test_Compile_Inline(t *testing.T) { Metadata: pipeline.Metadata{ Clone: true, Environment: []string{"steps", "services", "secrets"}, + AutoCancel: &pipeline.CancelOptions{}, }, Stages: []*pipeline.Stage{ { @@ -2389,6 +2413,7 @@ func Test_Compile_Inline(t *testing.T) { Metadata: pipeline.Metadata{ Clone: true, Environment: []string{"steps", "services", "secrets"}, + AutoCancel: &pipeline.CancelOptions{}, }, Stages: []*pipeline.Stage{ { @@ -2562,6 +2587,7 @@ func Test_Compile_Inline(t *testing.T) { Metadata: pipeline.Metadata{ Clone: true, Environment: []string{"steps", "services", "secrets"}, + AutoCancel: &pipeline.CancelOptions{}, }, Steps: []*pipeline.Container{ { @@ -2678,6 +2704,7 @@ func Test_Compile_Inline(t *testing.T) { Metadata: pipeline.Metadata{ Clone: true, Environment: []string{"steps", "services", "secrets"}, + AutoCancel: &pipeline.CancelOptions{}, }, Steps: []*pipeline.Container{ { @@ -2717,6 +2744,7 @@ func Test_Compile_Inline(t *testing.T) { Engine: "native", Type: "repo", Origin: &pipeline.Container{}, + Pull: "build_start", }, &pipeline.Secret{ Name: "docker_username", @@ -2724,6 +2752,7 @@ func Test_Compile_Inline(t *testing.T) { Engine: "native", Type: "repo", Origin: &pipeline.Container{}, + Pull: "build_start", }, &pipeline.Secret{ Name: "docker_password", @@ -2731,6 +2760,7 @@ func Test_Compile_Inline(t *testing.T) { Engine: "vault", Type: "repo", Origin: &pipeline.Container{}, + Pull: "build_start", }, &pipeline.Secret{ Name: "docker_username", @@ -2738,6 +2768,7 @@ func Test_Compile_Inline(t *testing.T) { Engine: "native", Type: "org", Origin: &pipeline.Container{}, + Pull: "build_start", }, &pipeline.Secret{ Name: "docker_password", @@ -2745,6 +2776,7 @@ func Test_Compile_Inline(t *testing.T) { Engine: "vault", Type: "org", Origin: &pipeline.Container{}, + Pull: "build_start", }, &pipeline.Secret{ Name: "docker_username", @@ -2752,6 +2784,7 @@ func Test_Compile_Inline(t *testing.T) { Engine: "native", Type: "shared", Origin: &pipeline.Container{}, + Pull: "build_start", }, &pipeline.Secret{ Name: "docker_password", @@ -2759,6 +2792,7 @@ func Test_Compile_Inline(t *testing.T) { Engine: "vault", Type: "shared", Origin: &pipeline.Container{}, + Pull: "build_start", }, }, }, @@ -2775,6 +2809,7 @@ func Test_Compile_Inline(t *testing.T) { Metadata: pipeline.Metadata{ Clone: true, Environment: []string{"steps", "services", "secrets"}, + AutoCancel: &pipeline.CancelOptions{}, }, Steps: []*pipeline.Container{ { @@ -2850,6 +2885,7 @@ func Test_Compile_Inline(t *testing.T) { Metadata: pipeline.Metadata{ Clone: true, Environment: []string{"steps", "services", "secrets"}, + AutoCancel: &pipeline.CancelOptions{}, }, Steps: []*pipeline.Container{ { @@ -2894,6 +2930,7 @@ func Test_Compile_Inline(t *testing.T) { Metadata: pipeline.Metadata{ Clone: true, Environment: []string{"steps", "services", "secrets"}, + AutoCancel: &pipeline.CancelOptions{}, }, Stages: []*pipeline.Stage{ { diff --git a/compiler/native/doc.go b/compiler/native/doc.go index 81877d3da..be02778d1 100644 --- a/compiler/native/doc.go +++ b/compiler/native/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package native provides the ability for Vela to // reconstruct a yaml configuration into an executable diff --git a/compiler/native/environment.go b/compiler/native/environment.go index 7536731a6..5841825b3 100644 --- a/compiler/native/environment.go +++ b/compiler/native/environment.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native @@ -92,18 +90,6 @@ func (c *client) EnvironmentStep(s *yaml.Step, stageEnv raw.StringSliceMap) (*ya // gather set of default environment variables defaultEnv := environment(c.build, c.metadata, c.repo, c.user) - // check if the compiler is setup for a local pipeline - // and the step isn't setup to run in a detached state - if c.local && !s.Detach { - // capture all environment variables from the local environment - for _, e := range os.Environ() { - // split the environment variable on = into a key value pair - parts := strings.SplitN(e, "=", 2) - - env[parts[0]] = parts[1] - } - } - // inject the declared stage environment // WARNING: local env can override global + stage env = appendMap(env, stageEnv) @@ -122,6 +108,17 @@ func (c *client) EnvironmentStep(s *yaml.Step, stageEnv raw.StringSliceMap) (*ya env[k] = v } + // check if the compiler is setup for a local pipeline + if c.local && !s.Detach { + // capture all environment variables from the local environment + for _, e := range os.Environ() { + // split the environment variable on = into a key value pair + parts := strings.SplitN(e, "=", 2) + + env[parts[0]] = parts[1] + } + } + // inject the declared parameter // variables to the build step for k, v := range s.Parameters { @@ -194,17 +191,6 @@ func (c *client) EnvironmentSecrets(s yaml.SecretSlice, globalEnv raw.StringSlic // gather set of default environment variables defaultEnv := environment(c.build, c.metadata, c.repo, c.user) - // check if the compiler is setup for a local pipeline - if c.local { - // capture all environment variables from the local environment - for _, e := range os.Environ() { - // split the environment variable on = into a key value pair - parts := strings.SplitN(e, "=", 2) - - env[parts[0]] = parts[1] - } - } - // inject the declared global environment // WARNING: local env can override global env = appendMap(env, globalEnv) @@ -223,6 +209,17 @@ func (c *client) EnvironmentSecrets(s yaml.SecretSlice, globalEnv raw.StringSlic env[k] = v } + // check if the compiler is setup for a local pipeline + if c.local { + // capture all environment variables from the local environment + for _, e := range os.Environ() { + // split the environment variable on = into a key value pair + parts := strings.SplitN(e, "=", 2) + + env[parts[0]] = parts[1] + } + } + // inject the declared parameter // variables to the build secret for k, v := range secret.Origin.Parameters { @@ -252,6 +249,14 @@ func (c *client) EnvironmentBuild() map[string]string { // gather set of default environment variables defaultEnv := environment(c.build, c.metadata, c.repo, c.user) + // inject the default environment + // variables to the build + // we do this after injecting the declared environment + // to ensure the default env overrides any conflicts + for k, v := range defaultEnv { + env[k] = v + } + // check if the compiler is setup for a local pipeline if c.local { // capture all environment variables from the local environment @@ -263,14 +268,6 @@ func (c *client) EnvironmentBuild() map[string]string { } } - // inject the default environment - // variables to the build secret - // we do this after injecting the declared environment - // to ensure the default env overrides any conflicts - for k, v := range defaultEnv { - env[k] = v - } - return env } diff --git a/compiler/native/environment_test.go b/compiler/native/environment_test.go index 409a26cfa..3632ea5d2 100644 --- a/compiler/native/environment_test.go +++ b/compiler/native/environment_test.go @@ -1,12 +1,11 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native import ( "flag" "reflect" + "strings" "testing" "github.com/go-vela/types/raw" @@ -202,17 +201,47 @@ func TestNative_EnvironmentSteps(t *testing.T) { }, } - // run test + // run test non-local compiler, err := New(c) if err != nil { t.Errorf("Unable to create new compiler: %v", err) } + // run test local + compiler.WithLocal(true) + + t.Setenv("VELA_BUILD_COMMIT", "123abc") + got, err := compiler.EnvironmentSteps(s, e) if err != nil { t.Errorf("EnvironmentSteps returned err: %v", err) } + // cannot use complete diff since local compiler pulls from OS env + if !strings.EqualFold(got[0].Environment["VELA_BUILD_COMMIT"], "123abc") { + t.Errorf("EnvironmentSteps with local compiler should have set VELA_BUILD_COMMIT to 123abc, got %s", got[0].Environment["VELA_BUILD_COMMIT"]) + } + + // test without local + compiler.WithLocal(false) + + // reset s + s = yaml.StepSlice{ + &yaml.Step{ + Image: "alpine", + Name: str, + Pull: "always", + Environment: raw.StringSliceMap{ + "BUILD_CHANNEL": "foo", + }, + }, + } + + got, err = compiler.EnvironmentSteps(s, e) + if err != nil { + t.Errorf("EnvironmentSteps returned err: %v", err) + } + if diff := cmp.Diff(got, want); diff != "" { t.Errorf("EnvironmentSteps mismatch (-want +got):\n%s", diff) } diff --git a/compiler/native/expand.go b/compiler/native/expand.go index 02faface2..c0173417b 100644 --- a/compiler/native/expand.go +++ b/compiler/native/expand.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native @@ -91,7 +89,10 @@ func (c *client) ExpandSteps(s *yaml.Build, tmpls map[string]*yaml.Template, r * Steps: *check.ToPipeline(), } - pipeline = pipeline.Purge(r) + pipeline, err := pipeline.Purge(r) + if err != nil { + return nil, fmt.Errorf("unable to purge pipeline: %w", err) + } // if step purged, do not proceed with expansion if len(pipeline.Steps) == 0 { @@ -206,6 +207,10 @@ func (c *client) getTemplate(tmpl *yaml.Template, name string) ([]byte, error) { switch { case c.local: + a := &afero.Afero{ + Fs: afero.NewOsFs(), + } + // iterate over locally provided templates for _, t := range c.localTemplates { parts := strings.Split(t, ":") @@ -213,11 +218,8 @@ func (c *client) getTemplate(tmpl *yaml.Template, name string) ([]byte, error) { return nil, fmt.Errorf("local templates must be provided in the form :, got %s", t) } + // if local template has a match, read file path provided if strings.EqualFold(tmpl.Name, parts[0]) { - a := &afero.Afero{ - Fs: afero.NewOsFs(), - } - bytes, err = a.ReadFile(parts[1]) if err != nil { return bytes, err @@ -227,8 +229,22 @@ func (c *client) getTemplate(tmpl *yaml.Template, name string) ([]byte, error) { } } - // no template found in provided templates, exit with error - return nil, fmt.Errorf("unable to find template %s: not supplied in list %s", tmpl.Name, c.localTemplates) + // file type templates can be retrieved locally using `source` + if strings.EqualFold(tmpl.Type, "file") { + bytes, err = a.ReadFile(tmpl.Source) + if err != nil { + return nil, fmt.Errorf("unable to read file for template %s. `File` type templates must be located at `source` or supplied to local template files", tmpl.Name) + } + + return bytes, nil + } + + // local exec may still request remote templates + if !strings.EqualFold(tmpl.Type, "github") { + return nil, fmt.Errorf("unable to find template %s: not supplied in list %s", tmpl.Name, c.localTemplates) + } + + fallthrough case strings.EqualFold(tmpl.Type, "github"): // parse source from template diff --git a/compiler/native/expand_test.go b/compiler/native/expand_test.go index d2a8a92b6..0ea845cfc 100644 --- a/compiler/native/expand_test.go +++ b/compiler/native/expand_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native @@ -120,6 +118,7 @@ func TestNative_ExpandStages(t *testing.T) { Engine: "native", Type: "repo", Origin: yaml.Origin{}, + Pull: "build_start", }, &yaml.Secret{ Name: "foo_password", @@ -127,6 +126,7 @@ func TestNative_ExpandStages(t *testing.T) { Engine: "vault", Type: "repo", Origin: yaml.Origin{}, + Pull: "build_start", }, } @@ -289,6 +289,7 @@ func TestNative_ExpandSteps(t *testing.T) { Engine: "native", Type: "repo", Origin: yaml.Origin{}, + Pull: "build_start", }, &yaml.Secret{ Name: "foo_password", @@ -296,6 +297,7 @@ func TestNative_ExpandSteps(t *testing.T) { Engine: "vault", Type: "repo", Origin: yaml.Origin{}, + Pull: "build_start", }, } @@ -508,6 +510,7 @@ func TestNative_ExpandStepsMulti(t *testing.T) { Engine: "native", Type: "repo", Origin: yaml.Origin{}, + Pull: "build_start", }, &yaml.Secret{ Name: "foo_password", @@ -515,6 +518,7 @@ func TestNative_ExpandStepsMulti(t *testing.T) { Engine: "vault", Type: "repo", Origin: yaml.Origin{}, + Pull: "build_start", }, &yaml.Secret{ Name: "vault_token", @@ -522,6 +526,7 @@ func TestNative_ExpandStepsMulti(t *testing.T) { Engine: "native", Type: "repo", Origin: yaml.Origin{}, + Pull: "build_start", }, &yaml.Secret{ Origin: yaml.Origin{ @@ -806,6 +811,7 @@ func TestNative_ExpandSteps_TemplateCallTemplate(t *testing.T) { Engine: "native", Type: "repo", Origin: yaml.Origin{}, + Pull: "build_start", }, &yaml.Secret{ Name: "foo_password", @@ -813,6 +819,7 @@ func TestNative_ExpandSteps_TemplateCallTemplate(t *testing.T) { Engine: "vault", Type: "repo", Origin: yaml.Origin{}, + Pull: "build_start", }, } diff --git a/compiler/native/initialize.go b/compiler/native/initialize.go index b1824d5ab..e54b10ff1 100644 --- a/compiler/native/initialize.go +++ b/compiler/native/initialize.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native diff --git a/compiler/native/initialize_test.go b/compiler/native/initialize_test.go index 9b0468166..6a0b2d31c 100644 --- a/compiler/native/initialize_test.go +++ b/compiler/native/initialize_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native diff --git a/compiler/native/native.go b/compiler/native/native.go index d2b5ebd19..a93c6fd50 100644 --- a/compiler/native/native.go +++ b/compiler/native/native.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native diff --git a/compiler/native/native_test.go b/compiler/native/native_test.go index de1f60631..36be98195 100644 --- a/compiler/native/native_test.go +++ b/compiler/native/native_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native diff --git a/compiler/native/parse.go b/compiler/native/parse.go index 96e9ec25a..83a401ddf 100644 --- a/compiler/native/parse.go +++ b/compiler/native/parse.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native diff --git a/compiler/native/parse_test.go b/compiler/native/parse_test.go index 0bb5a0195..7176438e1 100644 --- a/compiler/native/parse_test.go +++ b/compiler/native/parse_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native @@ -322,12 +320,14 @@ func TestNative_Parse_StagesPipeline(t *testing.T) { Key: "org/repo/docker/username", Engine: "native", Type: "repo", + Pull: "build_start", }, &yaml.Secret{ Name: "docker_password", Key: "org/repo/docker/password", Engine: "vault", Type: "repo", + Pull: "build_start", }, }, } @@ -350,6 +350,7 @@ func TestNative_Parse_StagesPipeline(t *testing.T) { func TestNative_Parse_StepsPipeline(t *testing.T) { // setup types + tBool := true client, _ := New(cli.NewContext(nil, flag.NewFlagSet("test", 0), nil)) want := &yaml.Build{ Version: "1", @@ -357,6 +358,9 @@ func TestNative_Parse_StepsPipeline(t *testing.T) { Template: false, Clone: nil, Environment: []string{"steps", "services", "secrets"}, + AutoCancel: &yaml.CancelOptions{ + Running: &tBool, + }, }, Environment: map[string]string{ "HELLO": "Hello, Global Environment", @@ -419,12 +423,14 @@ func TestNative_Parse_StepsPipeline(t *testing.T) { Key: "org/repo/docker/username", Engine: "native", Type: "repo", + Pull: "build_start", }, &yaml.Secret{ Name: "docker_password", Key: "org/repo/docker/password", Engine: "vault", Type: "repo", + Pull: "build_start", }, }, } @@ -458,36 +464,42 @@ func TestNative_Parse_Secrets(t *testing.T) { Key: "org/repo/docker/username", Engine: "native", Type: "repo", + Pull: "build_start", }, &yaml.Secret{ Name: "docker_password", Key: "org/repo/docker/password", Engine: "vault", Type: "repo", + Pull: "build_start", }, &yaml.Secret{ Name: "docker_username", Key: "org/docker/username", Engine: "native", Type: "org", + Pull: "build_start", }, &yaml.Secret{ Name: "docker_password", Key: "org/docker/password", Engine: "vault", Type: "org", + Pull: "build_start", }, &yaml.Secret{ Name: "docker_username", Key: "org/team/docker/username", Engine: "native", Type: "shared", + Pull: "build_start", }, &yaml.Secret{ Name: "docker_password", Key: "org/team/docker/password", Engine: "vault", Type: "shared", + Pull: "build_start", }, }, } diff --git a/compiler/native/script.go b/compiler/native/script.go index 8256ee5a1..a5f09a38f 100644 --- a/compiler/native/script.go +++ b/compiler/native/script.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native diff --git a/compiler/native/script_test.go b/compiler/native/script_test.go index bde8adcda..c4855266d 100644 --- a/compiler/native/script_test.go +++ b/compiler/native/script_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native diff --git a/compiler/native/substitute.go b/compiler/native/substitute.go index fcfd2b263..e143cfc1b 100644 --- a/compiler/native/substitute.go +++ b/compiler/native/substitute.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native diff --git a/compiler/native/substitute_test.go b/compiler/native/substitute_test.go index da27378ac..a02d59f8f 100644 --- a/compiler/native/substitute_test.go +++ b/compiler/native/substitute_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native diff --git a/compiler/native/testdata/steps_pipeline.yml b/compiler/native/testdata/steps_pipeline.yml index aa28e2e21..5f6e22ffd 100644 --- a/compiler/native/testdata/steps_pipeline.yml +++ b/compiler/native/testdata/steps_pipeline.yml @@ -3,6 +3,8 @@ version: "1" metadata: template: false + auto_cancel: + running: true environment: HELLO: "Hello, Global Environment" diff --git a/compiler/native/transform.go b/compiler/native/transform.go index 4742ae700..1165e6a40 100644 --- a/compiler/native/transform.go +++ b/compiler/native/transform.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native @@ -115,7 +113,12 @@ func (c *client) TransformStages(r *pipeline.RuleData, p *yaml.Build) (*pipeline secret.Origin.ID = pattern } - return pipeline.Purge(r), nil + build, err := pipeline.Purge(r) + if err != nil { + return nil, fmt.Errorf("unable to purge pipeline: %w", err) + } + + return build, nil } // TransformSteps converts a yaml configuration with steps into an executable pipeline. @@ -194,5 +197,10 @@ func (c *client) TransformSteps(r *pipeline.RuleData, p *yaml.Build) (*pipeline. secret.Origin.ID = pattern } - return pipeline.Purge(r), nil + build, err := pipeline.Purge(r) + if err != nil { + return nil, fmt.Errorf("unable to purge pipeline: %w", err) + } + + return build, nil } diff --git a/compiler/native/transform_test.go b/compiler/native/transform_test.go index 4e5e832d5..743f9a46c 100644 --- a/compiler/native/transform_test.go +++ b/compiler/native/transform_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native @@ -114,7 +112,8 @@ func TestNative_TransformStages(t *testing.T) { ID: "__0", Version: "v1", Metadata: pipeline.Metadata{ - Clone: true, + Clone: true, + AutoCancel: &pipeline.CancelOptions{}, }, Services: pipeline.ContainerSlice{ &pipeline.Container{ @@ -169,7 +168,8 @@ func TestNative_TransformStages(t *testing.T) { ID: "localOrg_localRepo_1", Version: "v1", Metadata: pipeline.Metadata{ - Clone: true, + Clone: true, + AutoCancel: &pipeline.CancelOptions{}, }, Services: pipeline.ContainerSlice{ &pipeline.Container{ @@ -341,7 +341,8 @@ func TestNative_TransformSteps(t *testing.T) { ID: "__0", Version: "v1", Metadata: pipeline.Metadata{ - Clone: true, + Clone: true, + AutoCancel: &pipeline.CancelOptions{}, }, Services: pipeline.ContainerSlice{ &pipeline.Container{ @@ -391,7 +392,8 @@ func TestNative_TransformSteps(t *testing.T) { ID: "localOrg_localRepo_1", Version: "v1", Metadata: pipeline.Metadata{ - Clone: true, + Clone: true, + AutoCancel: &pipeline.CancelOptions{}, }, Services: pipeline.ContainerSlice{ &pipeline.Container{ diff --git a/compiler/native/validate.go b/compiler/native/validate.go index dec7c7af9..1d5b0440b 100644 --- a/compiler/native/validate.go +++ b/compiler/native/validate.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native diff --git a/compiler/native/validate_test.go b/compiler/native/validate_test.go index 772494aa7..550bbd3ae 100644 --- a/compiler/native/validate_test.go +++ b/compiler/native/validate_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native diff --git a/compiler/registry/doc.go b/compiler/registry/doc.go index 2064281e4..9de02660b 100644 --- a/compiler/registry/doc.go +++ b/compiler/registry/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package registry provides the ability for Vela to // integrate with different supported Template registries. diff --git a/compiler/registry/github/doc.go b/compiler/registry/github/doc.go index 1bab3812e..18201550f 100644 --- a/compiler/registry/github/doc.go +++ b/compiler/registry/github/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package github provides the ability for Vela to // integrate with GitHub or GitHub Enterprise as a diff --git a/compiler/registry/github/github.go b/compiler/registry/github/github.go index eb8177d02..2fbf3ffc4 100644 --- a/compiler/registry/github/github.go +++ b/compiler/registry/github/github.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package github @@ -9,7 +7,7 @@ import ( "net/url" "strings" - "github.com/google/go-github/v54/github" + "github.com/google/go-github/v56/github" "golang.org/x/oauth2" ) diff --git a/compiler/registry/github/github_test.go b/compiler/registry/github/github_test.go index d83619b4d..6ef509736 100644 --- a/compiler/registry/github/github_test.go +++ b/compiler/registry/github/github_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package github @@ -12,7 +10,7 @@ import ( "reflect" "testing" - "github.com/google/go-github/v54/github" + "github.com/google/go-github/v56/github" "golang.org/x/oauth2" ) diff --git a/compiler/registry/github/parse.go b/compiler/registry/github/parse.go index 9c40cf1c8..45657ed0a 100644 --- a/compiler/registry/github/parse.go +++ b/compiler/registry/github/parse.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package github diff --git a/compiler/registry/github/parse_test.go b/compiler/registry/github/parse_test.go index 1fe12ceab..4019f092e 100644 --- a/compiler/registry/github/parse_test.go +++ b/compiler/registry/github/parse_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package github diff --git a/compiler/registry/github/template.go b/compiler/registry/github/template.go index 573bbe689..a41cf16f8 100644 --- a/compiler/registry/github/template.go +++ b/compiler/registry/github/template.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package github @@ -13,7 +11,7 @@ import ( "github.com/go-vela/types/library" - "github.com/google/go-github/v54/github" + "github.com/google/go-github/v56/github" ) // Template captures the templated pipeline configuration from the GitHub repo. diff --git a/compiler/registry/github/template_test.go b/compiler/registry/github/template_test.go index af59a6d61..dd55fda7d 100644 --- a/compiler/registry/github/template_test.go +++ b/compiler/registry/github/template_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package github diff --git a/compiler/registry/github/testdata/template.json b/compiler/registry/github/testdata/template.json index 699a6b846..bbc31496a 100644 --- a/compiler/registry/github/testdata/template.json +++ b/compiler/registry/github/testdata/template.json @@ -8,11 +8,11 @@ "sha": "3d21ec53a331a6f037a91c368710b99387d012c1", "url": "https://api.github.com/repos/octokit/octokit.rb/contents/template.yml", "git_url": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/3d21ec53a331a6f037a91c368710b99387d012c1", - "html_url": "https://github.com/octokit/octokit.rb/blob/master/template.yml", - "download_url": "https://raw.githubusercontent.com/octokit/octokit.rb/master/template.yml", + "html_url": "https://github.com/octokit/octokit.rb/blob/main/template.yml", + "download_url": "https://raw.githubusercontent.com/octokit/octokit.rb/main/template.yml", "_links": { "git": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/3d21ec53a331a6f037a91c368710b99387d012c1", "self": "https://api.github.com/repos/octokit/octokit.rb/contents/template.yml", - "html": "https://github.com/octokit/octokit.rb/blob/master/template.yml" + "html": "https://github.com/octokit/octokit.rb/blob/main/template.yml" } } diff --git a/compiler/registry/registry.go b/compiler/registry/registry.go index fbe128439..2ea9caffe 100644 --- a/compiler/registry/registry.go +++ b/compiler/registry/registry.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package registry diff --git a/compiler/registry/source.go b/compiler/registry/source.go index c0974059f..42b3c7680 100644 --- a/compiler/registry/source.go +++ b/compiler/registry/source.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package registry diff --git a/compiler/template/doc.go b/compiler/template/doc.go index f9e37fb29..9bd6294eb 100644 --- a/compiler/template/doc.go +++ b/compiler/template/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package template provides the ability for Vela to // render a templated yaml configuration into an diff --git a/compiler/template/native/convert.go b/compiler/template/native/convert.go index 68385c6cb..ee45ef809 100644 --- a/compiler/template/native/convert.go +++ b/compiler/template/native/convert.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native diff --git a/compiler/template/native/convert_test.go b/compiler/template/native/convert_test.go index db0b42a8f..4ab988f03 100644 --- a/compiler/template/native/convert_test.go +++ b/compiler/template/native/convert_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native diff --git a/compiler/template/native/doc.go b/compiler/template/native/doc.go index 34c41a275..f8169c15b 100644 --- a/compiler/template/native/doc.go +++ b/compiler/template/native/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package native provides the ability for Vela to // render a templated yaml configuration into an diff --git a/compiler/template/native/render.go b/compiler/template/native/render.go index 869e4588a..d4185a3d3 100644 --- a/compiler/template/native/render.go +++ b/compiler/template/native/render.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native diff --git a/compiler/template/native/render_test.go b/compiler/template/native/render_test.go index 1380f6703..f4c92160d 100644 --- a/compiler/template/native/render_test.go +++ b/compiler/template/native/render_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native @@ -124,7 +122,7 @@ func TestNative_RenderBuild(t *testing.T) { got, err := RenderBuild("build", string(sFile), map[string]string{ "VELA_REPO_FULL_NAME": "octocat/hello-world", - "VELA_BUILD_BRANCH": "master", + "VELA_BUILD_BRANCH": "main", }, map[string]interface{}{}) if (err != nil) != tt.wantErr { t.Errorf("RenderBuild() error = %v, wantErr %v", err, tt.wantErr) diff --git a/compiler/template/native/testdata/build/conditional/build.yml b/compiler/template/native/testdata/build/conditional/build.yml index 6c5745632..39acce9f5 100644 --- a/compiler/template/native/testdata/build/conditional/build.yml +++ b/compiler/template/native/testdata/build/conditional/build.yml @@ -5,7 +5,7 @@ version: "1" steps: - {{ if (eq $br "master") }} + {{ if (eq $br "main") }} - name: install commands: diff --git a/compiler/template/native/testdata/step/conditional/step.yml b/compiler/template/native/testdata/step/conditional/step.yml index f3e4401e8..e46064ad3 100644 --- a/compiler/template/native/testdata/step/conditional/step.yml +++ b/compiler/template/native/testdata/step/conditional/step.yml @@ -5,6 +5,6 @@ steps: vars: image: golang:latest pull_policy: "pull: true" - branch: master + branch: main \ No newline at end of file diff --git a/compiler/template/native/testdata/step/conditional/tmpl.yml b/compiler/template/native/testdata/step/conditional/tmpl.yml index f198f06e8..932ffeda9 100644 --- a/compiler/template/native/testdata/step/conditional/tmpl.yml +++ b/compiler/template/native/testdata/step/conditional/tmpl.yml @@ -5,7 +5,7 @@ metadata: steps: - {{ if (eq $br "master") }} + {{ if (eq $br "main") }} - name: install commands: diff --git a/compiler/template/native/testdata/step/to_yaml/step.yml b/compiler/template/native/testdata/step/to_yaml/step.yml index c8baf13d0..152394b36 100644 --- a/compiler/template/native/testdata/step/to_yaml/step.yml +++ b/compiler/template/native/testdata/step/to_yaml/step.yml @@ -5,4 +5,4 @@ steps: vars: ruleset: event: [push, pull_request] - branch: [master] + branch: [main] diff --git a/compiler/template/native/testdata/step/to_yaml/want.yml b/compiler/template/native/testdata/step/to_yaml/want.yml index 2eaa32d2d..e739a1f3f 100644 --- a/compiler/template/native/testdata/step/to_yaml/want.yml +++ b/compiler/template/native/testdata/step/to_yaml/want.yml @@ -5,4 +5,4 @@ steps: image: alpine ruleset: event: [ push, pull_request ] - branch: [ master ] + branch: [ main ] diff --git a/compiler/template/starlark/convert.go b/compiler/template/starlark/convert.go index 474086316..9e7bfa70a 100644 --- a/compiler/template/starlark/convert.go +++ b/compiler/template/starlark/convert.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package starlark diff --git a/compiler/template/starlark/convert_test.go b/compiler/template/starlark/convert_test.go index b6eb03bf8..49101117e 100644 --- a/compiler/template/starlark/convert_test.go +++ b/compiler/template/starlark/convert_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package starlark diff --git a/compiler/template/starlark/render.go b/compiler/template/starlark/render.go index 3ed9cbb3c..4ff2c59ed 100644 --- a/compiler/template/starlark/render.go +++ b/compiler/template/starlark/render.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package starlark diff --git a/compiler/template/starlark/render_test.go b/compiler/template/starlark/render_test.go index 7bd25b06b..d07a74a6f 100644 --- a/compiler/template/starlark/render_test.go +++ b/compiler/template/starlark/render_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package starlark @@ -210,7 +208,7 @@ func TestNative_RenderBuild(t *testing.T) { got, err := RenderBuild("build", string(sFile), map[string]string{ "VELA_REPO_FULL_NAME": "octocat/hello-world", - "VELA_BUILD_BRANCH": "master", + "VELA_BUILD_BRANCH": "main", "VELA_REPO_ORG": "octocat", }, map[string]interface{}{}, tt.execLimit) if (err != nil) != tt.wantErr { diff --git a/compiler/template/starlark/starlark.go b/compiler/template/starlark/starlark.go index 0299ef259..98b9a2c64 100644 --- a/compiler/template/starlark/starlark.go +++ b/compiler/template/starlark/starlark.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package starlark diff --git a/compiler/template/starlark/starlark_test.go b/compiler/template/starlark/starlark_test.go index e3aa65626..325e4724c 100644 --- a/compiler/template/starlark/starlark_test.go +++ b/compiler/template/starlark/starlark_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package starlark diff --git a/compiler/template/starlark/testdata/build/conditional/build.star b/compiler/template/starlark/testdata/build/conditional/build.star index e00c5e3b8..5a1ab0b7b 100644 --- a/compiler/template/starlark/testdata/build/conditional/build.star +++ b/compiler/template/starlark/testdata/build/conditional/build.star @@ -4,7 +4,7 @@ def main(ctx): steps = [] for name in stepNames: - if name == "foo" and ctx["vela"]["build"]["branch"] == "master": + if name == "foo" and ctx["vela"]["build"]["branch"] == "main": steps.append(step(name)) return { diff --git a/compiler/template/starlark/testdata/build/large/want.yml b/compiler/template/starlark/testdata/build/large/want.yml index a9aaca543..a1604b551 100644 --- a/compiler/template/starlark/testdata/build/large/want.yml +++ b/compiler/template/starlark/testdata/build/large/want.yml @@ -56,7 +56,7 @@ stages: steps: - ruleset: if: - event: ['pull_request:opened', 'pull_request:synchronize'] + event: ['pull_request:opened', 'pull_request:synchronize', 'pull_request:reopened'] matcher: filepath operator: and secrets: @@ -112,7 +112,7 @@ stages: steps: - ruleset: if: - event: ['pull_request:opened', 'pull_request:synchronize'] + event: ['pull_request:opened', 'pull_request:synchronize', 'pull_request:reopened'] matcher: filepath operator: and secrets: @@ -168,7 +168,7 @@ stages: steps: - ruleset: if: - event: ['pull_request:opened', 'pull_request:synchronize'] + event: ['pull_request:opened', 'pull_request:synchronize', 'pull_request:reopened'] matcher: filepath operator: and secrets: @@ -224,7 +224,7 @@ stages: steps: - ruleset: if: - event: ['pull_request:opened', 'pull_request:synchronize'] + event: ['pull_request:opened', 'pull_request:synchronize', 'pull_request:reopened'] matcher: filepath operator: and secrets: @@ -280,7 +280,7 @@ stages: steps: - ruleset: if: - event: ['pull_request:opened', 'pull_request:synchronize'] + event: ['pull_request:opened', 'pull_request:synchronize', 'pull_request:reopened'] matcher: filepath operator: and secrets: @@ -336,7 +336,7 @@ stages: steps: - ruleset: if: - event: ['pull_request:opened', 'pull_request:synchronize'] + event: ['pull_request:opened', 'pull_request:synchronize', 'pull_request:reopened'] matcher: filepath operator: and secrets: @@ -392,7 +392,7 @@ stages: steps: - ruleset: if: - event: ['pull_request:opened', 'pull_request:synchronize'] + event: ['pull_request:opened', 'pull_request:synchronize', 'pull_request:reopened'] matcher: filepath operator: and secrets: @@ -448,7 +448,7 @@ stages: steps: - ruleset: if: - event: ['pull_request:opened', 'pull_request:synchronize'] + event: ['pull_request:opened', 'pull_request:synchronize', 'pull_request:reopened'] matcher: filepath operator: and secrets: @@ -504,7 +504,7 @@ stages: steps: - ruleset: if: - event: ['pull_request:opened', 'pull_request:synchronize'] + event: ['pull_request:opened', 'pull_request:synchronize', 'pull_request:reopened'] matcher: filepath operator: and secrets: @@ -560,7 +560,7 @@ stages: steps: - ruleset: if: - event: ['pull_request:opened', 'pull_request:synchronize'] + event: ['pull_request:opened', 'pull_request:synchronize', 'pull_request:reopened'] matcher: filepath operator: and secrets: @@ -616,7 +616,7 @@ stages: steps: - ruleset: if: - event: ['pull_request:opened', 'pull_request:synchronize'] + event: ['pull_request:opened', 'pull_request:synchronize', 'pull_request:reopened'] matcher: filepath operator: and secrets: @@ -672,7 +672,7 @@ stages: steps: - ruleset: if: - event: ['pull_request:opened', 'pull_request:synchronize'] + event: ['pull_request:opened', 'pull_request:synchronize', 'pull_request:reopened'] matcher: filepath operator: and secrets: @@ -728,7 +728,7 @@ stages: steps: - ruleset: if: - event: ['pull_request:opened', 'pull_request:synchronize'] + event: ['pull_request:opened', 'pull_request:synchronize', 'pull_request:reopened'] matcher: filepath operator: and secrets: @@ -784,7 +784,7 @@ stages: steps: - ruleset: if: - event: ['pull_request:opened', 'pull_request:synchronize'] + event: ['pull_request:opened', 'pull_request:synchronize', 'pull_request:reopened'] matcher: filepath operator: and secrets: @@ -840,7 +840,7 @@ stages: steps: - ruleset: if: - event: ['pull_request:opened', 'pull_request:synchronize'] + event: ['pull_request:opened', 'pull_request:synchronize', 'pull_request:reopened'] matcher: filepath operator: and secrets: @@ -896,7 +896,7 @@ stages: steps: - ruleset: if: - event: ['pull_request:opened', 'pull_request:synchronize'] + event: ['pull_request:opened', 'pull_request:synchronize', 'pull_request:reopened'] matcher: filepath operator: and secrets: diff --git a/compiler/template/template.go b/compiler/template/template.go index 75cc8eda9..6ace9c8c2 100644 --- a/compiler/template/template.go +++ b/compiler/template/template.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package template diff --git a/database/build/build.go b/database/build/build.go index ce750e5ee..8342471e7 100644 --- a/database/build/build.go +++ b/database/build/build.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/build/build_test.go b/database/build/build_test.go index 60dc540a2..ea99ec5e5 100644 --- a/database/build/build_test.go +++ b/database/build/build_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build @@ -266,7 +264,7 @@ func testRepo() *library.Repo { type AnyArgument struct{} // Match satisfies sqlmock.Argument interface. -func (a AnyArgument) Match(v driver.Value) bool { +func (a AnyArgument) Match(_ driver.Value) bool { return true } diff --git a/database/build/clean.go b/database/build/clean.go index 700998687..8e8f17836 100644 --- a/database/build/clean.go +++ b/database/build/clean.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/build/clean_test.go b/database/build/clean_test.go index 279268ff4..28eb29195 100644 --- a/database/build/clean_test.go +++ b/database/build/clean_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/build/count.go b/database/build/count.go index 57c84030c..02960a50d 100644 --- a/database/build/count.go +++ b/database/build/count.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/build/count_deployment.go b/database/build/count_deployment.go index 21e58c6c8..da3b23927 100644 --- a/database/build/count_deployment.go +++ b/database/build/count_deployment.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/build/count_deployment_test.go b/database/build/count_deployment_test.go index 4b067896d..6b4f83823 100644 --- a/database/build/count_deployment_test.go +++ b/database/build/count_deployment_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/build/count_org.go b/database/build/count_org.go index 90e01c5e8..1d01a2cde 100644 --- a/database/build/count_org.go +++ b/database/build/count_org.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/build/count_org_test.go b/database/build/count_org_test.go index 77b60652b..6b6283dbb 100644 --- a/database/build/count_org_test.go +++ b/database/build/count_org_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/build/count_repo.go b/database/build/count_repo.go index e7fcee5b8..152d867a2 100644 --- a/database/build/count_repo.go +++ b/database/build/count_repo.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/build/count_repo_test.go b/database/build/count_repo_test.go index c7f406b32..ebf0dbe47 100644 --- a/database/build/count_repo_test.go +++ b/database/build/count_repo_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/build/count_status.go b/database/build/count_status.go index 98d4acf5b..e95ec8e1e 100644 --- a/database/build/count_status.go +++ b/database/build/count_status.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/build/count_status_test.go b/database/build/count_status_test.go index c35d694e0..cea339953 100644 --- a/database/build/count_status_test.go +++ b/database/build/count_status_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/build/count_test.go b/database/build/count_test.go index c29d3f04f..bdcc57078 100644 --- a/database/build/count_test.go +++ b/database/build/count_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/build/create.go b/database/build/create.go index ff5d7a91d..02b09ab2d 100644 --- a/database/build/create.go +++ b/database/build/create.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore similar code with update.go package build diff --git a/database/build/create_test.go b/database/build/create_test.go index c425c5db7..179aba160 100644 --- a/database/build/create_test.go +++ b/database/build/create_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/build/delete.go b/database/build/delete.go index a7048c7e7..9d49f3c12 100644 --- a/database/build/delete.go +++ b/database/build/delete.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/build/delete_test.go b/database/build/delete_test.go index 93d1b5459..33ca6e3d6 100644 --- a/database/build/delete_test.go +++ b/database/build/delete_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/build/get.go b/database/build/get.go index 8c57d7fe6..02df1d42a 100644 --- a/database/build/get.go +++ b/database/build/get.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/build/get_repo.go b/database/build/get_repo.go index 7b37bc2a7..3728b6232 100644 --- a/database/build/get_repo.go +++ b/database/build/get_repo.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/build/get_repo_test.go b/database/build/get_repo_test.go index 8a36b55e9..714494e48 100644 --- a/database/build/get_repo_test.go +++ b/database/build/get_repo_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/build/get_test.go b/database/build/get_test.go index 9646224b7..1a9dfc58f 100644 --- a/database/build/get_test.go +++ b/database/build/get_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/build/index.go b/database/build/index.go index 51dec6eba..f5bea2898 100644 --- a/database/build/index.go +++ b/database/build/index.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/build/index_test.go b/database/build/index_test.go index 35dd25008..03d02fc8d 100644 --- a/database/build/index_test.go +++ b/database/build/index_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/build/interface.go b/database/build/interface.go index d2b8d9f41..c2b468e39 100644 --- a/database/build/interface.go +++ b/database/build/interface.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build @@ -60,6 +58,8 @@ type BuildInterface interface { ListBuildsForRepo(context.Context, *library.Repo, map[string]interface{}, int64, int64, int, int) ([]*library.Build, int64, error) // ListPendingAndRunningBuilds defines a function that gets a list of pending and running builds. ListPendingAndRunningBuilds(context.Context, string) ([]*library.BuildQueue, error) + // ListPendingAndRunningBuildsForRepo defines a function that gets a list of pending and running builds for a repo. + ListPendingAndRunningBuildsForRepo(context.Context, *library.Repo) ([]*library.Build, error) // UpdateBuild defines a function that updates an existing build. UpdateBuild(context.Context, *library.Build) (*library.Build, error) } diff --git a/database/build/last_repo.go b/database/build/last_repo.go index 81861c8b4..36b923379 100644 --- a/database/build/last_repo.go +++ b/database/build/last_repo.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/build/last_repo_test.go b/database/build/last_repo_test.go index 07e5549b2..42ba67c7d 100644 --- a/database/build/last_repo_test.go +++ b/database/build/last_repo_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build @@ -20,7 +18,7 @@ func TestBuild_Engine_LastBuildForRepo(t *testing.T) { _build.SetRepoID(1) _build.SetNumber(1) _build.SetDeployPayload(nil) - _build.SetBranch("master") + _build.SetBranch("main") _repo := testRepo() _repo.SetID(1) @@ -37,10 +35,10 @@ func TestBuild_Engine_LastBuildForRepo(t *testing.T) { // create expected result in mock _rows := sqlmock.NewRows( []string{"id", "repo_id", "pipeline_id", "number", "parent", "event", "event_action", "status", "error", "enqueued", "created", "started", "finished", "deploy", "deploy_payload", "clone", "source", "title", "message", "commit", "sender", "author", "email", "link", "branch", "ref", "base_ref", "head_ref", "host", "runtime", "distribution", "timestamp"}). - AddRow(1, 1, nil, 1, 0, "", "", "", "", 0, 0, 0, 0, "", nil, "", "", "", "", "", "", "", "", "", "master", "", "", "", "", "", "", 0) + AddRow(1, 1, nil, 1, 0, "", "", "", "", 0, 0, 0, 0, "", nil, "", "", "", "", "", "", "", "", "", "main", "", "", "", "", "", "", 0) // ensure the mock expects the query - _mock.ExpectQuery(`SELECT * FROM "builds" WHERE repo_id = $1 AND branch = $2 ORDER BY number DESC LIMIT 1`).WithArgs(1, "master").WillReturnRows(_rows) + _mock.ExpectQuery(`SELECT * FROM "builds" WHERE repo_id = $1 AND branch = $2 ORDER BY number DESC LIMIT 1`).WithArgs(1, "main").WillReturnRows(_rows) _sqlite := testSqlite(t) defer func() { _sql, _ := _sqlite.client.DB(); _sql.Close() }() @@ -74,7 +72,7 @@ func TestBuild_Engine_LastBuildForRepo(t *testing.T) { // run tests for _, test := range tests { t.Run(test.name, func(t *testing.T) { - got, err := test.database.LastBuildForRepo(context.TODO(), _repo, "master") + got, err := test.database.LastBuildForRepo(context.TODO(), _repo, "main") if test.failure { if err == nil { diff --git a/database/build/list.go b/database/build/list.go index 9809af5d9..109d2ae5f 100644 --- a/database/build/list.go +++ b/database/build/list.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/build/list_deployment.go b/database/build/list_deployment.go index 0d931fae7..4c7b3468d 100644 --- a/database/build/list_deployment.go +++ b/database/build/list_deployment.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build @@ -27,7 +25,7 @@ func (e *engine) ListBuildsForDeployment(ctx context.Context, d *library.Deploym builds := []*library.Build{} // count the results - count, err := e.CountBuildsForDeployment(context.TODO(), d, filters) + count, err := e.CountBuildsForDeployment(ctx, d, filters) if err != nil { return builds, 0, err } diff --git a/database/build/list_deployment_test.go b/database/build/list_deployment_test.go index 57a54522d..35eef81a5 100644 --- a/database/build/list_deployment_test.go +++ b/database/build/list_deployment_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/build/list_org.go b/database/build/list_org.go index 254c0c9e9..6fed59519 100644 --- a/database/build/list_org.go +++ b/database/build/list_org.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/build/list_org_test.go b/database/build/list_org_test.go index 95fc9a456..130ff8fbc 100644 --- a/database/build/list_org_test.go +++ b/database/build/list_org_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/build/list_pending_running.go b/database/build/list_pending_running.go index dbee3e704..de4b4ac68 100644 --- a/database/build/list_pending_running.go +++ b/database/build/list_pending_running.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/build/list_pending_running_repo.go b/database/build/list_pending_running_repo.go new file mode 100644 index 000000000..3c82ca419 --- /dev/null +++ b/database/build/list_pending_running_repo.go @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: Apache-2.0 + +package build + +import ( + "context" + + "github.com/go-vela/types/constants" + "github.com/go-vela/types/database" + "github.com/go-vela/types/library" +) + +// ListPendingAndRunningBuilds gets a list of all pending and running builds in the provided timeframe from the database. +func (e *engine) ListPendingAndRunningBuildsForRepo(ctx context.Context, repo *library.Repo) ([]*library.Build, error) { + e.logger.Trace("listing all pending and running builds from the database") + + // variables to store query results and return value + b := new([]database.Build) + builds := []*library.Build{} + + // send query to the database and store result in variable + err := e.client. + Table(constants.TableBuild). + Select("*"). + Where("repo_id = ?", repo.GetID()). + Where("status = 'running' OR status = 'pending'"). + Find(&b). + Error + if err != nil { + return nil, err + } + + // iterate through all query results + for _, build := range *b { + // https://golang.org/doc/faq#closures_and_goroutines + tmp := build + + // convert query result to library type + // + // https://pkg.go.dev/github.com/go-vela/types/database#Build.ToLibrary + builds = append(builds, tmp.ToLibrary()) + } + + return builds, nil +} diff --git a/database/build/list_pending_running_repo_test.go b/database/build/list_pending_running_repo_test.go new file mode 100644 index 000000000..089a6d7b3 --- /dev/null +++ b/database/build/list_pending_running_repo_test.go @@ -0,0 +1,148 @@ +// SPDX-License-Identifier: Apache-2.0 + +package build + +import ( + "context" + "reflect" + "testing" + + "github.com/DATA-DOG/go-sqlmock" + "github.com/go-vela/types/constants" + "github.com/go-vela/types/database" + "github.com/go-vela/types/library" +) + +func TestBuild_Engine_ListPendingAndRunningBuildsForRepo(t *testing.T) { + // setup types + _buildOne := testBuild() + _buildOne.SetID(1) + _buildOne.SetRepoID(1) + _buildOne.SetNumber(1) + _buildOne.SetStatus("running") + _buildOne.SetCreated(1) + _buildOne.SetDeployPayload(nil) + + _buildTwo := testBuild() + _buildTwo.SetID(2) + _buildTwo.SetRepoID(1) + _buildTwo.SetNumber(2) + _buildTwo.SetStatus("pending") + _buildTwo.SetCreated(1) + _buildTwo.SetDeployPayload(nil) + + _buildThree := testBuild() + _buildThree.SetID(3) + _buildThree.SetRepoID(2) + _buildThree.SetNumber(1) + _buildThree.SetStatus("pending") + _buildThree.SetCreated(1) + _buildThree.SetDeployPayload(nil) + + _repo := testRepo() + _repo.SetID(1) + _repo.SetUserID(1) + _repo.SetHash("baz") + _repo.SetOrg("foo") + _repo.SetName("bar") + _repo.SetFullName("foo/bar") + _repo.SetVisibility("public") + + _repoTwo := testRepo() + _repoTwo.SetID(2) + _repoTwo.SetUserID(1) + _repoTwo.SetHash("bazzy") + _repoTwo.SetOrg("foo") + _repoTwo.SetName("baz") + _repoTwo.SetFullName("foo/baz") + _repoTwo.SetVisibility("public") + + _postgres, _mock := testPostgres(t) + defer func() { _sql, _ := _postgres.client.DB(); _sql.Close() }() + + // create expected name query result in mock + _rows := sqlmock.NewRows( + []string{"id", "repo_id", "pipeline_id", "number", "parent", "event", "event_action", "status", "error", "enqueued", "created", "started", "finished", "deploy", "deploy_payload", "clone", "source", "title", "message", "commit", "sender", "author", "email", "link", "branch", "ref", "base_ref", "head_ref", "host", "runtime", "distribution", "timestamp"}). + AddRow(2, 1, nil, 2, 0, "", "", "pending", "", 0, 1, 0, 0, "", nil, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", 0). + AddRow(1, 1, nil, 1, 0, "", "", "running", "", 0, 1, 0, 0, "", nil, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", 0) + + // ensure the mock expects the name query + _mock.ExpectQuery(`SELECT * FROM "builds" WHERE repo_id = $1 AND (status = 'running' OR status = 'pending')`).WithArgs(1).WillReturnRows(_rows) + + _sqlite := testSqlite(t) + defer func() { _sql, _ := _sqlite.client.DB(); _sql.Close() }() + + _, err := _sqlite.CreateBuild(context.TODO(), _buildOne) + if err != nil { + t.Errorf("unable to create test build for sqlite: %v", err) + } + + _, err = _sqlite.CreateBuild(context.TODO(), _buildTwo) + if err != nil { + t.Errorf("unable to create test build for sqlite: %v", err) + } + + _, err = _sqlite.CreateBuild(context.TODO(), _buildThree) + if err != nil { + t.Errorf("unable to create test build for sqlite: %v", err) + } + + err = _sqlite.client.AutoMigrate(&database.Repo{}) + if err != nil { + t.Errorf("unable to create repo table for sqlite: %v", err) + } + + err = _sqlite.client.Table(constants.TableRepo).Create(database.RepoFromLibrary(_repo)).Error + if err != nil { + t.Errorf("unable to create test repo for sqlite: %v", err) + } + + err = _sqlite.client.Table(constants.TableRepo).Create(database.RepoFromLibrary(_repoTwo)).Error + if err != nil { + t.Errorf("unable to create test repo for sqlite: %v", err) + } + + // setup tests + tests := []struct { + failure bool + name string + database *engine + want []*library.Build + }{ + { + failure: false, + name: "postgres", + database: _postgres, + want: []*library.Build{_buildTwo, _buildOne}, + }, + { + failure: false, + name: "sqlite3", + database: _sqlite, + want: []*library.Build{_buildOne, _buildTwo}, + }, + } + + // run tests + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + got, err := test.database.ListPendingAndRunningBuildsForRepo(context.TODO(), _repo) + + if test.failure { + if err == nil { + t.Errorf("ListPendingAndRunningBuildsForRepo for %s should have returned err", test.name) + } + + return + } + + if err != nil { + t.Errorf("ListPendingAndRunningBuildsForRepo for %s returned err: %v", test.name, err) + } + + if !reflect.DeepEqual(got, test.want) { + t.Errorf("ListPendingAndRunningBuildsForRepo for %s is %v, want %v", test.name, got, test.want) + } + }) + } +} diff --git a/database/build/list_pending_running_test.go b/database/build/list_pending_running_test.go index 4ee71e1c7..9115745f3 100644 --- a/database/build/list_pending_running_test.go +++ b/database/build/list_pending_running_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/build/list_repo.go b/database/build/list_repo.go index 8ee78e35c..8b4386457 100644 --- a/database/build/list_repo.go +++ b/database/build/list_repo.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/build/list_repo_test.go b/database/build/list_repo_test.go index f16ed714d..bec52a723 100644 --- a/database/build/list_repo_test.go +++ b/database/build/list_repo_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/build/list_test.go b/database/build/list_test.go index 69d826755..54dae3e17 100644 --- a/database/build/list_test.go +++ b/database/build/list_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/build/opts.go b/database/build/opts.go index 69c912435..7792f9a12 100644 --- a/database/build/opts.go +++ b/database/build/opts.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/build/opts_test.go b/database/build/opts_test.go index 69afe0b4a..43fea307f 100644 --- a/database/build/opts_test.go +++ b/database/build/opts_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/build/table.go b/database/build/table.go index 91499ef4a..43a9f77c9 100644 --- a/database/build/table.go +++ b/database/build/table.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/build/table_test.go b/database/build/table_test.go index a08997fce..c37e1b475 100644 --- a/database/build/table_test.go +++ b/database/build/table_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/build/update.go b/database/build/update.go index bdd506187..ec647a879 100644 --- a/database/build/update.go +++ b/database/build/update.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore similar code with create.go package build diff --git a/database/build/update_test.go b/database/build/update_test.go index 7e5441145..67fe687d3 100644 --- a/database/build/update_test.go +++ b/database/build/update_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/database/close.go b/database/close.go index 0aff8e51d..6de839c95 100644 --- a/database/close.go +++ b/database/close.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/close_test.go b/database/close_test.go index fe0c55b00..7813513aa 100644 --- a/database/close_test.go +++ b/database/close_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/context.go b/database/context.go index fd08cc371..fd4cae217 100644 --- a/database/context.go +++ b/database/context.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/context_test.go b/database/context_test.go index 4037b26c0..d5887f864 100644 --- a/database/context_test.go +++ b/database/context_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/database.go b/database/database.go index ea93bfaaf..d4d31e228 100644 --- a/database/database.go +++ b/database/database.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database @@ -82,6 +80,7 @@ type ( // // * postgres // * sqlite3 +// . func New(opts ...EngineOpt) (Interface, error) { // create new database engine e := new(engine) diff --git a/database/database_test.go b/database/database_test.go index a1cfecc8a..a2ea86848 100644 --- a/database/database_test.go +++ b/database/database_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/doc.go b/database/doc.go index 42fe1feae..5e519db84 100644 --- a/database/doc.go +++ b/database/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package database provides the ability for Vela to // integrate with different supported SQL backends. diff --git a/database/driver.go b/database/driver.go index 1c3130094..4d743e9d7 100644 --- a/database/driver.go +++ b/database/driver.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/driver_test.go b/database/driver_test.go index 6d382d8cd..b3dad6144 100644 --- a/database/driver_test.go +++ b/database/driver_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/executable/clean.go b/database/executable/clean.go new file mode 100644 index 000000000..34579f778 --- /dev/null +++ b/database/executable/clean.go @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: Apache-2.0 + +package executable + +import ( + "context" + + "github.com/go-vela/types/constants" + "github.com/sirupsen/logrus" +) + +const CleanExecutablesPostgres = ` + DELETE FROM build_executables + USING builds + WHERE builds.id = build_executables.build_id + AND builds.status = 'error'; +` + +const CleanExecutablesSqlite = ` + DELETE FROM build_executables + WHERE build_id IN ( + SELECT build_id FROM build_executables e + INNER JOIN builds b + ON e.build_id=b.id + WHERE b.status = 'error' + ); +` + +// CleanBuildExecutables pops executables which have a corresponding build that was cleaned. +func (e *engine) CleanBuildExecutables(ctx context.Context) (int64, error) { + logrus.Trace("clearing build executables in the database") + + switch e.config.Driver { + case constants.DriverPostgres: + res := e.client.Exec(CleanExecutablesPostgres) + return res.RowsAffected, res.Error + default: + res := e.client.Exec(CleanExecutablesSqlite) + return res.RowsAffected, res.Error + } +} diff --git a/database/executable/clean_test.go b/database/executable/clean_test.go new file mode 100644 index 000000000..edcb0cf21 --- /dev/null +++ b/database/executable/clean_test.go @@ -0,0 +1,162 @@ +// SPDX-License-Identifier: Apache-2.0 + +package executable + +import ( + "context" + "fmt" + "testing" + + "github.com/DATA-DOG/go-sqlmock" + "github.com/go-vela/types/constants" + "github.com/go-vela/types/database" + "github.com/go-vela/types/library" +) + +func TestExecutable_Engine_CleanExecutables(t *testing.T) { + // setup types + _buildOne := testBuild() + _buildOne.SetID(1) + _buildOne.SetRepoID(1) + _buildOne.SetNumber(1) + _buildOne.SetStatus("pending") + _buildOne.SetCreated(1) + _buildOne.SetDeployPayload(nil) + + _buildTwo := testBuild() + _buildTwo.SetID(2) + _buildTwo.SetRepoID(1) + _buildTwo.SetNumber(2) + _buildTwo.SetStatus("error") + _buildTwo.SetCreated(1) + _buildTwo.SetDeployPayload(nil) + + _bExecutableOne := testBuildExecutable() + _bExecutableOne.SetID(1) + _bExecutableOne.SetBuildID(1) + _bExecutableOne.SetData([]byte("foo")) + + _bExecutableTwo := testBuildExecutable() + _bExecutableTwo.SetID(2) + _bExecutableTwo.SetBuildID(2) + _bExecutableTwo.SetData([]byte("bar")) + + _postgres, _mock := testPostgres(t) + defer func() { _sql, _ := _postgres.client.DB(); _sql.Close() }() + + _mock.ExpectExec("DELETE FROM build_executables USING builds WHERE builds.id = build_executables.build_id AND builds.status = 'error';"). + WillReturnResult(sqlmock.NewResult(1, 1)) + + _mock.ExpectQuery(`DELETE FROM "build_executables" WHERE build_id = $1 RETURNING *`).WithArgs(2).WillReturnError(fmt.Errorf("not found")) + + _sqlite := testSqlite(t) + defer func() { _sql, _ := _sqlite.client.DB(); _sql.Close() }() + + err := _sqlite.CreateBuildExecutable(context.TODO(), _bExecutableOne) + if err != nil { + t.Errorf("unable to create test build for sqlite: %v", err) + } + + err = _sqlite.CreateBuildExecutable(context.TODO(), _bExecutableTwo) + if err != nil { + t.Errorf("unable to create test build for sqlite: %v", err) + } + + err = _sqlite.client.AutoMigrate(&database.Build{}) + if err != nil { + t.Errorf("unable to create repo table for sqlite: %v", err) + } + + err = _sqlite.client.Table(constants.TableBuild).Create(database.BuildFromLibrary(_buildOne)).Error + if err != nil { + t.Errorf("unable to create test repo for sqlite: %v", err) + } + + err = _sqlite.client.Table(constants.TableBuild).Create(database.BuildFromLibrary(_buildTwo)).Error + if err != nil { + t.Errorf("unable to create test repo for sqlite: %v", err) + } + + // setup tests + tests := []struct { + failure bool + name string + database *engine + }{ + { + failure: false, + name: "postgres", + database: _postgres, + }, + { + failure: false, + name: "sqlite3", + database: _sqlite, + }, + } + + // run tests + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + got, err := test.database.CleanBuildExecutables(context.TODO()) + + if test.failure { + if err == nil { + t.Errorf("CleanExecutables for %s should have returned err", test.name) + } + + return + } + + if err != nil { + t.Errorf("CleanExecutables for %s returned err: %v", test.name, err) + } + + if got != 1 { + t.Errorf("CleanExecutables for %s should have affected 1 row, affected %d", test.name, got) + } + + _, err = test.database.PopBuildExecutable(context.TODO(), 2) + if err == nil { + t.Errorf("CleanExecutables for %s should have returned an error", test.name) + } + }) + } +} + +// testBuild is a test helper function to create a library +// Build type with all fields set to their zero values. +func testBuild() *library.Build { + return &library.Build{ + ID: new(int64), + RepoID: new(int64), + PipelineID: new(int64), + Number: new(int), + Parent: new(int), + Event: new(string), + EventAction: new(string), + Status: new(string), + Error: new(string), + Enqueued: new(int64), + Created: new(int64), + Started: new(int64), + Finished: new(int64), + Deploy: new(string), + Clone: new(string), + Source: new(string), + Title: new(string), + Message: new(string), + Commit: new(string), + Sender: new(string), + Author: new(string), + Email: new(string), + Link: new(string), + Branch: new(string), + Ref: new(string), + BaseRef: new(string), + HeadRef: new(string), + Host: new(string), + Runtime: new(string), + Distribution: new(string), + } +} diff --git a/database/executable/create.go b/database/executable/create.go index ac29ec768..1e240c495 100644 --- a/database/executable/create.go +++ b/database/executable/create.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package executable diff --git a/database/executable/create_test.go b/database/executable/create_test.go index e3f664314..23da9dfa7 100644 --- a/database/executable/create_test.go +++ b/database/executable/create_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package executable diff --git a/database/executable/executable.go b/database/executable/executable.go index 556d86754..6160cd39a 100644 --- a/database/executable/executable.go +++ b/database/executable/executable.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package executable diff --git a/database/executable/executable_test.go b/database/executable/executable_test.go index 20ebd6b49..665ca6da5 100644 --- a/database/executable/executable_test.go +++ b/database/executable/executable_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package executable diff --git a/database/executable/interface.go b/database/executable/interface.go index 9e3bd50b3..ee0cd056f 100644 --- a/database/executable/interface.go +++ b/database/executable/interface.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package executable @@ -22,6 +20,8 @@ type BuildExecutableInterface interface { // // https://en.wikipedia.org/wiki/Data_manipulation_language + // CleanBuildExecutables defines a function that deletes errored builds' corresponding executables. + CleanBuildExecutables(context.Context) (int64, error) // CreateBuildExecutable defines a function that creates a build executable. CreateBuildExecutable(context.Context, *library.BuildExecutable) error // PopBuildExecutable defines a function that gets and deletes a build executable. diff --git a/database/executable/opts.go b/database/executable/opts.go index fa601a03d..3f3bde340 100644 --- a/database/executable/opts.go +++ b/database/executable/opts.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package executable diff --git a/database/executable/opts_test.go b/database/executable/opts_test.go index 61876dd32..a2e1331bd 100644 --- a/database/executable/opts_test.go +++ b/database/executable/opts_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package executable diff --git a/database/executable/pop.go b/database/executable/pop.go index 64a2fbcf5..bd8e19ddb 100644 --- a/database/executable/pop.go +++ b/database/executable/pop.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package executable diff --git a/database/executable/pop_test.go b/database/executable/pop_test.go index cf282d013..1f6954316 100644 --- a/database/executable/pop_test.go +++ b/database/executable/pop_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package executable diff --git a/database/executable/table.go b/database/executable/table.go index c36834fe6..82fd1002f 100644 --- a/database/executable/table.go +++ b/database/executable/table.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package executable diff --git a/database/executable/table_test.go b/database/executable/table_test.go index b4f3cd057..deb1f353b 100644 --- a/database/executable/table_test.go +++ b/database/executable/table_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package executable diff --git a/database/flags.go b/database/flags.go index f8d4fd36e..852387b39 100644 --- a/database/flags.go +++ b/database/flags.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/hook/count.go b/database/hook/count.go index 47e9db7be..7f6d2449b 100644 --- a/database/hook/count.go +++ b/database/hook/count.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/database/hook/count_repo.go b/database/hook/count_repo.go index 2035ffef5..7b536804f 100644 --- a/database/hook/count_repo.go +++ b/database/hook/count_repo.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/database/hook/count_repo_test.go b/database/hook/count_repo_test.go index 7f3d20b5d..87f6c97bb 100644 --- a/database/hook/count_repo_test.go +++ b/database/hook/count_repo_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/database/hook/count_test.go b/database/hook/count_test.go index a9b87c830..96cc5560e 100644 --- a/database/hook/count_test.go +++ b/database/hook/count_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/database/hook/create.go b/database/hook/create.go index cce76611f..3ddbd4a9b 100644 --- a/database/hook/create.go +++ b/database/hook/create.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/database/hook/create_test.go b/database/hook/create_test.go index 0a4d4348c..cd5b6e62e 100644 --- a/database/hook/create_test.go +++ b/database/hook/create_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/database/hook/delete.go b/database/hook/delete.go index 3342a0580..96b00b12c 100644 --- a/database/hook/delete.go +++ b/database/hook/delete.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/database/hook/delete_test.go b/database/hook/delete_test.go index c900d176f..cbdef043e 100644 --- a/database/hook/delete_test.go +++ b/database/hook/delete_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/database/hook/get.go b/database/hook/get.go index 39168c52c..6119c0770 100644 --- a/database/hook/get.go +++ b/database/hook/get.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/database/hook/get_repo.go b/database/hook/get_repo.go index 7d7df0f7d..6182d86c9 100644 --- a/database/hook/get_repo.go +++ b/database/hook/get_repo.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/database/hook/get_repo_test.go b/database/hook/get_repo_test.go index bdeaf8d96..979755d2b 100644 --- a/database/hook/get_repo_test.go +++ b/database/hook/get_repo_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/database/hook/get_test.go b/database/hook/get_test.go index 65221504d..548d64989 100644 --- a/database/hook/get_test.go +++ b/database/hook/get_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/database/hook/get_webhook.go b/database/hook/get_webhook.go index 088432593..d7108ff4c 100644 --- a/database/hook/get_webhook.go +++ b/database/hook/get_webhook.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/database/hook/get_webhook_test.go b/database/hook/get_webhook_test.go index c55ae0edf..61f849315 100644 --- a/database/hook/get_webhook_test.go +++ b/database/hook/get_webhook_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/database/hook/hook.go b/database/hook/hook.go index e8bbe5e54..ff0358f23 100644 --- a/database/hook/hook.go +++ b/database/hook/hook.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/database/hook/hook_test.go b/database/hook/hook_test.go index 219b9772c..279ac2f97 100644 --- a/database/hook/hook_test.go +++ b/database/hook/hook_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/database/hook/index.go b/database/hook/index.go index c842fe1aa..2b8d4e682 100644 --- a/database/hook/index.go +++ b/database/hook/index.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/database/hook/index_test.go b/database/hook/index_test.go index 905c7a354..39eb6b944 100644 --- a/database/hook/index_test.go +++ b/database/hook/index_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/database/hook/interface.go b/database/hook/interface.go index e15134401..6a9cec8f6 100644 --- a/database/hook/interface.go +++ b/database/hook/interface.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/database/hook/last_repo.go b/database/hook/last_repo.go index b2be0c916..bf85be4dc 100644 --- a/database/hook/last_repo.go +++ b/database/hook/last_repo.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/database/hook/last_repo_test.go b/database/hook/last_repo_test.go index 5802a9486..25e794073 100644 --- a/database/hook/last_repo_test.go +++ b/database/hook/last_repo_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/database/hook/list.go b/database/hook/list.go index ebc1b49b3..8e0949be4 100644 --- a/database/hook/list.go +++ b/database/hook/list.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/database/hook/list_repo.go b/database/hook/list_repo.go index dc5535363..28220b1dd 100644 --- a/database/hook/list_repo.go +++ b/database/hook/list_repo.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/database/hook/list_repo_test.go b/database/hook/list_repo_test.go index c055b20dd..20c1c9152 100644 --- a/database/hook/list_repo_test.go +++ b/database/hook/list_repo_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/database/hook/list_test.go b/database/hook/list_test.go index fb5732f59..299585167 100644 --- a/database/hook/list_test.go +++ b/database/hook/list_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/database/hook/opts.go b/database/hook/opts.go index a6852a91a..e91c5ec6b 100644 --- a/database/hook/opts.go +++ b/database/hook/opts.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/database/hook/opts_test.go b/database/hook/opts_test.go index 4779e7e2a..cb3c37760 100644 --- a/database/hook/opts_test.go +++ b/database/hook/opts_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/database/hook/table.go b/database/hook/table.go index 651533444..c9221e9f4 100644 --- a/database/hook/table.go +++ b/database/hook/table.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/database/hook/table_test.go b/database/hook/table_test.go index a1a847f95..286c9bd2e 100644 --- a/database/hook/table_test.go +++ b/database/hook/table_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/database/hook/update.go b/database/hook/update.go index b349494ee..e990bbc9c 100644 --- a/database/hook/update.go +++ b/database/hook/update.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/database/hook/update_test.go b/database/hook/update_test.go index 9722de7c8..44828b5db 100644 --- a/database/hook/update_test.go +++ b/database/hook/update_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package hook diff --git a/database/integration_test.go b/database/integration_test.go index d52573192..8f5d2e837 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database @@ -298,6 +296,19 @@ func testBuilds(t *testing.T, db Interface, resources *Resources) { } methods["ListBuildsForRepo"] = true + // list the pending / running builds for a repo + list, err = db.ListPendingAndRunningBuildsForRepo(context.TODO(), resources.Repos[0]) + if err != nil { + t.Errorf("unable to list pending and running builds for repo %d: %v", resources.Repos[0].GetID(), err) + } + if int(count) != len(resources.Builds) { + t.Errorf("ListPendingAndRunningBuildsForRepo() is %v, want %v", count, len(resources.Builds)) + } + if !cmp.Equal(list, []*library.Build{resources.Builds[0], resources.Builds[1]}) { + t.Errorf("ListPendingAndRunningBuildsForRepo() is %v, want %v", list, []*library.Build{resources.Builds[0], resources.Builds[1]}) + } + methods["ListPendingAndRunningBuildsForRepo"] = true + // list the pending and running builds queueList, err := db.ListPendingAndRunningBuilds(context.TODO(), "0") if err != nil { @@ -425,6 +436,34 @@ func testExecutables(t *testing.T, db Interface, resources *Resources) { } methods["PopBuildExecutable"] = true + resources.Builds[0].SetStatus(constants.StatusError) + + _, err := db.UpdateBuild(context.TODO(), resources.Builds[0]) + if err != nil { + t.Errorf("unable to update build for clean executables test") + } + + err = db.CreateBuildExecutable(context.TODO(), resources.Executables[0]) + if err != nil { + t.Errorf("unable to create executable %d: %v", resources.Executables[0].GetID(), err) + } + + count, err := db.CleanBuildExecutables(context.TODO()) + if err != nil { + t.Errorf("unable to clean executable %d: %v", resources.Executables[0].GetID(), err) + } + + if count != 1 { + t.Errorf("CleanBuildExecutables should have affected 1 row, affected %d", count) + } + + _, err = db.PopBuildExecutable(context.TODO(), resources.Builds[0].GetID()) + if err == nil { + t.Errorf("build executable not cleaned") + } + + methods["CleanBuildExecutables"] = true + // ensure we called all the methods we expected to for method, called := range methods { if !called { @@ -1926,7 +1965,7 @@ func newResources() *Resources { deploymentOne.SetURL("https://github.com/github/octocat/deployments/1") deploymentOne.SetUser("octocat") deploymentOne.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135163") - deploymentOne.SetRef("refs/heads/master") + deploymentOne.SetRef("refs/heads/main") deploymentOne.SetTask("vela-deploy") deploymentOne.SetTarget("production") deploymentOne.SetDescription("Deployment request from Vela") @@ -1938,7 +1977,7 @@ func newResources() *Resources { deploymentTwo.SetURL("https://github.com/github/octocat/deployments/2") deploymentTwo.SetUser("octocat") deploymentTwo.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135164") - deploymentTwo.SetRef("refs/heads/master") + deploymentTwo.SetRef("refs/heads/main") deploymentTwo.SetTask("vela-deploy") deploymentTwo.SetTarget("production") deploymentTwo.SetDescription("Deployment request from Vela") diff --git a/database/interface.go b/database/interface.go index cc7428378..cffbda96f 100644 --- a/database/interface.go +++ b/database/interface.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/log/count.go b/database/log/count.go index 227426f94..b26066b94 100644 --- a/database/log/count.go +++ b/database/log/count.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package log diff --git a/database/log/count_build.go b/database/log/count_build.go index 3095e0a02..168d9e1c1 100644 --- a/database/log/count_build.go +++ b/database/log/count_build.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package log diff --git a/database/log/count_build_test.go b/database/log/count_build_test.go index 9c41c3944..c66422134 100644 --- a/database/log/count_build_test.go +++ b/database/log/count_build_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package log diff --git a/database/log/count_test.go b/database/log/count_test.go index cdaffc191..cb7f516dc 100644 --- a/database/log/count_test.go +++ b/database/log/count_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package log diff --git a/database/log/create.go b/database/log/create.go index 0f5d7e2db..e1c3a9212 100644 --- a/database/log/create.go +++ b/database/log/create.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore similar code with create.go package log diff --git a/database/log/create_test.go b/database/log/create_test.go index f8b406791..80514837c 100644 --- a/database/log/create_test.go +++ b/database/log/create_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package log diff --git a/database/log/delete.go b/database/log/delete.go index b97be07a3..7018396de 100644 --- a/database/log/delete.go +++ b/database/log/delete.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package log diff --git a/database/log/delete_test.go b/database/log/delete_test.go index 82e5f3303..3b3000fc6 100644 --- a/database/log/delete_test.go +++ b/database/log/delete_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package log diff --git a/database/log/get.go b/database/log/get.go index 64f574482..be02ee968 100644 --- a/database/log/get.go +++ b/database/log/get.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package log diff --git a/database/log/get_service.go b/database/log/get_service.go index 033f0cf4c..83d5f2f45 100644 --- a/database/log/get_service.go +++ b/database/log/get_service.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore similar code with get_step.go package log diff --git a/database/log/get_service_test.go b/database/log/get_service_test.go index 75acd1dbd..df998ffc1 100644 --- a/database/log/get_service_test.go +++ b/database/log/get_service_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package log diff --git a/database/log/get_step.go b/database/log/get_step.go index 77123a84b..da6d70cf7 100644 --- a/database/log/get_step.go +++ b/database/log/get_step.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore similar code with get_service.go package log diff --git a/database/log/get_step_test.go b/database/log/get_step_test.go index 172e68868..a6b3e324a 100644 --- a/database/log/get_step_test.go +++ b/database/log/get_step_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package log diff --git a/database/log/get_test.go b/database/log/get_test.go index 23360ce5c..a7ab5c2d1 100644 --- a/database/log/get_test.go +++ b/database/log/get_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package log diff --git a/database/log/index.go b/database/log/index.go index 25cc23a8b..c167f3825 100644 --- a/database/log/index.go +++ b/database/log/index.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package log diff --git a/database/log/index_test.go b/database/log/index_test.go index b65c8a492..400df2cb2 100644 --- a/database/log/index_test.go +++ b/database/log/index_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package log diff --git a/database/log/interface.go b/database/log/interface.go index a62bb94b8..92f5d6cdd 100644 --- a/database/log/interface.go +++ b/database/log/interface.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package log diff --git a/database/log/list.go b/database/log/list.go index 057090664..ae85a451e 100644 --- a/database/log/list.go +++ b/database/log/list.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package log diff --git a/database/log/list_build.go b/database/log/list_build.go index af5d03f61..183b1f167 100644 --- a/database/log/list_build.go +++ b/database/log/list_build.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package log diff --git a/database/log/list_build_test.go b/database/log/list_build_test.go index b14bf9c07..2f1dde7e5 100644 --- a/database/log/list_build_test.go +++ b/database/log/list_build_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package log diff --git a/database/log/list_test.go b/database/log/list_test.go index 644434167..1bcf1759e 100644 --- a/database/log/list_test.go +++ b/database/log/list_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package log diff --git a/database/log/log.go b/database/log/log.go index 6dc97e7c6..0b8378d8f 100644 --- a/database/log/log.go +++ b/database/log/log.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package log diff --git a/database/log/log_test.go b/database/log/log_test.go index 69e3835d5..f8b5bcadf 100644 --- a/database/log/log_test.go +++ b/database/log/log_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package log @@ -176,7 +174,7 @@ func testSqlite(t *testing.T) *engine { type AnyArgument struct{} // Match satisfies sqlmock.Argument interface. -func (a AnyArgument) Match(v driver.Value) bool { +func (a AnyArgument) Match(_ driver.Value) bool { return true } diff --git a/database/log/opts.go b/database/log/opts.go index 3cb1de5c4..03a913d2b 100644 --- a/database/log/opts.go +++ b/database/log/opts.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package log diff --git a/database/log/opts_test.go b/database/log/opts_test.go index 1d9728896..d2a098e15 100644 --- a/database/log/opts_test.go +++ b/database/log/opts_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package log diff --git a/database/log/table.go b/database/log/table.go index 089e55cc0..aa8c87cfe 100644 --- a/database/log/table.go +++ b/database/log/table.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package log diff --git a/database/log/table_test.go b/database/log/table_test.go index ad751bfed..49f072b5d 100644 --- a/database/log/table_test.go +++ b/database/log/table_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package log diff --git a/database/log/update.go b/database/log/update.go index 6ea7903d8..7929ab0fa 100644 --- a/database/log/update.go +++ b/database/log/update.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore similar code with update.go package log diff --git a/database/log/update_test.go b/database/log/update_test.go index 180e59e76..3550e0c94 100644 --- a/database/log/update_test.go +++ b/database/log/update_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package log diff --git a/database/opts.go b/database/opts.go index 42ab3d033..2e758d802 100644 --- a/database/opts.go +++ b/database/opts.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/opts_test.go b/database/opts_test.go index 446fd5903..7089d9271 100644 --- a/database/opts_test.go +++ b/database/opts_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/ping.go b/database/ping.go index 80968c152..51c502a80 100644 --- a/database/ping.go +++ b/database/ping.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/ping_test.go b/database/ping_test.go index 5b2fdb0c9..66cb37939 100644 --- a/database/ping_test.go +++ b/database/ping_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/pipeline/count.go b/database/pipeline/count.go index 33377d105..a251f571b 100644 --- a/database/pipeline/count.go +++ b/database/pipeline/count.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/database/pipeline/count_repo.go b/database/pipeline/count_repo.go index a3318a4e6..549a9ecc9 100644 --- a/database/pipeline/count_repo.go +++ b/database/pipeline/count_repo.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/database/pipeline/count_repo_test.go b/database/pipeline/count_repo_test.go index 0d2469e77..e40888f3c 100644 --- a/database/pipeline/count_repo_test.go +++ b/database/pipeline/count_repo_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline @@ -19,7 +17,7 @@ func TestPipeline_Engine_CountPipelinesForRepo(t *testing.T) { _pipelineOne.SetID(1) _pipelineOne.SetRepoID(1) _pipelineOne.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135163") - _pipelineOne.SetRef("refs/heads/master") + _pipelineOne.SetRef("refs/heads/main") _pipelineOne.SetType("yaml") _pipelineOne.SetVersion("1") diff --git a/database/pipeline/count_test.go b/database/pipeline/count_test.go index 6b638420a..829acfd58 100644 --- a/database/pipeline/count_test.go +++ b/database/pipeline/count_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline @@ -18,7 +16,7 @@ func TestPipeline_Engine_CountPipelines(t *testing.T) { _pipelineOne.SetID(1) _pipelineOne.SetRepoID(1) _pipelineOne.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135163") - _pipelineOne.SetRef("refs/heads/master") + _pipelineOne.SetRef("refs/heads/main") _pipelineOne.SetType("yaml") _pipelineOne.SetVersion("1") diff --git a/database/pipeline/create.go b/database/pipeline/create.go index 04b344c95..d3ba17711 100644 --- a/database/pipeline/create.go +++ b/database/pipeline/create.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/database/pipeline/create_test.go b/database/pipeline/create_test.go index 9077dad5e..f6a0b7af1 100644 --- a/database/pipeline/create_test.go +++ b/database/pipeline/create_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline @@ -18,7 +16,7 @@ func TestPipeline_Engine_CreatePipeline(t *testing.T) { _pipeline.SetID(1) _pipeline.SetRepoID(1) _pipeline.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135163") - _pipeline.SetRef("refs/heads/master") + _pipeline.SetRef("refs/heads/main") _pipeline.SetType("yaml") _pipeline.SetVersion("1") _pipeline.SetData([]byte{}) @@ -33,7 +31,7 @@ func TestPipeline_Engine_CreatePipeline(t *testing.T) { _mock.ExpectQuery(`INSERT INTO "pipelines" ("repo_id","commit","flavor","platform","ref","type","version","external_secrets","internal_secrets","services","stages","steps","templates","data","id") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15) RETURNING "id"`). - WithArgs(1, "48afb5bdc41ad69bf22588491333f7cf71135163", nil, nil, "refs/heads/master", "yaml", "1", false, false, false, false, false, false, AnyArgument{}, 1). + WithArgs(1, "48afb5bdc41ad69bf22588491333f7cf71135163", nil, nil, "refs/heads/main", "yaml", "1", false, false, false, false, false, false, AnyArgument{}, 1). WillReturnRows(_rows) _sqlite := testSqlite(t) diff --git a/database/pipeline/delete.go b/database/pipeline/delete.go index d473d5d4f..1f62c3048 100644 --- a/database/pipeline/delete.go +++ b/database/pipeline/delete.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/database/pipeline/delete_test.go b/database/pipeline/delete_test.go index 39e47a7dd..2b141b702 100644 --- a/database/pipeline/delete_test.go +++ b/database/pipeline/delete_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline @@ -17,7 +15,7 @@ func TestPipeline_Engine_DeletePipeline(t *testing.T) { _pipeline.SetID(1) _pipeline.SetRepoID(1) _pipeline.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135163") - _pipeline.SetRef("refs/heads/master") + _pipeline.SetRef("refs/heads/main") _pipeline.SetType("yaml") _pipeline.SetVersion("1") diff --git a/database/pipeline/get.go b/database/pipeline/get.go index 17ec6ab78..30a7f5d39 100644 --- a/database/pipeline/get.go +++ b/database/pipeline/get.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/database/pipeline/get_repo.go b/database/pipeline/get_repo.go index f165c18eb..934c0dcd2 100644 --- a/database/pipeline/get_repo.go +++ b/database/pipeline/get_repo.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/database/pipeline/get_repo_test.go b/database/pipeline/get_repo_test.go index 67161931d..e01a4514d 100644 --- a/database/pipeline/get_repo_test.go +++ b/database/pipeline/get_repo_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline @@ -19,7 +17,7 @@ func TestPipeline_Engine_GetPipelineForRepo(t *testing.T) { _pipeline.SetID(1) _pipeline.SetRepoID(1) _pipeline.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135163") - _pipeline.SetRef("refs/heads/master") + _pipeline.SetRef("refs/heads/main") _pipeline.SetType("yaml") _pipeline.SetVersion("1") _pipeline.SetData([]byte("foo")) @@ -30,7 +28,7 @@ func TestPipeline_Engine_GetPipelineForRepo(t *testing.T) { // create expected result in mock _rows := sqlmock.NewRows( []string{"id", "repo_id", "commit", "flavor", "platform", "ref", "type", "version", "services", "stages", "steps", "templates", "data"}). - AddRow(1, 1, "48afb5bdc41ad69bf22588491333f7cf71135163", "", "", "refs/heads/master", "yaml", "1", false, false, false, false, []byte{120, 94, 74, 203, 207, 7, 4, 0, 0, 255, 255, 2, 130, 1, 69}) + AddRow(1, 1, "48afb5bdc41ad69bf22588491333f7cf71135163", "", "", "refs/heads/main", "yaml", "1", false, false, false, false, []byte{120, 94, 74, 203, 207, 7, 4, 0, 0, 255, 255, 2, 130, 1, 69}) // ensure the mock expects the query _mock.ExpectQuery(`SELECT * FROM "pipelines" WHERE repo_id = $1 AND "commit" = $2 LIMIT 1`).WithArgs(1, "48afb5bdc41ad69bf22588491333f7cf71135163").WillReturnRows(_rows) diff --git a/database/pipeline/get_test.go b/database/pipeline/get_test.go index ca6d789f2..61119e6bb 100644 --- a/database/pipeline/get_test.go +++ b/database/pipeline/get_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline @@ -19,7 +17,7 @@ func TestPipeline_Engine_GetPipeline(t *testing.T) { _pipeline.SetID(1) _pipeline.SetRepoID(1) _pipeline.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135163") - _pipeline.SetRef("refs/heads/master") + _pipeline.SetRef("refs/heads/main") _pipeline.SetType("yaml") _pipeline.SetVersion("1") _pipeline.SetData([]byte("foo")) @@ -30,7 +28,7 @@ func TestPipeline_Engine_GetPipeline(t *testing.T) { // create expected result in mock _rows := sqlmock.NewRows( []string{"id", "repo_id", "commit", "flavor", "platform", "ref", "type", "version", "services", "stages", "steps", "templates", "data"}). - AddRow(1, 1, "48afb5bdc41ad69bf22588491333f7cf71135163", "", "", "refs/heads/master", "yaml", "1", false, false, false, false, []byte{120, 94, 74, 203, 207, 7, 4, 0, 0, 255, 255, 2, 130, 1, 69}) + AddRow(1, 1, "48afb5bdc41ad69bf22588491333f7cf71135163", "", "", "refs/heads/main", "yaml", "1", false, false, false, false, []byte{120, 94, 74, 203, 207, 7, 4, 0, 0, 255, 255, 2, 130, 1, 69}) // ensure the mock expects the query _mock.ExpectQuery(`SELECT * FROM "pipelines" WHERE id = $1 LIMIT 1`).WithArgs(1).WillReturnRows(_rows) diff --git a/database/pipeline/index.go b/database/pipeline/index.go index 3189b728d..f49ecb58a 100644 --- a/database/pipeline/index.go +++ b/database/pipeline/index.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/database/pipeline/index_test.go b/database/pipeline/index_test.go index e72b5a593..71a168293 100644 --- a/database/pipeline/index_test.go +++ b/database/pipeline/index_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/database/pipeline/interface.go b/database/pipeline/interface.go index ae75ebd54..602cfbb1d 100644 --- a/database/pipeline/interface.go +++ b/database/pipeline/interface.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/database/pipeline/list.go b/database/pipeline/list.go index 54f8015c4..2299c8f6f 100644 --- a/database/pipeline/list.go +++ b/database/pipeline/list.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/database/pipeline/list_repo.go b/database/pipeline/list_repo.go index e8c38afab..f4ed90fde 100644 --- a/database/pipeline/list_repo.go +++ b/database/pipeline/list_repo.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline @@ -28,7 +26,7 @@ func (e *engine) ListPipelinesForRepo(ctx context.Context, r *library.Repo, page pipelines := []*library.Pipeline{} // count the results - count, err := e.CountPipelinesForRepo(context.TODO(), r) + count, err := e.CountPipelinesForRepo(ctx, r) if err != nil { return pipelines, 0, err } diff --git a/database/pipeline/list_repo_test.go b/database/pipeline/list_repo_test.go index 35cc2e769..840d4bd6b 100644 --- a/database/pipeline/list_repo_test.go +++ b/database/pipeline/list_repo_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline @@ -19,7 +17,7 @@ func TestPipeline_Engine_ListPipelinesForRepo(t *testing.T) { _pipelineOne.SetID(1) _pipelineOne.SetRepoID(1) _pipelineOne.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135163") - _pipelineOne.SetRef("refs/heads/master") + _pipelineOne.SetRef("refs/heads/main") _pipelineOne.SetType("yaml") _pipelineOne.SetVersion("1") _pipelineOne.SetData([]byte("foo")) @@ -45,7 +43,7 @@ func TestPipeline_Engine_ListPipelinesForRepo(t *testing.T) { // create expected result in mock _rows = sqlmock.NewRows( []string{"id", "repo_id", "commit", "flavor", "platform", "ref", "type", "version", "services", "stages", "steps", "templates", "data"}). - AddRow(1, 1, "48afb5bdc41ad69bf22588491333f7cf71135163", "", "", "refs/heads/master", "yaml", "1", false, false, false, false, []byte{120, 94, 74, 203, 207, 7, 4, 0, 0, 255, 255, 2, 130, 1, 69}). + AddRow(1, 1, "48afb5bdc41ad69bf22588491333f7cf71135163", "", "", "refs/heads/main", "yaml", "1", false, false, false, false, []byte{120, 94, 74, 203, 207, 7, 4, 0, 0, 255, 255, 2, 130, 1, 69}). AddRow(2, 1, "a49aaf4afae6431a79239c95247a2b169fd9f067", "", "", "refs/heads/main", "yaml", "1", false, false, false, false, []byte{120, 94, 74, 203, 207, 7, 4, 0, 0, 255, 255, 2, 130, 1, 69}) // ensure the mock expects the query diff --git a/database/pipeline/list_test.go b/database/pipeline/list_test.go index e1d14166e..02779e483 100644 --- a/database/pipeline/list_test.go +++ b/database/pipeline/list_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline @@ -19,7 +17,7 @@ func TestPipeline_Engine_ListPipelines(t *testing.T) { _pipelineOne.SetID(1) _pipelineOne.SetRepoID(1) _pipelineOne.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135163") - _pipelineOne.SetRef("refs/heads/master") + _pipelineOne.SetRef("refs/heads/main") _pipelineOne.SetType("yaml") _pipelineOne.SetVersion("1") _pipelineOne.SetData([]byte("foo")) @@ -45,7 +43,7 @@ func TestPipeline_Engine_ListPipelines(t *testing.T) { // create expected result in mock _rows = sqlmock.NewRows( []string{"id", "repo_id", "commit", "flavor", "platform", "ref", "type", "version", "services", "stages", "steps", "templates", "data"}). - AddRow(1, 1, "48afb5bdc41ad69bf22588491333f7cf71135163", "", "", "refs/heads/master", "yaml", "1", false, false, false, false, []byte{120, 94, 74, 203, 207, 7, 4, 0, 0, 255, 255, 2, 130, 1, 69}). + AddRow(1, 1, "48afb5bdc41ad69bf22588491333f7cf71135163", "", "", "refs/heads/main", "yaml", "1", false, false, false, false, []byte{120, 94, 74, 203, 207, 7, 4, 0, 0, 255, 255, 2, 130, 1, 69}). AddRow(2, 2, "a49aaf4afae6431a79239c95247a2b169fd9f067", "", "", "refs/heads/main", "yaml", "1", false, false, false, false, []byte{120, 94, 74, 203, 207, 7, 4, 0, 0, 255, 255, 2, 130, 1, 69}) // ensure the mock expects the query diff --git a/database/pipeline/opts.go b/database/pipeline/opts.go index e4d1e6d46..a05c92633 100644 --- a/database/pipeline/opts.go +++ b/database/pipeline/opts.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/database/pipeline/opts_test.go b/database/pipeline/opts_test.go index 2380bdda7..782c9af93 100644 --- a/database/pipeline/opts_test.go +++ b/database/pipeline/opts_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/database/pipeline/pipeline.go b/database/pipeline/pipeline.go index 7c9f29d8f..c900123ae 100644 --- a/database/pipeline/pipeline.go +++ b/database/pipeline/pipeline.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline @@ -53,7 +51,6 @@ func New(opts ...EngineOpt) (*engine, error) { e.client = new(gorm.DB) e.config = new(config) e.logger = new(logrus.Entry) - e.ctx = context.TODO() // apply all provided configuration options for _, opt := range opts { diff --git a/database/pipeline/pipeline_test.go b/database/pipeline/pipeline_test.go index 13d01393a..01582a62a 100644 --- a/database/pipeline/pipeline_test.go +++ b/database/pipeline/pipeline_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline @@ -206,6 +204,6 @@ func testPipeline() *library.Pipeline { type AnyArgument struct{} // Match satisfies sqlmock.Argument interface. -func (a AnyArgument) Match(v driver.Value) bool { +func (a AnyArgument) Match(_ driver.Value) bool { return true } diff --git a/database/pipeline/table.go b/database/pipeline/table.go index eef8b885a..eb399772c 100644 --- a/database/pipeline/table.go +++ b/database/pipeline/table.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/database/pipeline/table_test.go b/database/pipeline/table_test.go index 72add7aee..4a4463feb 100644 --- a/database/pipeline/table_test.go +++ b/database/pipeline/table_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/database/pipeline/update.go b/database/pipeline/update.go index 64d9dd561..5b12db3b1 100644 --- a/database/pipeline/update.go +++ b/database/pipeline/update.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/database/pipeline/update_test.go b/database/pipeline/update_test.go index f8ab6b3d3..a489913ab 100644 --- a/database/pipeline/update_test.go +++ b/database/pipeline/update_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline @@ -18,7 +16,7 @@ func TestPipeline_Engine_UpdatePipeline(t *testing.T) { _pipeline.SetID(1) _pipeline.SetRepoID(1) _pipeline.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135163") - _pipeline.SetRef("refs/heads/master") + _pipeline.SetRef("refs/heads/main") _pipeline.SetType("yaml") _pipeline.SetVersion("1") _pipeline.SetData([]byte{}) @@ -30,7 +28,7 @@ func TestPipeline_Engine_UpdatePipeline(t *testing.T) { _mock.ExpectExec(`UPDATE "pipelines" SET "repo_id"=$1,"commit"=$2,"flavor"=$3,"platform"=$4,"ref"=$5,"type"=$6,"version"=$7,"external_secrets"=$8,"internal_secrets"=$9,"services"=$10,"stages"=$11,"steps"=$12,"templates"=$13,"data"=$14 WHERE "id" = $15`). - WithArgs(1, "48afb5bdc41ad69bf22588491333f7cf71135163", nil, nil, "refs/heads/master", "yaml", "1", false, false, false, false, false, false, AnyArgument{}, 1). + WithArgs(1, "48afb5bdc41ad69bf22588491333f7cf71135163", nil, nil, "refs/heads/main", "yaml", "1", false, false, false, false, false, false, AnyArgument{}, 1). WillReturnResult(sqlmock.NewResult(1, 1)) _sqlite := testSqlite(t) diff --git a/database/repo/count.go b/database/repo/count.go index 3ef5297d1..c00001b9f 100644 --- a/database/repo/count.go +++ b/database/repo/count.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo diff --git a/database/repo/count_org.go b/database/repo/count_org.go index 0e44516e9..145042b55 100644 --- a/database/repo/count_org.go +++ b/database/repo/count_org.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo diff --git a/database/repo/count_org_test.go b/database/repo/count_org_test.go index f3657f3eb..c89299773 100644 --- a/database/repo/count_org_test.go +++ b/database/repo/count_org_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo diff --git a/database/repo/count_test.go b/database/repo/count_test.go index 668018315..c399411d6 100644 --- a/database/repo/count_test.go +++ b/database/repo/count_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo diff --git a/database/repo/count_user.go b/database/repo/count_user.go index bfa7f56ee..5cd71f2f0 100644 --- a/database/repo/count_user.go +++ b/database/repo/count_user.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo diff --git a/database/repo/count_user_test.go b/database/repo/count_user_test.go index 58342226e..a2b580a52 100644 --- a/database/repo/count_user_test.go +++ b/database/repo/count_user_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo diff --git a/database/repo/create.go b/database/repo/create.go index 800365e55..578b54fb6 100644 --- a/database/repo/create.go +++ b/database/repo/create.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore similar code with update.go package repo diff --git a/database/repo/create_test.go b/database/repo/create_test.go index 501f94955..af1432072 100644 --- a/database/repo/create_test.go +++ b/database/repo/create_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo diff --git a/database/repo/delete.go b/database/repo/delete.go index 4e0df1918..6432e4ce1 100644 --- a/database/repo/delete.go +++ b/database/repo/delete.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo diff --git a/database/repo/delete_test.go b/database/repo/delete_test.go index f7f64e1aa..30ff1d84c 100644 --- a/database/repo/delete_test.go +++ b/database/repo/delete_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo diff --git a/database/repo/get.go b/database/repo/get.go index 3adbaaffd..af9db8e1c 100644 --- a/database/repo/get.go +++ b/database/repo/get.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo diff --git a/database/repo/get_org.go b/database/repo/get_org.go index 2188e0a5e..2a1d053ea 100644 --- a/database/repo/get_org.go +++ b/database/repo/get_org.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo diff --git a/database/repo/get_org_test.go b/database/repo/get_org_test.go index b43ec143c..55b37a955 100644 --- a/database/repo/get_org_test.go +++ b/database/repo/get_org_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo diff --git a/database/repo/get_test.go b/database/repo/get_test.go index 060168fb6..00ec5a747 100644 --- a/database/repo/get_test.go +++ b/database/repo/get_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo diff --git a/database/repo/index.go b/database/repo/index.go index 8c90262a7..c2446bda9 100644 --- a/database/repo/index.go +++ b/database/repo/index.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo diff --git a/database/repo/index_test.go b/database/repo/index_test.go index d9a527b61..015090a3c 100644 --- a/database/repo/index_test.go +++ b/database/repo/index_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo diff --git a/database/repo/interface.go b/database/repo/interface.go index 6dad94d20..a69b5fa31 100644 --- a/database/repo/interface.go +++ b/database/repo/interface.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo diff --git a/database/repo/list.go b/database/repo/list.go index c65754c16..790227d63 100644 --- a/database/repo/list.go +++ b/database/repo/list.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo diff --git a/database/repo/list_org.go b/database/repo/list_org.go index 9809716bf..95783bd95 100644 --- a/database/repo/list_org.go +++ b/database/repo/list_org.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo diff --git a/database/repo/list_org_test.go b/database/repo/list_org_test.go index 6809006dc..f639df5d6 100644 --- a/database/repo/list_org_test.go +++ b/database/repo/list_org_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo diff --git a/database/repo/list_test.go b/database/repo/list_test.go index fd6e4dfbe..e4f0f7564 100644 --- a/database/repo/list_test.go +++ b/database/repo/list_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo diff --git a/database/repo/list_user.go b/database/repo/list_user.go index bf9b6ea8b..bc11fb1b2 100644 --- a/database/repo/list_user.go +++ b/database/repo/list_user.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo diff --git a/database/repo/list_user_test.go b/database/repo/list_user_test.go index 222348aea..b548d82c2 100644 --- a/database/repo/list_user_test.go +++ b/database/repo/list_user_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo diff --git a/database/repo/opts.go b/database/repo/opts.go index 41a2b9492..f65dcc368 100644 --- a/database/repo/opts.go +++ b/database/repo/opts.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo diff --git a/database/repo/opts_test.go b/database/repo/opts_test.go index 4f9e981ae..b9788a457 100644 --- a/database/repo/opts_test.go +++ b/database/repo/opts_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo diff --git a/database/repo/repo.go b/database/repo/repo.go index a74c34956..5e4300e19 100644 --- a/database/repo/repo.go +++ b/database/repo/repo.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo diff --git a/database/repo/repo_test.go b/database/repo/repo_test.go index 441fa3893..c86477a08 100644 --- a/database/repo/repo_test.go +++ b/database/repo/repo_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo @@ -206,6 +204,6 @@ func testRepo() *library.Repo { type AnyArgument struct{} // Match satisfies sqlmock.Argument interface. -func (a AnyArgument) Match(v driver.Value) bool { +func (a AnyArgument) Match(_ driver.Value) bool { return true } diff --git a/database/repo/table.go b/database/repo/table.go index b8a301c74..efc9833ba 100644 --- a/database/repo/table.go +++ b/database/repo/table.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo diff --git a/database/repo/table_test.go b/database/repo/table_test.go index 021f76673..d4aba45ed 100644 --- a/database/repo/table_test.go +++ b/database/repo/table_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo diff --git a/database/repo/update.go b/database/repo/update.go index fbbce6b64..0c3273ce2 100644 --- a/database/repo/update.go +++ b/database/repo/update.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore similar code with create.go package repo diff --git a/database/repo/update_test.go b/database/repo/update_test.go index db104c87b..ce8eaf438 100644 --- a/database/repo/update_test.go +++ b/database/repo/update_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo diff --git a/database/resource.go b/database/resource.go index 353f25513..35f7c7a97 100644 --- a/database/resource.go +++ b/database/resource.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Ine. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/resource_test.go b/database/resource_test.go index 328f04f58..aaa78548d 100644 --- a/database/resource_test.go +++ b/database/resource_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/schedule/count.go b/database/schedule/count.go index 7a0d8c1ee..e86b99a41 100644 --- a/database/schedule/count.go +++ b/database/schedule/count.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/database/schedule/count_active.go b/database/schedule/count_active.go index d65315186..cc78e37a6 100644 --- a/database/schedule/count_active.go +++ b/database/schedule/count_active.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/database/schedule/count_active_test.go b/database/schedule/count_active_test.go index dcf9d2cb0..6fb88849f 100644 --- a/database/schedule/count_active_test.go +++ b/database/schedule/count_active_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/database/schedule/count_repo.go b/database/schedule/count_repo.go index da806151c..471537d8f 100644 --- a/database/schedule/count_repo.go +++ b/database/schedule/count_repo.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/database/schedule/count_repo_test.go b/database/schedule/count_repo_test.go index 35c530d7c..9618f9cf8 100644 --- a/database/schedule/count_repo_test.go +++ b/database/schedule/count_repo_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/database/schedule/count_test.go b/database/schedule/count_test.go index c98ba7224..98090ab8f 100644 --- a/database/schedule/count_test.go +++ b/database/schedule/count_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/database/schedule/create.go b/database/schedule/create.go index 8a5907263..9bc2079eb 100644 --- a/database/schedule/create.go +++ b/database/schedule/create.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore similar code with update.go package schedule diff --git a/database/schedule/create_test.go b/database/schedule/create_test.go index 272e91a41..7a2a42cc2 100644 --- a/database/schedule/create_test.go +++ b/database/schedule/create_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/database/schedule/delete.go b/database/schedule/delete.go index 765b31120..66e489d25 100644 --- a/database/schedule/delete.go +++ b/database/schedule/delete.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/database/schedule/delete_test.go b/database/schedule/delete_test.go index 8dff8ad78..7a0a8ae76 100644 --- a/database/schedule/delete_test.go +++ b/database/schedule/delete_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/database/schedule/get.go b/database/schedule/get.go index e4540f0f0..9f352d72b 100644 --- a/database/schedule/get.go +++ b/database/schedule/get.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/database/schedule/get_repo.go b/database/schedule/get_repo.go index d0ddc4271..6ee2e6bb7 100644 --- a/database/schedule/get_repo.go +++ b/database/schedule/get_repo.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/database/schedule/get_repo_test.go b/database/schedule/get_repo_test.go index 998b58fc3..f21c11fb0 100644 --- a/database/schedule/get_repo_test.go +++ b/database/schedule/get_repo_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/database/schedule/get_test.go b/database/schedule/get_test.go index bc4a61f75..55b9321ea 100644 --- a/database/schedule/get_test.go +++ b/database/schedule/get_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/database/schedule/index.go b/database/schedule/index.go index 6b88199fa..11834bf4f 100644 --- a/database/schedule/index.go +++ b/database/schedule/index.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/database/schedule/index_test.go b/database/schedule/index_test.go index 145fd5ac7..b24ef61c4 100644 --- a/database/schedule/index_test.go +++ b/database/schedule/index_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/database/schedule/interface.go b/database/schedule/interface.go index 402499ab1..8d80a7c36 100644 --- a/database/schedule/interface.go +++ b/database/schedule/interface.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/database/schedule/list.go b/database/schedule/list.go index fbba87ca2..4904a1149 100644 --- a/database/schedule/list.go +++ b/database/schedule/list.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/database/schedule/list_active.go b/database/schedule/list_active.go index 0afd4ddc5..07616a7de 100644 --- a/database/schedule/list_active.go +++ b/database/schedule/list_active.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/database/schedule/list_active_test.go b/database/schedule/list_active_test.go index 2bce7ed06..7c604f10f 100644 --- a/database/schedule/list_active_test.go +++ b/database/schedule/list_active_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/database/schedule/list_repo.go b/database/schedule/list_repo.go index 9d0cfed5e..c5d7866ca 100644 --- a/database/schedule/list_repo.go +++ b/database/schedule/list_repo.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/database/schedule/list_repo_test.go b/database/schedule/list_repo_test.go index 2d573448d..baddeef6a 100644 --- a/database/schedule/list_repo_test.go +++ b/database/schedule/list_repo_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/database/schedule/list_test.go b/database/schedule/list_test.go index 5b4095724..463a9dfd9 100644 --- a/database/schedule/list_test.go +++ b/database/schedule/list_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/database/schedule/opts.go b/database/schedule/opts.go index cb2c89cfe..f5f596d26 100644 --- a/database/schedule/opts.go +++ b/database/schedule/opts.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/database/schedule/opts_test.go b/database/schedule/opts_test.go index 6159801e3..93a2d3565 100644 --- a/database/schedule/opts_test.go +++ b/database/schedule/opts_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/database/schedule/schedule.go b/database/schedule/schedule.go index 269278f52..a55bd2eb9 100644 --- a/database/schedule/schedule.go +++ b/database/schedule/schedule.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/database/schedule/schedule_test.go b/database/schedule/schedule_test.go index 69fea7cc9..d3126a745 100644 --- a/database/schedule/schedule_test.go +++ b/database/schedule/schedule_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/database/schedule/table.go b/database/schedule/table.go index 9ebccf864..ea8e99cb3 100644 --- a/database/schedule/table.go +++ b/database/schedule/table.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/database/schedule/table_test.go b/database/schedule/table_test.go index c0d785ed1..40cd064eb 100644 --- a/database/schedule/table_test.go +++ b/database/schedule/table_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/database/schedule/update.go b/database/schedule/update.go index 23ab855ba..87a0e5a9e 100644 --- a/database/schedule/update.go +++ b/database/schedule/update.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/database/schedule/update_test.go b/database/schedule/update_test.go index 235ccfc43..45f9dbdf8 100644 --- a/database/schedule/update_test.go +++ b/database/schedule/update_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/database/secret/count.go b/database/secret/count.go index 32e646074..fd4158d8a 100644 --- a/database/secret/count.go +++ b/database/secret/count.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/secret/count_org.go b/database/secret/count_org.go index abb554405..79dec8c44 100644 --- a/database/secret/count_org.go +++ b/database/secret/count_org.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/secret/count_org_test.go b/database/secret/count_org_test.go index bf8134a70..500d29878 100644 --- a/database/secret/count_org_test.go +++ b/database/secret/count_org_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/secret/count_repo.go b/database/secret/count_repo.go index 698b9d0c5..8fd9b0090 100644 --- a/database/secret/count_repo.go +++ b/database/secret/count_repo.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/secret/count_repo_test.go b/database/secret/count_repo_test.go index 127631dd1..3e688b0c2 100644 --- a/database/secret/count_repo_test.go +++ b/database/secret/count_repo_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/secret/count_team.go b/database/secret/count_team.go index e42902b1e..2dcce27ef 100644 --- a/database/secret/count_team.go +++ b/database/secret/count_team.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/secret/count_team_test.go b/database/secret/count_team_test.go index 4f67ccec8..9800b34fd 100644 --- a/database/secret/count_team_test.go +++ b/database/secret/count_team_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/secret/count_test.go b/database/secret/count_test.go index c14174d81..127cb3371 100644 --- a/database/secret/count_test.go +++ b/database/secret/count_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/secret/create.go b/database/secret/create.go index 83f54a87c..4c8853bd8 100644 --- a/database/secret/create.go +++ b/database/secret/create.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore similar code with update.go package secret diff --git a/database/secret/create_test.go b/database/secret/create_test.go index 80514d70a..2d86fbb0c 100644 --- a/database/secret/create_test.go +++ b/database/secret/create_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/secret/delete.go b/database/secret/delete.go index 44d2f7e39..b4068faec 100644 --- a/database/secret/delete.go +++ b/database/secret/delete.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/secret/delete_test.go b/database/secret/delete_test.go index d56caeeb4..0c078c98f 100644 --- a/database/secret/delete_test.go +++ b/database/secret/delete_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/secret/get.go b/database/secret/get.go index b07c8e52b..c8cafa2df 100644 --- a/database/secret/get.go +++ b/database/secret/get.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/secret/get_org.go b/database/secret/get_org.go index 759fa2c8b..950368735 100644 --- a/database/secret/get_org.go +++ b/database/secret/get_org.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/secret/get_org_test.go b/database/secret/get_org_test.go index 73f4b04d8..fbdaf1f17 100644 --- a/database/secret/get_org_test.go +++ b/database/secret/get_org_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/secret/get_repo.go b/database/secret/get_repo.go index 9442aa779..b33b0d58d 100644 --- a/database/secret/get_repo.go +++ b/database/secret/get_repo.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/secret/get_repo_test.go b/database/secret/get_repo_test.go index 7e3a70cb0..5f8678546 100644 --- a/database/secret/get_repo_test.go +++ b/database/secret/get_repo_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/secret/get_team.go b/database/secret/get_team.go index 6c28fb7df..b11a9fd41 100644 --- a/database/secret/get_team.go +++ b/database/secret/get_team.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/secret/get_team_test.go b/database/secret/get_team_test.go index 3239e2c27..30854550e 100644 --- a/database/secret/get_team_test.go +++ b/database/secret/get_team_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/secret/get_test.go b/database/secret/get_test.go index 0698a8b32..f57232a02 100644 --- a/database/secret/get_test.go +++ b/database/secret/get_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/secret/index.go b/database/secret/index.go index df728a510..f0cd1837d 100644 --- a/database/secret/index.go +++ b/database/secret/index.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/secret/index_test.go b/database/secret/index_test.go index ca6a756c3..97e52f970 100644 --- a/database/secret/index_test.go +++ b/database/secret/index_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/secret/interface.go b/database/secret/interface.go index bbfa608b2..e431fd458 100644 --- a/database/secret/interface.go +++ b/database/secret/interface.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/secret/list.go b/database/secret/list.go index b07003366..08746332c 100644 --- a/database/secret/list.go +++ b/database/secret/list.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/secret/list_org.go b/database/secret/list_org.go index d337329d5..bb57d4eb3 100644 --- a/database/secret/list_org.go +++ b/database/secret/list_org.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/secret/list_org_test.go b/database/secret/list_org_test.go index 795f1409e..ecde40520 100644 --- a/database/secret/list_org_test.go +++ b/database/secret/list_org_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/secret/list_repo.go b/database/secret/list_repo.go index 584b38494..213ee9353 100644 --- a/database/secret/list_repo.go +++ b/database/secret/list_repo.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/secret/list_repo_test.go b/database/secret/list_repo_test.go index 6d9dbd05a..dece5e57e 100644 --- a/database/secret/list_repo_test.go +++ b/database/secret/list_repo_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/secret/list_team.go b/database/secret/list_team.go index 81d5c4589..1f5e317c5 100644 --- a/database/secret/list_team.go +++ b/database/secret/list_team.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/secret/list_team_test.go b/database/secret/list_team_test.go index 33920ead3..40d311805 100644 --- a/database/secret/list_team_test.go +++ b/database/secret/list_team_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/secret/list_test.go b/database/secret/list_test.go index fce58be8f..22f8ea11f 100644 --- a/database/secret/list_test.go +++ b/database/secret/list_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/secret/opts.go b/database/secret/opts.go index 3de29ea71..cb1589d32 100644 --- a/database/secret/opts.go +++ b/database/secret/opts.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/secret/opts_test.go b/database/secret/opts_test.go index 67ea1ced1..f446c09f2 100644 --- a/database/secret/opts_test.go +++ b/database/secret/opts_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/secret/secret.go b/database/secret/secret.go index 97be7e3ea..7cf9981c8 100644 --- a/database/secret/secret.go +++ b/database/secret/secret.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/secret/secret_test.go b/database/secret/secret_test.go index b15f7b224..ce9e8b5b7 100644 --- a/database/secret/secret_test.go +++ b/database/secret/secret_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/secret/table.go b/database/secret/table.go index 4659e5afb..ed10fbdb4 100644 --- a/database/secret/table.go +++ b/database/secret/table.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/secret/table_test.go b/database/secret/table_test.go index 127325075..0e7d60297 100644 --- a/database/secret/table_test.go +++ b/database/secret/table_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/secret/update.go b/database/secret/update.go index 447071979..04fc98b84 100644 --- a/database/secret/update.go +++ b/database/secret/update.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore similar code with create.go package secret diff --git a/database/secret/update_test.go b/database/secret/update_test.go index cb32fe1d4..74576535e 100644 --- a/database/secret/update_test.go +++ b/database/secret/update_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/database/service/clean.go b/database/service/clean.go index aa3cda50a..e9e42de58 100644 --- a/database/service/clean.go +++ b/database/service/clean.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/database/service/clean_test.go b/database/service/clean_test.go index c469a3127..a3edada5b 100644 --- a/database/service/clean_test.go +++ b/database/service/clean_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/database/service/count.go b/database/service/count.go index 2ea1d374f..dd1f63188 100644 --- a/database/service/count.go +++ b/database/service/count.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/database/service/count_build.go b/database/service/count_build.go index 85d7e8b9e..a70c326d2 100644 --- a/database/service/count_build.go +++ b/database/service/count_build.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/database/service/count_build_test.go b/database/service/count_build_test.go index 3dec30151..09b013c0c 100644 --- a/database/service/count_build_test.go +++ b/database/service/count_build_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/database/service/count_test.go b/database/service/count_test.go index 9de85b5e3..bbd0b6faf 100644 --- a/database/service/count_test.go +++ b/database/service/count_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/database/service/create.go b/database/service/create.go index 068d9b076..dc5726dea 100644 --- a/database/service/create.go +++ b/database/service/create.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/database/service/create_test.go b/database/service/create_test.go index de5bd429c..b284bd4f8 100644 --- a/database/service/create_test.go +++ b/database/service/create_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/database/service/delete.go b/database/service/delete.go index 1fd80dfd9..90fc552f6 100644 --- a/database/service/delete.go +++ b/database/service/delete.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/database/service/delete_test.go b/database/service/delete_test.go index adc1191e6..3600242d9 100644 --- a/database/service/delete_test.go +++ b/database/service/delete_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/database/service/get.go b/database/service/get.go index 14a6f5698..aacda2904 100644 --- a/database/service/get.go +++ b/database/service/get.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/database/service/get_build.go b/database/service/get_build.go index b0d65803a..8822743f8 100644 --- a/database/service/get_build.go +++ b/database/service/get_build.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/database/service/get_build_test.go b/database/service/get_build_test.go index b639570b5..cd188c818 100644 --- a/database/service/get_build_test.go +++ b/database/service/get_build_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/database/service/get_test.go b/database/service/get_test.go index 2d89d4433..e5d694b9c 100644 --- a/database/service/get_test.go +++ b/database/service/get_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/database/service/interface.go b/database/service/interface.go index 6a4ecdc64..90982afa0 100644 --- a/database/service/interface.go +++ b/database/service/interface.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/database/service/list.go b/database/service/list.go index 4ee397e5e..5da3a06ed 100644 --- a/database/service/list.go +++ b/database/service/list.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/database/service/list_build.go b/database/service/list_build.go index 8dec937ca..b273835f8 100644 --- a/database/service/list_build.go +++ b/database/service/list_build.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/database/service/list_build_test.go b/database/service/list_build_test.go index 061f4c6f3..64ad9b1b2 100644 --- a/database/service/list_build_test.go +++ b/database/service/list_build_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/database/service/list_image.go b/database/service/list_image.go index 758e8651a..f5267d5da 100644 --- a/database/service/list_image.go +++ b/database/service/list_image.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/database/service/list_image_test.go b/database/service/list_image_test.go index 5272fb742..fdf8a35fa 100644 --- a/database/service/list_image_test.go +++ b/database/service/list_image_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/database/service/list_status.go b/database/service/list_status.go index c5df5afb5..dde89795a 100644 --- a/database/service/list_status.go +++ b/database/service/list_status.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/database/service/list_status_test.go b/database/service/list_status_test.go index 54015f286..0b6e7ea1a 100644 --- a/database/service/list_status_test.go +++ b/database/service/list_status_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/database/service/list_test.go b/database/service/list_test.go index 95c9ab861..24f718e94 100644 --- a/database/service/list_test.go +++ b/database/service/list_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/database/service/opts.go b/database/service/opts.go index 398cdb6b0..c06c6a931 100644 --- a/database/service/opts.go +++ b/database/service/opts.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/database/service/opts_test.go b/database/service/opts_test.go index b871ec924..043d1e290 100644 --- a/database/service/opts_test.go +++ b/database/service/opts_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/database/service/service.go b/database/service/service.go index 4fb016f8b..0f1b92b7d 100644 --- a/database/service/service.go +++ b/database/service/service.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/database/service/service_test.go b/database/service/service_test.go index c9d658769..e1f6f92f3 100644 --- a/database/service/service_test.go +++ b/database/service/service_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/database/service/table.go b/database/service/table.go index fad3aae2a..7cf7561c3 100644 --- a/database/service/table.go +++ b/database/service/table.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/database/service/table_test.go b/database/service/table_test.go index 9897ad4df..16a4ccd3a 100644 --- a/database/service/table_test.go +++ b/database/service/table_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/database/service/update.go b/database/service/update.go index 8c8d229fd..677a2c71c 100644 --- a/database/service/update.go +++ b/database/service/update.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/database/service/update_test.go b/database/service/update_test.go index 29f41c66f..6e8001deb 100644 --- a/database/service/update_test.go +++ b/database/service/update_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/database/step/clean.go b/database/step/clean.go index 54e686e86..09c74543d 100644 --- a/database/step/clean.go +++ b/database/step/clean.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/database/step/clean_test.go b/database/step/clean_test.go index e772751ac..4384d7719 100644 --- a/database/step/clean_test.go +++ b/database/step/clean_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/database/step/count.go b/database/step/count.go index 6f8a665b4..de91f1649 100644 --- a/database/step/count.go +++ b/database/step/count.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/database/step/count_build.go b/database/step/count_build.go index 448e04d7d..9dfbab289 100644 --- a/database/step/count_build.go +++ b/database/step/count_build.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/database/step/count_build_test.go b/database/step/count_build_test.go index df5a830f4..e6561d996 100644 --- a/database/step/count_build_test.go +++ b/database/step/count_build_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/database/step/count_test.go b/database/step/count_test.go index dc473bd96..be8faecba 100644 --- a/database/step/count_test.go +++ b/database/step/count_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/database/step/create.go b/database/step/create.go index 2d18bc9ce..7b9603a44 100644 --- a/database/step/create.go +++ b/database/step/create.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/database/step/create_test.go b/database/step/create_test.go index 0bf3ffca6..8910f8b21 100644 --- a/database/step/create_test.go +++ b/database/step/create_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/database/step/delete.go b/database/step/delete.go index d5107dea8..b5a6c9912 100644 --- a/database/step/delete.go +++ b/database/step/delete.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/database/step/delete_test.go b/database/step/delete_test.go index d77f81a25..44def389b 100644 --- a/database/step/delete_test.go +++ b/database/step/delete_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/database/step/get.go b/database/step/get.go index 1b07d1f6a..183f760c1 100644 --- a/database/step/get.go +++ b/database/step/get.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/database/step/get_build.go b/database/step/get_build.go index 49aed7551..a0f970fb8 100644 --- a/database/step/get_build.go +++ b/database/step/get_build.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/database/step/get_build_test.go b/database/step/get_build_test.go index 8428598f5..f1bd6715e 100644 --- a/database/step/get_build_test.go +++ b/database/step/get_build_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/database/step/get_test.go b/database/step/get_test.go index b30ced1b0..18d9934ff 100644 --- a/database/step/get_test.go +++ b/database/step/get_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/database/step/interface.go b/database/step/interface.go index e7a377d26..a2a289aa3 100644 --- a/database/step/interface.go +++ b/database/step/interface.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/database/step/list.go b/database/step/list.go index 3c7fedbc9..1d0976ba6 100644 --- a/database/step/list.go +++ b/database/step/list.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/database/step/list_build.go b/database/step/list_build.go index f338b1374..f14fdc67e 100644 --- a/database/step/list_build.go +++ b/database/step/list_build.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/database/step/list_build_test.go b/database/step/list_build_test.go index 4ebe4c0be..20e13792e 100644 --- a/database/step/list_build_test.go +++ b/database/step/list_build_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/database/step/list_image.go b/database/step/list_image.go index cd02af894..0a98720cc 100644 --- a/database/step/list_image.go +++ b/database/step/list_image.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/database/step/list_image_test.go b/database/step/list_image_test.go index b7170634f..6b3e6be12 100644 --- a/database/step/list_image_test.go +++ b/database/step/list_image_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/database/step/list_status.go b/database/step/list_status.go index 9b54e3b7f..470369394 100644 --- a/database/step/list_status.go +++ b/database/step/list_status.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/database/step/list_status_test.go b/database/step/list_status_test.go index 7716b02e9..c025554d4 100644 --- a/database/step/list_status_test.go +++ b/database/step/list_status_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/database/step/list_test.go b/database/step/list_test.go index c98852b1b..348d4508b 100644 --- a/database/step/list_test.go +++ b/database/step/list_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/database/step/opts.go b/database/step/opts.go index 80db4689c..3c783b6f5 100644 --- a/database/step/opts.go +++ b/database/step/opts.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/database/step/opts_test.go b/database/step/opts_test.go index 4ea1d64c0..1b9a3c424 100644 --- a/database/step/opts_test.go +++ b/database/step/opts_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/database/step/step.go b/database/step/step.go index 43e905797..9437bd118 100644 --- a/database/step/step.go +++ b/database/step/step.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/database/step/step_test.go b/database/step/step_test.go index 136d5ca40..bbd2a09da 100644 --- a/database/step/step_test.go +++ b/database/step/step_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/database/step/table.go b/database/step/table.go index ffd44c6c6..aa4997ffc 100644 --- a/database/step/table.go +++ b/database/step/table.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/database/step/table_test.go b/database/step/table_test.go index 08900c753..f39f24639 100644 --- a/database/step/table_test.go +++ b/database/step/table_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/database/step/update.go b/database/step/update.go index c9e5f73d0..d655e15e0 100644 --- a/database/step/update.go +++ b/database/step/update.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/database/step/update_test.go b/database/step/update_test.go index 38d8c1bdb..60907aff2 100644 --- a/database/step/update_test.go +++ b/database/step/update_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/database/user/count.go b/database/user/count.go index 6786f6e92..dc5554b37 100644 --- a/database/user/count.go +++ b/database/user/count.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package user diff --git a/database/user/count_test.go b/database/user/count_test.go index 912e7c511..78af924aa 100644 --- a/database/user/count_test.go +++ b/database/user/count_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package user diff --git a/database/user/create.go b/database/user/create.go index 33808c2e4..6010d1e8f 100644 --- a/database/user/create.go +++ b/database/user/create.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore similar code in update.go package user diff --git a/database/user/create_test.go b/database/user/create_test.go index f08b1372b..283bdb443 100644 --- a/database/user/create_test.go +++ b/database/user/create_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package user diff --git a/database/user/delete.go b/database/user/delete.go index 7cafb61c8..5747bf404 100644 --- a/database/user/delete.go +++ b/database/user/delete.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package user diff --git a/database/user/delete_test.go b/database/user/delete_test.go index 76db55ecb..c06ccf5e2 100644 --- a/database/user/delete_test.go +++ b/database/user/delete_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package user diff --git a/database/user/get.go b/database/user/get.go index 33f9ea7be..e488ce73f 100644 --- a/database/user/get.go +++ b/database/user/get.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package user diff --git a/database/user/get_name.go b/database/user/get_name.go index c975ca883..d23ce1611 100644 --- a/database/user/get_name.go +++ b/database/user/get_name.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package user diff --git a/database/user/get_name_test.go b/database/user/get_name_test.go index 71d72e181..855fdfaaa 100644 --- a/database/user/get_name_test.go +++ b/database/user/get_name_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package user diff --git a/database/user/get_test.go b/database/user/get_test.go index 9a122d4e2..8ad1b3c77 100644 --- a/database/user/get_test.go +++ b/database/user/get_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package user diff --git a/database/user/index.go b/database/user/index.go index eb2ef5544..25c3edef3 100644 --- a/database/user/index.go +++ b/database/user/index.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package user diff --git a/database/user/index_test.go b/database/user/index_test.go index c3c96b3de..79a819009 100644 --- a/database/user/index_test.go +++ b/database/user/index_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package user diff --git a/database/user/interface.go b/database/user/interface.go index ffbb62bfb..a5801d53a 100644 --- a/database/user/interface.go +++ b/database/user/interface.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package user diff --git a/database/user/list.go b/database/user/list.go index 70e8c26d8..aaa24644d 100644 --- a/database/user/list.go +++ b/database/user/list.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package user diff --git a/database/user/list_lite.go b/database/user/list_lite.go index f5b2bc1fa..83a40be56 100644 --- a/database/user/list_lite.go +++ b/database/user/list_lite.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package user diff --git a/database/user/list_lite_test.go b/database/user/list_lite_test.go index df279c39d..2f3a12dc5 100644 --- a/database/user/list_lite_test.go +++ b/database/user/list_lite_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package user diff --git a/database/user/list_test.go b/database/user/list_test.go index dcf1970b4..da61b5b67 100644 --- a/database/user/list_test.go +++ b/database/user/list_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package user diff --git a/database/user/opts.go b/database/user/opts.go index 135cd789f..4901e5be3 100644 --- a/database/user/opts.go +++ b/database/user/opts.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package user diff --git a/database/user/opts_test.go b/database/user/opts_test.go index 867b4ad9c..77c74506c 100644 --- a/database/user/opts_test.go +++ b/database/user/opts_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package user diff --git a/database/user/table.go b/database/user/table.go index 890e91a1b..070546435 100644 --- a/database/user/table.go +++ b/database/user/table.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package user diff --git a/database/user/table_test.go b/database/user/table_test.go index 4f7b82ce2..ef84c28ce 100644 --- a/database/user/table_test.go +++ b/database/user/table_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package user diff --git a/database/user/update.go b/database/user/update.go index 04d932e9d..043ed71de 100644 --- a/database/user/update.go +++ b/database/user/update.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore similar code in create.go package user diff --git a/database/user/update_test.go b/database/user/update_test.go index 58a909b5c..83b455d77 100644 --- a/database/user/update_test.go +++ b/database/user/update_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package user diff --git a/database/user/user.go b/database/user/user.go index 67f9413e8..2cf13feb2 100644 --- a/database/user/user.go +++ b/database/user/user.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package user diff --git a/database/user/user_test.go b/database/user/user_test.go index 1586103a7..a3ab4ff11 100644 --- a/database/user/user_test.go +++ b/database/user/user_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package user @@ -195,6 +193,6 @@ func testUser() *library.User { type AnyArgument struct{} // Match satisfies sqlmock.Argument interface. -func (a AnyArgument) Match(v driver.Value) bool { +func (a AnyArgument) Match(_ driver.Value) bool { return true } diff --git a/database/validate.go b/database/validate.go index 18f07cb84..4c519d081 100644 --- a/database/validate.go +++ b/database/validate.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Ine. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/validate_test.go b/database/validate_test.go index 60761e215..36b60fb98 100644 --- a/database/validate_test.go +++ b/database/validate_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Ine. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/worker/count.go b/database/worker/count.go index f85227840..eef910c36 100644 --- a/database/worker/count.go +++ b/database/worker/count.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package worker diff --git a/database/worker/count_test.go b/database/worker/count_test.go index 00acef108..c8f246f18 100644 --- a/database/worker/count_test.go +++ b/database/worker/count_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package worker diff --git a/database/worker/create.go b/database/worker/create.go index 4fd4a28d6..12b386319 100644 --- a/database/worker/create.go +++ b/database/worker/create.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package worker diff --git a/database/worker/create_test.go b/database/worker/create_test.go index dcf937e55..dad81473a 100644 --- a/database/worker/create_test.go +++ b/database/worker/create_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package worker diff --git a/database/worker/delete.go b/database/worker/delete.go index c3c29fd5b..ba846db91 100644 --- a/database/worker/delete.go +++ b/database/worker/delete.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package worker diff --git a/database/worker/delete_test.go b/database/worker/delete_test.go index 3a0b658d9..53984b4c6 100644 --- a/database/worker/delete_test.go +++ b/database/worker/delete_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package worker diff --git a/database/worker/get.go b/database/worker/get.go index b2a033983..12201d4d5 100644 --- a/database/worker/get.go +++ b/database/worker/get.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package worker diff --git a/database/worker/get_hostname.go b/database/worker/get_hostname.go index 6a2a89796..3370620a0 100644 --- a/database/worker/get_hostname.go +++ b/database/worker/get_hostname.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package worker diff --git a/database/worker/get_hostname_test.go b/database/worker/get_hostname_test.go index e20e7e43b..fc4802d70 100644 --- a/database/worker/get_hostname_test.go +++ b/database/worker/get_hostname_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package worker diff --git a/database/worker/get_test.go b/database/worker/get_test.go index 9fc017f92..e5249fda1 100644 --- a/database/worker/get_test.go +++ b/database/worker/get_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package worker diff --git a/database/worker/index.go b/database/worker/index.go index 8f6dd23c5..3220d4a63 100644 --- a/database/worker/index.go +++ b/database/worker/index.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package worker diff --git a/database/worker/index_test.go b/database/worker/index_test.go index 7a55ebe57..57e43ef70 100644 --- a/database/worker/index_test.go +++ b/database/worker/index_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package worker diff --git a/database/worker/interface.go b/database/worker/interface.go index 840ed21af..c594c556a 100644 --- a/database/worker/interface.go +++ b/database/worker/interface.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package worker diff --git a/database/worker/list.go b/database/worker/list.go index 4ab1a4c5b..dbf8ff2a7 100644 --- a/database/worker/list.go +++ b/database/worker/list.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package worker diff --git a/database/worker/list_test.go b/database/worker/list_test.go index 7eadb700a..9c5331fe4 100644 --- a/database/worker/list_test.go +++ b/database/worker/list_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package worker diff --git a/database/worker/opts.go b/database/worker/opts.go index 2d07f41f9..71048282b 100644 --- a/database/worker/opts.go +++ b/database/worker/opts.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package worker diff --git a/database/worker/opts_test.go b/database/worker/opts_test.go index e2efb2997..f627d25ed 100644 --- a/database/worker/opts_test.go +++ b/database/worker/opts_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package worker diff --git a/database/worker/table.go b/database/worker/table.go index 304b1dddf..9fcfdd113 100644 --- a/database/worker/table.go +++ b/database/worker/table.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package worker diff --git a/database/worker/table_test.go b/database/worker/table_test.go index 8e37f22de..652b76fab 100644 --- a/database/worker/table_test.go +++ b/database/worker/table_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package worker diff --git a/database/worker/update.go b/database/worker/update.go index d84d63eaf..3cae0d164 100644 --- a/database/worker/update.go +++ b/database/worker/update.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package worker diff --git a/database/worker/update_test.go b/database/worker/update_test.go index e8832bc37..d077bc567 100644 --- a/database/worker/update_test.go +++ b/database/worker/update_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package worker diff --git a/database/worker/worker.go b/database/worker/worker.go index 7f9277dc1..09b69176a 100644 --- a/database/worker/worker.go +++ b/database/worker/worker.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package worker diff --git a/database/worker/worker_test.go b/database/worker/worker_test.go index 00096c2a9..a219d1ffc 100644 --- a/database/worker/worker_test.go +++ b/database/worker/worker_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package worker diff --git a/docker-compose.yml b/docker-compose.yml index 6a596e45e..349d0d34b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,4 @@ -# Copyright (c) 2022 Target Brands, Inc. All rights reserved. -# -# Use of this source code is governed by the LICENSE file in this repository. +# SPDX-License-Identifier: Apache-2.0 version: '3' @@ -37,10 +35,13 @@ services: VELA_ADDR: 'http://localhost:8080' VELA_WEBUI_ADDR: 'http://localhost:8888' VELA_LOG_LEVEL: trace + # comment the line below to use registration flow VELA_SECRET: 'zB7mrKDTZqNeNTD8z47yG4DHywspAh' + QUEUE_PUBLIC_KEY: 'DXsJkoTSkHlG26d75LyHJG+KQsXPr8VKPpmH/78zmko=' VELA_SERVER_PRIVATE_KEY: 'F534FF2A080E45F38E05DC70752E6787' VELA_USER_REFRESH_TOKEN_DURATION: 90m VELA_USER_ACCESS_TOKEN_DURATION: 60m + VELA_WORKER_AUTH_TOKEN_DURATION: 3m VELA_DISABLE_WEBHOOK_VALIDATION: 'true' VELA_ENABLE_SECURE_COOKIE: 'false' VELA_REPO_ALLOWLIST: '*' @@ -55,6 +56,7 @@ services: - redis - vault + # The `worker` compose service hosts the Vela build daemon. # # This component is used for pulling builds from the FIFO @@ -69,17 +71,17 @@ services: environment: EXECUTOR_DRIVER: linux QUEUE_DRIVER: redis - QUEUE_ADDR: 'redis://redis:6379' - QUEUE_PUBLIC_KEY: 'DXsJkoTSkHlG26d75LyHJG+KQsXPr8VKPpmH/78zmko=' VELA_BUILD_LIMIT: 1 VELA_BUILD_TIMEOUT: 30m VELA_LOG_LEVEL: trace VELA_RUNTIME_DRIVER: docker VELA_RUNTIME_PRIVILEGED_IMAGES: 'target/vela-docker' + VELA_EXECUTOR_ENFORCE_TRUSTED_REPOS: 'true' VELA_SERVER_ADDR: 'http://server:8080' + # comment the 3 lines below to use registration flow VELA_SERVER_SECRET: 'zB7mrKDTZqNeNTD8z47yG4DHywspAh' WORKER_ADDR: 'http://worker:8080' - WORKER_CHECK_IN: 5m + WORKER_CHECK_IN: 2m restart: always ports: - '8081:8080' diff --git a/go.mod b/go.mod index 2cbfeab99..569c0f247 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/go-vela/server -go 1.19 +go 1.21 replace github.com/go-vela/types => ../types @@ -9,44 +9,43 @@ require ( github.com/DATA-DOG/go-sqlmock v1.5.0 github.com/Masterminds/semver/v3 v3.2.1 github.com/Masterminds/sprig/v3 v3.2.3 - github.com/adhocore/gronx v1.6.5 - github.com/alicebob/miniredis/v2 v2.30.5 - github.com/aws/aws-sdk-go v1.44.334 + github.com/adhocore/gronx v1.6.6 + github.com/alicebob/miniredis/v2 v2.31.0 + github.com/aws/aws-sdk-go v1.47.9 github.com/buildkite/yaml v0.0.0-20181016232759-0caa5f0796e3 github.com/drone/envsubst v1.0.3 github.com/gin-gonic/gin v1.9.1 github.com/go-playground/assert/v2 v2.2.0 - github.com/go-vela/types v0.20.2-0.20230822144153-14b37585731d - github.com/golang-jwt/jwt/v5 v5.0.0 - github.com/google/go-cmp v0.5.9 - github.com/google/go-github/v54 v54.0.0 - github.com/google/uuid v1.3.1 + github.com/go-vela/types v0.22.0 + github.com/golang-jwt/jwt/v5 v5.1.0 + github.com/google/go-cmp v0.6.0 + github.com/google/go-github/v56 v56.0.0 + github.com/google/uuid v1.4.0 github.com/goware/urlx v0.3.2 github.com/hashicorp/go-cleanhttp v0.5.2 github.com/hashicorp/go-multierror v1.1.1 - github.com/hashicorp/go-retryablehttp v0.7.4 - github.com/hashicorp/vault/api v1.9.2 + github.com/hashicorp/go-retryablehttp v0.7.5 + github.com/hashicorp/vault/api v1.10.0 github.com/joho/godotenv v1.5.1 github.com/pkg/errors v0.9.1 - github.com/prometheus/client_golang v1.16.0 - github.com/redis/go-redis/v9 v9.1.0 + github.com/prometheus/client_golang v1.17.0 + github.com/redis/go-redis/v9 v9.3.0 github.com/sirupsen/logrus v1.9.3 - github.com/spf13/afero v1.9.5 + github.com/spf13/afero v1.10.0 github.com/urfave/cli/v2 v2.25.7 - go.starlark.net v0.0.0-20230829175125-68633c9954b0 - golang.org/x/crypto v0.12.0 - golang.org/x/oauth2 v0.11.0 - golang.org/x/sync v0.3.0 + go.starlark.net v0.0.0-20231101134539-556fd59b42f6 + golang.org/x/crypto v0.15.0 + golang.org/x/oauth2 v0.14.0 + golang.org/x/sync v0.5.0 gopkg.in/square/go-jose.v2 v2.6.0 - gorm.io/driver/postgres v1.5.2 - gorm.io/driver/sqlite v1.5.3 - gorm.io/gorm v1.25.4 - k8s.io/apimachinery v0.28.1 + gorm.io/driver/postgres v1.5.4 + gorm.io/driver/sqlite v1.5.4 + gorm.io/gorm v1.25.5 + k8s.io/apimachinery v0.28.3 ) require ( github.com/Masterminds/goutils v1.1.1 // indirect - github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect github.com/PuerkitoBio/purell v1.1.1 // indirect github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a // indirect @@ -56,7 +55,6 @@ require ( github.com/cenkalti/backoff/v3 v3.0.0 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect - github.com/cloudflare/circl v1.3.3 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/fatih/color v1.10.0 // indirect @@ -85,7 +83,7 @@ require ( github.com/imdario/mergo v0.3.11 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect - github.com/jackc/pgx/v5 v5.3.1 // indirect + github.com/jackc/pgx/v5 v5.4.3 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect @@ -98,7 +96,7 @@ require ( github.com/mattn/go-isatty v0.0.19 // indirect github.com/mattn/go-sqlite3 v1.14.17 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect - github.com/microcosm-cc/bluemonday v1.0.25 // indirect + github.com/microcosm-cc/bluemonday v1.0.26 // indirect github.com/mitchellh/copystructure v1.0.0 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect @@ -106,9 +104,9 @@ require ( github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pelletier/go-toml/v2 v2.0.8 // indirect - github.com/prometheus/client_model v0.3.0 // indirect - github.com/prometheus/common v0.42.0 // indirect - github.com/prometheus/procfs v0.10.1 // indirect + github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect + github.com/prometheus/common v0.44.0 // indirect + github.com/prometheus/procfs v0.11.1 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/ryanuber/go-glob v1.0.0 // indirect github.com/shopspring/decimal v1.2.0 // indirect @@ -118,9 +116,9 @@ require ( github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect github.com/yuin/gopher-lua v1.1.0 // indirect golang.org/x/arch v0.3.0 // indirect - golang.org/x/net v0.14.0 // indirect - golang.org/x/sys v0.11.0 // indirect - golang.org/x/text v0.12.0 // indirect + golang.org/x/net v0.18.0 // indirect + golang.org/x/sys v0.14.0 // indirect + golang.org/x/text v0.14.0 // indirect golang.org/x/time v0.3.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.31.0 // indirect diff --git a/go.sum b/go.sum index f508a79ed..88a73f80d 100644 --- a/go.sum +++ b/go.sum @@ -42,6 +42,7 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60= github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= +github.com/DmitriyVTitov/size v1.5.0/go.mod h1:le6rNI4CoLQV1b9gzp1+3d7hMAD/uu2QcJ+aYbNgiU0= github.com/FZambia/sentinel v1.0.0 h1:KJ0ryjKTZk5WMp0dXvSdNqp3lFaW1fNFuEYfrkLOYIc= github.com/FZambia/sentinel v1.0.0/go.mod h1:ytL1Am/RLlAoAXG6Kj5LNuw/TRRQrv2rt2FT26vP5gI= github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI= @@ -51,33 +52,32 @@ github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0 github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= github.com/Masterminds/sprig/v3 v3.2.3 h1:eL2fZNezLomi0uOLqjQoN6BfsDD+fyLtgbJMAj9n6YA= github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBaRMhvYXJNkGuM= -github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 h1:wPbRQzjjwFc0ih8puEVAOFGELsn1zoIIYdxvML7mDxA= -github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8/go.mod h1:I0gYDMZ6Z5GRU7l58bNFSkPTFN6Yl12dsUlAZ8xy98g= github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI= github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M= github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= -github.com/adhocore/gronx v1.6.5 h1:/pryEagBKz3WqUgpgvtL51eBN2rJLXowuW7rpS+jrew= -github.com/adhocore/gronx v1.6.5/go.mod h1:7oUY1WAU8rEJWmAxXR2DN0JaO4gi9khSgKjiRypqteg= +github.com/adhocore/gronx v1.6.6 h1:Gk1OAP4CCSs2/i3f7HHwB2tX/EtYP3TzzWSHvesTR4k= +github.com/adhocore/gronx v1.6.6/go.mod h1:7oUY1WAU8rEJWmAxXR2DN0JaO4gi9khSgKjiRypqteg= github.com/alicebob/gopher-json v0.0.0-20180125190556-5a6b3ba71ee6/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc= github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a h1:HbKu58rmZpUGpz5+4FfNmIU+FmZg2P3Xaj2v2bfNWmk= github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc= github.com/alicebob/miniredis/v2 v2.11.1/go.mod h1:UA48pmi7aSazcGAvcdKcBB49z521IC9VjTTRz2nIaJE= -github.com/alicebob/miniredis/v2 v2.30.5 h1:3r6kTHdKnuP4fkS8k2IrvSfxpxUTcW1SOL0wN7b7Dt0= -github.com/alicebob/miniredis/v2 v2.30.5/go.mod h1:b25qWj4fCEsBeAAR2mlb0ufImGC6uH3VlUfb/HS5zKg= +github.com/alicebob/miniredis/v2 v2.31.0 h1:ObEFUNlJwoIiyjxdrYF0QIDE7qXcLc7D3WpSH4c22PU= +github.com/alicebob/miniredis/v2 v2.31.0/go.mod h1:UB/T2Uztp7MlFSDakaX1sTXUv5CASoprx0wulRT6HBg= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= -github.com/aws/aws-sdk-go v1.44.334 h1:h2bdbGb//fez6Sv6PaYv868s9liDeoYM6hYsAqTB4MU= -github.com/aws/aws-sdk-go v1.44.334/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= +github.com/aws/aws-sdk-go v1.47.9 h1:rarTsos0mA16q+huicGx0e560aYRtOucV5z2Mw23JRY= +github.com/aws/aws-sdk-go v1.47.9/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk= github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= -github.com/bsm/ginkgo/v2 v2.9.5 h1:rtVBYPs3+TC5iLUVOis1B9tjLTup7Cj5IfzosKtvTJ0= -github.com/bsm/gomega v1.26.0 h1:LhQm+AFcgV2M0WyKroMASzAzCAJVpAxQXv4SaI9a69Y= +github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs= +github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c= +github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA= +github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0= github.com/buildkite/yaml v0.0.0-20181016232759-0caa5f0796e3 h1:q+sMKdA6L8LyGVudTkpGoC73h6ak2iWSPFiFo/pFOU8= github.com/buildkite/yaml v0.0.0-20181016232759-0caa5f0796e3/go.mod h1:5hCug3EZaHXU3FdCA3gJm0YTNi+V+ooA2qNTiVpky4A= -github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s= github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= @@ -93,9 +93,6 @@ github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWR github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtMxxK7fi4I= -github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs= -github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= @@ -143,16 +140,18 @@ github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91 github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js= github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= github.com/go-test/deep v1.0.2 h1:onZX1rnHT3Wv6cqNgYyFOOlgVKJrksuCMCRvJStbMYw= +github.com/go-test/deep v1.0.2/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= -github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE= -github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= +github.com/golang-jwt/jwt/v5 v5.1.0 h1:UGKbA/IPjtS6zLcdB7i5TyACMgSbOTiR8qzXgw8HWQU= +github.com/golang-jwt/jwt/v5 v5.1.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= @@ -192,10 +191,10 @@ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/go-github/v54 v54.0.0 h1:OZdXwow4EAD5jEo5qg+dGFH2DpkyZvVsAehjvJuUL/c= -github.com/google/go-github/v54 v54.0.0/go.mod h1:Sw1LXWHhXRZtzJ9LI5fyJg9wbQzYvFhW8W5P2yaAQ7s= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-github/v56 v56.0.0 h1:TysL7dMa/r7wsQi44BjqlwaHvwlFlqkK8CtBWCX3gb4= +github.com/google/go-github/v56 v56.0.0/go.mod h1:D8cdcX98YWJvi7TLo7zM4/h8ZTx6u6fwGEkCdisopo0= github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -217,8 +216,8 @@ github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLe github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= -github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= +github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g= @@ -233,11 +232,12 @@ github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9n github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= github.com/hashicorp/go-hclog v0.16.2 h1:K4ev2ib4LdQETX5cSZBG0DVLk1jwGqSPXBjdah3veNs= +github.com/hashicorp/go-hclog v0.16.2/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= -github.com/hashicorp/go-retryablehttp v0.7.4 h1:ZQgVdpTdAL7WpMIwLzCfbalOcSUdkDZnpUv3/+BxzFA= -github.com/hashicorp/go-retryablehttp v0.7.4/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8= +github.com/hashicorp/go-retryablehttp v0.7.5 h1:bJj+Pj19UZMIweq/iie+1u5YCdGrnxCT9yvm0e+Nd5M= +github.com/hashicorp/go-retryablehttp v0.7.5/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8= github.com/hashicorp/go-rootcerts v1.0.2 h1:jzhAVGtqPKbwpyCPELlgNWhE1znq+qwJtW5Oi2viEzc= github.com/hashicorp/go-rootcerts v1.0.2/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8= github.com/hashicorp/go-secure-stdlib/parseutil v0.1.6 h1:om4Al8Oy7kCm/B86rLCLah4Dt5Aa0Fr5rYBG60OzwHQ= @@ -251,8 +251,8 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= -github.com/hashicorp/vault/api v1.9.2 h1:YjkZLJ7K3inKgMZ0wzCU9OHqc+UqMQyXsPXnf3Cl2as= -github.com/hashicorp/vault/api v1.9.2/go.mod h1:jo5Y/ET+hNyz+JnKDt8XLAdKs+AM0G5W0Vp1IrFI8N8= +github.com/hashicorp/vault/api v1.10.0 h1:/US7sIjWN6Imp4o/Rj1Ce2Nr5bki/AXi9vAW3p2tOJQ= +github.com/hashicorp/vault/api v1.10.0/go.mod h1:jo5Y/ET+hNyz+JnKDt8XLAdKs+AM0G5W0Vp1IrFI8N8= github.com/huandu/xstrings v1.3.3 h1:/Gcsuc1x8JVbJ9/rlye4xZnVAbEkGauT8lbebqcQws4= github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= @@ -263,8 +263,8 @@ github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsI github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk= github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= -github.com/jackc/pgx/v5 v5.3.1 h1:Fcr8QJ1ZeLi5zsPZqQeUZhNhxfkkKBOgJuYkJHoBOtU= -github.com/jackc/pgx/v5 v5.3.1/go.mod h1:t3JDKnCBlYIc0ewLF0Q7B8MXmoIaBOZj/ic7iHozM/8= +github.com/jackc/pgx/v5 v5.4.3 h1:cxFyXhxlvAifxnkKKdlxv8XqUf59tDlYjnV5YYfsJJY= +github.com/jackc/pgx/v5 v5.4.3/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSljmHRA= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= @@ -287,6 +287,7 @@ github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8t github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -308,8 +309,8 @@ github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6 github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= -github.com/microcosm-cc/bluemonday v1.0.25 h1:4NEwSfiJ+Wva0VxN5B8OwMicaJvD8r9tlJWm9rtloEg= -github.com/microcosm-cc/bluemonday v1.0.25/go.mod h1:ZIOjCQp1OrzBBPIJmfX4qDYFuhU02nx4bn030ixfHLE= +github.com/microcosm-cc/bluemonday v1.0.26 h1:xbqSvqzQMeEHCqMi64VAs4d8uy6Mequs3rQ0k/Khz58= +github.com/microcosm-cc/bluemonday v1.0.26/go.mod h1:JyzOCs9gkyQyjs+6h10UEVSe02CGwkhd72Xdqh78TWs= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ= github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= @@ -335,19 +336,20 @@ github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qR github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= -github.com/prometheus/client_golang v1.16.0 h1:yk/hx9hDbrGHovbci4BY+pRMfSuuat626eFsHb7tmT8= -github.com/prometheus/client_golang v1.16.0/go.mod h1:Zsulrv/L9oM40tJ7T815tM89lFEugiJ9HzIqaAx4LKc= +github.com/prometheus/client_golang v1.17.0 h1:rl2sfwZMtSthVU752MqfjQozy7blglC+1SOtjMAMh+Q= +github.com/prometheus/client_golang v1.17.0/go.mod h1:VeL+gMmOAxkS2IqfCq0ZmHSL+LjWfWDUmp1mBz9JgUY= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.3.0 h1:UBgGFHqYdG/TPFD1B1ogZywDqEkwp3fBMvqdiQ7Xew4= -github.com/prometheus/client_model v0.3.0/go.mod h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w= -github.com/prometheus/common v0.42.0 h1:EKsfXEYo4JpWMHH5cg+KOUWeuJSov1Id8zGR8eeI1YM= -github.com/prometheus/common v0.42.0/go.mod h1:xBwqVerjNdUDjgODMpudtOMwlOwf2SaTr1yjz4b7Zbc= -github.com/prometheus/procfs v0.10.1 h1:kYK1Va/YMlutzCGazswoHKo//tZVlFpKYh+PymziUAg= -github.com/prometheus/procfs v0.10.1/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM= -github.com/redis/go-redis/v9 v9.1.0 h1:137FnGdk+EQdCbye1FW+qOEcY5S+SpY9T0NiuqvtfMY= -github.com/redis/go-redis/v9 v9.1.0/go.mod h1:urWj3He21Dj5k4TK1y59xH8Uj6ATueP8AH1cY3lZl4c= +github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 h1:v7DLqVdK4VrYkVD5diGdl4sxJurKJEMnODWRJlxV9oM= +github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU= +github.com/prometheus/common v0.44.0 h1:+5BrQJwiBB9xsMygAB3TNvpQKOwlkc25LbISbrdOOfY= +github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO7x0VV9VvuY= +github.com/prometheus/procfs v0.11.1 h1:xRC8Iq1yyca5ypa9n1EZnWZkt7dwcoRPQwX/5gwaUuI= +github.com/prometheus/procfs v0.11.1/go.mod h1:eesXgaPo1q7lBpVMoMy0ZOFTth9hBn4W/y0/p/ScXhY= +github.com/redis/go-redis/v9 v9.3.0 h1:RiVDjmig62jIWp7Kk4XVLs0hzV6pI3PyTnnL0cnn0u0= +github.com/redis/go-redis/v9 v9.3.0/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= @@ -357,8 +359,8 @@ github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXY github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= -github.com/spf13/afero v1.9.5 h1:stMpOSZFs//0Lv29HduCmli3GUfpFoF3Y1Q/aXj/wVM= -github.com/spf13/afero v1.9.5/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ= +github.com/spf13/afero v1.10.0 h1:EaGW2JJh15aKOejeuJ+wpFSHnbd7GE6Wvp3TsNhb6LY= +github.com/spf13/afero v1.10.0/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ= github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng= github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -399,8 +401,8 @@ go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= -go.starlark.net v0.0.0-20230829175125-68633c9954b0 h1:mr0wY3kXIH4jJZPj1HYmK35saEoo+2aQkdD1Dh/IssM= -go.starlark.net v0.0.0-20230829175125-68633c9954b0/go.mod h1:jxU+3+j+71eXOW14274+SmmuW82qJzl6iZSeqEtTGds= +go.starlark.net v0.0.0-20231101134539-556fd59b42f6 h1:+eC0F/k4aBLC4szgOcjd7bDTEnpxADJyWJE0yowgM3E= +go.starlark.net v0.0.0-20231101134539-556fd59b42f6/go.mod h1:LcLNIzVOMp4oV+uusnpk+VU+SzXaJakUuBjoCSWH5dM= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k= golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= @@ -414,8 +416,8 @@ golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= -golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk= -golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= +golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA= +golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -483,10 +485,9 @@ golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= -golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14= -golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= +golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg= +golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -496,8 +497,8 @@ golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20201109201403-9fd604954f58/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.11.0 h1:vPL4xzxBM4niKCW6g9whtaWVXTJf1U5e4aZxxFx/gbU= -golang.org/x/oauth2 v0.11.0/go.mod h1:LdF7O/8bLR/qWK9DrpXmbHLTouvRHK0SgJl0GmDBchk= +golang.org/x/oauth2 v0.14.0 h1:P0Vrf/2538nmC0H+pEQ3MNFRRnVR7RlqyVw+bvm26z0= +golang.org/x/oauth2 v0.14.0/go.mod h1:lAtNWgaWfL4cm7j2OV8TxGi9Qb7ECORx8DktCY74OwM= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -509,8 +510,8 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= -golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE= +golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190204203706-41f3e6584952/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -549,20 +550,16 @@ golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= -golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= +golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.0.0-20220526004731-065cf7ba2467/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -573,8 +570,8 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc= -golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -730,6 +727,7 @@ google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/square/go-jose.v2 v2.6.0 h1:NGk74WTnPKBNUhNzQX7PYcTLUjoq7mzKk2OKbvwk2iI= gopkg.in/square/go-jose.v2 v2.6.0/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= @@ -741,12 +739,12 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gorm.io/driver/postgres v1.5.2 h1:ytTDxxEv+MplXOfFe3Lzm7SjG09fcdb3Z/c056DTBx0= -gorm.io/driver/postgres v1.5.2/go.mod h1:fmpX0m2I1PKuR7mKZiEluwrP3hbs+ps7JIGMUBpCgl8= -gorm.io/driver/sqlite v1.5.3 h1:7/0dUgX28KAcopdfbRWWl68Rflh6osa4rDh+m51KL2g= -gorm.io/driver/sqlite v1.5.3/go.mod h1:qxAuCol+2r6PannQDpOP1FP6ag3mKi4esLnB/jHed+4= -gorm.io/gorm v1.25.4 h1:iyNd8fNAe8W9dvtlgeRI5zSVZPsq3OpcTu37cYcpCmw= -gorm.io/gorm v1.25.4/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k= +gorm.io/driver/postgres v1.5.4 h1:Iyrp9Meh3GmbSuyIAGyjkN+n9K+GHX9b9MqsTL4EJCo= +gorm.io/driver/postgres v1.5.4/go.mod h1:Bgo89+h0CRcdA33Y6frlaHHVuTdOf87pmyzwW9C/BH0= +gorm.io/driver/sqlite v1.5.4 h1:IqXwXi8M/ZlPzH/947tn5uik3aYQslP9BVveoax0nV0= +gorm.io/driver/sqlite v1.5.4/go.mod h1:qxAuCol+2r6PannQDpOP1FP6ag3mKi4esLnB/jHed+4= +gorm.io/gorm v1.25.5 h1:zR9lOiiYf09VNh5Q1gphfyia1JpiClIWG9hQaxB/mls= +gorm.io/gorm v1.25.5/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= @@ -754,8 +752,8 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= -k8s.io/apimachinery v0.28.1 h1:EJD40og3GizBSV3mkIoXQBsws32okPOy+MkRyzh6nPY= -k8s.io/apimachinery v0.28.1/go.mod h1:X0xh/chESs2hP9koe+SdIAcXWcQ+RM5hy0ZynB+yEvw= +k8s.io/apimachinery v0.28.3 h1:B1wYx8txOaCQG0HmYF6nbpU8dg6HvA06x5tEffvOe7A= +k8s.io/apimachinery v0.28.3/go.mod h1:uQTKmIqs+rAYaq+DFaoD2X7pcjLOqbQX2AOiO0nIpb8= k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg= k8s.io/klog/v2 v2.100.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0= k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 h1:qY1Ad8PODbnymg2pRbkyMT/ylpTrCM8P2RJ0yroCyIk= @@ -765,3 +763,4 @@ rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= +sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= diff --git a/internal/token/compose.go b/internal/token/compose.go index 61bea7a32..6e48647e2 100644 --- a/internal/token/compose.go +++ b/internal/token/compose.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package token diff --git a/internal/token/compose_test.go b/internal/token/compose_test.go index ff01b543d..a73bf912b 100644 --- a/internal/token/compose_test.go +++ b/internal/token/compose_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package token diff --git a/internal/token/manager.go b/internal/token/manager.go index 22daf3636..c02484b87 100644 --- a/internal/token/manager.go +++ b/internal/token/manager.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package token diff --git a/internal/token/mint.go b/internal/token/mint.go index 7d2ff8f64..22c9599b9 100644 --- a/internal/token/mint.go +++ b/internal/token/mint.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package token diff --git a/internal/token/parse.go b/internal/token/parse.go index ad5423ee6..c42d90686 100644 --- a/internal/token/parse.go +++ b/internal/token/parse.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package token diff --git a/internal/token/parse_test.go b/internal/token/parse_test.go index c7dc2422f..c1e5d3ac0 100644 --- a/internal/token/parse_test.go +++ b/internal/token/parse_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package token diff --git a/internal/token/refresh.go b/internal/token/refresh.go index 9ba8c3187..678c5ccb0 100644 --- a/internal/token/refresh.go +++ b/internal/token/refresh.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package token diff --git a/internal/token/refresh_test.go b/internal/token/refresh_test.go index ee7a96077..6618b88c9 100644 --- a/internal/token/refresh_test.go +++ b/internal/token/refresh_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package token @@ -53,7 +51,7 @@ func TestTokenManager_Refresh(t *testing.T) { } defer func() { - db.DeleteUser(context.TODO(), u) + _ = db.DeleteUser(context.TODO(), u) db.Close() }() @@ -114,7 +112,7 @@ func TestTokenManager_Refresh_Expired(t *testing.T) { } defer func() { - db.DeleteUser(context.TODO(), u) + _ = db.DeleteUser(context.TODO(), u) db.Close() }() diff --git a/mock/server/authentication.go b/mock/server/authentication.go index ea7bb76a1..5c99ee8c9 100644 --- a/mock/server/authentication.go +++ b/mock/server/authentication.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package server @@ -87,3 +85,17 @@ func validateToken(c *gin.Context) { c.JSON(http.StatusOK, "vela-server") } + +// validateOAuthToken returns mock response for a http GET. +// +// Don't pass "Authorization" in header to receive an unauthorized error message. +func validateOAuthToken(c *gin.Context) { + err := "error" + + token := c.Request.Header.Get("Authorization") + if len(token) == 0 { + c.AbortWithStatusJSON(http.StatusUnauthorized, types.Error{Message: &err}) + } + + c.JSON(http.StatusOK, "oauth token was created by vela") +} diff --git a/mock/server/build.go b/mock/server/build.go index cc24af60c..3edc55bf0 100644 --- a/mock/server/build.go +++ b/mock/server/build.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package server @@ -39,8 +37,8 @@ const ( "author": "OctoKitty", "email": "octokitty@github.com", "link": "https://vela.example.company.com/github/octocat/1", - "branch": "master", - "ref": "refs/heads/master", + "branch": "main", + "ref": "refs/heads/main", "base_ref": "", "host": "example.company.com", "runtime": "docker", @@ -71,8 +69,8 @@ const ( "author": "OctoKitty", "email": "octokitty@github.com", "link": "https://vela.example.company.com/github/octocat/1", - "branch": "master", - "ref": "refs/heads/master", + "branch": "main", + "ref": "refs/heads/main", "base_ref": "", "host": "ed95dcc0687c", "runtime": "", @@ -100,8 +98,8 @@ const ( "author": "OctoKitty", "email": "octokitty@github.com", "link": "https://vela.example.company.com/github/octocat/1", - "branch": "master", - "ref": "refs/heads/master", + "branch": "main", + "ref": "refs/heads/main", "base_ref": "", "host": "82823eb770b0", "runtime": "", diff --git a/mock/server/deployment.go b/mock/server/deployment.go index 79b6bdfe3..875432823 100644 --- a/mock/server/deployment.go +++ b/mock/server/deployment.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package server @@ -23,7 +21,7 @@ const ( "url": "https://api.github.com/repos/github/octocat/deployments/1", "user": "octocat", "commit": "48afb5bdc41ad69bf22588491333f7cf71135163", - "ref": "master", + "ref": "main", "task": "deploy:vela", "target": "production", "description": "Deployment request from Vela" @@ -37,7 +35,7 @@ const ( "url": "https://api.github.com/repos/github/octocat/deployments/2", "user": "octocat", "commit": "48afb5bdc41ad69bf22588491333f7cf71135163", - "ref": "master", + "ref": "main", "task": "deploy:vela", "target": "production", "description": "Deployment request from Vela" @@ -48,7 +46,7 @@ const ( "url": "https://api.github.com/repos/github/octocat/deployments/1", "user": "octocat", "commit": "48afb5bdc41ad69bf22588491333f7cf71135163", - "ref": "master", + "ref": "main", "task": "deploy:vela", "target": "production", "description": "Deployment request from Vela" diff --git a/mock/server/hook.go b/mock/server/hook.go index d2c21da46..9c874de4a 100644 --- a/mock/server/hook.go +++ b/mock/server/hook.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore duplicate with user code package server @@ -27,7 +25,7 @@ const ( "created": 1563475419, "host": "github.com", "event": "push", - "branch": "master", + "branch": "main", "error": "", "status": "success", "link": "https://github.com/github/octocat/settings/hooks/1" @@ -44,7 +42,7 @@ const ( "created": 1563475420, "host": "github.com", "event": "push", - "branch": "master", + "branch": "main", "error": "", "status": "success", "link": "https://github.com/github/octocat/settings/hooks/1" @@ -58,7 +56,7 @@ const ( "created": 1563475419, "host": "github.com", "event": "push", - "branch": "master", + "branch": "main", "error": "", "status": "success", "link": "https://github.com/github/octocat/settings/hooks/1" diff --git a/mock/server/log.go b/mock/server/log.go index 3becfff38..fffefaedf 100644 --- a/mock/server/log.go +++ b/mock/server/log.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package server diff --git a/mock/server/pipeline.go b/mock/server/pipeline.go index 021960ea3..73ee1b42f 100644 --- a/mock/server/pipeline.go +++ b/mock/server/pipeline.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package server @@ -112,7 +110,7 @@ templates: "commit": "48afb5bdc41ad69bf22588491333f7cf71135163", "flavor": "", "platform": "", - "ref": "refs/heads/master", + "ref": "refs/heads/main", "type": "yaml", "version": "1", "external_secrets": false, @@ -132,7 +130,7 @@ templates: "commit": "a49aaf4afae6431a79239c95247a2b169fd9f067", "flavor": "", "platform": "", - "ref": "refs/heads/master", + "ref": "refs/heads/main", "type": "yaml", "version": "1", "external_secrets": false, @@ -149,7 +147,7 @@ templates: "commit": "48afb5bdc41ad69bf22588491333f7cf71135163", "flavor": "", "platform": "", - "ref": "refs/heads/master", + "ref": "refs/heads/main", "type": "yaml", "version": "1", "external_secrets": false, diff --git a/mock/server/repo.go b/mock/server/repo.go index fe4ac2ca9..724ba875b 100644 --- a/mock/server/repo.go +++ b/mock/server/repo.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package server @@ -25,7 +23,7 @@ const ( "full_name": "github/octocat", "link": "https://github.com/github/octocat", "clone": "https://github.com/github/octocat", - "branch": "master", + "branch": "main", "build_limit": 10, "timeout": 60, "visibility": "public", @@ -48,7 +46,7 @@ const ( "full_name": "github/octocat", "link": "https://github.com/github/octocat", "clone": "https://github.com/github/octocat", - "branch": "master", + "branch": "main", "build_limit": 10, "timeout": 60, "visibility": "public", @@ -68,7 +66,7 @@ const ( "full_name": "github/octokitty", "link": "https://github.com/github/octokitty", "clone": "https://github.com/github/octokitty", - "branch": "master", + "branch": "main", "build_limit": 10, "timeout": 60, "visibility": "public", diff --git a/mock/server/schedule.go b/mock/server/schedule.go index a1acc54f7..4e34e69fd 100644 --- a/mock/server/schedule.go +++ b/mock/server/schedule.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package server diff --git a/mock/server/scm.go b/mock/server/scm.go index 9b14e3c58..0dea97c37 100644 --- a/mock/server/scm.go +++ b/mock/server/scm.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package server @@ -13,7 +11,7 @@ import ( "github.com/go-vela/types" ) -// syncRepo has a param :repo returns mock JSON for a http GET. +// syncRepo has a param :repo returns mock JSON for a http PATCH. // // Pass "not-found" to :repo to test receiving a http 404 response. func syncRepo(c *gin.Context) { @@ -29,7 +27,7 @@ func syncRepo(c *gin.Context) { c.JSON(http.StatusOK, fmt.Sprintf("Repo %s has been synced", r)) } -// syncRepos has a param :org returns mock JSON for a http GET. +// syncRepos has a param :org returns mock JSON for a http PATCH. // // Pass "not-found" to :repo to test receiving a http 404 response. func syncRepos(c *gin.Context) { diff --git a/mock/server/secret.go b/mock/server/secret.go index eb1bcd72a..6f27a4a69 100644 --- a/mock/server/secret.go +++ b/mock/server/secret.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore duplicate with user code package server diff --git a/mock/server/server.go b/mock/server/server.go index 7bc668719..699062868 100644 --- a/mock/server/server.go +++ b/mock/server/server.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package server @@ -29,7 +27,7 @@ func FakeHandler() http.Handler { e.PUT("/api/v1/admin/service", updateService) e.PUT("/api/v1/admin/step", updateStep) e.PUT("/api/v1/admin/user", updateUser) - e.POST("/api/v1/admin/workers/:worker/register-token", registerToken) + e.POST("/api/v1/admin/workers/:worker/register", registerToken) e.PUT("api/v1/admin/clean", cleanResoures) // mock endpoints for build calls @@ -85,8 +83,8 @@ func FakeHandler() http.Handler { e.DELETE("/api/v1/repos/:org/:repo", removeRepo) e.PATCH("/api/v1/repos/:org/:repo/repair", repairRepo) e.PATCH("/api/v1/repos/:org/:repo/chown", chownRepo) - e.GET("/api/v1/scm/repos/:org/:repo/sync", syncRepo) - e.GET("/api/v1/scm/orgs/:org/sync", syncRepos) + e.PATCH("/api/v1/scm/repos/:org/:repo/sync", syncRepo) + e.PATCH("/api/v1/scm/orgs/:org/sync", syncRepos) // mock endpoints for secret calls e.GET("/api/v1/secrets/:engine/:type/:org/:name/:secret", getSecret) @@ -136,6 +134,10 @@ func FakeHandler() http.Handler { e.GET("/authenticate", getAuthenticate) e.POST("/authenticate/token", getAuthenticateFromToken) e.GET("/validate-token", validateToken) + e.GET("/validate-oauth", validateOAuthToken) + + // mock endpoint for queue credentials + e.GET("/api/v1/queue/info", getQueueCreds) return e } diff --git a/mock/server/service.go b/mock/server/service.go index 0d4ce36f1..4de3d5fad 100644 --- a/mock/server/service.go +++ b/mock/server/service.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore duplicate with user code package server diff --git a/mock/server/step.go b/mock/server/step.go index c7111aded..3e70b3879 100644 --- a/mock/server/step.go +++ b/mock/server/step.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore duplicate with user code package server diff --git a/mock/server/user.go b/mock/server/user.go index 85029962b..1ec672b47 100644 --- a/mock/server/user.go +++ b/mock/server/user.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore duplicate with user code package server diff --git a/mock/server/worker.go b/mock/server/worker.go index 51aedfa80..b8e1d724f 100644 --- a/mock/server/worker.go +++ b/mock/server/worker.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package server @@ -75,6 +73,14 @@ const ( RegisterTokenResp = `{ "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ3b3JrZXIiLCJpYXQiOjE1MTYyMzkwMjIsInRva2VuX3R5cGUiOiJXb3JrZXJSZWdpc3RlciJ9.gEzKaZB-sDd_gFCVF5uGo2mcf3iy9CrXDTLPZ6PTsTc" }` + + // QueueInfoResp represents a JSON return for an admin requesting a queue registration info. + // + //not actual credentials. + QueueInfoResp = `{ + "queue_public_key": "DXeyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ98zmko=", + "queue_address": "redis://redis:6000" + }` ) // getWorkers returns mock JSON for a http GET. @@ -199,3 +205,25 @@ func registerToken(c *gin.Context) { c.JSON(http.StatusCreated, body) } + +// getQueueCreds returns mock JSON for a http GET. +// +// Pass "" to Authorization header to test receiving a http 401 response. +func getQueueCreds(c *gin.Context) { + token := c.Request.Header.Get("Authorization") + // verify token if empty + if token == "" { + msg := "unable get queue credentials; invalid registration token" + + c.AbortWithStatusJSON(http.StatusUnauthorized, types.Error{Message: &msg}) + + return + } + + data := []byte(QueueInfoResp) + + var body library.QueueInfo + _ = json.Unmarshal(data, &body) + + c.JSON(http.StatusCreated, body) +} diff --git a/queue/context.go b/queue/context.go index e5bf48c78..405935476 100644 --- a/queue/context.go +++ b/queue/context.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package queue diff --git a/queue/context_test.go b/queue/context_test.go index 92218a1f4..fc2805452 100644 --- a/queue/context_test.go +++ b/queue/context_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package queue diff --git a/queue/doc.go b/queue/doc.go index 5c08b1b0d..c243d87ad 100644 --- a/queue/doc.go +++ b/queue/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package queue provides the ability for Vela to integrate // with different supported Queue backends. diff --git a/queue/flags.go b/queue/flags.go index 2e78b11da..6fc3a6f19 100644 --- a/queue/flags.go +++ b/queue/flags.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package queue diff --git a/queue/queue.go b/queue/queue.go index fca90b8a2..8288375e1 100644 --- a/queue/queue.go +++ b/queue/queue.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package queue diff --git a/queue/queue_test.go b/queue/queue_test.go index 61bcfd527..e6fe243c9 100644 --- a/queue/queue_test.go +++ b/queue/queue_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package queue @@ -30,10 +28,12 @@ func TestQueue_New(t *testing.T) { { failure: false, setup: &Setup{ - Driver: "redis", - Address: fmt.Sprintf("redis://%s", _redis.Addr()), - Routes: []string{"foo"}, - Cluster: false, + Driver: "redis", + Address: fmt.Sprintf("redis://%s", _redis.Addr()), + Routes: []string{"foo"}, + Cluster: false, + PrivateKey: "bOiFT7Y9e0jpOqaapTa3NzUkAve3VdRvyowgsY/vtlcK5L4RADOh9uTe1UVLdu3l/a0hvhiIkkLidUwVBhASWA==", + PublicKey: "CuS+EQAzofbk3tVFS3bt5f2tIb4YiJJC4nVMFQYQElg=", }, }, { diff --git a/queue/redis/doc.go b/queue/redis/doc.go index d75e65027..a95f8b4af 100644 --- a/queue/redis/doc.go +++ b/queue/redis/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package redis provides the ability for Vela to // integrate with a Redis server as a queue backend. diff --git a/queue/redis/driver.go b/queue/redis/driver.go index acec11514..5d5410bf9 100644 --- a/queue/redis/driver.go +++ b/queue/redis/driver.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package redis diff --git a/queue/redis/driver_test.go b/queue/redis/driver_test.go index 2e5d4bd96..e9736d326 100644 --- a/queue/redis/driver_test.go +++ b/queue/redis/driver_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package redis diff --git a/queue/redis/length.go b/queue/redis/length.go index 7ed4ecd8b..c4d7bb7c3 100644 --- a/queue/redis/length.go +++ b/queue/redis/length.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package redis diff --git a/queue/redis/length_test.go b/queue/redis/length_test.go index d9622594c..0049b3809 100644 --- a/queue/redis/length_test.go +++ b/queue/redis/length_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package redis diff --git a/queue/redis/opts.go b/queue/redis/opts.go index 5589eeb92..582994fea 100644 --- a/queue/redis/opts.go +++ b/queue/redis/opts.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package redis @@ -96,6 +94,10 @@ func WithPrivateKey(key string) ClientOpt { c.config.PrivateKey = new([64]byte) copy(c.config.PrivateKey[:], decoded) + if len(*c.config.PrivateKey) != 64 { + return errors.New("no valid queue signing private key provided") + } + if c.config.PrivateKey == nil { return errors.New("unable to copy decoded queue signing private key, copied key is nil") } @@ -132,8 +134,12 @@ func WithPublicKey(key string) ClientOpt { c.config.PublicKey = new([32]byte) copy(c.config.PublicKey[:], decoded) + if len(*c.config.PublicKey) != 32 { + return errors.New("no valid queue public key provided") + } + if c.config.PublicKey == nil { - return errors.New("unable to copy decoded queue signing public key, copied key is nil") + return errors.New("unable to copy decoded queue public key, copied key is nil") } if len(c.config.PublicKey) == 0 { diff --git a/queue/redis/opts_test.go b/queue/redis/opts_test.go index 3f99e3857..aa775c121 100644 --- a/queue/redis/opts_test.go +++ b/queue/redis/opts_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package redis diff --git a/queue/redis/ping.go b/queue/redis/ping.go new file mode 100644 index 000000000..57d97a901 --- /dev/null +++ b/queue/redis/ping.go @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: Apache-2.0 + +package redis + +import ( + "context" + "fmt" +) + +// Ping contacts the queue to test its connection. +func (c *client) Ping(ctx context.Context) error { + // send ping request to client + err := c.Redis.Ping(ctx).Err() + if err != nil { + c.Logger.Debugf("unable to ping Redis queue.") + return fmt.Errorf("unable to establish connection to Redis queue") + } + + return nil +} diff --git a/queue/redis/ping_test.go b/queue/redis/ping_test.go new file mode 100644 index 000000000..29f84ee26 --- /dev/null +++ b/queue/redis/ping_test.go @@ -0,0 +1,61 @@ +// SPDX-License-Identifier: Apache-2.0 + +package redis + +import ( + "context" + "fmt" + "github.com/alicebob/miniredis/v2" + "testing" + "time" +) + +func TestRedis_Ping_Good(t *testing.T) { + _redis, err := miniredis.Run() + if err != nil { + t.Errorf("unable to create miniredis instance: %v", err) + } + + defer _redis.Close() + + // setup redis mock + goodRedis, err := New( + WithAddress(fmt.Sprintf("redis://%s", _redis.Addr())), + WithChannels("foo"), + WithCluster(false), + WithTimeout(5*time.Second), + ) + if err != nil { + t.Errorf("unable to create queue service: %v", err) + } + + // run tests + err = goodRedis.Ping(context.Background()) + + if err != nil { + t.Errorf("Ping returned err: %v", err) + } +} + +func TestRedis_Ping_Bad(t *testing.T) { + _redis, err := miniredis.Run() + if err != nil { + t.Errorf("unable to create miniredis instance: %v", err) + } + + defer _redis.Close() + + // setup redis mock + badRedis, _ := New( + WithAddress(fmt.Sprintf("redis://%s", _redis.Addr())), + WithChannels("foo"), + WithCluster(false), + WithTimeout(5*time.Second), + ) + _redis.SetError("not aiv") + // run tests + err = badRedis.Ping(context.Background()) + if err == nil { + t.Errorf("Ping should have returned err: %v", err) + } +} diff --git a/queue/redis/pop.go b/queue/redis/pop.go index 65a043e8b..250d0c915 100644 --- a/queue/redis/pop.go +++ b/queue/redis/pop.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package redis @@ -46,11 +44,6 @@ func (c *client) Pop(ctx context.Context, routes []string) (*types.Item, error) return nil, err } - // this should already be validated on startup - if c.config.PublicKey == nil || len(*c.config.PublicKey) != 32 { - return nil, errors.New("no valid signing public key provided") - } - // extract signed item from pop results signed := []byte(result[1]) diff --git a/queue/redis/pop_test.go b/queue/redis/pop_test.go index 9490a4a31..eb05030bd 100644 --- a/queue/redis/pop_test.go +++ b/queue/redis/pop_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package redis diff --git a/queue/redis/push.go b/queue/redis/push.go index 66c8a386a..5bf4ead03 100644 --- a/queue/redis/push.go +++ b/queue/redis/push.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package redis @@ -27,11 +25,6 @@ func (c *client) Push(ctx context.Context, channel string, item []byte) error { var out []byte - // this should already be validated on startup - if c.config.PrivateKey == nil || len(*c.config.PrivateKey) != 64 { - return errors.New("no valid signing private key provided") - } - c.Logger.Tracef("signing item for queue %s", channel) // sign the item using the private key generated using sign diff --git a/queue/redis/push_test.go b/queue/redis/push_test.go index e61792ea9..5db7e1510 100644 --- a/queue/redis/push_test.go +++ b/queue/redis/push_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package redis diff --git a/queue/redis/redis.go b/queue/redis/redis.go index 4e4f68aea..643cb51e2 100644 --- a/queue/redis/redis.go +++ b/queue/redis/redis.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package redis diff --git a/queue/redis/redis_test.go b/queue/redis/redis_test.go index 6b9a47913..7994d18b4 100644 --- a/queue/redis/redis_test.go +++ b/queue/redis/redis_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package redis @@ -67,8 +65,8 @@ var ( Commit: String("48afb5bdc41ad69bf22588491333f7cf71135163"), Sender: String("OctoKitty"), Author: String("OctoKitty"), - Branch: String("master"), - Ref: String("refs/heads/master"), + Branch: String("main"), + Ref: String("refs/heads/main"), BaseRef: String(""), Host: String("example.company.com"), Runtime: String("docker"), @@ -82,7 +80,7 @@ var ( FullName: String("github/octocat"), Link: String("https://github.com/github/octocat"), Clone: String("https://github.com/github/octocat.git"), - Branch: String("master"), + Branch: String("main"), Timeout: Int64(60), Visibility: String("public"), Private: Bool(false), diff --git a/queue/redis/route.go b/queue/redis/route.go index 1da4b19db..a25a537c6 100644 --- a/queue/redis/route.go +++ b/queue/redis/route.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package redis diff --git a/queue/redis/route_test.go b/queue/redis/route_test.go index 23328df43..e849f085b 100644 --- a/queue/redis/route_test.go +++ b/queue/redis/route_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package redis diff --git a/queue/service.go b/queue/service.go index 307364b50..fd36a64bc 100644 --- a/queue/service.go +++ b/queue/service.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package queue @@ -32,6 +30,10 @@ type Service interface { // item to the specified route in the queue. Push(context.Context, string, []byte) error + // Ping defines a function that checks the + // connection to the queue. + Ping(context.Context) error + // Route defines a function that decides which // channel a build gets placed within the queue. Route(*pipeline.Worker) (string, error) diff --git a/queue/setup.go b/queue/setup.go index ed0f131c8..f240c9fe6 100644 --- a/queue/setup.go +++ b/queue/setup.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package queue @@ -92,6 +90,10 @@ func (s *Setup) Validate() error { return fmt.Errorf("no queue routes provided") } + if len(s.PublicKey) == 0 { + return fmt.Errorf("no queue public key was provided") + } + // setup is valid return nil } diff --git a/queue/setup_test.go b/queue/setup_test.go index 4b2e35ede..be22971c7 100644 --- a/queue/setup_test.go +++ b/queue/setup_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package queue @@ -23,10 +21,11 @@ func TestQueue_Setup_Redis(t *testing.T) { defer _redis.Close() _setup := &Setup{ - Driver: "redis", - Address: fmt.Sprintf("redis://%s", _redis.Addr()), - Routes: []string{"foo"}, - Cluster: false, + Driver: "redis", + Address: fmt.Sprintf("redis://%s", _redis.Addr()), + Routes: []string{"foo"}, + Cluster: false, + PublicKey: "CuS+EQAzofbk3tVFS3bt5f2tIb4YiJJC4nVMFQYQElg=", } _, err = _setup.Redis() @@ -63,19 +62,21 @@ func TestQueue_Setup_Validate(t *testing.T) { { failure: false, setup: &Setup{ - Driver: "redis", - Address: "redis://redis.example.com", - Routes: []string{"foo"}, - Cluster: false, + Driver: "redis", + Address: "redis://redis.example.com", + Routes: []string{"foo"}, + Cluster: false, + PublicKey: "CuS+EQAzofbk3tVFS3bt5f2tIb4YiJJC4nVMFQYQElg=", }, }, { failure: false, setup: &Setup{ - Driver: "kafka", - Address: "kafka://kafka.example.com", - Routes: []string{"foo"}, - Cluster: false, + Driver: "kafka", + Address: "kafka://kafka.example.com", + Routes: []string{"foo"}, + Cluster: false, + PublicKey: "CuS+EQAzofbk3tVFS3bt5f2tIb4YiJJC4nVMFQYQElg=", }, }, { diff --git a/random/random.go b/random/random.go index 0a5953ed0..5d621a8b4 100644 --- a/random/random.go +++ b/random/random.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package random diff --git a/router/admin.go b/router/admin.go index 96764617f..cc321346e 100644 --- a/router/admin.go +++ b/router/admin.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package router @@ -23,7 +21,8 @@ import ( // PUT /api/v1/admin/secret // PUT /api/v1/admin/service // PUT /api/v1/admin/step -// PUT /api/v1/admin/user. +// PUT /api/v1/admin/user +// POST /api/v1/admin/workers/:worker/register. func AdminHandlers(base *gin.RouterGroup) { // Admin endpoints _admin := base.Group("/admin", perm.MustPlatformAdmin()) @@ -59,6 +58,6 @@ func AdminHandlers(base *gin.RouterGroup) { _admin.PUT("/user", admin.UpdateUser) // Admin worker endpoint - _admin.POST("/workers/:worker/register-token", admin.RegisterToken) + _admin.POST("/workers/:worker/register", admin.RegisterToken) } // end of admin endpoints } diff --git a/router/build.go b/router/build.go index c8cc0d688..d912b6788 100644 --- a/router/build.go +++ b/router/build.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package router @@ -62,6 +60,7 @@ func BuildHandlers(base *gin.RouterGroup) { b.DELETE("/cancel", executors.Establish(), perm.MustWrite(), build.CancelBuild) b.GET("/logs", perm.MustRead(), log.ListLogsForBuild) b.GET("/token", perm.MustWorkerAuthToken(), build.GetBuildToken) + b.GET("/graph", perm.MustRead(), build.GetBuildGraph) b.GET("/executable", perm.MustBuildAccess(), build.GetBuildExecutable) // Service endpoints diff --git a/router/deployment.go b/router/deployment.go index eabbc48c6..4269da663 100644 --- a/router/deployment.go +++ b/router/deployment.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package router diff --git a/router/doc.go b/router/doc.go index 17052a2b5..403d7fe7c 100644 --- a/router/doc.go +++ b/router/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package router provides the routing engine for Vela // to serve and process API requests. diff --git a/router/hook.go b/router/hook.go index f5e1aa1db..503ad77c1 100644 --- a/router/hook.go +++ b/router/hook.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package router diff --git a/router/log.go b/router/log.go index 71c6674c8..6fbea4888 100644 --- a/router/log.go +++ b/router/log.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package router diff --git a/router/middleware/allowlist.go b/router/middleware/allowlist.go index 78fd9b2de..edfe5feb2 100644 --- a/router/middleware/allowlist.go +++ b/router/middleware/allowlist.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/allowlist_schedule.go b/router/middleware/allowlist_schedule.go index 8872d0361..d22a7aa20 100644 --- a/router/middleware/allowlist_schedule.go +++ b/router/middleware/allowlist_schedule.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/allowlist_schedule_test.go b/router/middleware/allowlist_schedule_test.go index a9b03ae28..1461b8719 100644 --- a/router/middleware/allowlist_schedule_test.go +++ b/router/middleware/allowlist_schedule_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/allowlist_test.go b/router/middleware/allowlist_test.go index abf54f273..2bc59623d 100644 --- a/router/middleware/allowlist_test.go +++ b/router/middleware/allowlist_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/auth/auth.go b/router/middleware/auth/auth.go index 968ceabfb..09e9319c2 100644 --- a/router/middleware/auth/auth.go +++ b/router/middleware/auth/auth.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package auth diff --git a/router/middleware/auth/auth_test.go b/router/middleware/auth/auth_test.go index 850309c04..7a7993a98 100644 --- a/router/middleware/auth/auth_test.go +++ b/router/middleware/auth/auth_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package auth diff --git a/router/middleware/auth/doc.go b/router/middleware/auth/doc.go index e50ae3a1a..870360cce 100644 --- a/router/middleware/auth/doc.go +++ b/router/middleware/auth/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package token provides the ability for inserting // Vela token resources into or extracting Vela token diff --git a/router/middleware/build/build.go b/router/middleware/build/build.go index 3b0b4f0d8..70eba1b9a 100644 --- a/router/middleware/build/build.go +++ b/router/middleware/build/build.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/router/middleware/build/build_test.go b/router/middleware/build/build_test.go index 40e52f52f..d3e82a24e 100644 --- a/router/middleware/build/build_test.go +++ b/router/middleware/build/build_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build @@ -90,8 +88,8 @@ func TestBuild_Establish(t *testing.T) { } defer func() { - db.DeleteBuild(context.TODO(), want) - db.DeleteRepo(context.TODO(), r) + _ = db.DeleteBuild(context.TODO(), want) + _ = db.DeleteRepo(context.TODO(), r) db.Close() }() @@ -173,7 +171,7 @@ func TestBuild_Establish_NoBuildParameter(t *testing.T) { } defer func() { - db.DeleteRepo(context.TODO(), r) + _ = db.DeleteRepo(context.TODO(), r) db.Close() }() @@ -221,7 +219,7 @@ func TestBuild_Establish_InvalidBuildParameter(t *testing.T) { } defer func() { - db.DeleteRepo(context.TODO(), r) + _ = db.DeleteRepo(context.TODO(), r) db.Close() }() @@ -269,7 +267,7 @@ func TestBuild_Establish_NoBuild(t *testing.T) { } defer func() { - db.DeleteRepo(context.TODO(), r) + _ = db.DeleteRepo(context.TODO(), r) db.Close() }() diff --git a/router/middleware/build/context.go b/router/middleware/build/context.go index b4f753c5e..99f358add 100644 --- a/router/middleware/build/context.go +++ b/router/middleware/build/context.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/router/middleware/build/context_test.go b/router/middleware/build/context_test.go index 73aa0a319..43dd8fe5f 100644 --- a/router/middleware/build/context_test.go +++ b/router/middleware/build/context_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package build diff --git a/router/middleware/build/doc.go b/router/middleware/build/doc.go index bbe90cf70..4ae0b0851 100644 --- a/router/middleware/build/doc.go +++ b/router/middleware/build/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package build provides the ability for inserting // Vela build resources into or extracting Vela build diff --git a/router/middleware/claims/claims.go b/router/middleware/claims/claims.go index 5ba2784f6..a81a456fe 100644 --- a/router/middleware/claims/claims.go +++ b/router/middleware/claims/claims.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package claims diff --git a/router/middleware/claims/claims_test.go b/router/middleware/claims/claims_test.go index c98f191fa..2eb89b3bd 100644 --- a/router/middleware/claims/claims_test.go +++ b/router/middleware/claims/claims_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package claims @@ -275,7 +273,7 @@ func TestClaims_Establish_BadToken(t *testing.T) { } defer func() { - db.DeleteUser(_context.TODO(), u) + _ = db.DeleteUser(_context.TODO(), u) db.Close() }() diff --git a/router/middleware/claims/context.go b/router/middleware/claims/context.go index 5e51b2b4f..da800172e 100644 --- a/router/middleware/claims/context.go +++ b/router/middleware/claims/context.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package claims diff --git a/router/middleware/claims/context_test.go b/router/middleware/claims/context_test.go index b29fd739c..55bbf9241 100644 --- a/router/middleware/claims/context_test.go +++ b/router/middleware/claims/context_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package claims diff --git a/router/middleware/claims/doc.go b/router/middleware/claims/doc.go index f91ec309c..72d016e2a 100644 --- a/router/middleware/claims/doc.go +++ b/router/middleware/claims/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package claims provides the ability for inserting // token claims resources into or extracting token claims diff --git a/router/middleware/compiler.go b/router/middleware/compiler.go index bb552ac51..503040192 100644 --- a/router/middleware/compiler.go +++ b/router/middleware/compiler.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/compiler_test.go b/router/middleware/compiler_test.go index cb60685d2..8a64f5176 100644 --- a/router/middleware/compiler_test.go +++ b/router/middleware/compiler_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/database.go b/router/middleware/database.go index fbbf91eea..38755fa89 100644 --- a/router/middleware/database.go +++ b/router/middleware/database.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/database_test.go b/router/middleware/database_test.go index b0ba77b04..8b7cca49c 100644 --- a/router/middleware/database_test.go +++ b/router/middleware/database_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/default_build_limit.go b/router/middleware/default_build_limit.go index c4d2c1d65..a8d245635 100644 --- a/router/middleware/default_build_limit.go +++ b/router/middleware/default_build_limit.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/default_build_limit_test.go b/router/middleware/default_build_limit_test.go index a0ed48c2e..6ee0f1a4f 100644 --- a/router/middleware/default_build_limit_test.go +++ b/router/middleware/default_build_limit_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/default_repo_events.go b/router/middleware/default_repo_events.go index 65e5ed5b0..1b869c5b2 100644 --- a/router/middleware/default_repo_events.go +++ b/router/middleware/default_repo_events.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/default_repo_events_test.go b/router/middleware/default_repo_events_test.go index 83cfc1703..b1b7e187f 100644 --- a/router/middleware/default_repo_events_test.go +++ b/router/middleware/default_repo_events_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/default_timeout.go b/router/middleware/default_timeout.go index ba6c620e7..49c98de32 100644 --- a/router/middleware/default_timeout.go +++ b/router/middleware/default_timeout.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/default_timeout_test.go b/router/middleware/default_timeout_test.go index 2c80a9dc2..07df8fc24 100644 --- a/router/middleware/default_timeout_test.go +++ b/router/middleware/default_timeout_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/doc.go b/router/middleware/doc.go index 36ab883b0..5705c19be 100644 --- a/router/middleware/doc.go +++ b/router/middleware/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package middleware provides the ability for injecting Vela // resources into the middleware chain for the API. diff --git a/router/middleware/executors/context.go b/router/middleware/executors/context.go index 2f2a28d6a..d040fa73a 100644 --- a/router/middleware/executors/context.go +++ b/router/middleware/executors/context.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package executors diff --git a/router/middleware/executors/context_test.go b/router/middleware/executors/context_test.go index 875c101ab..3cabdb687 100644 --- a/router/middleware/executors/context_test.go +++ b/router/middleware/executors/context_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package executors diff --git a/router/middleware/executors/doc.go b/router/middleware/executors/doc.go index 5a75b0cf3..8602a39a2 100644 --- a/router/middleware/executors/doc.go +++ b/router/middleware/executors/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package executors provides the ability for inserting // Vela executors resources into or extracting Vela build diff --git a/router/middleware/executors/executor_test.go b/router/middleware/executors/executor_test.go index bebed311e..66006b6e2 100644 --- a/router/middleware/executors/executor_test.go +++ b/router/middleware/executors/executor_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package executors diff --git a/router/middleware/executors/executors.go b/router/middleware/executors/executors.go index 9bd779223..705bac0d4 100644 --- a/router/middleware/executors/executors.go +++ b/router/middleware/executors/executors.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package executors diff --git a/router/middleware/header.go b/router/middleware/header.go index 39ae9b68c..f04180bfd 100644 --- a/router/middleware/header.go +++ b/router/middleware/header.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/header_test.go b/router/middleware/header_test.go index 86f79d41a..ab13f992a 100644 --- a/router/middleware/header_test.go +++ b/router/middleware/header_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/logger.go b/router/middleware/logger.go index a6cb7f835..57bc11253 100644 --- a/router/middleware/logger.go +++ b/router/middleware/logger.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware @@ -20,6 +18,20 @@ import ( "github.com/sirupsen/logrus" ) +// This file, in part, reproduces portions of +// https://github.com/elastic/ecs-logging-go-logrus/blob/v1.0.0/formatter.go +// to handle our custom fields in Format(). + +// ECSFormatter holds ECS parameter information for logging. +type ECSFormatter struct { + // DataKey allows users to put all the log entry parameters into a + // nested dictionary at a given key. + // + // DataKey is ignored for well-defined fields, such as "error", + // which will instead be stored under the appropriate ECS fields. + DataKey string +} + // Logger returns a gin.HandlerFunc (middleware) that logs requests using logrus. // // Requests with errors are logged using logrus.Error(). @@ -98,7 +110,7 @@ func Logger(logger *logrus.Logger, timeFormat string) gin.HandlerFunc { // Append error field if this is an erroneous request. entry.Error(c.Errors.String()) } else { - entry.Info() + entry.Infof("%v %v %v %s %s", fields["status"], fields["latency"], fields["ip"], fields["method"], fields["path"]) } } } @@ -114,3 +126,63 @@ func sanitize(body interface{}) interface{} { return body } + +// Format formats logrus.Entry as ECS-compliant JSON, +// mapping our custom fields to ECS fields. +func (f *ECSFormatter) Format(e *logrus.Entry) ([]byte, error) { + datahint := len(e.Data) + if f.DataKey != "" { + datahint = 2 + } + + data := make(logrus.Fields, datahint) + if len(e.Data) > 0 { + extraData := data + if f.DataKey != "" { + extraData = make(logrus.Fields, len(e.Data)) + } + + for k, v := range e.Data { + switch k { + case "ip": + data["client.ip"] = v + case "latency": + data["event.duration"] = v + case "method": + data["http.request.method"] = v + case "path": + data["url.path"] = v + case "status": + data["http.response.status_code"] = v + case "user-agent": + data["user_agent.name"] = v + case "version": + data["user_agent.version"] = v + default: + extraData[k] = v + } + } + + if f.DataKey != "" && len(extraData) > 0 { + data[f.DataKey] = extraData + } + } + + // ecsVersion holds the version of ECS with which the formatter is compatible. + data["ecs.version"] = "1.6.0" + ecopy := *e + ecopy.Data = data + e = &ecopy + + ecsFieldMap := logrus.FieldMap{ + logrus.FieldKeyTime: "@timestamp", + logrus.FieldKeyMsg: "message", + logrus.FieldKeyLevel: "log.level", + } + + jf := logrus.JSONFormatter{ + TimestampFormat: "2006-01-02T15:04:05.000Z0700", + FieldMap: ecsFieldMap, + } + return jf.Format(e) +} diff --git a/router/middleware/logger_test.go b/router/middleware/logger_test.go index 5204763e7..4a699520a 100644 --- a/router/middleware/logger_test.go +++ b/router/middleware/logger_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware @@ -67,7 +65,6 @@ func TestMiddleware_Logger(t *testing.T) { payload, _ := json.Marshal(`{"foo": "bar"}`) wantLevel := logrus.InfoLevel - wantMessage := "" logger, hook := test.NewNullLogger() defer hook.Reset() @@ -106,8 +103,16 @@ func TestMiddleware_Logger(t *testing.T) { t.Errorf("Logger Level is %v, want %v", gotLevel, wantLevel) } - if !reflect.DeepEqual(gotMessage, wantMessage) { - t.Errorf("Logger Message is %v, want %v", gotMessage, wantMessage) + if gotMessage == "" { + t.Errorf("Logger Message is %v, want non-empty string", gotMessage) + } + + if strings.Contains(gotMessage, "GET") { + t.Errorf("Logger Message is %v, want message to contain GET", gotMessage) + } + + if !strings.Contains(gotMessage, "POST") { + t.Errorf("Logger Message is %v, message shouldn't contain POST", gotMessage) } } @@ -217,3 +222,48 @@ func TestMiddleware_Logger_Sanitize(t *testing.T) { } } } + +func TestMiddleware_Format(t *testing.T) { + + wantLabels := "labels.vela" + + // setup data, fields, and logger + formatter := &ECSFormatter{ + DataKey: wantLabels, + } + + fields := logrus.Fields{ + "ip": "123.4.5.6", + "method": http.MethodGet, + "path": "/foobar", + "latency": 0, + "status": http.StatusOK, + "user-agent": "foobar", + "version": "v1.0.0", + "org": "foo", + } + + logger := logrus.NewEntry(logrus.StandardLogger()) + entry := logger.WithFields(fields) + + got, err := formatter.Format(entry) + + // run test + + if err != nil { + t.Errorf("Format returned err: %v", err) + } + + if got == nil { + t.Errorf("Format returned nothing, want a log") + } + + if !strings.Contains(string(got), "GET") { + t.Errorf("Format returned %v, want to contain GET", string(got)) + } + + if !strings.Contains(string(got), "/foobar") { + t.Errorf("Format returned %v, want to contain /foobar", string(got)) + } + +} diff --git a/router/middleware/max_build_limit.go b/router/middleware/max_build_limit.go index 197054d19..3bfd08a42 100644 --- a/router/middleware/max_build_limit.go +++ b/router/middleware/max_build_limit.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/max_build_limit_test.go b/router/middleware/max_build_limit_test.go index 00e3516c9..75c2facaf 100644 --- a/router/middleware/max_build_limit_test.go +++ b/router/middleware/max_build_limit_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/metadata.go b/router/middleware/metadata.go index bbea0b85b..67ed62157 100644 --- a/router/middleware/metadata.go +++ b/router/middleware/metadata.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/metadata_test.go b/router/middleware/metadata_test.go index 7d2644379..0baaee36a 100644 --- a/router/middleware/metadata_test.go +++ b/router/middleware/metadata_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/org/context.go b/router/middleware/org/context.go index ebcee9c83..03f913237 100644 --- a/router/middleware/org/context.go +++ b/router/middleware/org/context.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package org diff --git a/router/middleware/org/context_test.go b/router/middleware/org/context_test.go index 9a6b0f69d..8d5ff76f1 100644 --- a/router/middleware/org/context_test.go +++ b/router/middleware/org/context_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package org diff --git a/router/middleware/org/doc.go b/router/middleware/org/doc.go index 32c3d410a..7e34254ae 100644 --- a/router/middleware/org/doc.go +++ b/router/middleware/org/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package org provides the ability for inserting // Vela org resources into or extracting Vela org diff --git a/router/middleware/org/org.go b/router/middleware/org/org.go index 153807e4b..b53c223d8 100644 --- a/router/middleware/org/org.go +++ b/router/middleware/org/org.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package org diff --git a/router/middleware/org/org_test.go b/router/middleware/org/org_test.go index 2a0396ca4..fe56f15d9 100644 --- a/router/middleware/org/org_test.go +++ b/router/middleware/org/org_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package org @@ -62,7 +60,7 @@ func TestOrg_Establish(t *testing.T) { } defer func() { - db.DeleteRepo(context.TODO(), r) + _ = db.DeleteRepo(context.TODO(), r) db.Close() }() diff --git a/router/middleware/payload.go b/router/middleware/payload.go index c2241fa9f..fff9b2263 100644 --- a/router/middleware/payload.go +++ b/router/middleware/payload.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/payload_test.go b/router/middleware/payload_test.go index 235cec5b9..6b9bc1805 100644 --- a/router/middleware/payload_test.go +++ b/router/middleware/payload_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/perm/doc.go b/router/middleware/perm/doc.go index 4cb5ad472..a0aca85cf 100644 --- a/router/middleware/perm/doc.go +++ b/router/middleware/perm/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package perm provides the ability for validating the access // control to Vela resources in the middleware chain for the API. diff --git a/router/middleware/perm/perm.go b/router/middleware/perm/perm.go index 3e02e33be..5bc9291e3 100644 --- a/router/middleware/perm/perm.go +++ b/router/middleware/perm/perm.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package perm @@ -188,6 +186,7 @@ func MustSecretAdmin() gin.HandlerFunc { n := util.PathParameter(c, "name") s := util.PathParameter(c, "secret") m := c.Request.Method + ctx := c.Request.Context() // create log fields from API metadata fields := logrus.Fields{ @@ -262,7 +261,7 @@ func MustSecretAdmin() gin.HandlerFunc { case constants.SecretOrg: logger.Debugf("verifying user %s has 'admin' permissions for org %s", u.GetName(), o) - perm, err := scm.FromContext(c).OrgAccess(u, o) + perm, err := scm.FromContext(c).OrgAccess(ctx, u, o) if err != nil { logger.Errorf("unable to get user %s access level for org %s: %v", u.GetName(), o, err) } @@ -277,7 +276,7 @@ func MustSecretAdmin() gin.HandlerFunc { case constants.SecretRepo: logger.Debugf("verifying user %s has 'admin' permissions for repo %s/%s", u.GetName(), o, n) - perm, err := scm.FromContext(c).RepoAccess(u, u.GetToken(), o, n) + perm, err := scm.FromContext(c).RepoAccess(ctx, u, u.GetToken(), o, n) if err != nil { logger.Errorf("unable to get user %s access level for repo %s/%s: %v", u.GetName(), o, n, err) } @@ -303,7 +302,7 @@ func MustSecretAdmin() gin.HandlerFunc { logger.Debugf("gathering teams user %s is a member of in the org %s", u.GetName(), o) - teams, err := scm.FromContext(c).ListUsersTeamsForOrg(u, o) + teams, err := scm.FromContext(c).ListUsersTeamsForOrg(ctx, u, o) if err != nil { logger.Errorf("unable to get users %s teams for org %s: %v", u.GetName(), o, err) } @@ -318,7 +317,7 @@ func MustSecretAdmin() gin.HandlerFunc { } else { logger.Debugf("verifying user %s has 'admin' permissions for team %s/%s", u.GetName(), o, n) - perm, err := scm.FromContext(c).TeamAccess(u, o, n) + perm, err := scm.FromContext(c).TeamAccess(ctx, u, o, n) if err != nil { logger.Errorf("unable to get user %s access level for team %s/%s: %v", u.GetName(), o, n, err) } @@ -366,7 +365,7 @@ func MustAdmin() gin.HandlerFunc { } // query source to determine requesters permissions for the repo using the requester's token - perm, err := scm.FromContext(c).RepoAccess(u, u.GetToken(), r.GetOrg(), r.GetName()) + perm, err := scm.FromContext(c).RepoAccess(ctx, u, u.GetToken(), r.GetOrg(), r.GetName()) if err != nil { // requester may not have permissions to use the Github API endpoint (requires read access) // try again using the repo owner token @@ -381,7 +380,7 @@ func MustAdmin() gin.HandlerFunc { return } - perm, err = scm.FromContext(c).RepoAccess(u, ro.GetToken(), r.GetOrg(), r.GetName()) + perm, err = scm.FromContext(c).RepoAccess(ctx, u, ro.GetToken(), r.GetOrg(), r.GetName()) if err != nil { logger.Errorf("unable to get user %s access level for repo %s", u.GetName(), r.GetFullName()) } @@ -425,7 +424,7 @@ func MustWrite() gin.HandlerFunc { } // query source to determine requesters permissions for the repo using the requester's token - perm, err := scm.FromContext(c).RepoAccess(u, u.GetToken(), r.GetOrg(), r.GetName()) + perm, err := scm.FromContext(c).RepoAccess(ctx, u, u.GetToken(), r.GetOrg(), r.GetName()) if err != nil { // requester may not have permissions to use the Github API endpoint (requires read access) // try again using the repo owner token @@ -440,7 +439,7 @@ func MustWrite() gin.HandlerFunc { return } - perm, err = scm.FromContext(c).RepoAccess(u, ro.GetToken(), r.GetOrg(), r.GetName()) + perm, err = scm.FromContext(c).RepoAccess(ctx, u, ro.GetToken(), r.GetOrg(), r.GetName()) if err != nil { logger.Errorf("unable to get user %s access level for repo %s", u.GetName(), r.GetFullName()) } @@ -508,7 +507,7 @@ func MustRead() gin.HandlerFunc { } // query source to determine requesters permissions for the repo using the requester's token - perm, err := scm.FromContext(c).RepoAccess(u, u.GetToken(), r.GetOrg(), r.GetName()) + perm, err := scm.FromContext(c).RepoAccess(ctx, u, u.GetToken(), r.GetOrg(), r.GetName()) if err != nil { // requester may not have permissions to use the Github API endpoint (requires read access) // try again using the repo owner token @@ -523,7 +522,7 @@ func MustRead() gin.HandlerFunc { return } - perm, err = scm.FromContext(c).RepoAccess(u, ro.GetToken(), r.GetOrg(), r.GetName()) + perm, err = scm.FromContext(c).RepoAccess(ctx, u, ro.GetToken(), r.GetOrg(), r.GetName()) if err != nil { logger.Errorf("unable to get user %s access level for repo %s", u.GetName(), r.GetFullName()) } diff --git a/router/middleware/perm/perm_test.go b/router/middleware/perm/perm_test.go index aa5ed7543..c2c9642e4 100644 --- a/router/middleware/perm/perm_test.go +++ b/router/middleware/perm/perm_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package perm @@ -60,7 +58,7 @@ func TestPerm_MustPlatformAdmin(t *testing.T) { } defer func() { - db.DeleteUser(_context.TODO(), u) + _ = db.DeleteUser(_context.TODO(), u) db.Close() }() @@ -148,7 +146,7 @@ func TestPerm_MustPlatformAdmin_NotAdmin(t *testing.T) { } defer func() { - db.DeleteUser(_context.TODO(), u) + _ = db.DeleteUser(_context.TODO(), u) db.Close() }() @@ -275,7 +273,7 @@ func TestPerm_MustWorkerRegisterToken_PlatAdmin(t *testing.T) { } defer func() { - db.DeleteUser(_context.TODO(), u) + _ = db.DeleteUser(_context.TODO(), u) db.Close() }() @@ -445,8 +443,8 @@ func TestPerm_MustBuildAccess(t *testing.T) { ctx := _context.TODO() defer func() { - db.DeleteBuild(ctx, b) - db.DeleteRepo(_context.TODO(), r) + _ = db.DeleteBuild(ctx, b) + _ = db.DeleteRepo(_context.TODO(), r) db.Close() }() @@ -536,9 +534,9 @@ func TestPerm_MustBuildAccess_PlatAdmin(t *testing.T) { } defer func() { - db.DeleteBuild(ctx, b) - db.DeleteRepo(_context.TODO(), r) - db.DeleteUser(_context.TODO(), u) + _ = db.DeleteBuild(ctx, b) + _ = db.DeleteRepo(_context.TODO(), r) + _ = db.DeleteUser(_context.TODO(), u) db.Close() }() @@ -624,8 +622,8 @@ func TestPerm_MustBuildToken_WrongBuild(t *testing.T) { } defer func() { - db.DeleteBuild(ctx, b) - db.DeleteRepo(_context.TODO(), r) + _ = db.DeleteBuild(ctx, b) + _ = db.DeleteRepo(_context.TODO(), r) db.Close() }() @@ -710,8 +708,8 @@ func TestPerm_MustSecretAdmin_BuildToken_Repo(t *testing.T) { } defer func() { - db.DeleteBuild(ctx, b) - db.DeleteRepo(_context.TODO(), r) + _ = db.DeleteBuild(ctx, b) + _ = db.DeleteRepo(_context.TODO(), r) db.Close() }() @@ -793,8 +791,8 @@ func TestPerm_MustSecretAdmin_BuildToken_Org(t *testing.T) { } defer func() { - db.DeleteBuild(ctx, b) - db.DeleteRepo(_context.TODO(), r) + _ = db.DeleteBuild(ctx, b) + _ = db.DeleteRepo(_context.TODO(), r) db.Close() }() @@ -876,8 +874,8 @@ func TestPerm_MustSecretAdmin_BuildToken_Shared(t *testing.T) { } defer func() { - db.DeleteBuild(ctx, b) - db.DeleteRepo(_context.TODO(), r) + _ = db.DeleteBuild(ctx, b) + _ = db.DeleteRepo(_context.TODO(), r) db.Close() }() @@ -957,8 +955,8 @@ func TestPerm_MustAdmin(t *testing.T) { } defer func() { - db.DeleteRepo(_context.TODO(), r) - db.DeleteUser(_context.TODO(), u) + _ = db.DeleteRepo(_context.TODO(), r) + _ = db.DeleteUser(_context.TODO(), u) db.Close() }() @@ -1055,8 +1053,8 @@ func TestPerm_MustAdmin_PlatAdmin(t *testing.T) { } defer func() { - db.DeleteRepo(_context.TODO(), r) - db.DeleteUser(_context.TODO(), u) + _ = db.DeleteRepo(_context.TODO(), r) + _ = db.DeleteUser(_context.TODO(), u) db.Close() }() @@ -1153,8 +1151,8 @@ func TestPerm_MustAdmin_NotAdmin(t *testing.T) { } defer func() { - db.DeleteRepo(_context.TODO(), r) - db.DeleteUser(_context.TODO(), u) + _ = db.DeleteRepo(_context.TODO(), r) + _ = db.DeleteUser(_context.TODO(), u) db.Close() }() @@ -1251,8 +1249,8 @@ func TestPerm_MustWrite(t *testing.T) { } defer func() { - db.DeleteRepo(_context.TODO(), r) - db.DeleteUser(_context.TODO(), u) + _ = db.DeleteRepo(_context.TODO(), r) + _ = db.DeleteUser(_context.TODO(), u) db.Close() }() @@ -1349,8 +1347,8 @@ func TestPerm_MustWrite_PlatAdmin(t *testing.T) { } defer func() { - db.DeleteRepo(_context.TODO(), r) - db.DeleteUser(_context.TODO(), u) + _ = db.DeleteRepo(_context.TODO(), r) + _ = db.DeleteUser(_context.TODO(), u) db.Close() }() @@ -1447,8 +1445,8 @@ func TestPerm_MustWrite_RepoAdmin(t *testing.T) { } defer func() { - db.DeleteRepo(_context.TODO(), r) - db.DeleteUser(_context.TODO(), u) + _ = db.DeleteRepo(_context.TODO(), r) + _ = db.DeleteUser(_context.TODO(), u) db.Close() }() @@ -1545,8 +1543,8 @@ func TestPerm_MustWrite_NotWrite(t *testing.T) { } defer func() { - db.DeleteRepo(_context.TODO(), r) - db.DeleteUser(_context.TODO(), u) + _ = db.DeleteRepo(_context.TODO(), r) + _ = db.DeleteUser(_context.TODO(), u) db.Close() }() @@ -1643,8 +1641,8 @@ func TestPerm_MustRead(t *testing.T) { } defer func() { - db.DeleteRepo(_context.TODO(), r) - db.DeleteUser(_context.TODO(), u) + _ = db.DeleteRepo(_context.TODO(), r) + _ = db.DeleteUser(_context.TODO(), u) db.Close() }() @@ -1741,8 +1739,8 @@ func TestPerm_MustRead_PlatAdmin(t *testing.T) { } defer func() { - db.DeleteRepo(_context.TODO(), r) - db.DeleteUser(_context.TODO(), u) + _ = db.DeleteRepo(_context.TODO(), r) + _ = db.DeleteUser(_context.TODO(), u) db.Close() }() @@ -1841,8 +1839,8 @@ func TestPerm_MustRead_WorkerBuildToken(t *testing.T) { } defer func() { - db.DeleteBuild(ctx, b) - db.DeleteRepo(_context.TODO(), r) + _ = db.DeleteBuild(ctx, b) + _ = db.DeleteRepo(_context.TODO(), r) db.Close() }() @@ -1925,8 +1923,8 @@ func TestPerm_MustRead_RepoAdmin(t *testing.T) { } defer func() { - db.DeleteRepo(_context.TODO(), r) - db.DeleteUser(_context.TODO(), u) + _ = db.DeleteRepo(_context.TODO(), r) + _ = db.DeleteUser(_context.TODO(), u) db.Close() }() @@ -2023,8 +2021,8 @@ func TestPerm_MustRead_RepoWrite(t *testing.T) { } defer func() { - db.DeleteRepo(_context.TODO(), r) - db.DeleteUser(_context.TODO(), u) + _ = db.DeleteRepo(_context.TODO(), r) + _ = db.DeleteUser(_context.TODO(), u) db.Close() }() @@ -2121,8 +2119,8 @@ func TestPerm_MustRead_RepoPublic(t *testing.T) { } defer func() { - db.DeleteRepo(_context.TODO(), r) - db.DeleteUser(_context.TODO(), u) + _ = db.DeleteRepo(_context.TODO(), r) + _ = db.DeleteUser(_context.TODO(), u) db.Close() }() @@ -2219,8 +2217,8 @@ func TestPerm_MustRead_NotRead(t *testing.T) { } defer func() { - db.DeleteRepo(_context.TODO(), r) - db.DeleteUser(_context.TODO(), u) + _ = db.DeleteRepo(_context.TODO(), r) + _ = db.DeleteUser(_context.TODO(), u) db.Close() }() diff --git a/router/middleware/pipeline/context.go b/router/middleware/pipeline/context.go index 6aab4037e..d5218c3d7 100644 --- a/router/middleware/pipeline/context.go +++ b/router/middleware/pipeline/context.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/router/middleware/pipeline/context_test.go b/router/middleware/pipeline/context_test.go index ddc5b8bbd..d9379d943 100644 --- a/router/middleware/pipeline/context_test.go +++ b/router/middleware/pipeline/context_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/router/middleware/pipeline/doc.go b/router/middleware/pipeline/doc.go index e6f19504d..9c4c9bb14 100644 --- a/router/middleware/pipeline/doc.go +++ b/router/middleware/pipeline/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package pipeline provides the ability for inserting // Vela pipeline resources into or extracting Vela pipeline diff --git a/router/middleware/pipeline/pipeline.go b/router/middleware/pipeline/pipeline.go index b3f2e57af..61f308854 100644 --- a/router/middleware/pipeline/pipeline.go +++ b/router/middleware/pipeline/pipeline.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline @@ -66,7 +64,7 @@ func Establish() gin.HandlerFunc { pipeline, err := database.FromContext(c).GetPipelineForRepo(ctx, p, r) if err != nil { // assume the pipeline doesn't exist in the database yet (before pipeline support was added) // send API call to capture the pipeline configuration file - config, err := scm.FromContext(c).ConfigBackoff(u, r, p) + config, err := scm.FromContext(c).ConfigBackoff(ctx, u, r, p) if err != nil { retErr := fmt.Errorf("unable to get pipeline configuration for %s: %w", entry, err) diff --git a/router/middleware/pipeline/pipeline_test.go b/router/middleware/pipeline/pipeline_test.go index aaff5fb1a..545edb338 100644 --- a/router/middleware/pipeline/pipeline_test.go +++ b/router/middleware/pipeline/pipeline_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline @@ -83,7 +81,7 @@ func TestPipeline_Establish(t *testing.T) { want.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135163") want.SetFlavor("") want.SetPlatform("") - want.SetRef("refs/heads/master") + want.SetRef("refs/heads/main") want.SetType("yaml") want.SetVersion("1") want.SetExternalSecrets(false) @@ -103,8 +101,8 @@ func TestPipeline_Establish(t *testing.T) { } defer func() { - db.DeletePipeline(context.TODO(), want) - db.DeleteRepo(context.TODO(), r) + _ = db.DeletePipeline(context.TODO(), want) + _ = db.DeleteRepo(context.TODO(), r) db.Close() }() @@ -186,7 +184,7 @@ func TestPipeline_Establish_NoPipelineParameter(t *testing.T) { } defer func() { - db.DeleteRepo(context.TODO(), r) + _ = db.DeleteRepo(context.TODO(), r) db.Close() }() @@ -289,8 +287,8 @@ func TestPipeline_Establish_NoPipeline(t *testing.T) { } defer func() { - db.DeleteRepo(context.TODO(), r) - db.DeleteUser(context.TODO(), u) + _ = db.DeleteRepo(context.TODO(), r) + _ = db.DeleteUser(context.TODO(), u) db.Close() }() diff --git a/router/middleware/pipeline/testdata/yml.json b/router/middleware/pipeline/testdata/yml.json index 458ecaa44..fbcb8e6dd 100644 --- a/router/middleware/pipeline/testdata/yml.json +++ b/router/middleware/pipeline/testdata/yml.json @@ -8,11 +8,11 @@ "sha": "3d21ec53a331a6f037a91c368710b99387d012c1", "url": "https://api.github.com/repos/octokit/octokit.rb/contents/.vela.yml", "git_url": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/3d21ec53a331a6f037a91c368710b99387d012c1", - "html_url": "https://github.com/octokit/octokit.rb/blob/master/.vela.yml", - "download_url": "https://raw.githubusercontent.com/octokit/octokit.rb/master/.vela.yml", + "html_url": "https://github.com/octokit/octokit.rb/blob/main/.vela.yml", + "download_url": "https://raw.githubusercontent.com/octokit/octokit.rb/main/.vela.yml", "_links": { "git": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/3d21ec53a331a6f037a91c368710b99387d012c1", "self": "https://api.github.com/repos/octokit/octokit.rb/contents/.vela.yml", - "html": "https://github.com/octokit/octokit.rb/blob/master/.vela.yml" + "html": "https://github.com/octokit/octokit.rb/blob/main/.vela.yml" } } \ No newline at end of file diff --git a/router/middleware/queue.go b/router/middleware/queue.go index bce53650a..0ebbe72ca 100644 --- a/router/middleware/queue.go +++ b/router/middleware/queue.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/queue_test.go b/router/middleware/queue_test.go index 80c22ce07..2f6a05fa6 100644 --- a/router/middleware/queue_test.go +++ b/router/middleware/queue_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/repo/context.go b/router/middleware/repo/context.go index 00c72c321..620aaf0c8 100644 --- a/router/middleware/repo/context.go +++ b/router/middleware/repo/context.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo diff --git a/router/middleware/repo/context_test.go b/router/middleware/repo/context_test.go index 90dbef902..ebcadf01e 100644 --- a/router/middleware/repo/context_test.go +++ b/router/middleware/repo/context_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo diff --git a/router/middleware/repo/doc.go b/router/middleware/repo/doc.go index 028ebe70b..40710054a 100644 --- a/router/middleware/repo/doc.go +++ b/router/middleware/repo/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package repo provides the ability for inserting // Vela repo resources into or extracting Vela repo diff --git a/router/middleware/repo/repo.go b/router/middleware/repo/repo.go index fcc898f9e..748a17bb7 100644 --- a/router/middleware/repo/repo.go +++ b/router/middleware/repo/repo.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo diff --git a/router/middleware/repo/repo_test.go b/router/middleware/repo/repo_test.go index 861537bcc..0f0ac4082 100644 --- a/router/middleware/repo/repo_test.go +++ b/router/middleware/repo/repo_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package repo @@ -69,7 +67,7 @@ func TestRepo_Establish(t *testing.T) { } defer func() { - db.DeleteRepo(context.TODO(), want) + _ = db.DeleteRepo(context.TODO(), want) db.Close() }() diff --git a/router/middleware/schedule/context.go b/router/middleware/schedule/context.go index 7ce62871c..258c243ca 100644 --- a/router/middleware/schedule/context.go +++ b/router/middleware/schedule/context.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/router/middleware/schedule/context_test.go b/router/middleware/schedule/context_test.go index fb73d0b32..c75974fa0 100644 --- a/router/middleware/schedule/context_test.go +++ b/router/middleware/schedule/context_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/router/middleware/schedule/schedule.go b/router/middleware/schedule/schedule.go index 65f78c4e0..59de83e41 100644 --- a/router/middleware/schedule/schedule.go +++ b/router/middleware/schedule/schedule.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package schedule diff --git a/router/middleware/schedule_frequency.go b/router/middleware/schedule_frequency.go index 243c2ad06..4b9d50e22 100644 --- a/router/middleware/schedule_frequency.go +++ b/router/middleware/schedule_frequency.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/schedule_frequency_test.go b/router/middleware/schedule_frequency_test.go index 171f96ad3..6ed5dd869 100644 --- a/router/middleware/schedule_frequency_test.go +++ b/router/middleware/schedule_frequency_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/scm.go b/router/middleware/scm.go index 43573f1c9..3f6ddee87 100644 --- a/router/middleware/scm.go +++ b/router/middleware/scm.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/scm_test.go b/router/middleware/scm_test.go index a0752c41d..2c37a3de9 100644 --- a/router/middleware/scm_test.go +++ b/router/middleware/scm_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/secret.go b/router/middleware/secret.go index 66f28af78..449d28de7 100644 --- a/router/middleware/secret.go +++ b/router/middleware/secret.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/secret_test.go b/router/middleware/secret_test.go index 9ca21fd24..544cd28cf 100644 --- a/router/middleware/secret_test.go +++ b/router/middleware/secret_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/secure_cookie.go b/router/middleware/secure_cookie.go index 6c8de9ba2..3291a1c66 100644 --- a/router/middleware/secure_cookie.go +++ b/router/middleware/secure_cookie.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/secure_cookie_test.go b/router/middleware/secure_cookie_test.go index 60fa73eb4..c7ceb83b9 100644 --- a/router/middleware/secure_cookie_test.go +++ b/router/middleware/secure_cookie_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/service/context.go b/router/middleware/service/context.go index eeae1ba64..7083879ea 100644 --- a/router/middleware/service/context.go +++ b/router/middleware/service/context.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/router/middleware/service/context_test.go b/router/middleware/service/context_test.go index d944ceff3..6751bc92f 100644 --- a/router/middleware/service/context_test.go +++ b/router/middleware/service/context_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/router/middleware/service/doc.go b/router/middleware/service/doc.go index 698d41aaa..eb2b2973a 100644 --- a/router/middleware/service/doc.go +++ b/router/middleware/service/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package service provides the ability for inserting // Vela service resources into or extracting Vela service diff --git a/router/middleware/service/service.go b/router/middleware/service/service.go index e6ef94c59..1d974f4e6 100644 --- a/router/middleware/service/service.go +++ b/router/middleware/service/service.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service diff --git a/router/middleware/service/service_test.go b/router/middleware/service/service_test.go index 4d21cb122..fba880671 100644 --- a/router/middleware/service/service_test.go +++ b/router/middleware/service/service_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package service @@ -79,9 +77,9 @@ func TestService_Establish(t *testing.T) { } defer func() { - db.DeleteBuild(context.TODO(), b) - db.DeleteRepo(context.TODO(), r) - db.DeleteService(context.TODO(), want) + _ = db.DeleteBuild(context.TODO(), b) + _ = db.DeleteRepo(context.TODO(), r) + _ = db.DeleteService(context.TODO(), want) db.Close() }() @@ -168,7 +166,7 @@ func TestService_Establish_NoBuild(t *testing.T) { } defer func() { - db.DeleteRepo(context.TODO(), r) + _ = db.DeleteRepo(context.TODO(), r) db.Close() }() @@ -221,8 +219,8 @@ func TestService_Establish_NoServiceParameter(t *testing.T) { } defer func() { - db.DeleteBuild(context.TODO(), b) - db.DeleteRepo(context.TODO(), r) + _ = db.DeleteBuild(context.TODO(), b) + _ = db.DeleteRepo(context.TODO(), r) db.Close() }() @@ -277,8 +275,8 @@ func TestService_Establish_InvalidServiceParameter(t *testing.T) { } defer func() { - db.DeleteBuild(context.TODO(), b) - db.DeleteRepo(context.TODO(), r) + _ = db.DeleteBuild(context.TODO(), b) + _ = db.DeleteRepo(context.TODO(), r) db.Close() }() @@ -333,8 +331,8 @@ func TestService_Establish_NoService(t *testing.T) { } defer func() { - db.DeleteBuild(context.TODO(), b) - db.DeleteRepo(context.TODO(), r) + _ = db.DeleteBuild(context.TODO(), b) + _ = db.DeleteRepo(context.TODO(), r) db.Close() }() diff --git a/router/middleware/signing.go b/router/middleware/signing.go index 05c63b8e5..6b9dd4c1f 100644 --- a/router/middleware/signing.go +++ b/router/middleware/signing.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware @@ -16,3 +14,21 @@ func QueueSigningPrivateKey(key string) gin.HandlerFunc { c.Next() } } + +// QueueSigningPublicKey is a middleware function that attaches the public key used +// to open signed items that are pushed to the queue. +func QueueSigningPublicKey(key string) gin.HandlerFunc { + return func(c *gin.Context) { + c.Set("public-key", key) + c.Next() + } +} + +// QueueAddress is a middleware function that attaches the queue address used +// to open the connection to the queue. +func QueueAddress(address string) gin.HandlerFunc { + return func(c *gin.Context) { + c.Set("queue-address", address) + c.Next() + } +} diff --git a/router/middleware/signing_test.go b/router/middleware/signing_test.go new file mode 100644 index 000000000..3f152a3c9 --- /dev/null +++ b/router/middleware/signing_test.go @@ -0,0 +1,108 @@ +// SPDX-License-Identifier: Apache-2.0 + +package middleware + +import ( + "net/http" + "net/http/httptest" + "reflect" + "testing" + + "github.com/gin-gonic/gin" +) + +func TestMiddleware_QueueSigningPrivateKey(t *testing.T) { + // setup types + got := "" + want := "foobar" + + // setup context + gin.SetMode(gin.TestMode) + + resp := httptest.NewRecorder() + context, engine := gin.CreateTestContext(resp) + context.Request, _ = http.NewRequest(http.MethodGet, "/health", nil) + + // setup mock server + engine.Use(QueueSigningPrivateKey(want)) + engine.GET("/health", func(c *gin.Context) { + got = c.Value("queue.private-key").(string) + + c.Status(http.StatusOK) + }) + + // run test + engine.ServeHTTP(context.Writer, context.Request) + + if resp.Code != http.StatusOK { + t.Errorf("QueueSigningPrivateKey returned %v, want %v", resp.Code, http.StatusOK) + } + + if !reflect.DeepEqual(got, want) { + t.Errorf("QueueSigningPrivateKey is %v, want %v", got, want) + } +} + +func TestMiddleware_QueueSigningPublicKey(t *testing.T) { + // setup types + got := "" + want := "foobar" + + // setup context + gin.SetMode(gin.TestMode) + + resp := httptest.NewRecorder() + context, engine := gin.CreateTestContext(resp) + context.Request, _ = http.NewRequest(http.MethodGet, "/health", nil) + + // setup mock server + engine.Use(QueueSigningPublicKey(want)) + engine.GET("/health", func(c *gin.Context) { + got = c.Value("public-key").(string) + + c.Status(http.StatusOK) + }) + + // run test + engine.ServeHTTP(context.Writer, context.Request) + + if resp.Code != http.StatusOK { + t.Errorf("QueueSigningPublicKey returned %v, want %v", resp.Code, http.StatusOK) + } + + if !reflect.DeepEqual(got, want) { + t.Errorf("QueueSigningPublicKey is %v, want %v", got, want) + } +} + +func TestMiddleware_QueueAddress(t *testing.T) { + // setup types + got := "" + want := "foobar" + + // setup context + gin.SetMode(gin.TestMode) + + resp := httptest.NewRecorder() + context, engine := gin.CreateTestContext(resp) + context.Request, _ = http.NewRequest(http.MethodGet, "/health", nil) + + // setup mock server + engine.Use(QueueAddress(want)) + engine.GET("/health", func(c *gin.Context) { + got = c.Value("queue-address").(string) + + c.Status(http.StatusOK) + }) + + // run test + engine.ServeHTTP(context.Writer, context.Request) + + if resp.Code != http.StatusOK { + t.Errorf("QueueAddress returned %v, want %v", resp.Code, http.StatusOK) + } + + if !reflect.DeepEqual(got, want) { + t.Errorf("QueueAddress is %v, want %v", got, want) + } +} diff --git a/router/middleware/step/context.go b/router/middleware/step/context.go index deba61a33..f8c13740d 100644 --- a/router/middleware/step/context.go +++ b/router/middleware/step/context.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/router/middleware/step/context_test.go b/router/middleware/step/context_test.go index cd5b91e01..1b7932db2 100644 --- a/router/middleware/step/context_test.go +++ b/router/middleware/step/context_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/router/middleware/step/doc.go b/router/middleware/step/doc.go index 45ddd7e61..5738b3329 100644 --- a/router/middleware/step/doc.go +++ b/router/middleware/step/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package step provides the ability for inserting // Vela step resources into or extracting Vela step diff --git a/router/middleware/step/step.go b/router/middleware/step/step.go index 27d517efe..54fbfc1af 100644 --- a/router/middleware/step/step.go +++ b/router/middleware/step/step.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step diff --git a/router/middleware/step/step_test.go b/router/middleware/step/step_test.go index 9ca2c8faf..dd9dbafb5 100644 --- a/router/middleware/step/step_test.go +++ b/router/middleware/step/step_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package step @@ -81,9 +79,9 @@ func TestStep_Establish(t *testing.T) { } defer func() { - db.DeleteBuild(context.TODO(), b) - db.DeleteRepo(context.TODO(), r) - db.DeleteStep(want) + _ = db.DeleteBuild(context.TODO(), b) + _ = db.DeleteRepo(context.TODO(), r) + _ = db.DeleteStep(want) db.Close() }() @@ -170,7 +168,7 @@ func TestStep_Establish_NoBuild(t *testing.T) { } defer func() { - db.DeleteRepo(context.TODO(), r) + _ = db.DeleteRepo(context.TODO(), r) db.Close() }() @@ -223,8 +221,8 @@ func TestStep_Establish_NoStepParameter(t *testing.T) { } defer func() { - db.DeleteBuild(context.TODO(), b) - db.DeleteRepo(context.TODO(), r) + _ = db.DeleteBuild(context.TODO(), b) + _ = db.DeleteRepo(context.TODO(), r) db.Close() }() @@ -279,8 +277,8 @@ func TestStep_Establish_InvalidStepParameter(t *testing.T) { } defer func() { - db.DeleteBuild(context.TODO(), b) - db.DeleteRepo(context.TODO(), r) + _ = db.DeleteBuild(context.TODO(), b) + _ = db.DeleteRepo(context.TODO(), r) db.Close() }() @@ -335,8 +333,8 @@ func TestStep_Establish_NoStep(t *testing.T) { } defer func() { - db.DeleteBuild(context.TODO(), b) - db.DeleteRepo(context.TODO(), r) + _ = db.DeleteBuild(context.TODO(), b) + _ = db.DeleteRepo(context.TODO(), r) db.Close() }() diff --git a/router/middleware/token_manager.go b/router/middleware/token_manager.go index 0d8d78108..5fdc67c41 100644 --- a/router/middleware/token_manager.go +++ b/router/middleware/token_manager.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/token_manager_test.go b/router/middleware/token_manager_test.go index 2ba6e23f2..9a26f9b43 100644 --- a/router/middleware/token_manager_test.go +++ b/router/middleware/token_manager_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/user/context.go b/router/middleware/user/context.go index 944a1f3ee..0b4a54891 100644 --- a/router/middleware/user/context.go +++ b/router/middleware/user/context.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package user diff --git a/router/middleware/user/context_test.go b/router/middleware/user/context_test.go index 6cfe188ab..ced7cd896 100644 --- a/router/middleware/user/context_test.go +++ b/router/middleware/user/context_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package user diff --git a/router/middleware/user/doc.go b/router/middleware/user/doc.go index 42181f07d..2583d6c0e 100644 --- a/router/middleware/user/doc.go +++ b/router/middleware/user/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package user provides the ability for inserting // Vela user resources into or extracting Vela user diff --git a/router/middleware/user/user.go b/router/middleware/user/user.go index 9717e7fa6..71fdc1a2d 100644 --- a/router/middleware/user/user.go +++ b/router/middleware/user/user.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package user diff --git a/router/middleware/user/user_test.go b/router/middleware/user/user_test.go index 74bdd412e..d84a18847 100644 --- a/router/middleware/user/user_test.go +++ b/router/middleware/user/user_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package user @@ -93,7 +91,7 @@ func TestUser_Establish(t *testing.T) { } defer func() { - db.DeleteUser(_context.TODO(), want) + _ = db.DeleteUser(_context.TODO(), want) db.Close() }() diff --git a/router/middleware/webhook_validation.go b/router/middleware/webhook_validation.go index d1534513a..7c54a17a0 100644 --- a/router/middleware/webhook_validation.go +++ b/router/middleware/webhook_validation.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/webhook_validation_test.go b/router/middleware/webhook_validation_test.go index cb0f432fe..cb8a65639 100644 --- a/router/middleware/webhook_validation_test.go +++ b/router/middleware/webhook_validation_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/worker.go b/router/middleware/worker.go index 75b253de4..df7d11efe 100644 --- a/router/middleware/worker.go +++ b/router/middleware/worker.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/middleware/worker/context.go b/router/middleware/worker/context.go index 7e8930383..a7780a3e8 100644 --- a/router/middleware/worker/context.go +++ b/router/middleware/worker/context.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package worker diff --git a/router/middleware/worker/context_test.go b/router/middleware/worker/context_test.go index d48f0cd26..76efd687b 100644 --- a/router/middleware/worker/context_test.go +++ b/router/middleware/worker/context_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package worker diff --git a/router/middleware/worker/doc.go b/router/middleware/worker/doc.go index 44eaaa675..e01fdd8af 100644 --- a/router/middleware/worker/doc.go +++ b/router/middleware/worker/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package worker provides the ability for inserting // Vela worker resources into or extracting Vela worker diff --git a/router/middleware/worker/worker.go b/router/middleware/worker/worker.go index 2d5dc71cb..11586af9c 100644 --- a/router/middleware/worker/worker.go +++ b/router/middleware/worker/worker.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package worker diff --git a/router/middleware/worker/worker_test.go b/router/middleware/worker/worker_test.go index 53443e65b..2d3578cd0 100644 --- a/router/middleware/worker/worker_test.go +++ b/router/middleware/worker/worker_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package worker @@ -59,7 +57,7 @@ func TestWorker_Establish(t *testing.T) { } defer func() { - db.DeleteWorker(context.TODO(), want) + _ = db.DeleteWorker(context.TODO(), want) db.Close() }() diff --git a/router/middleware/worker_test.go b/router/middleware/worker_test.go index 5c141bdbb..7717d03c5 100644 --- a/router/middleware/worker_test.go +++ b/router/middleware/worker_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package middleware diff --git a/router/pipeline.go b/router/pipeline.go index b523f9495..7d11a4e2e 100644 --- a/router/pipeline.go +++ b/router/pipeline.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package router diff --git a/router/queue.go b/router/queue.go new file mode 100644 index 000000000..ca408ffe3 --- /dev/null +++ b/router/queue.go @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: Apache-2.0 + +package router + +import ( + "github.com/gin-gonic/gin" + "github.com/go-vela/server/api/queue" + "github.com/go-vela/server/router/middleware/perm" +) + +// QueueHandlers is a function that extends the provided base router group +// with the API handlers for queue registration functionality. +// +// POST /api/v1/queue/register. +func QueueHandlers(base *gin.RouterGroup) { + // Queue endpoints + _queue := base.Group("/queue") + { + _queue.GET("/info", perm.MustWorkerRegisterToken(), queue.Info) + } // end of queue endpoints +} diff --git a/router/repo.go b/router/repo.go index 7b7859f6a..0ed7d1be1 100644 --- a/router/repo.go +++ b/router/repo.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package router diff --git a/router/router.go b/router/router.go index f95c6bf4b..57f8e3d09 100644 --- a/router/router.go +++ b/router/router.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package router Vela server // @@ -81,6 +79,9 @@ func Load(options ...gin.HandlerFunc) *gin.Engine { // Validate Server Token endpoint r.GET("/validate-token", claims.Establish(), auth.ValidateServerToken) + // Validate OAuth Token endpoint + r.GET("/validate-oauth", claims.Establish(), auth.ValidateOAuthToken) + // Version endpoint r.GET("/version", api.Version) @@ -137,6 +138,8 @@ func Load(options ...gin.HandlerFunc) *gin.Engine { // Pipeline endpoints PipelineHandlers(baseAPI) + // Queue endpoints + QueueHandlers(baseAPI) } // end of api return r diff --git a/router/schedule.go b/router/schedule.go index 7c73e30c2..4a94f7737 100644 --- a/router/schedule.go +++ b/router/schedule.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package router diff --git a/router/scm.go b/router/scm.go index 40d745087..10c1cea81 100644 --- a/router/scm.go +++ b/router/scm.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package router @@ -14,8 +12,8 @@ import ( // ScmHandlers is a function that extends the provided base router group // with the API handlers for source code management functionality. // -// GET /api/v1/scm/orgs/:org/sync -// GET /api/v1/scm/repos/:org/:repo/sync . +// PATCH /api/v1/scm/orgs/:org/sync +// PATCH /api/v1/scm/repos/:org/:repo/sync . func ScmHandlers(base *gin.RouterGroup) { // SCM orgs endpoints orgs := base.Group("/scm/orgs") @@ -23,7 +21,7 @@ func ScmHandlers(base *gin.RouterGroup) { // SCM org endpoints org := orgs.Group("/:org", org.Establish()) { - org.GET("/sync", scm.SyncReposForOrg) + org.PATCH("/sync", scm.SyncReposForOrg) } // end of SCM org endpoints } // end of SCM orgs endpoints @@ -33,7 +31,7 @@ func ScmHandlers(base *gin.RouterGroup) { // SCM repo endpoints repo := repos.Group("/:org/:repo", org.Establish(), repo.Establish()) { - repo.GET("/sync", scm.SyncRepo) + repo.PATCH("/sync", scm.SyncRepo) } // end of SCM repo endpoints } // end of SCM repos endpoints } diff --git a/router/search.go b/router/search.go index 62e3542db..f5679048d 100644 --- a/router/search.go +++ b/router/search.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package router diff --git a/router/secret.go b/router/secret.go index 0ce94d982..419a0cab6 100644 --- a/router/secret.go +++ b/router/secret.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package router diff --git a/router/service.go b/router/service.go index 7b81e7af7..683a38b6f 100644 --- a/router/service.go +++ b/router/service.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore similar code with step package router diff --git a/router/step.go b/router/step.go index 9a53e4e97..d26f70385 100644 --- a/router/step.go +++ b/router/step.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore similar code with service package router diff --git a/router/user.go b/router/user.go index 31abe2d92..8f8e68fcc 100644 --- a/router/user.go +++ b/router/user.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package router diff --git a/router/worker.go b/router/worker.go index f85a84c45..9ab61ead0 100644 --- a/router/worker.go +++ b/router/worker.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package router diff --git a/scm/context.go b/scm/context.go index 6a831eb56..10337a0fa 100644 --- a/scm/context.go +++ b/scm/context.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package scm diff --git a/scm/context_test.go b/scm/context_test.go index d3031d9a7..e98afa30c 100644 --- a/scm/context_test.go +++ b/scm/context_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package scm diff --git a/scm/doc.go b/scm/doc.go index e30a7bcee..4376e55ca 100644 --- a/scm/doc.go +++ b/scm/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // package scm provides the ability for Vela to integrate // with different supported SCM providers. diff --git a/scm/flags.go b/scm/flags.go index 3dc36d139..84a9e879c 100644 --- a/scm/flags.go +++ b/scm/flags.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package scm diff --git a/scm/github/access.go b/scm/github/access.go index f5696a1ed..99e582cd0 100644 --- a/scm/github/access.go +++ b/scm/github/access.go @@ -1,20 +1,19 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package github import ( + "context" "strings" "github.com/sirupsen/logrus" "github.com/go-vela/types/library" - "github.com/google/go-github/v54/github" + "github.com/google/go-github/v56/github" ) // OrgAccess captures the user's access level for an org. -func (c *client) OrgAccess(u *library.User, org string) (string, error) { +func (c *client) OrgAccess(ctx context.Context, u *library.User, org string) (string, error) { c.Logger.WithFields(logrus.Fields{ "org": org, "user": u.GetName(), @@ -49,7 +48,7 @@ func (c *client) OrgAccess(u *library.User, org string) (string, error) { } // RepoAccess captures the user's access level for a repo. -func (c *client) RepoAccess(u *library.User, token, org, repo string) (string, error) { +func (c *client) RepoAccess(ctx context.Context, u *library.User, token, org, repo string) (string, error) { c.Logger.WithFields(logrus.Fields{ "org": org, "repo": repo, @@ -80,7 +79,7 @@ func (c *client) RepoAccess(u *library.User, token, org, repo string) (string, e } // TeamAccess captures the user's access level for a team. -func (c *client) TeamAccess(u *library.User, org, team string) (string, error) { +func (c *client) TeamAccess(ctx context.Context, u *library.User, org, team string) (string, error) { c.Logger.WithFields(logrus.Fields{ "org": org, "team": team, @@ -142,7 +141,7 @@ func (c *client) TeamAccess(u *library.User, org, team string) (string, error) { } // ListUsersTeamsForOrg captures the user's teams for an org. -func (c *client) ListUsersTeamsForOrg(u *library.User, org string) ([]string, error) { +func (c *client) ListUsersTeamsForOrg(ctx context.Context, u *library.User, org string) ([]string, error) { c.Logger.WithFields(logrus.Fields{ "org": org, "user": u.GetName(), diff --git a/scm/github/access_test.go b/scm/github/access_test.go index 0dcba9182..804715790 100644 --- a/scm/github/access_test.go +++ b/scm/github/access_test.go @@ -1,10 +1,9 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package github import ( + "context" "net/http" "net/http/httptest" "reflect" @@ -42,7 +41,7 @@ func TestGithub_OrgAccess_Admin(t *testing.T) { client, _ := NewTest(s.URL) // run test - got, err := client.OrgAccess(u, "github") + got, err := client.OrgAccess(context.TODO(), u, "github") if resp.Code != http.StatusOK { t.Errorf("OrgAccess returned %v, want %v", resp.Code, http.StatusOK) @@ -84,7 +83,7 @@ func TestGithub_OrgAccess_Member(t *testing.T) { client, _ := NewTest(s.URL) // run test - got, err := client.OrgAccess(u, "github") + got, err := client.OrgAccess(context.TODO(), u, "github") if resp.Code != http.StatusOK { t.Errorf("OrgAccess returned %v, want %v", resp.Code, http.StatusOK) @@ -114,7 +113,7 @@ func TestGithub_OrgAccess_NotFound(t *testing.T) { client, _ := NewTest(s.URL) // run test - got, err := client.OrgAccess(u, "github") + got, err := client.OrgAccess(context.TODO(), u, "github") if err == nil { t.Errorf("OrgAccess should have returned err") @@ -152,7 +151,7 @@ func TestGithub_OrgAccess_Pending(t *testing.T) { client, _ := NewTest(s.URL) // run test - got, err := client.OrgAccess(u, "github") + got, err := client.OrgAccess(context.TODO(), u, "github") if resp.Code != http.StatusOK { t.Errorf("OrgAccess returned %v, want %v", resp.Code, http.StatusOK) @@ -182,7 +181,7 @@ func TestGithub_OrgAccess_Personal(t *testing.T) { client, _ := NewTest(s.URL) // run test - got, err := client.OrgAccess(u, "foo") + got, err := client.OrgAccess(context.TODO(), u, "foo") if err != nil { t.Errorf("OrgAccess returned err: %v", err) @@ -220,7 +219,7 @@ func TestGithub_RepoAccess_Admin(t *testing.T) { client, _ := NewTest(s.URL) // run test - got, err := client.RepoAccess(u, u.GetToken(), "github", "octocat") + got, err := client.RepoAccess(context.TODO(), u, u.GetToken(), "github", "octocat") if resp.Code != http.StatusOK { t.Errorf("RepoAccess returned %v, want %v", resp.Code, http.StatusOK) @@ -250,7 +249,7 @@ func TestGithub_RepoAccess_NotFound(t *testing.T) { client, _ := NewTest(s.URL) // run test - got, err := client.RepoAccess(u, u.GetToken(), "github", "octocat") + got, err := client.RepoAccess(context.TODO(), u, u.GetToken(), "github", "octocat") if err == nil { t.Errorf("RepoAccess should have returned err") @@ -288,7 +287,7 @@ func TestGithub_TeamAccess_Admin(t *testing.T) { client, _ := NewTest(s.URL) // run test - got, err := client.TeamAccess(u, "github", "octocat") + got, err := client.TeamAccess(context.TODO(), u, "github", "octocat") if resp.Code != http.StatusOK { t.Errorf("TeamAccess returned %v, want %v", resp.Code, http.StatusOK) @@ -330,7 +329,7 @@ func TestGithub_TeamAccess_NoAccess(t *testing.T) { client, _ := NewTest(s.URL) // run test - got, err := client.TeamAccess(u, "github", "baz") + got, err := client.TeamAccess(context.TODO(), u, "github", "baz") if resp.Code != http.StatusOK { t.Errorf("TeamAccess returned %v, want %v", resp.Code, http.StatusOK) @@ -360,7 +359,7 @@ func TestGithub_TeamAccess_NotFound(t *testing.T) { client, _ := NewTest(s.URL) // run test - got, err := client.TeamAccess(u, "github", "octocat") + got, err := client.TeamAccess(context.TODO(), u, "github", "octocat") if err == nil { t.Errorf("TeamAccess should have returned err") @@ -398,7 +397,7 @@ func TestGithub_TeamList(t *testing.T) { client, _ := NewTest(s.URL) // run test - got, err := client.ListUsersTeamsForOrg(u, "github") + got, err := client.ListUsersTeamsForOrg(context.TODO(), u, "github") if resp.Code != http.StatusOK { t.Errorf("TeamAccess returned %v, want %v", resp.Code, http.StatusOK) diff --git a/scm/github/authentication.go b/scm/github/authentication.go index 7aa317cf1..adaf8e2b7 100644 --- a/scm/github/authentication.go +++ b/scm/github/authentication.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package github @@ -14,11 +12,11 @@ import ( "github.com/go-vela/server/random" "github.com/go-vela/types/library" - "github.com/google/go-github/v54/github" + "github.com/google/go-github/v56/github" ) // Authorize uses the given access token to authorize the user. -func (c *client) Authorize(token string) (string, error) { +func (c *client) Authorize(ctx context.Context, token string) (string, error) { c.Logger.Trace("authorizing user with token") // create GitHub OAuth client with user's token @@ -34,7 +32,7 @@ func (c *client) Authorize(token string) (string, error) { } // Login begins the authentication workflow for the session. -func (c *client) Login(w http.ResponseWriter, r *http.Request) (string, error) { +func (c *client) Login(ctx context.Context, w http.ResponseWriter, r *http.Request) (string, error) { c.Logger.Trace("processing login request") // generate a random string for creating the OAuth state @@ -57,7 +55,7 @@ func (c *client) Login(w http.ResponseWriter, r *http.Request) (string, error) { // Authenticate completes the authentication workflow for the session // and returns the remote user details. -func (c *client) Authenticate(w http.ResponseWriter, r *http.Request, oAuthState string) (*library.User, error) { +func (c *client) Authenticate(ctx context.Context, w http.ResponseWriter, r *http.Request, oAuthState string) (*library.User, error) { c.Logger.Trace("authenticating user") // get the OAuth code @@ -85,7 +83,7 @@ func (c *client) Authenticate(w http.ResponseWriter, r *http.Request, oAuthState } // authorize the user for the token - u, err := c.Authorize(token.AccessToken) + u, err := c.Authorize(ctx, token.AccessToken) if err != nil { return nil, err } @@ -98,7 +96,7 @@ func (c *client) Authenticate(w http.ResponseWriter, r *http.Request, oAuthState // AuthenticateToken completes the authentication workflow // for the session and returns the remote user details. -func (c *client) AuthenticateToken(r *http.Request) (*library.User, error) { +func (c *client) AuthenticateToken(ctx context.Context, r *http.Request) (*library.User, error) { c.Logger.Trace("authenticating user via token") token := r.Header.Get("Token") @@ -106,6 +104,32 @@ func (c *client) AuthenticateToken(r *http.Request) (*library.User, error) { return nil, errors.New("no token provided") } + // validate that the token was not created by vela + ok, err := c.ValidateOAuthToken(ctx, token) + if err != nil { + return nil, fmt.Errorf("unable to validate oauth token: %w", err) + } + + if ok { + return nil, errors.New("token must not be created by vela") + } + + u, err := c.Authorize(ctx, token) + if err != nil { + return nil, err + } + + return &library.User{ + Name: &u, + Token: &token, + }, nil +} + +// ValidateOAuthToken takes a user oauth integration token and +// validates that it was created by the Vela OAuth app. +// In essence, the function expects either a 200 or 404 from the GitHub API and returns +// error in any other failure case. +func (c *client) ValidateOAuthToken(ctx context.Context, token string) (bool, error) { // create http client to connect to GitHub API transport := github.BasicAuthTransport{ Username: c.config.ClientID, @@ -123,7 +147,7 @@ func (c *client) AuthenticateToken(r *http.Request) (*library.User, error) { // parse the provided url into url type enterpriseURL, err := url.Parse(c.config.Address) if err != nil { - return nil, err + return false, err } // set the base and upload url client.BaseURL = enterpriseURL @@ -140,24 +164,11 @@ func (c *client) AuthenticateToken(r *http.Request) (*library.User, error) { case http.StatusNotFound: break default: - return nil, err + return false, err } } else if err != nil { - return nil, err - } - - // return error if the token was created by Vela - if resp.StatusCode != http.StatusNotFound { - return nil, errors.New("token must not be created by vela") - } - - u, err := c.Authorize(token) - if err != nil { - return nil, err + return false, err } - return &library.User{ - Name: &u, - Token: &token, - }, nil + return resp.StatusCode == http.StatusOK, nil } diff --git a/scm/github/authentication_test.go b/scm/github/authentication_test.go index d1b369a1f..47c524e4d 100644 --- a/scm/github/authentication_test.go +++ b/scm/github/authentication_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package github @@ -10,6 +8,8 @@ import ( "reflect" "testing" + _context "context" + "github.com/gin-gonic/gin" "github.com/go-vela/types/library" ) @@ -45,7 +45,7 @@ func TestGithub_Authenticate(t *testing.T) { client, _ := NewTest(s.URL) // run test - got, err := client.Authenticate(context.Writer, context.Request, "bar") + got, err := client.Authenticate(_context.TODO(), context.Writer, context.Request, "bar") if resp.Code != http.StatusOK { t.Errorf("Authenticate returned %v, want %v", resp.Code, http.StatusOK) @@ -80,7 +80,7 @@ func TestGithub_Authenticate_NoCode(t *testing.T) { client, _ := NewTest(s.URL) // run test - got, err := client.Authenticate(context.Writer, context.Request, "bar") + got, err := client.Authenticate(_context.TODO(), context.Writer, context.Request, "bar") if resp.Code != http.StatusOK { t.Errorf("Authenticate returned %v, want %v", resp.Code, http.StatusOK) @@ -115,7 +115,7 @@ func TestGithub_Authenticate_NoState(t *testing.T) { client, _ := NewTest(s.URL) // run test - got, err := client.Authenticate(context.Writer, context.Request, "bar") + got, err := client.Authenticate(_context.TODO(), context.Writer, context.Request, "bar") if resp.Code != http.StatusOK { t.Errorf("Authenticate returned %v, want %v", resp.Code, http.StatusOK) @@ -150,7 +150,7 @@ func TestGithub_Authenticate_BadToken(t *testing.T) { client, _ := NewTest(s.URL) // run test - got, err := client.Authenticate(context.Writer, context.Request, "bar") + got, err := client.Authenticate(_context.TODO(), context.Writer, context.Request, "bar") if resp.Code != http.StatusOK { t.Errorf("Authenticate returned %v, want %v", resp.Code, http.StatusOK) @@ -190,7 +190,7 @@ func TestGithub_Authenticate_NotFound(t *testing.T) { client, _ := NewTest(s.URL) // run test - got, err := client.Authenticate(context.Writer, context.Request, "bar") + got, err := client.Authenticate(_context.TODO(), context.Writer, context.Request, "bar") if resp.Code != http.StatusOK { t.Errorf("Authenticate returned %v, want %v", resp.Code, http.StatusOK) @@ -227,7 +227,7 @@ func TestGithub_Authorize(t *testing.T) { // run test want := "octocat" - got, err := client.Authorize("foobar") + got, err := client.Authorize(_context.TODO(), "foobar") if resp.Code != http.StatusOK { t.Errorf("Authorize returned %v, want %v", resp.Code, http.StatusOK) @@ -261,7 +261,7 @@ func TestGithub_Authorize_NotFound(t *testing.T) { client, _ := NewTest(s.URL) // run test - got, err := client.Authorize("foobar") + got, err := client.Authorize(_context.TODO(), "foobar") if resp.Code != http.StatusOK { t.Errorf("Authorize returned %v, want %v", resp.Code, http.StatusOK) @@ -296,7 +296,7 @@ func TestGithub_Login(t *testing.T) { client, _ := NewTest(s.URL) // run test - _, err := client.Login(context.Writer, context.Request) + _, err := client.Login(_context.TODO(), context.Writer, context.Request) if resp.Code != http.StatusTemporaryRedirect { t.Errorf("Login returned %v, want %v", resp.Code, http.StatusTemporaryRedirect) @@ -333,18 +333,18 @@ func TestGithub_AuthenticateToken(t *testing.T) { client, _ := NewTest(s.URL) // run test - got, err := client.AuthenticateToken(context.Request) + got, err := client.AuthenticateToken(_context.TODO(), context.Request) if resp.Code != http.StatusOK { - t.Errorf("Authenticate returned %v, want %v", resp.Code, http.StatusOK) + t.Errorf("AuthenticateToken returned %v, want %v", resp.Code, http.StatusOK) } if err != nil { - t.Errorf("Authenticate returned err: %v", err) + t.Errorf("AuthenticateToken returned err: %v", err) } if !reflect.DeepEqual(got, want) { - t.Errorf("Authenticate is %v, want %v", got, want) + t.Errorf("AuthenticateToken is %v, want %v", got, want) } } @@ -369,18 +369,18 @@ func TestGithub_AuthenticateToken_Invalid(t *testing.T) { client, _ := NewTest(s.URL) // run test - got, err := client.AuthenticateToken(context.Request) + got, err := client.AuthenticateToken(_context.TODO(), context.Request) if resp.Code != http.StatusOK { - t.Errorf("Authenticate returned %v, want %v", resp.Code, http.StatusOK) + t.Errorf("AuthenticateToken returned %v, want %v", resp.Code, http.StatusOK) } if err == nil { - t.Errorf("Authenticate did not return err") + t.Errorf("AuthenticateToken did not return err") } if got != nil { - t.Errorf("Authenticate is %v, want nil", got) + t.Errorf("AuthenticateToken is %v, want nil", got) } } @@ -410,7 +410,7 @@ func TestGithub_AuthenticateToken_Vela_OAuth(t *testing.T) { client, _ := NewTest(s.URL) // run test - _, err := client.AuthenticateToken(context.Request) + _, err := client.AuthenticateToken(_context.TODO(), context.Request) if resp.Code != http.StatusOK { t.Errorf("AuthenticateToken returned %v, want %v", resp.Code, http.StatusOK) @@ -421,6 +421,109 @@ func TestGithub_AuthenticateToken_Vela_OAuth(t *testing.T) { } } +func TestGithub_ValidateOAuthToken_Valid(t *testing.T) { + // setup context + gin.SetMode(gin.TestMode) + + resp := httptest.NewRecorder() + context, engine := gin.CreateTestContext(resp) + context.Request, _ = http.NewRequest(http.MethodGet, "/validate-oauth", nil) + + token := "foobar" + want := true + scmResponseCode := http.StatusOK + + engine.POST("/api/v3/applications/foo/token", func(c *gin.Context) { + c.Header("Content-Type", "application/json") + c.Status(scmResponseCode) + }) + + s := httptest.NewServer(engine) + defer s.Close() + + client, _ := NewTest(s.URL) + + // run test + got, err := client.ValidateOAuthToken(_context.TODO(), token) + + if got != want { + t.Errorf("ValidateOAuthToken returned %v, want %v", got, want) + } + + if err != nil { + t.Errorf("ValidateOAuthToken returned err: %v", err) + } +} + +func TestGithub_ValidateOAuthToken_Invalid(t *testing.T) { + // setup context + gin.SetMode(gin.TestMode) + + resp := httptest.NewRecorder() + context, engine := gin.CreateTestContext(resp) + context.Request, _ = http.NewRequest(http.MethodGet, "/validate-oauth", nil) + + token := "foobar" + want := false + // 404 from the mocked github server indicates an invalid oauth token + scmResponseCode := http.StatusNotFound + + engine.POST("/api/v3/applications/foo/token", func(c *gin.Context) { + c.Header("Content-Type", "application/json") + c.Status(scmResponseCode) + }) + + s := httptest.NewServer(engine) + defer s.Close() + + client, _ := NewTest(s.URL) + + // run test + got, err := client.ValidateOAuthToken(_context.TODO(), token) + + if got != want { + t.Errorf("ValidateOAuthToken returned %v, want %v", got, want) + } + + if err != nil { + t.Errorf("ValidateOAuthToken returned err: %v", err) + } +} + +func TestGithub_ValidateOAuthToken_Error(t *testing.T) { + // setup context + gin.SetMode(gin.TestMode) + + resp := httptest.NewRecorder() + context, engine := gin.CreateTestContext(resp) + context.Request, _ = http.NewRequest(http.MethodGet, "/validate-oauth", nil) + + token := "foobar" + want := false + scmResponseCode := http.StatusInternalServerError + + engine.POST("/api/v3/applications/foo/token", func(c *gin.Context) { + c.Header("Content-Type", "application/json") + c.Status(scmResponseCode) + }) + + s := httptest.NewServer(engine) + defer s.Close() + + client, _ := NewTest(s.URL) + + // run test + got, err := client.ValidateOAuthToken(_context.TODO(), token) + + if got != want { + t.Errorf("ValidateOAuthToken returned %v, want %v", got, want) + } + + if err == nil { + t.Errorf("ValidateOAuthToken did not return err") + } +} + func TestGithub_LoginWCreds(t *testing.T) { // setup context gin.SetMode(gin.TestMode) @@ -441,10 +544,10 @@ func TestGithub_LoginWCreds(t *testing.T) { client, _ := NewTest(s.URL) // run test - _, err := client.Login(context.Writer, context.Request) + _, err := client.Login(_context.TODO(), context.Writer, context.Request) if resp.Code != http.StatusOK { - t.Errorf("Enable returned %v, want %v", resp.Code, http.StatusOK) + t.Errorf("Login returned %v, want %v", resp.Code, http.StatusOK) } if err != nil { diff --git a/scm/github/changeset.go b/scm/github/changeset.go index 21e8f511c..39b1f01db 100644 --- a/scm/github/changeset.go +++ b/scm/github/changeset.go @@ -1,20 +1,19 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package github import ( + "context" "fmt" "github.com/sirupsen/logrus" "github.com/go-vela/types/library" - "github.com/google/go-github/v54/github" + "github.com/google/go-github/v56/github" ) // Changeset captures the list of files changed for a commit. -func (c *client) Changeset(u *library.User, r *library.Repo, sha string) ([]string, error) { +func (c *client) Changeset(ctx context.Context, u *library.User, r *library.Repo, sha string) ([]string, error) { c.Logger.WithFields(logrus.Fields{ "org": r.GetOrg(), "repo": r.GetName(), @@ -43,7 +42,7 @@ func (c *client) Changeset(u *library.User, r *library.Repo, sha string) ([]stri } // ChangesetPR captures the list of files changed for a pull request. -func (c *client) ChangesetPR(u *library.User, r *library.Repo, number int) ([]string, error) { +func (c *client) ChangesetPR(ctx context.Context, u *library.User, r *library.Repo, number int) ([]string, error) { c.Logger.WithFields(logrus.Fields{ "org": r.GetOrg(), "repo": r.GetName(), diff --git a/scm/github/changeset_test.go b/scm/github/changeset_test.go index cd4fdbe57..2fefbad93 100644 --- a/scm/github/changeset_test.go +++ b/scm/github/changeset_test.go @@ -1,10 +1,9 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package github import ( + "context" "net/http" "net/http/httptest" "reflect" @@ -46,7 +45,7 @@ func TestGithub_Changeset(t *testing.T) { client, _ := NewTest(s.URL) // run test - got, err := client.Changeset(u, r, "6dcb09b5b57875f334f61aebed695e2e4193db5e") + got, err := client.Changeset(context.TODO(), u, r, "6dcb09b5b57875f334f61aebed695e2e4193db5e") if resp.Code != http.StatusOK { t.Errorf("Changeset returned %v, want %v", resp.Code, http.StatusOK) @@ -92,7 +91,7 @@ func TestGithub_ChangesetPR(t *testing.T) { client, _ := NewTest(s.URL) // run test - got, err := client.ChangesetPR(u, r, 1) + got, err := client.ChangesetPR(context.TODO(), u, r, 1) if resp.Code != http.StatusOK { t.Errorf("ChangesetPR returned %v, want %v", resp.Code, http.StatusOK) diff --git a/scm/github/deployment.go b/scm/github/deployment.go index 2d59edd42..52b81a88a 100644 --- a/scm/github/deployment.go +++ b/scm/github/deployment.go @@ -1,21 +1,20 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package github import ( + "context" "encoding/json" "github.com/sirupsen/logrus" "github.com/go-vela/types/library" "github.com/go-vela/types/raw" - "github.com/google/go-github/v54/github" + "github.com/google/go-github/v56/github" ) // GetDeployment gets a deployment from the GitHub repo. -func (c *client) GetDeployment(u *library.User, r *library.Repo, id int64) (*library.Deployment, error) { +func (c *client) GetDeployment(ctx context.Context, u *library.User, r *library.Repo, id int64) (*library.Deployment, error) { c.Logger.WithFields(logrus.Fields{ "org": r.GetOrg(), "repo": r.GetName(), @@ -53,7 +52,7 @@ func (c *client) GetDeployment(u *library.User, r *library.Repo, id int64) (*lib } // GetDeploymentCount counts a list of deployments from the GitHub repo. -func (c *client) GetDeploymentCount(u *library.User, r *library.Repo) (int64, error) { +func (c *client) GetDeploymentCount(ctx context.Context, u *library.User, r *library.Repo) (int64, error) { c.Logger.WithFields(logrus.Fields{ "org": r.GetOrg(), "repo": r.GetName(), @@ -95,7 +94,7 @@ func (c *client) GetDeploymentCount(u *library.User, r *library.Repo) (int64, er } // GetDeploymentList gets a list of deployments from the GitHub repo. -func (c *client) GetDeploymentList(u *library.User, r *library.Repo, page, perPage int) ([]*library.Deployment, error) { +func (c *client) GetDeploymentList(ctx context.Context, u *library.User, r *library.Repo, page, perPage int) ([]*library.Deployment, error) { c.Logger.WithFields(logrus.Fields{ "org": r.GetOrg(), "repo": r.GetName(), @@ -149,7 +148,7 @@ func (c *client) GetDeploymentList(u *library.User, r *library.Repo, page, perPa } // CreateDeployment creates a new deployment for the GitHub repo. -func (c *client) CreateDeployment(u *library.User, r *library.Repo, d *library.Deployment) error { +func (c *client) CreateDeployment(ctx context.Context, u *library.User, r *library.Repo, d *library.Deployment) error { c.Logger.WithFields(logrus.Fields{ "org": r.GetOrg(), "repo": r.GetName(), diff --git a/scm/github/deployment_test.go b/scm/github/deployment_test.go index 2136c0da4..4558bb783 100644 --- a/scm/github/deployment_test.go +++ b/scm/github/deployment_test.go @@ -1,10 +1,9 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package github import ( + "context" "net/http" "net/http/httptest" "reflect" @@ -59,7 +58,7 @@ func TestGithub_CreateDeployment(t *testing.T) { client, _ := NewTest(s.URL, "https://foo.bar.com") // run test - err := client.CreateDeployment(u, r, d) + err := client.CreateDeployment(context.TODO(), u, r, d) if resp.Code != http.StatusOK { t.Errorf("CreateDeployment returned %v, want %v", resp.Code, http.StatusOK) @@ -113,7 +112,7 @@ func TestGithub_GetDeployment(t *testing.T) { client, _ := NewTest(s.URL, "https://foo.bar.com") // run test - got, err := client.GetDeployment(u, r, 1) + got, err := client.GetDeployment(context.TODO(), u, r, 1) if resp.Code != http.StatusOK { t.Errorf("GetDeployment returned %v, want %v", resp.Code, http.StatusOK) @@ -161,7 +160,7 @@ func TestGithub_GetDeploymentCount(t *testing.T) { client, _ := NewTest(s.URL, "https://foo.bar.com") // run test - got, err := client.GetDeploymentCount(u, r) + got, err := client.GetDeploymentCount(context.TODO(), u, r) if resp.Code != http.StatusOK { t.Errorf("GetDeployment returned %v, want %v", resp.Code, http.StatusOK) @@ -233,7 +232,7 @@ func TestGithub_GetDeploymentList(t *testing.T) { client, _ := NewTest(s.URL, "https://foo.bar.com") // run test - got, err := client.GetDeploymentList(u, r, 1, 100) + got, err := client.GetDeploymentList(context.TODO(), u, r, 1, 100) if resp.Code != http.StatusOK { t.Errorf("GetDeployment returned %v, want %v", resp.Code, http.StatusOK) diff --git a/scm/github/doc.go b/scm/github/doc.go index e47f97555..1c6627dc0 100644 --- a/scm/github/doc.go +++ b/scm/github/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package github provides the ability for Vela to // integrate with GitHub or GitHub Enterprise as a scm provider. diff --git a/scm/github/driver.go b/scm/github/driver.go index 2a0065f73..1a17f5f0f 100644 --- a/scm/github/driver.go +++ b/scm/github/driver.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package github diff --git a/scm/github/driver_test.go b/scm/github/driver_test.go index 1567ef4c1..42b9f8f1e 100644 --- a/scm/github/driver_test.go +++ b/scm/github/driver_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package github diff --git a/scm/github/github.go b/scm/github/github.go index 723584585..e81d3c0d7 100644 --- a/scm/github/github.go +++ b/scm/github/github.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package github @@ -9,7 +7,7 @@ import ( "fmt" "net/url" - "github.com/google/go-github/v54/github" + "github.com/google/go-github/v56/github" "github.com/sirupsen/logrus" "golang.org/x/oauth2" @@ -28,8 +26,6 @@ const ( eventInitialize = "initialize" ) -var ctx = context.Background() - type config struct { // specifies the address to use for the GitHub client Address string diff --git a/scm/github/github_test.go b/scm/github/github_test.go index 4a23cee67..6d3c6536c 100644 --- a/scm/github/github_test.go +++ b/scm/github/github_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package github @@ -12,7 +10,7 @@ import ( "reflect" "testing" - "github.com/google/go-github/v54/github" + "github.com/google/go-github/v56/github" "golang.org/x/oauth2" ) diff --git a/scm/github/opts.go b/scm/github/opts.go index 79d128142..df6d46506 100644 --- a/scm/github/opts.go +++ b/scm/github/opts.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package github diff --git a/scm/github/opts_test.go b/scm/github/opts_test.go index 2419bc528..40ed4da87 100644 --- a/scm/github/opts_test.go +++ b/scm/github/opts_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package github diff --git a/scm/github/org.go b/scm/github/org.go index ef9e43ca4..48b3701a8 100644 --- a/scm/github/org.go +++ b/scm/github/org.go @@ -1,10 +1,9 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package github import ( + "context" "net/http" "github.com/sirupsen/logrus" @@ -13,7 +12,7 @@ import ( ) // GetOrgName gets org name from Github. -func (c *client) GetOrgName(u *library.User, o string) (string, error) { +func (c *client) GetOrgName(ctx context.Context, u *library.User, o string) (string, error) { c.Logger.WithFields(logrus.Fields{ "org": o, "user": u.GetName(), diff --git a/scm/github/org_test.go b/scm/github/org_test.go index b0512f9b9..b9d64e84a 100644 --- a/scm/github/org_test.go +++ b/scm/github/org_test.go @@ -1,10 +1,9 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package github import ( + "context" "net/http" "net/http/httptest" "reflect" @@ -42,7 +41,7 @@ func TestGithub_GetOrgName(t *testing.T) { client, _ := NewTest(s.URL) // run test - got, err := client.GetOrgName(u, "github") + got, err := client.GetOrgName(context.TODO(), u, "github") if resp.Code != http.StatusOK { t.Errorf("GetOrgName returned %v, want %v", resp.Code, http.StatusOK) @@ -84,7 +83,7 @@ func TestGithub_GetOrgName_Personal(t *testing.T) { client, _ := NewTest(s.URL) // run test - got, err := client.GetOrgName(u, "octocat") + got, err := client.GetOrgName(context.TODO(), u, "octocat") if resp.Code != http.StatusOK { t.Errorf("GetOrgName returned %v, want %v", resp.Code, http.StatusOK) @@ -123,7 +122,7 @@ func TestGithub_GetOrgName_Fail(t *testing.T) { client, _ := NewTest(s.URL) // run test - _, err := client.GetOrgName(u, "octocat") + _, err := client.GetOrgName(context.TODO(), u, "octocat") if err == nil { t.Error("GetOrgName should return error") diff --git a/scm/github/repo.go b/scm/github/repo.go index 726c81811..e4d502295 100644 --- a/scm/github/repo.go +++ b/scm/github/repo.go @@ -1,10 +1,9 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package github import ( + "context" "fmt" "net/http" "strconv" @@ -15,19 +14,19 @@ import ( "github.com/go-vela/types/constants" "github.com/go-vela/types/library" - "github.com/google/go-github/v54/github" + "github.com/google/go-github/v56/github" ) // ConfigBackoff is a wrapper for Config that will retry five times if the function // fails to retrieve the yaml/yml file. -func (c *client) ConfigBackoff(u *library.User, r *library.Repo, ref string) (data []byte, err error) { +func (c *client) ConfigBackoff(ctx context.Context, u *library.User, r *library.Repo, ref string) (data []byte, err error) { // number of times to retry retryLimit := 5 for i := 0; i < retryLimit; i++ { logrus.Debugf("Fetching config file - Attempt %d", i+1) // attempt to fetch the config - data, err = c.Config(u, r, ref) + data, err = c.Config(ctx, u, r, ref) // return err if the last attempt returns error if err != nil && i == retryLimit-1 { @@ -48,7 +47,7 @@ func (c *client) ConfigBackoff(u *library.User, r *library.Repo, ref string) (da } // Config gets the pipeline configuration from the GitHub repo. -func (c *client) Config(u *library.User, r *library.Repo, ref string) ([]byte, error) { +func (c *client) Config(ctx context.Context, u *library.User, r *library.Repo, ref string) ([]byte, error) { c.Logger.WithFields(logrus.Fields{ "org": r.GetOrg(), "repo": r.GetName(), @@ -93,7 +92,7 @@ func (c *client) Config(u *library.User, r *library.Repo, ref string) ([]byte, e } // Disable deactivates a repo by deleting the webhook. -func (c *client) Disable(u *library.User, org, name string) error { +func (c *client) Disable(ctx context.Context, u *library.User, org, name string) error { c.Logger.WithFields(logrus.Fields{ "org": org, "repo": name, @@ -151,7 +150,7 @@ func (c *client) Disable(u *library.User, org, name string) error { } // Enable activates a repo by creating the webhook. -func (c *client) Enable(u *library.User, r *library.Repo, h *library.Hook) (*library.Hook, string, error) { +func (c *client) Enable(ctx context.Context, u *library.User, r *library.Repo, h *library.Hook) (*library.Hook, string, error) { c.Logger.WithFields(logrus.Fields{ "org": r.GetOrg(), "repo": r.GetName(), @@ -219,7 +218,7 @@ func (c *client) Enable(u *library.User, r *library.Repo, h *library.Hook) (*lib } // Update edits a repo webhook. -func (c *client) Update(u *library.User, r *library.Repo, hookID int64) (bool, error) { +func (c *client) Update(ctx context.Context, u *library.User, r *library.Repo, hookID int64) (bool, error) { c.Logger.WithFields(logrus.Fields{ "org": r.GetOrg(), "repo": r.GetName(), @@ -270,7 +269,7 @@ func (c *client) Update(u *library.User, r *library.Repo, hookID int64) (bool, e } // Status sends the commit status for the given SHA from the GitHub repo. -func (c *client) Status(u *library.User, b *library.Build, org, name string) error { +func (c *client) Status(ctx context.Context, u *library.User, b *library.Build, org, name string) error { c.Logger.WithFields(logrus.Fields{ "build": b.GetNumber(), "org": org, @@ -372,7 +371,7 @@ func (c *client) Status(u *library.User, b *library.Build, org, name string) err } // GetRepo gets repo information from Github. -func (c *client) GetRepo(u *library.User, r *library.Repo) (*library.Repo, error) { +func (c *client) GetRepo(ctx context.Context, u *library.User, r *library.Repo) (*library.Repo, error) { c.Logger.WithFields(logrus.Fields{ "org": r.GetOrg(), "repo": r.GetName(), @@ -392,7 +391,7 @@ func (c *client) GetRepo(u *library.User, r *library.Repo) (*library.Repo, error } // GetOrgAndRepoName returns the name of the org and the repository in the SCM. -func (c *client) GetOrgAndRepoName(u *library.User, o string, r string) (string, string, error) { +func (c *client) GetOrgAndRepoName(ctx context.Context, u *library.User, o string, r string) (string, string, error) { c.Logger.WithFields(logrus.Fields{ "org": o, "repo": r, @@ -412,7 +411,7 @@ func (c *client) GetOrgAndRepoName(u *library.User, o string, r string) (string, } // ListUserRepos returns a list of all repos the user has access to. -func (c *client) ListUserRepos(u *library.User) ([]*library.Repo, error) { +func (c *client) ListUserRepos(ctx context.Context, u *library.User) ([]*library.Repo, error) { c.Logger.WithFields(logrus.Fields{ "user": u.GetName(), }).Tracef("listing source repositories for %s", u.GetName()) @@ -490,7 +489,7 @@ func toLibraryRepo(gr github.Repository) *library.Repo { // GetPullRequest defines a function that retrieves // a pull request for a repo. -func (c *client) GetPullRequest(u *library.User, r *library.Repo, number int) (string, string, string, string, error) { +func (c *client) GetPullRequest(ctx context.Context, u *library.User, r *library.Repo, number int) (string, string, string, string, error) { c.Logger.WithFields(logrus.Fields{ "org": r.GetOrg(), "repo": r.GetName(), @@ -514,7 +513,7 @@ func (c *client) GetPullRequest(u *library.User, r *library.Repo, number int) (s } // GetHTMLURL retrieves the html_url from repository contents from the GitHub repo. -func (c *client) GetHTMLURL(u *library.User, org, repo, name, ref string) (string, error) { +func (c *client) GetHTMLURL(ctx context.Context, u *library.User, org, repo, name, ref string) (string, error) { c.Logger.WithFields(logrus.Fields{ "org": org, "repo": repo, @@ -550,7 +549,7 @@ func (c *client) GetHTMLURL(u *library.User, org, repo, name, ref string) (strin } // GetBranch defines a function that retrieves a branch for a repo. -func (c *client) GetBranch(u *library.User, r *library.Repo, branch string) (string, string, error) { +func (c *client) GetBranch(ctx context.Context, u *library.User, r *library.Repo, branch string) (string, string, error) { c.Logger.WithFields(logrus.Fields{ "org": r.GetOrg(), "repo": r.GetName(), @@ -560,7 +559,8 @@ func (c *client) GetBranch(u *library.User, r *library.Repo, branch string) (str // create GitHub OAuth client with user's token client := c.newClientToken(u.GetToken()) - data, _, err := client.Repositories.GetBranch(ctx, r.GetOrg(), r.GetName(), branch, true) + maxRedirects := 3 + data, _, err := client.Repositories.GetBranch(ctx, r.GetOrg(), r.GetName(), branch, maxRedirects) if err != nil { return "", "", err } diff --git a/scm/github/repo_test.go b/scm/github/repo_test.go index 92f1a9ab0..231ef19e0 100644 --- a/scm/github/repo_test.go +++ b/scm/github/repo_test.go @@ -1,10 +1,9 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package github import ( + "context" "fmt" "net/http" "net/http/httptest" @@ -58,7 +57,7 @@ func TestGithub_Config_YML(t *testing.T) { client, _ := NewTest(s.URL) // run test - got, err := client.Config(u, r, "") + got, err := client.Config(context.TODO(), u, r, "") if resp.Code != http.StatusOK { t.Errorf("Config returned %v, want %v", resp.Code, http.StatusOK) @@ -112,7 +111,7 @@ func TestGithub_ConfigBackoff_YML(t *testing.T) { client, _ := NewTest(s.URL) // run test - got, err := client.Config(u, r, "") + got, err := client.Config(context.TODO(), u, r, "") if resp.Code != http.StatusOK { t.Errorf("Config returned %v, want %v", resp.Code, http.StatusOK) @@ -154,7 +153,7 @@ func TestGithub_Config_YML_BadRequest(t *testing.T) { client, _ := NewTest(s.URL) // run test - got, err := client.Config(u, r, "") + got, err := client.Config(context.TODO(), u, r, "") if resp.Code != http.StatusOK { t.Errorf("Config returned %v, want %v", resp.Code, http.StatusOK) @@ -208,7 +207,7 @@ func TestGithub_Config_YAML(t *testing.T) { client, _ := NewTest(s.URL) // run test - got, err := client.Config(u, r, "") + got, err := client.Config(context.TODO(), u, r, "") if resp.Code != http.StatusOK { t.Errorf("Config returned %v, want %v", resp.Code, http.StatusOK) @@ -263,7 +262,7 @@ func TestGithub_Config_Star(t *testing.T) { client, _ := NewTest(s.URL) // run test - got, err := client.Config(u, r, "") + got, err := client.Config(context.TODO(), u, r, "") if resp.Code != http.StatusOK { t.Errorf("Config returned %v, want %v", resp.Code, http.StatusOK) @@ -318,7 +317,7 @@ func TestGithub_Config_Py(t *testing.T) { client, _ := NewTest(s.URL) // run test - got, err := client.Config(u, r, "") + got, err := client.Config(context.TODO(), u, r, "") if resp.Code != http.StatusOK { t.Errorf("Config returned %v, want %v", resp.Code, http.StatusOK) @@ -365,7 +364,7 @@ func TestGithub_Config_YAML_BadRequest(t *testing.T) { client, _ := NewTest(s.URL) // run test - got, err := client.Config(u, r, "") + got, err := client.Config(context.TODO(), u, r, "") if resp.Code != http.StatusOK { t.Errorf("Config returned %v, want %v", resp.Code, http.StatusOK) @@ -407,7 +406,7 @@ func TestGithub_Config_NotFound(t *testing.T) { client, _ := NewTest(s.URL) // run test - got, err := client.Config(u, r, "") + got, err := client.Config(context.TODO(), u, r, "") if resp.Code != http.StatusOK { t.Errorf("Config returned %v, want %v", resp.Code, http.StatusOK) @@ -450,7 +449,7 @@ func TestGithub_Disable(t *testing.T) { client, _ := NewTest(s.URL, "https://foo.bar.com") // run test - err := client.Disable(u, "foo", "bar") + err := client.Disable(context.TODO(), u, "foo", "bar") if resp.Code != http.StatusOK { t.Errorf("Disable returned %v, want %v", resp.Code, http.StatusOK) @@ -484,7 +483,7 @@ func TestGithub_Disable_NotFoundHooks(t *testing.T) { client, _ := NewTest(s.URL, "https://foo.bar.com") // run test - err := client.Disable(u, "foo", "bar") + err := client.Disable(context.TODO(), u, "foo", "bar") if resp.Code != http.StatusOK { t.Errorf("Disable returned %v, want %v", resp.Code, http.StatusOK) @@ -523,7 +522,7 @@ func TestGithub_Disable_HooksButNotFound(t *testing.T) { client, _ := NewTest(s.URL, "https://foos.ball.com") // run test - err := client.Disable(u, "foo", "bar") + err := client.Disable(context.TODO(), u, "foo", "bar") if resp.Code != http.StatusOK { t.Errorf("Disable returned %v, want %v", resp.Code, http.StatusOK) @@ -565,7 +564,7 @@ func TestGithub_Disable_MultipleHooks(t *testing.T) { client, _ := NewTest(s.URL, "https://foo.bar.com") // run test - err := client.Disable(u, "foo", "bar") + err := client.Disable(context.TODO(), u, "foo", "bar") if count != wantCount { t.Errorf("Count returned %d, want %d", count, wantCount) @@ -620,7 +619,7 @@ func TestGithub_Enable(t *testing.T) { client, _ := NewTest(s.URL) // run test - got, _, err := client.Enable(u, r, new(library.Hook)) + got, _, err := client.Enable(context.TODO(), u, r, new(library.Hook)) if resp.Code != http.StatusOK { t.Errorf("Enable returned %v, want %v", resp.Code, http.StatusOK) @@ -669,7 +668,7 @@ func TestGithub_Update(t *testing.T) { client, _ := NewTest(s.URL) // run test - _, err := client.Update(u, r, hookID) + _, err := client.Update(context.TODO(), u, r, hookID) if resp.Code != http.StatusOK { t.Errorf("Update returned %v, want %v", resp.Code, http.StatusOK) @@ -706,7 +705,7 @@ func TestGithub_Update_webhookExists_True(t *testing.T) { client, _ := NewTest(s.URL) // run test - webhookExists, err := client.Update(u, r, 0) + webhookExists, err := client.Update(context.TODO(), u, r, 0) if !webhookExists { t.Errorf("Update returned %v, want %v", webhookExists, true) @@ -743,7 +742,7 @@ func TestGithub_Update_webhookExists_False(t *testing.T) { client, _ := NewTest(s.URL) // run test - webhookExists, err := client.Update(u, r, 0) + webhookExists, err := client.Update(context.TODO(), u, r, 0) if webhookExists { t.Errorf("Update returned %v, want %v", webhookExists, false) @@ -788,7 +787,7 @@ func TestGithub_Status_Deployment(t *testing.T) { client, _ := NewTest(s.URL) // run test - err := client.Status(u, b, "foo", "bar") + err := client.Status(context.TODO(), u, b, "foo", "bar") if resp.Code != http.StatusOK { t.Errorf("Status returned %v, want %v", resp.Code, http.StatusOK) @@ -832,7 +831,7 @@ func TestGithub_Status_Running(t *testing.T) { client, _ := NewTest(s.URL) // run test - err := client.Status(u, b, "foo", "bar") + err := client.Status(context.TODO(), u, b, "foo", "bar") if resp.Code != http.StatusOK { t.Errorf("Status returned %v, want %v", resp.Code, http.StatusOK) @@ -876,7 +875,7 @@ func TestGithub_Status_Success(t *testing.T) { client, _ := NewTest(s.URL) // run test - err := client.Status(u, b, "foo", "bar") + err := client.Status(context.TODO(), u, b, "foo", "bar") if resp.Code != http.StatusOK { t.Errorf("Status returned %v, want %v", resp.Code, http.StatusOK) @@ -920,7 +919,7 @@ func TestGithub_Status_Failure(t *testing.T) { client, _ := NewTest(s.URL) // run test - err := client.Status(u, b, "foo", "bar") + err := client.Status(context.TODO(), u, b, "foo", "bar") if resp.Code != http.StatusOK { t.Errorf("Status returned %v, want %v", resp.Code, http.StatusOK) @@ -964,7 +963,7 @@ func TestGithub_Status_Killed(t *testing.T) { client, _ := NewTest(s.URL) // run test - err := client.Status(u, b, "foo", "bar") + err := client.Status(context.TODO(), u, b, "foo", "bar") if resp.Code != http.StatusOK { t.Errorf("Status returned %v, want %v", resp.Code, http.StatusOK) @@ -1008,7 +1007,7 @@ func TestGithub_Status_Skipped(t *testing.T) { client, _ := NewTest(s.URL) // run test - err := client.Status(u, b, "foo", "bar") + err := client.Status(context.TODO(), u, b, "foo", "bar") if resp.Code != http.StatusOK { t.Errorf("Status returned %v, want %v", resp.Code, http.StatusOK) @@ -1052,7 +1051,7 @@ func TestGithub_Status_Error(t *testing.T) { client, _ := NewTest(s.URL) // run test - err := client.Status(u, b, "foo", "bar") + err := client.Status(context.TODO(), u, b, "foo", "bar") if resp.Code != http.StatusOK { t.Errorf("Status returned %v, want %v", resp.Code, http.StatusOK) @@ -1095,7 +1094,7 @@ func TestGithub_GetRepo(t *testing.T) { want.SetFullName("octocat/Hello-World") want.SetLink("https://github.com/octocat/Hello-World") want.SetClone("https://github.com/octocat/Hello-World.git") - want.SetBranch("master") + want.SetBranch("main") want.SetPrivate(false) want.SetTopics([]string{"octocat", "atom", "electron", "api"}) want.SetVisibility("public") @@ -1103,7 +1102,7 @@ func TestGithub_GetRepo(t *testing.T) { client, _ := NewTest(s.URL) // run test - got, err := client.GetRepo(u, r) + got, err := client.GetRepo(context.TODO(), u, r) if resp.Code != http.StatusOK { t.Errorf("GetRepo returned %v, want %v", resp.Code, http.StatusOK) @@ -1146,7 +1145,7 @@ func TestGithub_GetRepo_Fail(t *testing.T) { client, _ := NewTest(s.URL) // run test - _, err := client.GetRepo(u, r) + _, err := client.GetRepo(context.TODO(), u, r) if err == nil { t.Error("GetRepo should return error") @@ -1181,7 +1180,7 @@ func TestGithub_GetOrgAndRepoName(t *testing.T) { client, _ := NewTest(s.URL) // run test - gotOrg, gotRepo, err := client.GetOrgAndRepoName(u, "octocat", "Hello-World") + gotOrg, gotRepo, err := client.GetOrgAndRepoName(context.TODO(), u, "octocat", "Hello-World") if resp.Code != http.StatusOK { t.Errorf("GetRepoName returned %v, want %v", resp.Code, http.StatusOK) @@ -1224,7 +1223,7 @@ func TestGithub_GetOrgAndRepoName_Fail(t *testing.T) { client, _ := NewTest(s.URL) // run test - _, _, err := client.GetOrgAndRepoName(u, "octocat", "Hello-World") + _, _, err := client.GetOrgAndRepoName(context.TODO(), u, "octocat", "Hello-World") if err == nil { t.Error("GetRepoName should return error") @@ -1259,7 +1258,7 @@ func TestGithub_ListUserRepos(t *testing.T) { r.SetFullName("octocat/Hello-World") r.SetLink("https://github.com/octocat/Hello-World") r.SetClone("https://github.com/octocat/Hello-World.git") - r.SetBranch("master") + r.SetBranch("main") r.SetPrivate(false) r.SetTopics([]string{"octocat", "atom", "electron", "api"}) r.SetVisibility("public") @@ -1269,7 +1268,7 @@ func TestGithub_ListUserRepos(t *testing.T) { client, _ := NewTest(s.URL) // run test - got, err := client.ListUserRepos(u) + got, err := client.ListUserRepos(context.TODO(), u) if err != nil { t.Errorf("Status returned err: %v", err) @@ -1307,7 +1306,7 @@ func TestGithub_ListUserRepos_Ineligible(t *testing.T) { client, _ := NewTest(s.URL) // run test - got, err := client.ListUserRepos(u) + got, err := client.ListUserRepos(context.TODO(), u) if err != nil { t.Errorf("Status returned err: %v", err) @@ -1345,14 +1344,14 @@ func TestGithub_GetPullRequest(t *testing.T) { r.SetName("Hello-World") wantCommit := "6dcb09b5b57875f334f61aebed695e2e4193db5e" - wantBranch := "master" - wantBaseRef := "master" + wantBranch := "main" + wantBaseRef := "main" wantHeadRef := "new-topic" client, _ := NewTest(s.URL) // run test - gotCommit, gotBranch, gotBaseRef, gotHeadRef, err := client.GetPullRequest(u, r, 1) + gotCommit, gotBranch, gotBaseRef, gotHeadRef, err := client.GetPullRequest(context.TODO(), u, r, 1) if err != nil { t.Errorf("Status returned err: %v", err) @@ -1409,7 +1408,7 @@ func TestGithub_GetBranch(t *testing.T) { client, _ := NewTest(s.URL) // run test - gotBranch, gotCommit, err := client.GetBranch(u, r, "main") + gotBranch, gotCommit, err := client.GetBranch(context.TODO(), u, r, "main") if err != nil { t.Errorf("Status returned err: %v", err) diff --git a/scm/github/testdata/get_pull_request.json b/scm/github/testdata/get_pull_request.json index c5dcc6467..455dc9c76 100644 --- a/scm/github/testdata/get_pull_request.json +++ b/scm/github/testdata/get_pull_request.json @@ -291,7 +291,7 @@ "stargazers_count": 80, "watchers_count": 80, "size": 108, - "default_branch": "master", + "default_branch": "main", "open_issues_count": 0, "is_template": true, "topics": [ @@ -326,8 +326,8 @@ } }, "base": { - "label": "octocat:master", - "ref": "master", + "label": "octocat:main", + "ref": "main", "sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e", "user": { "login": "octocat", @@ -426,7 +426,7 @@ "stargazers_count": 80, "watchers_count": 80, "size": 108, - "default_branch": "master", + "default_branch": "main", "open_issues_count": 0, "is_template": true, "topics": [ diff --git a/scm/github/testdata/get_repo.json b/scm/github/testdata/get_repo.json index 630ce53e5..4e110616d 100644 --- a/scm/github/testdata/get_repo.json +++ b/scm/github/testdata/get_repo.json @@ -75,7 +75,7 @@ "stargazers_count": 80, "watchers_count": 80, "size": 108, - "default_branch": "master", + "default_branch": "main", "open_issues_count": 0, "is_template": true, "topics": [ diff --git a/scm/github/testdata/hooks/deployment.json b/scm/github/testdata/hooks/deployment.json index 34b21e143..f12dae46d 100644 --- a/scm/github/testdata/hooks/deployment.json +++ b/scm/github/testdata/hooks/deployment.json @@ -5,7 +5,7 @@ "id": 145988746, "node_id": "MDEwOkRlcGxveW1lbnQxNDU5ODg3NDY=", "sha": "f95f852bd8fca8fcc58a9a2d6c842781e32a215e", - "ref": "master", + "ref": "main", "task": "deploy", "payload": { "foo": "test1", @@ -131,7 +131,7 @@ "forks": 1, "open_issues": 2, "watchers": 0, - "default_branch": "master" + "default_branch": "main" }, "sender": { "login": "Codertocat", diff --git a/scm/github/testdata/hooks/deployment_commit.json b/scm/github/testdata/hooks/deployment_commit.json index fbbfa7553..528d9eeb8 100644 --- a/scm/github/testdata/hooks/deployment_commit.json +++ b/scm/github/testdata/hooks/deployment_commit.json @@ -129,7 +129,7 @@ "forks": 1, "open_issues": 2, "watchers": 0, - "default_branch": "master" + "default_branch": "main" }, "sender": { "login": "Codertocat", diff --git a/scm/github/testdata/hooks/deployment_unexpected_json_payload.json b/scm/github/testdata/hooks/deployment_unexpected_json_payload.json index c49f9a84a..5fad3f6c3 100644 --- a/scm/github/testdata/hooks/deployment_unexpected_json_payload.json +++ b/scm/github/testdata/hooks/deployment_unexpected_json_payload.json @@ -5,7 +5,7 @@ "id": 145988746, "node_id": "MDEwOkRlcGxveW1lbnQxNDU5ODg3NDY=", "sha": "f95f852bd8fca8fcc58a9a2d6c842781e32a215e", - "ref": "master", + "ref": "main", "task": "deploy", "payload": { "foo": { @@ -132,7 +132,7 @@ "forks": 1, "open_issues": 2, "watchers": 0, - "default_branch": "master" + "default_branch": "main" }, "sender": { "login": "Codertocat", diff --git a/scm/github/testdata/hooks/deployment_unexpected_text_payload.json b/scm/github/testdata/hooks/deployment_unexpected_text_payload.json index c91a9ebed..a4de6c8d3 100644 --- a/scm/github/testdata/hooks/deployment_unexpected_text_payload.json +++ b/scm/github/testdata/hooks/deployment_unexpected_text_payload.json @@ -5,7 +5,7 @@ "id": 145988746, "node_id": "MDEwOkRlcGxveW1lbnQxNDU5ODg3NDY=", "sha": "f95f852bd8fca8fcc58a9a2d6c842781e32a215e", - "ref": "master", + "ref": "main", "task": "deploy", "payload": "foo", "original_environment": "production", @@ -128,7 +128,7 @@ "forks": 1, "open_issues": 2, "watchers": 0, - "default_branch": "master" + "default_branch": "main" }, "sender": { "login": "Codertocat", diff --git a/scm/github/testdata/hooks/issue_comment_created.json b/scm/github/testdata/hooks/issue_comment_created.json index aab7789cc..dd5cb87f5 100644 --- a/scm/github/testdata/hooks/issue_comment_created.json +++ b/scm/github/testdata/hooks/issue_comment_created.json @@ -171,7 +171,7 @@ "forks": 0, "open_issues": 1, "watchers": 0, - "default_branch": "master" + "default_branch": "main" }, "sender": { "login": "Codertocat", diff --git a/scm/github/testdata/hooks/issue_comment_deleted.json b/scm/github/testdata/hooks/issue_comment_deleted.json index 42a5552fc..501dbc837 100644 --- a/scm/github/testdata/hooks/issue_comment_deleted.json +++ b/scm/github/testdata/hooks/issue_comment_deleted.json @@ -171,7 +171,7 @@ "forks": 0, "open_issues": 1, "watchers": 0, - "default_branch": "master" + "default_branch": "main" }, "sender": { "login": "Codertocat", diff --git a/scm/github/testdata/hooks/issue_comment_pr.json b/scm/github/testdata/hooks/issue_comment_pr.json index 4cfae19ae..fa162ed02 100644 --- a/scm/github/testdata/hooks/issue_comment_pr.json +++ b/scm/github/testdata/hooks/issue_comment_pr.json @@ -177,7 +177,7 @@ "forks": 0, "open_issues": 1, "watchers": 0, - "default_branch": "master" + "default_branch": "main" }, "sender": { "login": "Codertocat", diff --git a/scm/github/testdata/hooks/pull_request.json b/scm/github/testdata/hooks/pull_request.json index ffcd0c4a1..2d16c9ee7 100644 --- a/scm/github/testdata/hooks/pull_request.json +++ b/scm/github/testdata/hooks/pull_request.json @@ -33,7 +33,7 @@ "type": "User", "site_admin": false }, - "body": "This is a pretty simple change that we need to pull into master.", + "body": "This is a pretty simple change that we need to pull into main.", "created_at": "2018-05-30T20:18:30Z", "updated_at": "2018-05-30T20:18:50Z", "closed_at": "2018-05-30T20:18:50Z", @@ -173,12 +173,12 @@ "forks": 0, "open_issues": 1, "watchers": 0, - "default_branch": "master" + "default_branch": "main" } }, "base": { - "label": "Codertocat:master", - "ref": "master", + "label": "Codertocat:main", + "ref": "main", "sha": "a10867b14bb761a232cd80139fbd4c0d33264240", "user": { "login": "Codertocat", @@ -291,7 +291,7 @@ "forks": 0, "open_issues": 1, "watchers": 0, - "default_branch": "master" + "default_branch": "main" } }, "_links": { @@ -425,7 +425,7 @@ "forks": 0, "open_issues": 1, "watchers": 0, - "default_branch": "master" + "default_branch": "main" }, "sender": { "login": "Codertocat", diff --git a/scm/github/testdata/hooks/pull_request_closed_action.json b/scm/github/testdata/hooks/pull_request_closed_action.json index cc6380473..5aecb6806 100644 --- a/scm/github/testdata/hooks/pull_request_closed_action.json +++ b/scm/github/testdata/hooks/pull_request_closed_action.json @@ -33,7 +33,7 @@ "type": "User", "site_admin": false }, - "body": "This is a pretty simple change that we need to pull into master.", + "body": "This is a pretty simple change that we need to pull into main.", "created_at": "2018-05-30T20:18:30Z", "updated_at": "2018-05-30T20:18:50Z", "closed_at": "2018-05-30T20:18:50Z", @@ -173,12 +173,12 @@ "forks": 0, "open_issues": 1, "watchers": 0, - "default_branch": "master" + "default_branch": "main" } }, "base": { - "label": "Codertocat:master", - "ref": "master", + "label": "Codertocat:main", + "ref": "main", "sha": "a10867b14bb761a232cd80139fbd4c0d33264240", "user": { "login": "Codertocat", @@ -291,7 +291,7 @@ "forks": 0, "open_issues": 1, "watchers": 0, - "default_branch": "master" + "default_branch": "main" } }, "_links": { @@ -425,7 +425,7 @@ "forks": 0, "open_issues": 1, "watchers": 0, - "default_branch": "master" + "default_branch": "main" }, "sender": { "login": "Codertocat", diff --git a/scm/github/testdata/hooks/pull_request_closed_state.json b/scm/github/testdata/hooks/pull_request_closed_state.json index a74a828e8..65491ce94 100644 --- a/scm/github/testdata/hooks/pull_request_closed_state.json +++ b/scm/github/testdata/hooks/pull_request_closed_state.json @@ -33,7 +33,7 @@ "type": "User", "site_admin": false }, - "body": "This is a pretty simple change that we need to pull into master.", + "body": "This is a pretty simple change that we need to pull into main.", "created_at": "2018-05-30T20:18:30Z", "updated_at": "2018-05-30T20:18:50Z", "closed_at": "2018-05-30T20:18:50Z", @@ -173,12 +173,12 @@ "forks": 0, "open_issues": 1, "watchers": 0, - "default_branch": "master" + "default_branch": "main" } }, "base": { - "label": "Codertocat:master", - "ref": "master", + "label": "Codertocat:main", + "ref": "main", "sha": "a10867b14bb761a232cd80139fbd4c0d33264240", "user": { "login": "Codertocat", @@ -291,7 +291,7 @@ "forks": 0, "open_issues": 1, "watchers": 0, - "default_branch": "master" + "default_branch": "main" } }, "_links": { @@ -425,7 +425,7 @@ "forks": 0, "open_issues": 1, "watchers": 0, - "default_branch": "master" + "default_branch": "main" }, "sender": { "login": "Codertocat", diff --git a/scm/github/testdata/hooks/push.json b/scm/github/testdata/hooks/push.json index 7058efe6b..9bc15cdb0 100644 --- a/scm/github/testdata/hooks/push.json +++ b/scm/github/testdata/hooks/push.json @@ -1,5 +1,5 @@ { - "ref": "refs/heads/master", + "ref": "refs/heads/main", "before": "d3d9188fc87a6977343e922c128f162a86018d76", "after": "9c93babf58917cd6f6f6772b5df2b098f507ff95", "created": false, @@ -154,9 +154,9 @@ "forks": 0, "open_issues": 2, "watchers": 0, - "default_branch": "master", + "default_branch": "main", "stargazers": 0, - "master_branch": "master", + "master_branch": "main", "topics": [ "go", "vela" diff --git a/scm/github/testdata/hooks/push_no_sender.json b/scm/github/testdata/hooks/push_no_sender.json index f9bef26d3..b87fc8c93 100644 --- a/scm/github/testdata/hooks/push_no_sender.json +++ b/scm/github/testdata/hooks/push_no_sender.json @@ -1,5 +1,5 @@ { - "ref": "refs/heads/master", + "ref": "refs/heads/main", "before": "d3d9188fc87a6977343e922c128f162a86018d76", "after": "9c93babf58917cd6f6f6772b5df2b098f507ff95", "created": false, @@ -154,9 +154,9 @@ "forks": 0, "open_issues": 2, "watchers": 0, - "default_branch": "master", + "default_branch": "main", "stargazers": 0, - "master_branch": "master", + "master_branch": "main", "topics": [ "go", "vela" diff --git a/scm/github/testdata/hooks/repository_archived.json b/scm/github/testdata/hooks/repository_archived.json index b9c0ff71b..2cc42e07a 100644 --- a/scm/github/testdata/hooks/repository_archived.json +++ b/scm/github/testdata/hooks/repository_archived.json @@ -92,7 +92,7 @@ "forks": 0, "open_issues": 2, "watchers": 0, - "default_branch": "master" + "default_branch": "main" }, "enterprise": { "id": 1, diff --git a/scm/github/testdata/hooks/repository_publicized.json b/scm/github/testdata/hooks/repository_publicized.json index 50d8ff5d1..e75125ebe 100644 --- a/scm/github/testdata/hooks/repository_publicized.json +++ b/scm/github/testdata/hooks/repository_publicized.json @@ -92,7 +92,7 @@ "forks": 0, "open_issues": 2, "watchers": 0, - "default_branch": "master" + "default_branch": "main" }, "enterprise": { "id": 1, diff --git a/scm/github/testdata/hooks/repository_rename.json b/scm/github/testdata/hooks/repository_rename.json index 69652ce44..51f49ff4b 100644 --- a/scm/github/testdata/hooks/repository_rename.json +++ b/scm/github/testdata/hooks/repository_rename.json @@ -99,7 +99,7 @@ "forks": 0, "open_issues": 2, "watchers": 0, - "default_branch": "master" + "default_branch": "main" }, "enterprise": { "id": 1, diff --git a/scm/github/testdata/hooks/repository_transferred.json b/scm/github/testdata/hooks/repository_transferred.json index 2fdea23f6..37e9b2f83 100644 --- a/scm/github/testdata/hooks/repository_transferred.json +++ b/scm/github/testdata/hooks/repository_transferred.json @@ -118,7 +118,7 @@ "forks": 0, "open_issues": 2, "watchers": 0, - "default_branch": "master" + "default_branch": "main" }, "enterprise": { "id": 1, diff --git a/scm/github/testdata/listuserrepos.json b/scm/github/testdata/listuserrepos.json index 4cfcb4253..acbe35a85 100644 --- a/scm/github/testdata/listuserrepos.json +++ b/scm/github/testdata/listuserrepos.json @@ -76,7 +76,7 @@ "stargazers_count": 80, "watchers_count": 80, "size": 108, - "default_branch": "master", + "default_branch": "main", "open_issues_count": 0, "is_template": true, "topics": [ diff --git a/scm/github/testdata/listuserrepos_ineligible.json b/scm/github/testdata/listuserrepos_ineligible.json index dec89bc8f..1cd26690c 100644 --- a/scm/github/testdata/listuserrepos_ineligible.json +++ b/scm/github/testdata/listuserrepos_ineligible.json @@ -76,7 +76,7 @@ "stargazers_count": 80, "watchers_count": 80, "size": 108, - "default_branch": "master", + "default_branch": "main", "open_issues_count": 0, "is_template": true, "topics": [ @@ -188,7 +188,7 @@ "stargazers_count": 80, "watchers_count": 80, "size": 108, - "default_branch": "master", + "default_branch": "main", "open_issues_count": 0, "is_template": true, "topics": [ diff --git a/scm/github/testdata/py.json b/scm/github/testdata/py.json index 6e9917242..cd33aa29e 100644 --- a/scm/github/testdata/py.json +++ b/scm/github/testdata/py.json @@ -8,11 +8,11 @@ "sha": "3d21ec53a331a6f037a91c368710b99387d012c1", "url": "https://api.github.com/repos/octokit/octokit.rb/contents/.vela.py", "git_url": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/3d21ec53a331a6f037a91c368710b99387d012c1", - "html_url": "https://github.com/octokit/octokit.rb/blob/master/.vela.py", - "download_url": "https://raw.githubusercontent.com/octokit/octokit.rb/master/.vela.py", + "html_url": "https://github.com/octokit/octokit.rb/blob/main/.vela.py", + "download_url": "https://raw.githubusercontent.com/octokit/octokit.rb/main/.vela.py", "_links": { "git": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/3d21ec53a331a6f037a91c368710b99387d012c1", "self": "https://api.github.com/repos/octokit/octokit.rb/contents/.vela.py", - "html": "https://github.com/octokit/octokit.rb/blob/master/.vela.py" + "html": "https://github.com/octokit/octokit.rb/blob/main/.vela.py" } } diff --git a/scm/github/testdata/star.json b/scm/github/testdata/star.json index e1bc3a00d..b6d909593 100644 --- a/scm/github/testdata/star.json +++ b/scm/github/testdata/star.json @@ -8,11 +8,11 @@ "sha": "3d21ec53a331a6f037a91c368710b99387d012c1", "url": "https://api.github.com/repos/octokit/octokit.rb/contents/.vela.star", "git_url": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/3d21ec53a331a6f037a91c368710b99387d012c1", - "html_url": "https://github.com/octokit/octokit.rb/blob/master/.vela.star", - "download_url": "https://raw.githubusercontent.com/octokit/octokit.rb/master/.vela.star", + "html_url": "https://github.com/octokit/octokit.rb/blob/main/.vela.star", + "download_url": "https://raw.githubusercontent.com/octokit/octokit.rb/main/.vela.star", "_links": { "git": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/3d21ec53a331a6f037a91c368710b99387d012c1", "self": "https://api.github.com/repos/octokit/octokit.rb/contents/.vela.star", - "html": "https://github.com/octokit/octokit.rb/blob/master/.vela.star" + "html": "https://github.com/octokit/octokit.rb/blob/main/.vela.star" } } diff --git a/scm/github/testdata/yaml.json b/scm/github/testdata/yaml.json index fd1ec65f1..f8c6acab3 100644 --- a/scm/github/testdata/yaml.json +++ b/scm/github/testdata/yaml.json @@ -8,11 +8,11 @@ "sha": "3d21ec53a331a6f037a91c368710b99387d012c1", "url": "https://api.github.com/repos/octokit/octokit.rb/contents/.vela.yaml", "git_url": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/3d21ec53a331a6f037a91c368710b99387d012c1", - "html_url": "https://github.com/octokit/octokit.rb/blob/master/.vela.yaml", - "download_url": "https://raw.githubusercontent.com/octokit/octokit.rb/master/.vela.yaml", + "html_url": "https://github.com/octokit/octokit.rb/blob/main/.vela.yaml", + "download_url": "https://raw.githubusercontent.com/octokit/octokit.rb/main/.vela.yaml", "_links": { "git": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/3d21ec53a331a6f037a91c368710b99387d012c1", "self": "https://api.github.com/repos/octokit/octokit.rb/contents/.vela.yaml", - "html": "https://github.com/octokit/octokit.rb/blob/master/.vela.yaml" + "html": "https://github.com/octokit/octokit.rb/blob/main/.vela.yaml" } } diff --git a/scm/github/testdata/yml.json b/scm/github/testdata/yml.json index 9364dec2f..a84c704be 100644 --- a/scm/github/testdata/yml.json +++ b/scm/github/testdata/yml.json @@ -8,11 +8,11 @@ "sha": "3d21ec53a331a6f037a91c368710b99387d012c1", "url": "https://api.github.com/repos/octokit/octokit.rb/contents/.vela.yml", "git_url": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/3d21ec53a331a6f037a91c368710b99387d012c1", - "html_url": "https://github.com/octokit/octokit.rb/blob/master/.vela.yml", - "download_url": "https://raw.githubusercontent.com/octokit/octokit.rb/master/.vela.yml", + "html_url": "https://github.com/octokit/octokit.rb/blob/main/.vela.yml", + "download_url": "https://raw.githubusercontent.com/octokit/octokit.rb/main/.vela.yml", "_links": { "git": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/3d21ec53a331a6f037a91c368710b99387d012c1", "self": "https://api.github.com/repos/octokit/octokit.rb/contents/.vela.yml", - "html": "https://github.com/octokit/octokit.rb/blob/master/.vela.yml" + "html": "https://github.com/octokit/octokit.rb/blob/main/.vela.yml" } } diff --git a/scm/github/webhook.go b/scm/github/webhook.go index 3c7d1e0b3..9e243df29 100644 --- a/scm/github/webhook.go +++ b/scm/github/webhook.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package github @@ -20,13 +18,13 @@ import ( "github.com/go-vela/types" "github.com/go-vela/types/constants" "github.com/go-vela/types/library" - "github.com/google/go-github/v54/github" + "github.com/google/go-github/v56/github" ) // ProcessWebhook parses the webhook from a repo. // //nolint:nilerr // ignore webhook returning nil -func (c *client) ProcessWebhook(request *http.Request) (*types.Webhook, error) { +func (c *client) ProcessWebhook(ctx context.Context, request *http.Request) (*types.Webhook, error) { c.Logger.Tracef("processing GitHub webhook") // create our own record of the hook and populate its fields @@ -85,7 +83,7 @@ func (c *client) ProcessWebhook(request *http.Request) (*types.Webhook, error) { } // VerifyWebhook verifies the webhook from a repo. -func (c *client) VerifyWebhook(request *http.Request, r *library.Repo) error { +func (c *client) VerifyWebhook(ctx context.Context, request *http.Request, r *library.Repo) error { c.Logger.WithFields(logrus.Fields{ "org": r.GetOrg(), "repo": r.GetName(), @@ -225,9 +223,10 @@ func (c *client) processPREvent(h *library.Hook, payload *github.PullRequestEven return &types.Webhook{Hook: h}, nil } - // skip if the pull request action is not opened, synchronize + // skip if the pull request action is not opened, synchronize, or reopened if !strings.EqualFold(payload.GetAction(), "opened") && - !strings.EqualFold(payload.GetAction(), "synchronize") { + !strings.EqualFold(payload.GetAction(), "synchronize") && + !strings.EqualFold(payload.GetAction(), "reopened") { return &types.Webhook{Hook: h}, nil } diff --git a/scm/github/webhook_test.go b/scm/github/webhook_test.go index bac0692be..59139a99f 100644 --- a/scm/github/webhook_test.go +++ b/scm/github/webhook_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package github @@ -54,7 +52,7 @@ func TestGithub_ProcessWebhook_Push(t *testing.T) { wantHook.SetCreated(time.Now().UTC().Unix()) wantHook.SetHost("github.com") wantHook.SetEvent("push") - wantHook.SetBranch("master") + wantHook.SetBranch("main") wantHook.SetStatus(constants.StatusSuccess) wantHook.SetLink("https://github.com/Codertocat/Hello-World/settings/hooks") @@ -64,7 +62,7 @@ func TestGithub_ProcessWebhook_Push(t *testing.T) { wantRepo.SetFullName("Codertocat/Hello-World") wantRepo.SetLink("https://github.com/Codertocat/Hello-World") wantRepo.SetClone("https://github.com/Codertocat/Hello-World.git") - wantRepo.SetBranch("master") + wantRepo.SetBranch("main") wantRepo.SetPrivate(false) wantRepo.SetTopics([]string{"go", "vela"}) @@ -78,8 +76,8 @@ func TestGithub_ProcessWebhook_Push(t *testing.T) { wantBuild.SetSender("Codertocat") wantBuild.SetAuthor("Codertocat") wantBuild.SetEmail("21031067+Codertocat@users.noreply.github.com") - wantBuild.SetBranch("master") - wantBuild.SetRef("refs/heads/master") + wantBuild.SetBranch("main") + wantBuild.SetRef("refs/heads/main") wantBuild.SetBaseRef("") want := &types.Webhook{ @@ -89,7 +87,7 @@ func TestGithub_ProcessWebhook_Push(t *testing.T) { Build: wantBuild, } - got, err := client.ProcessWebhook(request) + got, err := client.ProcessWebhook(context.TODO(), request) if err != nil { t.Errorf("ProcessWebhook returned err: %v", err) @@ -133,7 +131,7 @@ func TestGithub_ProcessWebhook_Push_NoSender(t *testing.T) { wantHook.SetCreated(time.Now().UTC().Unix()) wantHook.SetHost("github.com") wantHook.SetEvent("push") - wantHook.SetBranch("master") + wantHook.SetBranch("main") wantHook.SetStatus(constants.StatusSuccess) wantHook.SetLink("https://github.com/Codertocat/Hello-World/settings/hooks") @@ -143,7 +141,7 @@ func TestGithub_ProcessWebhook_Push_NoSender(t *testing.T) { wantRepo.SetFullName("Codertocat/Hello-World") wantRepo.SetLink("https://github.com/Codertocat/Hello-World") wantRepo.SetClone("https://github.com/Codertocat/Hello-World.git") - wantRepo.SetBranch("master") + wantRepo.SetBranch("main") wantRepo.SetPrivate(false) wantRepo.SetTopics([]string{"go", "vela"}) @@ -157,8 +155,8 @@ func TestGithub_ProcessWebhook_Push_NoSender(t *testing.T) { wantBuild.SetSender("Codertocat") wantBuild.SetAuthor("Codertocat") wantBuild.SetEmail("21031067+Codertocat@users.noreply.github.com") - wantBuild.SetBranch("master") - wantBuild.SetRef("refs/heads/master") + wantBuild.SetBranch("main") + wantBuild.SetRef("refs/heads/main") wantBuild.SetBaseRef("") want := &types.Webhook{ @@ -168,7 +166,7 @@ func TestGithub_ProcessWebhook_Push_NoSender(t *testing.T) { Build: wantBuild, } - got, err := client.ProcessWebhook(request) + got, err := client.ProcessWebhook(context.TODO(), request) if err != nil { t.Errorf("ProcessWebhook returned err: %v", err) @@ -212,7 +210,7 @@ func TestGithub_ProcessWebhook_PullRequest(t *testing.T) { wantHook.SetCreated(time.Now().UTC().Unix()) wantHook.SetHost("github.com") wantHook.SetEvent("pull_request") - wantHook.SetBranch("master") + wantHook.SetBranch("main") wantHook.SetStatus(constants.StatusSuccess) wantHook.SetLink("https://github.com/Codertocat/Hello-World/settings/hooks") @@ -222,7 +220,7 @@ func TestGithub_ProcessWebhook_PullRequest(t *testing.T) { wantRepo.SetFullName("Codertocat/Hello-World") wantRepo.SetLink("https://github.com/Codertocat/Hello-World") wantRepo.SetClone("https://github.com/Codertocat/Hello-World.git") - wantRepo.SetBranch("master") + wantRepo.SetBranch("main") wantRepo.SetPrivate(false) wantRepo.SetTopics(nil) @@ -237,9 +235,9 @@ func TestGithub_ProcessWebhook_PullRequest(t *testing.T) { wantBuild.SetSender("Codertocat") wantBuild.SetAuthor("Codertocat") wantBuild.SetEmail("") - wantBuild.SetBranch("master") + wantBuild.SetBranch("main") wantBuild.SetRef("refs/pull/1/head") - wantBuild.SetBaseRef("master") + wantBuild.SetBaseRef("main") wantBuild.SetHeadRef("changes") want := &types.Webhook{ @@ -250,7 +248,7 @@ func TestGithub_ProcessWebhook_PullRequest(t *testing.T) { Build: wantBuild, } - got, err := client.ProcessWebhook(request) + got, err := client.ProcessWebhook(context.TODO(), request) if err != nil { t.Errorf("ProcessWebhook returned err: %v", err) @@ -294,7 +292,7 @@ func TestGithub_ProcessWebhook_PullRequest_ClosedAction(t *testing.T) { wantHook.SetCreated(time.Now().UTC().Unix()) wantHook.SetHost("github.com") wantHook.SetEvent("pull_request") - wantHook.SetBranch("master") + wantHook.SetBranch("main") wantHook.SetStatus(constants.StatusSuccess) wantHook.SetLink("https://github.com/Codertocat/Hello-World/settings/hooks") @@ -305,7 +303,7 @@ func TestGithub_ProcessWebhook_PullRequest_ClosedAction(t *testing.T) { Build: nil, } - got, err := client.ProcessWebhook(request) + got, err := client.ProcessWebhook(context.TODO(), request) if err != nil { t.Errorf("ProcessWebhook returned err: %v", err) @@ -349,7 +347,7 @@ func TestGithub_ProcessWebhook_PullRequest_ClosedState(t *testing.T) { wantHook.SetCreated(time.Now().UTC().Unix()) wantHook.SetHost("github.com") wantHook.SetEvent("pull_request") - wantHook.SetBranch("master") + wantHook.SetBranch("main") wantHook.SetStatus(constants.StatusSuccess) wantHook.SetLink("https://github.com/Codertocat/Hello-World/settings/hooks") @@ -360,7 +358,7 @@ func TestGithub_ProcessWebhook_PullRequest_ClosedState(t *testing.T) { Build: nil, } - got, err := client.ProcessWebhook(request) + got, err := client.ProcessWebhook(context.TODO(), request) if err != nil { t.Errorf("ProcessWebhook returned err: %v", err) @@ -381,7 +379,7 @@ func TestGithub_ProcessWebhook_Deployment(t *testing.T) { wantHook.SetSourceID("7bd477e4-4415-11e9-9359-0d41fdf9567e") wantHook.SetWebhookID(123456) wantHook.SetCreated(time.Now().UTC().Unix()) - wantHook.SetBranch("master") + wantHook.SetBranch("main") wantHook.SetLink("https://github.com/Codertocat/Hello-World/settings/hooks") wantHook.SetHost("github.com") wantHook.SetEvent("deployment") @@ -393,7 +391,7 @@ func TestGithub_ProcessWebhook_Deployment(t *testing.T) { wantRepo.SetFullName("Codertocat/Hello-World") wantRepo.SetLink("https://github.com/Codertocat/Hello-World") wantRepo.SetClone("https://github.com/Codertocat/Hello-World.git") - wantRepo.SetBranch("master") + wantRepo.SetBranch("main") wantRepo.SetPrivate(false) wantRepo.SetTopics(nil) @@ -408,8 +406,8 @@ func TestGithub_ProcessWebhook_Deployment(t *testing.T) { wantBuild.SetSender("Codertocat") wantBuild.SetAuthor("Codertocat") wantBuild.SetEmail("") - wantBuild.SetBranch("master") - wantBuild.SetRef("refs/heads/master") + wantBuild.SetBranch("main") + wantBuild.SetRef("refs/heads/main") type args struct { file string @@ -457,7 +455,7 @@ func TestGithub_ProcessWebhook_Deployment(t *testing.T) { Build: tt.args.build, } - got, err := client.ProcessWebhook(request) + got, err := client.ProcessWebhook(context.TODO(), request) if (err != nil) != tt.wantErr { t.Errorf("ProcessWebhook() error = %v, wantErr %v", err, tt.wantErr) return @@ -501,7 +499,7 @@ func TestGithub_ProcessWebhook_Deployment_Commit(t *testing.T) { wantHook.SetSourceID("7bd477e4-4415-11e9-9359-0d41fdf9567e") wantHook.SetWebhookID(123456) wantHook.SetCreated(time.Now().UTC().Unix()) - wantHook.SetBranch("master") + wantHook.SetBranch("main") wantHook.SetLink("https://github.com/Codertocat/Hello-World/settings/hooks") wantHook.SetHost("github.com") wantHook.SetEvent("deployment") @@ -513,7 +511,7 @@ func TestGithub_ProcessWebhook_Deployment_Commit(t *testing.T) { wantRepo.SetFullName("Codertocat/Hello-World") wantRepo.SetLink("https://github.com/Codertocat/Hello-World") wantRepo.SetClone("https://github.com/Codertocat/Hello-World.git") - wantRepo.SetBranch("master") + wantRepo.SetBranch("main") wantRepo.SetPrivate(false) wantRepo.SetTopics(nil) @@ -528,8 +526,8 @@ func TestGithub_ProcessWebhook_Deployment_Commit(t *testing.T) { wantBuild.SetSender("Codertocat") wantBuild.SetAuthor("Codertocat") wantBuild.SetEmail("") - wantBuild.SetBranch("master") - wantBuild.SetRef("refs/heads/master") + wantBuild.SetBranch("main") + wantBuild.SetRef("refs/heads/main") want := &types.Webhook{ Comment: "", @@ -538,7 +536,7 @@ func TestGithub_ProcessWebhook_Deployment_Commit(t *testing.T) { Build: wantBuild, } - got, err := client.ProcessWebhook(request) + got, err := client.ProcessWebhook(context.TODO(), request) if err != nil { t.Errorf("ProcessWebhook returned err: %v", err) @@ -591,7 +589,7 @@ func TestGithub_ProcessWebhook_BadGithubEvent(t *testing.T) { Build: nil, } - got, err := client.ProcessWebhook(request) + got, err := client.ProcessWebhook(context.TODO(), request) if err != nil { t.Errorf("ProcessWebhook returned err: %v", err) @@ -644,7 +642,7 @@ func TestGithub_ProcessWebhook_BadContentType(t *testing.T) { Build: nil, } - got, err := client.ProcessWebhook(request) + got, err := client.ProcessWebhook(context.TODO(), request) if err != nil { t.Errorf("ProcessWebhook returned err: %v", err) @@ -681,7 +679,7 @@ func TestGithub_VerifyWebhook_EmptyRepo(t *testing.T) { client, _ := NewTest(s.URL) // run test - err = client.VerifyWebhook(request, new(library.Repo)) + err = client.VerifyWebhook(context.TODO(), request, new(library.Repo)) if err != nil { t.Errorf("VerifyWebhook should have returned err") } @@ -698,7 +696,7 @@ func TestGithub_VerifyWebhook_NoSecret(t *testing.T) { r.SetFullName("Codertocat/Hello-World") r.SetLink("https://github.com/Codertocat/Hello-World") r.SetClone("https://github.com/Codertocat/Hello-World.git") - r.SetBranch("master") + r.SetBranch("main") r.SetPrivate(false) // setup request @@ -722,7 +720,7 @@ func TestGithub_VerifyWebhook_NoSecret(t *testing.T) { client, _ := NewTest(s.URL) // run test - err = client.VerifyWebhook(request, r) + err = client.VerifyWebhook(context.TODO(), request, r) if err != nil { t.Errorf("VerifyWebhook should have returned err") } @@ -770,7 +768,7 @@ func TestGithub_ProcessWebhook_IssueComment_PR(t *testing.T) { wantRepo.SetFullName("Codertocat/Hello-World") wantRepo.SetLink("https://github.com/Codertocat/Hello-World") wantRepo.SetClone("https://github.com/Codertocat/Hello-World.git") - wantRepo.SetBranch("master") + wantRepo.SetBranch("main") wantRepo.SetPrivate(false) wantRepo.SetTopics(nil) @@ -794,7 +792,7 @@ func TestGithub_ProcessWebhook_IssueComment_PR(t *testing.T) { Build: wantBuild, } - got, err := client.ProcessWebhook(request) + got, err := client.ProcessWebhook(context.TODO(), request) if err != nil { t.Errorf("ProcessWebhook returned err: %v", err) @@ -847,7 +845,7 @@ func TestGithub_ProcessWebhook_IssueComment_Created(t *testing.T) { wantRepo.SetFullName("Codertocat/Hello-World") wantRepo.SetLink("https://github.com/Codertocat/Hello-World") wantRepo.SetClone("https://github.com/Codertocat/Hello-World.git") - wantRepo.SetBranch("master") + wantRepo.SetBranch("main") wantRepo.SetPrivate(false) wantRepo.SetTopics(nil) @@ -861,7 +859,7 @@ func TestGithub_ProcessWebhook_IssueComment_Created(t *testing.T) { wantBuild.SetSender("Codertocat") wantBuild.SetAuthor("Codertocat") wantBuild.SetEmail("") - wantBuild.SetRef("refs/heads/master") + wantBuild.SetRef("refs/heads/main") want := &types.Webhook{ Comment: "ok to test", @@ -871,7 +869,7 @@ func TestGithub_ProcessWebhook_IssueComment_Created(t *testing.T) { Build: wantBuild, } - got, err := client.ProcessWebhook(request) + got, err := client.ProcessWebhook(context.TODO(), request) if err != nil { t.Errorf("ProcessWebhook returned err: %v", err) @@ -926,7 +924,7 @@ func TestGithub_ProcessWebhook_IssueComment_Deleted(t *testing.T) { Build: nil, } - got, err := client.ProcessWebhook(request) + got, err := client.ProcessWebhook(context.TODO(), request) if err != nil { t.Errorf("ProcessWebhook returned err: %v", err) @@ -969,7 +967,7 @@ func TestGitHub_ProcessWebhook_RepositoryRename(t *testing.T) { wantHook.SetHost("github.com") wantHook.SetEvent(constants.EventRepository) wantHook.SetEventAction(constants.ActionRenamed) - wantHook.SetBranch("master") + wantHook.SetBranch("main") wantHook.SetStatus(constants.StatusSuccess) wantHook.SetLink("https://github.com/Codertocat/Hello-World/settings/hooks") @@ -980,7 +978,7 @@ func TestGitHub_ProcessWebhook_RepositoryRename(t *testing.T) { wantRepo.SetFullName("Codertocat/Hello-World") wantRepo.SetLink("https://octocoders.github.io/Codertocat/Hello-World") wantRepo.SetClone("https://octocoders.github.io/Codertocat/Hello-World.git") - wantRepo.SetBranch("master") + wantRepo.SetBranch("main") wantRepo.SetPrivate(false) wantRepo.SetTopics(nil) @@ -990,7 +988,7 @@ func TestGitHub_ProcessWebhook_RepositoryRename(t *testing.T) { Repo: wantRepo, } - got, err := client.ProcessWebhook(request) + got, err := client.ProcessWebhook(context.TODO(), request) if err != nil { t.Errorf("ProcessWebhook returned err: %v", err) @@ -1033,7 +1031,7 @@ func TestGitHub_ProcessWebhook_RepositoryTransfer(t *testing.T) { wantHook.SetHost("github.com") wantHook.SetEvent(constants.EventRepository) wantHook.SetEventAction(constants.ActionTransferred) - wantHook.SetBranch("master") + wantHook.SetBranch("main") wantHook.SetStatus(constants.StatusSuccess) wantHook.SetLink("https://github.com/Codertocat/Hello-World/settings/hooks") @@ -1044,7 +1042,7 @@ func TestGitHub_ProcessWebhook_RepositoryTransfer(t *testing.T) { wantRepo.SetFullName("Codertocat/Hello-World") wantRepo.SetLink("https://octocoders.github.io/Codertocat/Hello-World") wantRepo.SetClone("https://octocoders.github.io/Codertocat/Hello-World.git") - wantRepo.SetBranch("master") + wantRepo.SetBranch("main") wantRepo.SetPrivate(false) wantRepo.SetTopics(nil) @@ -1054,7 +1052,7 @@ func TestGitHub_ProcessWebhook_RepositoryTransfer(t *testing.T) { Repo: wantRepo, } - got, err := client.ProcessWebhook(request) + got, err := client.ProcessWebhook(context.TODO(), request) if err != nil { t.Errorf("ProcessWebhook returned err: %v", err) @@ -1097,7 +1095,7 @@ func TestGitHub_ProcessWebhook_RepositoryArchived(t *testing.T) { wantHook.SetHost("github.com") wantHook.SetEvent(constants.EventRepository) wantHook.SetEventAction("archived") - wantHook.SetBranch("master") + wantHook.SetBranch("main") wantHook.SetStatus(constants.StatusSuccess) wantHook.SetLink("https://github.com/Codertocat/Hello-World/settings/hooks") @@ -1108,7 +1106,7 @@ func TestGitHub_ProcessWebhook_RepositoryArchived(t *testing.T) { wantRepo.SetFullName("Codertocat/Hello-World") wantRepo.SetLink("https://octocoders.github.io/Codertocat/Hello-World") wantRepo.SetClone("https://octocoders.github.io/Codertocat/Hello-World.git") - wantRepo.SetBranch("master") + wantRepo.SetBranch("main") wantRepo.SetPrivate(false) wantRepo.SetTopics(nil) @@ -1118,7 +1116,7 @@ func TestGitHub_ProcessWebhook_RepositoryArchived(t *testing.T) { Repo: wantRepo, } - got, err := client.ProcessWebhook(request) + got, err := client.ProcessWebhook(context.TODO(), request) if err != nil { t.Errorf("ProcessWebhook returned err: %v", err) @@ -1182,7 +1180,7 @@ func TestGitHub_ProcessWebhook_RepositoryEdited(t *testing.T) { Repo: wantRepo, } - got, err := client.ProcessWebhook(request) + got, err := client.ProcessWebhook(context.TODO(), request) if err != nil { t.Errorf("ProcessWebhook returned err: %v", err) @@ -1225,7 +1223,7 @@ func TestGitHub_ProcessWebhook_Repository(t *testing.T) { wantHook.SetHost("github.com") wantHook.SetEvent(constants.EventRepository) wantHook.SetEventAction("publicized") - wantHook.SetBranch("master") + wantHook.SetBranch("main") wantHook.SetStatus(constants.StatusSuccess) wantHook.SetLink("https://github.com/Codertocat/Hello-World/settings/hooks") @@ -1236,7 +1234,7 @@ func TestGitHub_ProcessWebhook_Repository(t *testing.T) { wantRepo.SetFullName("Codertocat/Hello-World") wantRepo.SetLink("https://octocoders.github.io/Codertocat/Hello-World") wantRepo.SetClone("https://octocoders.github.io/Codertocat/Hello-World.git") - wantRepo.SetBranch("master") + wantRepo.SetBranch("main") wantRepo.SetPrivate(false) wantRepo.SetTopics(nil) @@ -1246,7 +1244,7 @@ func TestGitHub_ProcessWebhook_Repository(t *testing.T) { Repo: wantRepo, } - got, err := client.ProcessWebhook(request) + got, err := client.ProcessWebhook(context.TODO(), request) if err != nil { t.Errorf("ProcessWebhook returned err: %v", err) @@ -1300,7 +1298,7 @@ func TestGithub_Redeliver_Webhook(t *testing.T) { client, _ := NewTest(s.URL, "https://foo.bar.com") // run test - err := client.RedeliverWebhook(ctx, u, _repo, _hook) + err := client.RedeliverWebhook(context.TODO(), u, _repo, _hook) if err != nil { t.Errorf("RedeliverWebhook returned err: %v", err) @@ -1348,7 +1346,7 @@ func TestGithub_GetDeliveryID(t *testing.T) { ghClient := client.newClientToken(*u.Token) // run test - got, err := client.getDeliveryID(ctx, ghClient, _repo, _hook) + got, err := client.getDeliveryID(context.TODO(), ghClient, _repo, _hook) if err != nil { t.Errorf("RedeliverWebhook returned err: %v", err) diff --git a/scm/scm.go b/scm/scm.go index 2bd5c8170..1614d80ea 100644 --- a/scm/scm.go +++ b/scm/scm.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package scm diff --git a/scm/scm_test.go b/scm/scm_test.go index d99b8bbac..233108758 100644 --- a/scm/scm_test.go +++ b/scm/scm_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package scm diff --git a/scm/service.go b/scm/service.go index ae9488724..1c394485d 100644 --- a/scm/service.go +++ b/scm/service.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package scm @@ -25,36 +23,40 @@ type Service interface { // Authorize defines a function that uses the // given access token to authorize the user. - Authorize(string) (string, error) + Authorize(context.Context, string) (string, error) // Authenticate defines a function that completes // the OAuth workflow for the session. - Authenticate(http.ResponseWriter, *http.Request, string) (*library.User, error) + Authenticate(context.Context, http.ResponseWriter, *http.Request, string) (*library.User, error) // AuthenticateToken defines a function that completes // the OAuth workflow for the session using PAT Token - AuthenticateToken(*http.Request) (*library.User, error) + AuthenticateToken(context.Context, *http.Request) (*library.User, error) + + // ValidateOAuthToken defines a function that validates + // an OAuth access token was created by Vela + ValidateOAuthToken(context.Context, string) (bool, error) // Login defines a function that begins // the OAuth workflow for the session. - Login(http.ResponseWriter, *http.Request) (string, error) + Login(context.Context, http.ResponseWriter, *http.Request) (string, error) // Access SCM Interface Functions // OrgAccess defines a function that captures // the user's access level for an org. - OrgAccess(*library.User, string) (string, error) + OrgAccess(context.Context, *library.User, string) (string, error) // RepoAccess defines a function that captures // the user's access level for a repo. - RepoAccess(*library.User, string, string, string) (string, error) + RepoAccess(context.Context, *library.User, string, string, string) (string, error) // TeamAccess defines a function that captures // the user's access level for a team. - TeamAccess(*library.User, string, string) (string, error) + TeamAccess(context.Context, *library.User, string, string) (string, error) // Teams SCM Interface Functions // ListUsersTeamsForOrg defines a function that captures // the user's teams for an org - ListUsersTeamsForOrg(*library.User, string) ([]string, error) + ListUsersTeamsForOrg(context.Context, *library.User, string) ([]string, error) // Changeset SCM Interface Functions @@ -62,79 +64,79 @@ type Service interface { // of files changed for a commit. // // https://en.wikipedia.org/wiki/Changeset. - Changeset(*library.User, *library.Repo, string) ([]string, error) + Changeset(context.Context, *library.User, *library.Repo, string) ([]string, error) // ChangesetPR defines a function that captures the list // of files changed for a pull request. // // https://en.wikipedia.org/wiki/Changeset. - ChangesetPR(*library.User, *library.Repo, int) ([]string, error) + ChangesetPR(context.Context, *library.User, *library.Repo, int) ([]string, error) // Deployment SCM Interface Functions // GetDeployment defines a function that // gets a deployment by number and repo. - GetDeployment(*library.User, *library.Repo, int64) (*library.Deployment, error) + GetDeployment(context.Context, *library.User, *library.Repo, int64) (*library.Deployment, error) // GetDeploymentCount defines a function that // counts a list of all deployment for a repo. - GetDeploymentCount(*library.User, *library.Repo) (int64, error) + GetDeploymentCount(context.Context, *library.User, *library.Repo) (int64, error) // GetDeploymentList defines a function that gets // a list of all deployments for a repo. - GetDeploymentList(*library.User, *library.Repo, int, int) ([]*library.Deployment, error) + GetDeploymentList(context.Context, *library.User, *library.Repo, int, int) ([]*library.Deployment, error) // CreateDeployment defines a function that // creates a new deployment. - CreateDeployment(*library.User, *library.Repo, *library.Deployment) error + CreateDeployment(context.Context, *library.User, *library.Repo, *library.Deployment) error // Repo SCM Interface Functions // Config defines a function that captures // the pipeline configuration from a repo. - Config(*library.User, *library.Repo, string) ([]byte, error) + Config(context.Context, *library.User, *library.Repo, string) ([]byte, error) // ConfigBackoff is a truncated constant backoff wrapper for Config. // Retry again in five seconds if Config fails to retrieve yaml/yml file. // Will return an error after five failed attempts. - ConfigBackoff(*library.User, *library.Repo, string) ([]byte, error) + ConfigBackoff(context.Context, *library.User, *library.Repo, string) ([]byte, error) // Disable defines a function that deactivates // a repo by destroying the webhook. - Disable(*library.User, string, string) error + Disable(context.Context, *library.User, string, string) error // Enable defines a function that activates // a repo by creating the webhook. - Enable(*library.User, *library.Repo, *library.Hook) (*library.Hook, string, error) + Enable(context.Context, *library.User, *library.Repo, *library.Hook) (*library.Hook, string, error) // Update defines a function that updates // a webhook for a specified repo. - Update(*library.User, *library.Repo, int64) (bool, error) + Update(context.Context, *library.User, *library.Repo, int64) (bool, error) // Status defines a function that sends the // commit status for the given SHA from a repo. - Status(*library.User, *library.Build, string, string) error + Status(context.Context, *library.User, *library.Build, string, string) error // ListUserRepos defines a function that retrieves // all repos with admin rights for the user. - ListUserRepos(*library.User) ([]*library.Repo, error) + ListUserRepos(context.Context, *library.User) ([]*library.Repo, error) // GetBranch defines a function that retrieves // a branch for a repo. - GetBranch(*library.User, *library.Repo, string) (string, string, error) + GetBranch(context.Context, *library.User, *library.Repo, string) (string, string, error) // GetPullRequest defines a function that retrieves // a pull request for a repo. - GetPullRequest(*library.User, *library.Repo, int) (string, string, string, string, error) + GetPullRequest(context.Context, *library.User, *library.Repo, int) (string, string, string, string, error) // GetRepo defines a function that retrieves // details for a repo. - GetRepo(*library.User, *library.Repo) (*library.Repo, error) + GetRepo(context.Context, *library.User, *library.Repo) (*library.Repo, error) // GetOrgAndRepoName defines a function that retrieves // the name of the org and repo in the SCM. - GetOrgAndRepoName(*library.User, string, string) (string, string, error) + GetOrgAndRepoName(context.Context, *library.User, string, string) (string, string, error) // GetOrg defines a function that retrieves // the name for an org in the SCM. - GetOrgName(*library.User, string) (string, error) + GetOrgName(context.Context, *library.User, string) (string, error) // GetHTMLURL defines a function that retrieves // a repository file's html_url. - GetHTMLURL(*library.User, string, string, string, string) (string, error) + GetHTMLURL(context.Context, *library.User, string, string, string, string) (string, error) // Webhook SCM Interface Functions // ProcessWebhook defines a function that // parses the webhook from a repo. - ProcessWebhook(*http.Request) (*types.Webhook, error) + ProcessWebhook(context.Context, *http.Request) (*types.Webhook, error) // VerifyWebhook defines a function that // verifies the webhook from a repo. - VerifyWebhook(*http.Request, *library.Repo) error + VerifyWebhook(context.Context, *http.Request, *library.Repo) error // RedeliverWebhook defines a function that // redelivers the webhook from the SCM. RedeliverWebhook(context.Context, *library.User, *library.Repo, *library.Hook) error diff --git a/scm/setup.go b/scm/setup.go index 16cfb14f3..b779e8ab2 100644 --- a/scm/setup.go +++ b/scm/setup.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package scm diff --git a/scm/setup_test.go b/scm/setup_test.go index c11717107..f3ad759a4 100644 --- a/scm/setup_test.go +++ b/scm/setup_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package scm diff --git a/secret/context.go b/secret/context.go index f685d99a0..b1b6eb458 100644 --- a/secret/context.go +++ b/secret/context.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/secret/context_test.go b/secret/context_test.go index 87f6afe06..4e92573e7 100644 --- a/secret/context_test.go +++ b/secret/context_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/secret/doc.go b/secret/doc.go index b15a4b102..96fa79046 100644 --- a/secret/doc.go +++ b/secret/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package secret provides the ability for Vela to integrate // with different supported Secret backends. diff --git a/secret/flags.go b/secret/flags.go index d2544600b..58ed6a42e 100644 --- a/secret/flags.go +++ b/secret/flags.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/secret/native/count.go b/secret/native/count.go index 94ae5b994..d76da83cc 100644 --- a/secret/native/count.go +++ b/secret/native/count.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native diff --git a/secret/native/count_test.go b/secret/native/count_test.go index dc0f7a8d8..33ab448be 100644 --- a/secret/native/count_test.go +++ b/secret/native/count_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native @@ -35,7 +33,7 @@ func TestNative_Count(t *testing.T) { } defer func() { - db.DeleteSecret(context.TODO(), sec) + _ = db.DeleteSecret(context.TODO(), sec) db.Close() }() diff --git a/secret/native/create.go b/secret/native/create.go index 3f865ef34..7d0f026c8 100644 --- a/secret/native/create.go +++ b/secret/native/create.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native diff --git a/secret/native/create_test.go b/secret/native/create_test.go index b0e7df1fa..dd1b6b0ff 100644 --- a/secret/native/create_test.go +++ b/secret/native/create_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native @@ -38,7 +36,7 @@ func TestNative_Create_Org(t *testing.T) { } defer func() { - db.DeleteSecret(context.TODO(), want) + _ = db.DeleteSecret(context.TODO(), want) db.Close() }() @@ -85,7 +83,7 @@ func TestNative_Create_Repo(t *testing.T) { } defer func() { - db.DeleteSecret(context.TODO(), want) + _ = db.DeleteSecret(context.TODO(), want) db.Close() }() @@ -132,7 +130,7 @@ func TestNative_Create_Shared(t *testing.T) { } defer func() { - db.DeleteSecret(context.TODO(), want) + _ = db.DeleteSecret(context.TODO(), want) db.Close() }() @@ -179,7 +177,7 @@ func TestNative_Create_Invalid(t *testing.T) { } defer func() { - db.DeleteSecret(context.TODO(), sec) + _ = db.DeleteSecret(context.TODO(), sec) db.Close() }() diff --git a/secret/native/delete.go b/secret/native/delete.go index 1b92406c4..54662a9f6 100644 --- a/secret/native/delete.go +++ b/secret/native/delete.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native diff --git a/secret/native/delete_test.go b/secret/native/delete_test.go index 4d8120182..96838d575 100644 --- a/secret/native/delete_test.go +++ b/secret/native/delete_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native @@ -35,7 +33,7 @@ func TestNative_Delete(t *testing.T) { } defer func() { - db.DeleteSecret(context.TODO(), sec) + _ = db.DeleteSecret(context.TODO(), sec) db.Close() }() diff --git a/secret/native/doc.go b/secret/native/doc.go index 7cd54caec..a45a668a1 100644 --- a/secret/native/doc.go +++ b/secret/native/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package native provides the ability for Vela to // integrate with the Database as a secret backend. diff --git a/secret/native/driver.go b/secret/native/driver.go index babd04d64..022967d53 100644 --- a/secret/native/driver.go +++ b/secret/native/driver.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native diff --git a/secret/native/driver_test.go b/secret/native/driver_test.go index ec0038df5..a18369e86 100644 --- a/secret/native/driver_test.go +++ b/secret/native/driver_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native diff --git a/secret/native/get.go b/secret/native/get.go index 81fc43266..ae80f1d09 100644 --- a/secret/native/get.go +++ b/secret/native/get.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native diff --git a/secret/native/get_test.go b/secret/native/get_test.go index 5a85ce001..8272c9e99 100644 --- a/secret/native/get_test.go +++ b/secret/native/get_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native @@ -39,7 +37,7 @@ func TestNative_Get(t *testing.T) { defer db.Close() defer func() { - db.DeleteSecret(context.TODO(), want) + _ = db.DeleteSecret(context.TODO(), want) db.Close() }() diff --git a/secret/native/list.go b/secret/native/list.go index 8ce639e77..6e153c422 100644 --- a/secret/native/list.go +++ b/secret/native/list.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native diff --git a/secret/native/list_test.go b/secret/native/list_test.go index 0f47e4122..f7bba5b81 100644 --- a/secret/native/list_test.go +++ b/secret/native/list_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native @@ -56,8 +54,8 @@ func TestNative_List(t *testing.T) { } defer func() { - db.DeleteSecret(context.TODO(), sOne) - db.DeleteSecret(context.TODO(), sTwo) + _ = db.DeleteSecret(context.TODO(), sOne) + _ = db.DeleteSecret(context.TODO(), sTwo) db.Close() }() diff --git a/secret/native/native.go b/secret/native/native.go index 99b015715..fb4319673 100644 --- a/secret/native/native.go +++ b/secret/native/native.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native diff --git a/secret/native/native_test.go b/secret/native/native_test.go index 0a5e3ee49..17cd465fd 100644 --- a/secret/native/native_test.go +++ b/secret/native/native_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native diff --git a/secret/native/opts.go b/secret/native/opts.go index 0c4396348..1278b2bb5 100644 --- a/secret/native/opts.go +++ b/secret/native/opts.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native diff --git a/secret/native/opts_test.go b/secret/native/opts_test.go index 0d9d968df..fc101fc49 100644 --- a/secret/native/opts_test.go +++ b/secret/native/opts_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native diff --git a/secret/native/update.go b/secret/native/update.go index 805528a04..cd928de8c 100644 --- a/secret/native/update.go +++ b/secret/native/update.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native diff --git a/secret/native/update_test.go b/secret/native/update_test.go index 612794c86..3b4e13172 100644 --- a/secret/native/update_test.go +++ b/secret/native/update_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package native @@ -55,7 +53,7 @@ func TestNative_Update(t *testing.T) { } defer func() { - db.DeleteSecret(context.TODO(), original) + _ = db.DeleteSecret(context.TODO(), original) db.Close() }() diff --git a/secret/secret.go b/secret/secret.go index edeec6c93..75496e449 100644 --- a/secret/secret.go +++ b/secret/secret.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/secret/secret_test.go b/secret/secret_test.go index 21ab33ee4..da399fab8 100644 --- a/secret/secret_test.go +++ b/secret/secret_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/secret/service.go b/secret/service.go index 39b718c45..6357dad05 100644 --- a/secret/service.go +++ b/secret/service.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/secret/setup.go b/secret/setup.go index e0a28a8a8..2e6e4b6b7 100644 --- a/secret/setup.go +++ b/secret/setup.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/secret/setup_test.go b/secret/setup_test.go index ef4492681..887943104 100644 --- a/secret/setup_test.go +++ b/secret/setup_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package secret diff --git a/secret/vault/count.go b/secret/vault/count.go index 9cbc2b217..a6995d2ee 100644 --- a/secret/vault/count.go +++ b/secret/vault/count.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package vault diff --git a/secret/vault/count_test.go b/secret/vault/count_test.go index 97a9e8f4c..3589011f1 100644 --- a/secret/vault/count_test.go +++ b/secret/vault/count_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package vault diff --git a/secret/vault/create.go b/secret/vault/create.go index 5bf2b16bf..6666d0f85 100644 --- a/secret/vault/create.go +++ b/secret/vault/create.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package vault diff --git a/secret/vault/create_test.go b/secret/vault/create_test.go index ea263e378..bcb41b60a 100644 --- a/secret/vault/create_test.go +++ b/secret/vault/create_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package vault diff --git a/secret/vault/delete.go b/secret/vault/delete.go index 68b94c880..ef3521c54 100644 --- a/secret/vault/delete.go +++ b/secret/vault/delete.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package vault diff --git a/secret/vault/delete_test.go b/secret/vault/delete_test.go index a509e1301..4fbe02473 100644 --- a/secret/vault/delete_test.go +++ b/secret/vault/delete_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package vault diff --git a/secret/vault/doc.go b/secret/vault/doc.go index 12b1d8332..8a4f5e2a5 100644 --- a/secret/vault/doc.go +++ b/secret/vault/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package vault provides the ability for Vela to // integrate with HashiCorp Vault as a secret backend. diff --git a/secret/vault/driver.go b/secret/vault/driver.go index f51bbdbc8..ad9a4858c 100644 --- a/secret/vault/driver.go +++ b/secret/vault/driver.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package vault diff --git a/secret/vault/driver_test.go b/secret/vault/driver_test.go index 9e4589fe8..4a0975766 100644 --- a/secret/vault/driver_test.go +++ b/secret/vault/driver_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package vault diff --git a/secret/vault/get.go b/secret/vault/get.go index df03641d9..eeba1e996 100644 --- a/secret/vault/get.go +++ b/secret/vault/get.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package vault diff --git a/secret/vault/get_test.go b/secret/vault/get_test.go index 1739dbab6..66f582727 100644 --- a/secret/vault/get_test.go +++ b/secret/vault/get_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package vault diff --git a/secret/vault/list.go b/secret/vault/list.go index 1243afbd6..be5638e41 100644 --- a/secret/vault/list.go +++ b/secret/vault/list.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package vault diff --git a/secret/vault/list_test.go b/secret/vault/list_test.go index d93ef985f..127a127a2 100644 --- a/secret/vault/list_test.go +++ b/secret/vault/list_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package vault diff --git a/secret/vault/opts.go b/secret/vault/opts.go index 575049203..5bc500ded 100644 --- a/secret/vault/opts.go +++ b/secret/vault/opts.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package vault diff --git a/secret/vault/opts_test.go b/secret/vault/opts_test.go index a7e0f77df..050187e23 100644 --- a/secret/vault/opts_test.go +++ b/secret/vault/opts_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package vault diff --git a/secret/vault/refresh.go b/secret/vault/refresh.go index 461d49fe8..ba5f06319 100644 --- a/secret/vault/refresh.go +++ b/secret/vault/refresh.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package vault diff --git a/secret/vault/refresh_test.go b/secret/vault/refresh_test.go index 33b41fa35..9fa3f62d1 100644 --- a/secret/vault/refresh_test.go +++ b/secret/vault/refresh_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package vault diff --git a/secret/vault/update.go b/secret/vault/update.go index f5a7b4068..9082b2ff4 100644 --- a/secret/vault/update.go +++ b/secret/vault/update.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package vault diff --git a/secret/vault/update_test.go b/secret/vault/update_test.go index 78774d46d..c17c2c936 100644 --- a/secret/vault/update_test.go +++ b/secret/vault/update_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package vault diff --git a/secret/vault/vault.go b/secret/vault/vault.go index 997ff46f5..c1b0c9508 100644 --- a/secret/vault/vault.go +++ b/secret/vault/vault.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package vault diff --git a/secret/vault/vault_test.go b/secret/vault/vault_test.go index 7ba0ac254..1e61c7941 100644 --- a/secret/vault/vault_test.go +++ b/secret/vault/vault_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package vault diff --git a/util/util.go b/util/util.go index 31cdd1104..840dbc04f 100644 --- a/util/util.go +++ b/util/util.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package util diff --git a/version/version.go b/version/version.go index 30312ee24..f6dfde329 100644 --- a/version/version.go +++ b/version/version.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package version