1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-19 13:29:41 +02:00

refactor(stack): stack build process backend only [EE-4342] (#7750)

This commit is contained in:
Oscar Zhou 2022-10-05 22:33:59 +13:00 committed by GitHub
parent 83a1ce9d2a
commit e9de484c3e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
65 changed files with 2270 additions and 942 deletions

View file

@ -17,6 +17,7 @@ import (
githttp "github.com/go-git/go-git/v5/plumbing/transport/http"
"github.com/pkg/errors"
"github.com/portainer/portainer/api/archive"
gittypes "github.com/portainer/portainer/api/git/types"
)
const (
@ -483,9 +484,9 @@ func (a *azureClient) listFiles(ctx context.Context, opt fetchOption) ([]string,
func checkAzureStatusCode(err error, code int) error {
if code == http.StatusNotFound {
return ErrIncorrectRepositoryURL
return gittypes.ErrIncorrectRepositoryURL
} else if code == http.StatusUnauthorized || code == http.StatusNonAuthoritativeInfo {
return ErrAuthenticationFailure
return gittypes.ErrAuthenticationFailure
}
return err
}

View file

@ -9,6 +9,7 @@ import (
"time"
_ "github.com/joho/godotenv/autoload"
gittypes "github.com/portainer/portainer/api/git/types"
"github.com/stretchr/testify/assert"
)
@ -145,7 +146,7 @@ func TestService_ListFiles_Azure(t *testing.T) {
extensions: []string{},
expect: expectResult{
shouldFail: true,
err: ErrAuthenticationFailure,
err: gittypes.ErrAuthenticationFailure,
},
},
{
@ -161,7 +162,7 @@ func TestService_ListFiles_Azure(t *testing.T) {
extensions: []string{},
expect: expectResult{
shouldFail: true,
err: ErrAuthenticationFailure,
err: gittypes.ErrAuthenticationFailure,
},
},
{
@ -240,7 +241,7 @@ func TestService_ListFiles_Azure(t *testing.T) {
extensions: []string{},
expect: expectResult{
shouldFail: true,
err: ErrIncorrectRepositoryURL,
err: gittypes.ErrIncorrectRepositoryURL,
},
},
}

View file

@ -7,6 +7,7 @@ import (
"net/url"
"testing"
gittypes "github.com/portainer/portainer/api/git/types"
"github.com/stretchr/testify/assert"
)
@ -466,7 +467,7 @@ func Test_listRefs_azure(t *testing.T) {
password: "test-token",
},
expect: expectResult{
err: ErrAuthenticationFailure,
err: gittypes.ErrAuthenticationFailure,
},
},
{
@ -477,7 +478,7 @@ func Test_listRefs_azure(t *testing.T) {
password: "",
},
expect: expectResult{
err: ErrAuthenticationFailure,
err: gittypes.ErrAuthenticationFailure,
},
},
{
@ -488,7 +489,7 @@ func Test_listRefs_azure(t *testing.T) {
password: accessToken,
},
expect: expectResult{
err: ErrIncorrectRepositoryURL,
err: gittypes.ErrIncorrectRepositoryURL,
},
},
}
@ -540,7 +541,7 @@ func Test_listFiles_azure(t *testing.T) {
},
expect: expectResult{
shouldFail: true,
err: ErrAuthenticationFailure,
err: gittypes.ErrAuthenticationFailure,
},
},
{
@ -555,7 +556,7 @@ func Test_listFiles_azure(t *testing.T) {
},
expect: expectResult{
shouldFail: true,
err: ErrAuthenticationFailure,
err: gittypes.ErrAuthenticationFailure,
},
},
{
@ -599,7 +600,7 @@ func Test_listFiles_azure(t *testing.T) {
},
expect: expectResult{
shouldFail: true,
err: ErrIncorrectRepositoryURL,
err: gittypes.ErrIncorrectRepositoryURL,
},
},
}

View file

