git

package
v0.7.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2024 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HTTP_URL_PROTOCOL              = "http://"
	HTTPS_URL_PROTOCOL             = "https://"
	BITBUCKET_CLONE_BASE_URL       = "https://bitbucket.org/"
	BITBUCKET_GITOPS_DIR           = "bitbucketGitOps"
	BITBUCKET_REPO_NOT_FOUND_ERROR = "404 Not Found"
	BITBUCKET_COMMIT_TIME_LAYOUT   = "2001-01-01T10:00:00+00:00"
)
View Source
const (
	GIT_WORKING_DIR       = "/tmp/gitops/"
	GetRepoUrlStage       = "Get Repo RedirectionUrl"
	CreateRepoStage       = "Create Repo"
	CloneHttpStage        = "Clone Http"
	CreateReadmeStage     = "Create Readme"
	CloneSshStage         = "Clone Ssh"
	GITLAB_PROVIDER       = "GITLAB"
	GITHUB_PROVIDER       = "GITHUB"
	AZURE_DEVOPS_PROVIDER = "AZURE_DEVOPS"
	BITBUCKET_PROVIDER    = "BITBUCKET_CLOUD"
	GITHUB_API_V3         = "api/v3"
	GITHUB_HOST           = "github.com"
	GIT_TLS_DIR           = "/tmp/gitops/tls"
)
View Source
const PushErrorMessage = "failed to push some refs"

Variables

This section is empty.

Functions

func CreateGitlabClient

func CreateGitlabClient(host, token string, tlsConfig *tls.Config) (*gitlab.Client, error)

func GetGitConfig

func GetGitConfig(gitOpsConfigReadService config.GitOpsConfigReadService) (*bean.GitConfig, error)

func SanitiseCustomGitRepoURL

func SanitiseCustomGitRepoURL(activeGitOpsConfig apiGitOpsBean.GitOpsConfigDto, gitRepoURL string) (sanitisedGitRepoURL string)

SanitiseCustomGitRepoURL - It will sanitise the user given repository url based on GitOps provider

Case BITBUCKET_PROVIDER:

  • The clone URL format https://<user-name>@bitbucket.org/<workspace-name>/<repo-name>.git
  • Here the <user-name> can differ from user to user. SanitiseCustomGitRepoURL will return the repo url in format : https://bitbucket.org/<workspace-name>/<repo-name>.git

Case AZURE_DEVOPS_PROVIDER:

  • The clone URL format https://<organisation-name>@dev.azure.com/<organisation-name>/<project-name>/_git/<repo-name>
  • Here the <user-name> can differ from user to user. SanitiseCustomGitRepoURL will return the repo url in format : https://dev.azure.com/<organisation-name>/<project-name>/_git/<repo-name>

Types

type ChartConfig

type ChartConfig struct {
	ChartName      string
	ChartLocation  string
	FileName       string //filename
	FileContent    string
	ReleaseMessage string
	ChartRepoName  string
	UserName       string
	UserEmailId    string
	// contains filtered or unexported fields
}

func (*ChartConfig) GetBitBucketBaseDir added in v0.7.2

func (c *ChartConfig) GetBitBucketBaseDir() string

func (*ChartConfig) SetBitBucketBaseDir added in v0.7.2

func (c *ChartConfig) SetBitBucketBaseDir(dir string)

type DetailedErrorGitOpsConfigActions

type DetailedErrorGitOpsConfigActions struct {
	SuccessfulStages []string         `json:"successfulStages"`
	StageErrorMap    map[string]error `json:"stageErrorMap"`
	ValidatedOn      time.Time        `json:"validatedOn"`
	DeleteRepoFailed bool             `json:"deleteRepoFailed"`
}

type GitAzureClient

type GitAzureClient struct {
	// contains filtered or unexported fields
}

func NewGitAzureClient

func NewGitAzureClient(token string, host string, project string, logger *zap.SugaredLogger, gitOpsHelper *GitOpsHelper, tlsConfig *tls.Config) (GitAzureClient, error)

func (GitAzureClient) CommitValues

func (impl GitAzureClient) CommitValues(ctx context.Context, config *ChartConfig, gitOpsConfig *bean2.GitOpsConfigDto) (commitHash string, commitTime time.Time, err error)

func (GitAzureClient) CreateReadme

func (impl GitAzureClient) CreateReadme(ctx context.Context, config *bean2.GitOpsConfigDto) (string, error)

func (GitAzureClient) CreateRepository

func (impl GitAzureClient) CreateRepository(ctx context.Context, config *bean2.GitOpsConfigDto) (url string, isNew bool, detailedErrorGitOpsConfigActions DetailedErrorGitOpsConfigActions)

func (GitAzureClient) DeleteRepository

func (impl GitAzureClient) DeleteRepository(config *bean2.GitOpsConfigDto) (err error)

func (GitAzureClient) GetRepoUrl

func (impl GitAzureClient) GetRepoUrl(config *bean2.GitOpsConfigDto) (repoUrl string, err error)

type GitBitbucketClient

type GitBitbucketClient struct {
	// contains filtered or unexported fields
}

func NewGitBitbucketClient

func NewGitBitbucketClient(username, token, host string, logger *zap.SugaredLogger, gitOpsHelper *GitOpsHelper, tlsConfig *tls.Config) GitBitbucketClient

func (GitBitbucketClient) CommitValues

func (impl GitBitbucketClient) CommitValues(ctx context.Context, config *ChartConfig, gitOpsConfig *bean2.GitOpsConfigDto) (commitHash string, commitTime time.Time, err error)

func (GitBitbucketClient) CreateReadme

func (impl GitBitbucketClient) CreateReadme(ctx context.Context, config *bean2.GitOpsConfigDto) (string, error)

func (GitBitbucketClient) CreateRepository

func (impl GitBitbucketClient) CreateRepository(ctx context.Context, config *bean2.GitOpsConfigDto) (url string, isNew bool, detailedErrorGitOpsConfigActions DetailedErrorGitOpsConfigActions)

func (GitBitbucketClient) DeleteRepository

func (impl GitBitbucketClient) DeleteRepository(config *bean2.GitOpsConfigDto) (err error)

func (GitBitbucketClient) GetRepoUrl

func (impl GitBitbucketClient) GetRepoUrl(config *bean2.GitOpsConfigDto) (repoUrl string, err error)

type GitFactory

type GitFactory struct {
	Client       GitOpsClient
	GitOpsHelper *GitOpsHelper
	// contains filtered or unexported fields
}

func NewGitFactory

func NewGitFactory(logger *zap.SugaredLogger, gitOpsConfigReadService config.GitOpsConfigReadService) (*GitFactory, error)

func (*GitFactory) GetGitLabGroupPath

func (factory *GitFactory) GetGitLabGroupPath(gitOpsConfig *gitOps.GitOpsConfigDto) (string, error)

func (*GitFactory) NewClientForValidation

func (factory *GitFactory) NewClientForValidation(gitOpsConfig *gitOps.GitOpsConfigDto) (GitOpsClient, *GitOpsHelper, error)

func (*GitFactory) Reload

func (factory *GitFactory) Reload(gitOpsConfigReadService config.GitOpsConfigReadService) error

type GitHubClient

type GitHubClient struct {
	// contains filtered or unexported fields
}

func NewGithubClient

func NewGithubClient(host string, token string, org string, logger *zap.SugaredLogger,
	gitOpsHelper *GitOpsHelper, tlsConfig *tls.Config) (GitHubClient, error)

func (GitHubClient) CommitValues

func (impl GitHubClient) CommitValues(ctx context.Context, config *ChartConfig, gitOpsConfig *bean2.GitOpsConfigDto) (commitHash string, commitTime time.Time, err error)

func (GitHubClient) CreateReadme

func (impl GitHubClient) CreateReadme(ctx context.Context, config *bean2.GitOpsConfigDto) (string, error)

func (GitHubClient) CreateRepository

func (impl GitHubClient) CreateRepository(ctx context.Context, config *bean2.GitOpsConfigDto) (url string, isNew bool, detailedErrorGitOpsConfigActions DetailedErrorGitOpsConfigActions)

func (GitHubClient) DeleteRepository

func (impl GitHubClient) DeleteRepository(config *bean2.GitOpsConfigDto) error