@ -6,14 +6,14 @@ import (
"path/filepath"
"strings"
"github.com/pkg/errors"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/config"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/object"
githttp "github.com/go-git/go-git/v5/plumbing/transport/http"
"github.com/go-git/go-git/v5/storage/memory"
"github.com/pkg/errors"
gittypes "github.com/portainer/portainer/api/git/types"
)
type gitClient struct {
@ -41,7 +41,7 @@ func (c *gitClient) download(ctx context.Context, dst string, opt cloneOption) e
if err != nil {
if err.Error() == "authentication required" {
return ErrAuthenticationFailure
return gittypes.ErrAuthenticationFailure
}
return errors.Wrap(err, "failed to clone git repository")
}
@ -66,7 +66,7 @@ func (c *gitClient) latestCommitID(ctx context.Context, opt fetchOption) (string
refs, err := remote.List(listOptions)
if err != nil {
if err.Error() == "authentication required" {
return "", ErrAuthenticationFailure
return "", gittypes.ErrAuthenticationFailure
}
return "", errors.Wrap(err, "failed to list repository refs")
}
@ -172,9 +172,9 @@ func (c *gitClient) listFiles(ctx context.Context, opt fetchOption) ([]string, e
func checkGitError(err error) error {
errMsg := err.Error()
if errMsg == "repository not found" {
return ErrIncorrectRepositoryURL
return gittypes.ErrIncorrectRepositoryURL
} else if errMsg == "authentication required" {
return ErrAuthenticationFailure
return gittypes.ErrAuthenticationFailure
}
return err
}

View file

@ -6,6 +6,7 @@ import (
"testing"
"time"
gittypes "github.com/portainer/portainer/api/git/types"
"github.com/stretchr/testify/assert"
)
@ -99,7 +100,7 @@ func TestService_ListFiles_GitHub(t *testing.T) {
extensions: []string{},
expect: expectResult{
shouldFail: true,
err: ErrAuthenticationFailure,
err: gittypes.ErrAuthenticationFailure,
},
},
{
@ -115,7 +116,7 @@ func TestService_ListFiles_GitHub(t *testing.T) {
extensions: []string{},
expect: expectResult{
shouldFail: true,
err: ErrAuthenticationFailure,
err: gittypes.ErrAuthenticationFailure,
},
},
{
@ -194,7 +195,7 @@ func TestService_ListFiles_GitHub(t *testing.T) {
extensions: []string{},
expect: expectResult{
shouldFail: true,
err: ErrIncorrectRepositoryURL,
err: gittypes.ErrIncorrectRepositoryURL,
},
},
}

View file

@ -6,11 +6,11 @@ import (
"path/filepath"
"testing"
"github.com/portainer/portainer/api/archive"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/pkg/errors"
"github.com/portainer/portainer/api/archive"
gittypes "github.com/portainer/portainer/api/git/types"
"github.com/stretchr/testify/assert"
)
@ -148,7 +148,7 @@ func Test_listRefsPrivateRepository(t *testing.T) {
password: "test-token",
},
expect: expectResult{
err: ErrAuthenticationFailure,
err: gittypes.ErrAuthenticationFailure,
},
},
{
@ -159,7 +159,7 @@ func Test_listRefsPrivateRepository(t *testing.T) {
password: "",
},
expect: expectResult{
err: ErrAuthenticationFailure,
err: gittypes.ErrAuthenticationFailure,
},
},
{
@ -170,7 +170,7 @@ func Test_listRefsPrivateRepository(t *testing.T) {
password: accessToken,
},
expect: expectResult{
err: ErrIncorrectRepositoryURL,
err: gittypes.ErrIncorrectRepositoryURL,
},
},
}
@ -222,7 +222,7 @@ func Test_listFilesPrivateRepository(t *testing.T) {
},
expect: expectResult{
shouldFail: true,
err: ErrAuthenticationFailure,
err: gittypes.ErrAuthenticationFailure,
},
},
{
@ -237,7 +237,7 @@ func Test_listFilesPrivateRepository(t *testing.T) {
},
expect: expectResult{
shouldFail: true,
err: ErrAuthenticationFailure,
err: gittypes.ErrAuthenticationFailure,
},
},
{
@ -281,7 +281,7 @@ func Test_listFilesPrivateRepository(t *testing.T) {
},
expect: expectResult{
shouldFail: true,
err: ErrIncorrectRepositoryURL,
err: gittypes.ErrIncorrectRepositoryURL,
},
},
}

View file

@ -2,7 +2,6 @@ package git
import (
"context"
"errors"
"log"
"strings"
"sync"
@ -12,9 +11,6 @@ import (
)
var (
ErrIncorrectRepositoryURL = errors.New("Git repository could not be found, please ensure that the URL is correct.")
ErrAuthenticationFailure = errors.New("Authentication failed, please ensure that the git credentials are correct.")
REPOSITORY_CACHE_SIZE = 4
REPOSITORY_CACHE_TTL = 5 * time.Minute
)

View file

@ -1,5 +1,12 @@
package gittypes
import "errors"
var (
ErrIncorrectRepositoryURL = errors.New("Git repository could not be found, please ensure that the URL is correct.")
ErrAuthenticationFailure = errors.New("Authentication failed, please ensure that the git credentials are correct.")
)
// RepoConfig represents a configuration for a repo
type RepoConfig struct {
// The repo url