func (GitHubClient) GetRepoUrl

func (impl GitHubClient) GetRepoUrl(config *bean2.GitOpsConfigDto) (repoUrl string, err error)

type GitLabClient

type GitLabClient struct {
	// contains filtered or unexported fields
}

func (GitLabClient) CommitValues

func (impl GitLabClient) CommitValues(ctx context.Context, config *ChartConfig, gitOpsConfig *bean2.GitOpsConfigDto) (commitHash string, commitTime time.Time, err error)

func (GitLabClient) CreateReadme

func (impl GitLabClient) CreateReadme(ctx context.Context, config *bean2.GitOpsConfigDto) (string, error)

func (GitLabClient) CreateRepository

func (impl GitLabClient) CreateRepository(ctx context.Context, config *bean2.GitOpsConfigDto) (url string, isNew bool, detailedErrorGitOpsConfigActions DetailedErrorGitOpsConfigActions)

func (GitLabClient) DeleteProject

func (impl GitLabClient) DeleteProject(projectName string) (err error)

func (GitLabClient) DeleteRepository

func (impl GitLabClient) DeleteRepository(config *bean2.GitOpsConfigDto) (err error)

func (GitLabClient) GetRepoUrl

func (impl GitLabClient) GetRepoUrl(config *bean2.GitOpsConfigDto) (repoUrl string, err error)

type GitOperationService

type GitOperationService interface {
	CreateGitRepositoryForDevtronApp(ctx context.Context, gitOpsRepoName string, userId int32) (chartGitAttribute *commonBean.ChartGitAttribute, err error)
	CreateReadmeInGitRepo(ctx context.Context, gitOpsRepoName string, userId int32) error
	GitPull(clonedDir string, repoUrl string) error

	CommitValues(ctx context.Context, chartGitAttr *ChartConfig) (commitHash string, commitTime time.Time, err error)
	PushChartToGitRepo(ctx context.Context, gitOpsRepoName, referenceTemplate, version, tempReferenceTemplateDir, repoUrl string, userId int32) (err error)
	PushChartToGitOpsRepoForHelmApp(ctx context.Context, PushChartToGitRequest *bean.PushChartToGitRequestDTO, requirementsConfig *ChartConfig, valuesConfig *ChartConfig) (*commonBean.ChartGitAttribute, string, error)

	CreateRepository(ctx context.Context, dto *apiBean.GitOpsConfigDto, userId int32) (string, bool, error)
	GetRepoUrlByRepoName(repoName string) (string, error)

	CloneInDir(repoUrl, chartDir string) (string, error)
	ReloadGitOpsProvider() error
	UpdateGitHostUrlByProvider(request *apiBean.GitOpsConfigDto) error
}

type GitOperationServiceImpl

type GitOperationServiceImpl struct {
	// contains filtered or unexported fields
}

func NewGitOperationServiceImpl

func NewGitOperationServiceImpl(logger *zap.SugaredLogger, gitFactory *GitFactory,
	gitOpsConfigReadService config.GitOpsConfigReadService,
	chartTemplateService util.ChartTemplateService,
	envVariables *globalUtil.EnvironmentVariables) *GitOperationServiceImpl

func (*GitOperationServiceImpl) CloneInDir

func (impl *GitOperationServiceImpl) CloneInDir(repoUrl, chartDir string) (string, error)

func (*GitOperationServiceImpl) CommitValues

func (impl *GitOperationServiceImpl) CommitValues(ctx context.Context, chartGitAttr *ChartConfig) (commitHash string, commitTime time.Time, err error)

func (*GitOperationServiceImpl) CreateGitRepositoryForDevtronApp added in v0.7.1

func (impl *GitOperationServiceImpl) CreateGitRepositoryForDevtronApp(ctx context.Context, gitOpsRepoName string, userId int32) (chartGitAttribute *commonBean.ChartGitAttribute, err error)

func (*GitOperationServiceImpl) CreateReadmeInGitRepo

func (impl *GitOperationServiceImpl) CreateReadmeInGitRepo(ctx context.Context, gitOpsRepoName string, userId int32) error

func (*GitOperationServiceImpl) CreateRepository

func (impl *GitOperationServiceImpl) CreateRepository(ctx context.Context, dto *apiBean.GitOpsConfigDto, userId int32) (string, bool, error)

func (*GitOperationServiceImpl) GetRepoUrlByRepoName

func (impl *GitOperationServiceImpl) GetRepoUrlByRepoName(repoName string) (string, error)

func (*GitOperationServiceImpl) GitPull

func (impl *GitOperationServiceImpl) GitPull(clonedDir string, repoUrl string) error

func (*GitOperationServiceImpl) PushChartToGitOpsRepoForHelmApp

func (impl *GitOperationServiceImpl) PushChartToGitOpsRepoForHelmApp(ctx context.Context, PushChartToGitRequest *bean.PushChartToGitRequestDTO, requirementsConfig *ChartConfig, valuesConfig *ChartConfig) (*commonBean.ChartGitAttribute, string, error)

PushChartToGitOpsRepoForHelmApp pushes built chart to GitOps repo (Specific implementation for Helm Apps) TODO refactoring: Make a common method for both PushChartToGitRepo and PushChartToGitOpsRepoForHelmApp

func (*GitOperationServiceImpl) PushChartToGitRepo

func (impl *GitOperationServiceImpl) PushChartToGitRepo(ctx context.Context, gitOpsRepoName, referenceTemplate, version, tempReferenceTemplateDir, repoUrl string, userId int32) (err error)

func (*GitOperationServiceImpl) ReloadGitOpsProvider

func (impl *GitOperationServiceImpl) ReloadGitOpsProvider() error

func (*GitOperationServiceImpl) UpdateGitHostUrlByProvider

func (impl *GitOperationServiceImpl) UpdateGitHostUrlByProvider(request *apiBean.GitOpsConfigDto) error

type GitOpsClient

type GitOpsClient interface {
	CreateRepository(ctx context.Context, config *gitOps.GitOpsConfigDto) (url string, isNew bool, detailedErrorGitOpsConfigActions DetailedErrorGitOpsConfigActions)
	CommitValues(ctx context.Context, config *ChartConfig, gitOpsConfig *gitOps.GitOpsConfigDto) (commitHash string, commitTime time.Time, err error)
	GetRepoUrl(config *gitOps.GitOpsConfigDto) (repoUrl string, err error)
	DeleteRepository(config *gitOps.GitOpsConfigDto) error
	CreateReadme(ctx context.Context, config *gitOps.GitOpsConfigDto) (string, error)
}

func NewGitLabClient

func NewGitLabClient(config *bean.GitConfig, logger *zap.SugaredLogger, gitOpsHelper *GitOpsHelper, tlsConfig *tls.Config) (GitOpsClient, error)

func NewGitOpsClient

func NewGitOpsClient(config *bean.GitConfig, logger *zap.SugaredLogger, gitOpsHelper *GitOpsHelper) (GitOpsClient, error)

type GitOpsHelper

type GitOpsHelper struct {
	Auth *git.BasicAuth
	// contains filtered or unexported fields
}

GitOpsHelper GitOps Helper maintains the auth creds in state and is used by implementation of git client implementations and GitFactory

func NewGitOpsHelperImpl

func NewGitOpsHelperImpl(auth *git.BasicAuth, logger *zap.SugaredLogger, tlsConfig *bean.TLSConfig, isTlsEnabled bool) *GitOpsHelper

func (*GitOpsHelper) Clone

func (impl *GitOpsHelper) Clone(url, targetDir string) (clonedDir string, err error)

func (*GitOpsHelper) CommitAndPushAllChanges

func (impl *GitOpsHelper) CommitAndPushAllChanges(ctx context.Context, repoRoot, commitMsg, name, emailId string) (commitHash string, err error)

func (*GitOpsHelper) GetCloneDirectory

func (impl *GitOpsHelper) GetCloneDirectory(targetDir string) (clonedDir string)

func (*GitOpsHelper) Pull

func (impl *GitOpsHelper) Pull(repoRoot string) (err error)

func (*GitOpsHelper) SetAuth

func (impl *GitOpsHelper) SetAuth(auth *git.BasicAuth)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL