Skip to content

Commit 7599ba6

Browse files
Cr 10692 support bitbucket (#494)
* split runtime install funcs to new file * bump autopilot to 0.4.2 * hide new git providers behind hidden --enable-git-providers flag * updated dockerfile * updated go-sdk to 0.45.0 * updated version to 0.0.441 * unhide cluster commands Co-authored-by: Kim Aharfi <kim.aharfi@codefresh.io>
1 parent a9d22f5 commit 7599ba6

28 files changed

+3230
-2568
lines changed

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.18.0-alpine3.15 as base
1+
FROM golang:1.18.4-alpine3.16 as base
22

33
WORKDIR /go/src/github.com/codefresh-io/cli-v2
44

@@ -26,7 +26,7 @@ RUN go mod verify
2626

2727
############################### CLI ###############################
2828
### Compile
29-
FROM golang:1.18.0-alpine3.15 as codefresh-build
29+
FROM golang:1.18.4-alpine3.16 as codefresh-build
3030

3131
WORKDIR /go/src/github.com/codefresh-io/cli-v2
3232

@@ -44,7 +44,7 @@ ARG SEGMENT_WRITE_KEY
4444
RUN make local DEV_MODE=false SEGMENT_WRITE_KEY=${SEGMENT_WRITE_KEY}
4545

4646
### Run
47-
FROM alpine:3.15 as codefresh
47+
FROM alpine:3.16 as codefresh
4848

4949
WORKDIR /go/src/github.com/codefresh-io/cli-v2
5050

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=v0.0.440
1+
VERSION=v0.0.441
22

33
OUT_DIR=dist
44
YEAR?=$(shell date +"%Y")

cmd/commands/cluster.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ var (
8181

8282
func NewClusterCommand() *cobra.Command {
8383
cmd := &cobra.Command{
84-
Hidden: true, // until app-proxy is working correctly
8584
Use: "cluster",
8685
Short: "Manage clusters of Codefresh runtimes",
8786
PersistentPreRunE: cfConfig.RequireAuthentication,

cmd/commands/common.go

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ import (
3333
"github.com/codefresh-io/cli-v2/pkg/store"
3434
"github.com/codefresh-io/cli-v2/pkg/util"
3535

36-
"github.com/argoproj-labs/argocd-autopilot/pkg/git"
37-
autoPilotUtil "github.com/argoproj-labs/argocd-autopilot/pkg/util"
36+
apgit "github.com/argoproj-labs/argocd-autopilot/pkg/git"
37+
aputil "github.com/argoproj-labs/argocd-autopilot/pkg/util"
3838
"github.com/manifoldco/promptui"
3939
"github.com/spf13/cobra"
4040
"github.com/spf13/pflag"
@@ -115,7 +115,7 @@ func askUserIfToInstallDemoResources(cmd *cobra.Command, sampleInstall *bool) er
115115
return nil
116116
}
117117

118-
func ensureRepo(cmd *cobra.Command, runtimeName string, cloneOpts *git.CloneOptions, fromAPI bool) error {
118+
func ensureRepo(cmd *cobra.Command, runtimeName string, cloneOpts *apgit.CloneOptions, fromAPI bool) error {
119119
ctx := cmd.Context()
120120
if cloneOpts.Repo != "" {
121121
return nil
@@ -151,7 +151,7 @@ func getRepoFromUserInput(cmd *cobra.Command) error {
151151
repoPrompt := promptui.Prompt{
152152
Label: "Repository URL",
153153
Validate: func(value string) error {
154-
host, orgRepo, _, _, _, _, _ := autoPilotUtil.ParseGitUrl(value)
154+
host, orgRepo, _, _, _, _, _ := aputil.ParseGitUrl(value)
155155
if host != "" && orgRepo != "" {
156156
return nil
157157
}
@@ -279,57 +279,50 @@ func getIngressClassFromUserSelect(ingressClassNames []string) (string, error) {
279279
return result, nil
280280
}
281281

282-
func inferProviderFromRepo(opts *git.CloneOptions) {
283-
if opts.Provider != "" {
284-
return
285-
}
286-
287-
if strings.Contains(opts.Repo, "github.com") {
288-
opts.Provider = "github"
289-
}
290-
if strings.Contains(opts.Repo, "gitlab.com") {
291-
opts.Provider = "gitlab"
292-
}
293-
}
294-
295-
func ensureGitToken(cmd *cobra.Command, cloneOpts *git.CloneOptions, verify bool) error {
296-
errMessage := "Value stored in environment variable GIT_TOKEN is invalid; enter a valid runtime token"
282+
// ensureGitToken gets the runtime token from the user (if !silent), and verifys it witht he provider (if available)
283+
func ensureGitToken(cmd *cobra.Command, gitProvider cfgit.Provider, cloneOpts *apgit.CloneOptions) error {
284+
ctx := cmd.Context()
285+
errMessage := "Value stored in environment variable GIT_TOKEN is invalid; enter a valid runtime token: %w"
297286
if cloneOpts.Auth.Password == "" && !store.Get().Silent {
298287
err := getGitTokenFromUserInput(cmd)
299-
errMessage = "Invalid runtime token; enter a valid token"
288+
errMessage = "Invalid runtime token; enter a valid token: %w"
300289
if err != nil {
301290
return err
302291
}
303292
}
304293

305-
if verify {
306-
err := cfgit.VerifyToken(cmd.Context(), cloneOpts.Provider, cloneOpts.Auth.Password, cfgit.RuntimeToken)
294+
if gitProvider != nil {
295+
err := gitProvider.VerifyToken(ctx, cfgit.RuntimeToken, cloneOpts.Auth.Password)
307296
if err != nil {
308297
// in case when we get invalid value from env variable TOKEN we clean
309298
cloneOpts.Auth.Password = ""
310-
return fmt.Errorf(errMessage)
299+
return fmt.Errorf(errMessage, err)
311300
}
312-
}
313-
314-
if cloneOpts.Auth.Password == "" {
301+
} else if cloneOpts.Auth.Password == "" {
315302
return fmt.Errorf("must provide a git token using --git-token")
316303
}
317304

318305
return nil
319306
}
320307

321-
func ensureGitPAT(cmd *cobra.Command, opts *RuntimeInstallOptions) error {
308+
// ensureGitPAT verifys the user's Personal Access Token (if it is different from the Runtime Token)
309+
func ensureGitPAT(ctx context.Context, opts *RuntimeInstallOptions) error {
322310
if opts.GitIntegrationRegistrationOpts.Token == "" {
323311
opts.GitIntegrationRegistrationOpts.Token = opts.InsCloneOpts.Auth.Password
324-
currentUser, err := cfConfig.NewClient().Users().GetCurrent(cmd.Context())
312+
currentUser, err := cfConfig.NewClient().Users().GetCurrent(ctx)
325313
if err != nil {
326314
return fmt.Errorf("failed to retrieve username from platform: %w", err)
327315
}
328316

329-
log.G(cmd.Context()).Infof("Personal git token was not provided. Using runtime git token to register user: \"%s\". You may replace your personal git token at any time from the UI in the user settings", currentUser.Name)
317+
log.G(ctx).Infof("Personal git token was not provided. Using runtime git token to register user: \"%s\". You may replace your personal git token at any time from the UI in the user settings", currentUser.Name)
318+
return nil
319+
}
320+
321+
if opts.gitProvider != nil {
322+
return opts.gitProvider.VerifyToken(ctx, cfgit.PersonalToken, opts.InsCloneOpts.Auth.Password)
330323
}
331324

332-
return cfgit.VerifyToken(cmd.Context(), opts.InsCloneOpts.Provider, opts.GitIntegrationRegistrationOpts.Token, cfgit.PersonalToken)
325+
return nil
333326
}
334327

335328
func getGitTokenFromUserInput(cmd *cobra.Command) error {

cmd/commands/git-source.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ func createDemoWorkflowTemplate(gsFs fs.FS) error {
811811
func createGithubExamplePipeline(opts *gitSourceGithubExampleOptions) error {
812812
if !store.Get().SkipIngress {
813813
// Create an ingress that will manage external access to the github eventsource service
814-
ingress := createGithubExampleIngress(opts.ingressClass, opts.ingressHost, opts.hostName, opts.ingressController, opts.runtimeName)
814+
ingress := createGithubExampleIngress(opts.ingressClass, opts.hostName, opts.ingressController, opts.runtimeName)
815815
ingressFilePath := opts.gsFs.Join(opts.gsCloneOpts.Path(), store.Get().GithubExampleIngressFileName)
816816

817817
ingressRedundanded, err := cleanUpFieldsIngressGithub(&ingress)
@@ -864,7 +864,7 @@ func createGithubExamplePipeline(opts *gitSourceGithubExampleOptions) error {
864864
return nil
865865
}
866866

867-
func createGithubExampleIngress(ingressClass string, ingressHost string, hostName string, ingressController ingressutil.IngressController, runtimeName string) *netv1.Ingress {
867+
func createGithubExampleIngress(ingressClass string, hostName string, ingressController ingressutil.IngressController, runtimeName string) *netv1.Ingress {
868868
ingressOptions := ingressutil.CreateIngressOptions{
869869
Name: store.Get().CodefreshDeliveryPipelines,
870870
IngressClassName: ingressClass,

cmd/commands/integrations.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ type (
4141
)
4242

4343
var gitProvidersByName = map[string]model.GitProviders{
44-
"github": model.GitProvidersGithub,
45-
"gitlab": model.GitProvidersGitlab,
44+
"bitbucket-server": model.GitProvidersBitbucketServer,
45+
"github": model.GitProvidersGithub,
46+
"gitlab": model.GitProvidersGitlab,
4647
}
4748

4849
func NewIntegrationCommand() *cobra.Command {
@@ -104,7 +105,7 @@ func NewGitIntegrationListCommand(client *sdk.AppProxyAPI) *cobra.Command {
104105
Use: "list",
105106
Short: "List your git integrations",
106107
Args: cobra.NoArgs,
107-
RunE: func(cmd *cobra.Command, args []string) error {
108+
RunE: func(cmd *cobra.Command, _ []string) error {
108109
if err := verifyOutputFormat(format, allowedFormats...); err != nil {
109110
return err
110111
}
@@ -223,7 +224,7 @@ func NewGitIntegrationAddCommand(client *sdk.AppProxyAPI) *cobra.Command {
223224
},
224225
}
225226

226-
cmd.Flags().StringVar(&provider, "provider", "github", "One of github|gitlab")
227+
cmd.Flags().StringVar(&provider, "provider", "github", "One of bitbucket-server|github|gitlab")
227228
cmd.Flags().StringVar(&apiURL, "api-url", "", "Git provider API Url")
228229
cmd.Flags().BoolVar(&accountAdminsOnly, "account-admins-only", false,
229230
"If true, this integration would only be visible to account admins (default: false)")

cmd/commands/pipeline.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func NewPipelineGetCommand() *cobra.Command {
6161
6262
<BIN> pipeline -r runtime_name -N namespace -n pipeline_name
6363
`),
64-
RunE: func(cmd *cobra.Command, args []string) error {
64+
RunE: func(cmd *cobra.Command, _ []string) error {
6565
ctx := cmd.Context()
6666

6767
return RunPipelineGet(ctx, name, namespace, runtime)
@@ -97,7 +97,7 @@ func NewPipelineListCommand() *cobra.Command {
9797
9898
<BIN> pipelines list -r <runtime>
9999
`),
100-
RunE: func(cmd *cobra.Command, args []string) error {
100+
RunE: func(cmd *cobra.Command, _ []string) error {
101101
ctx := cmd.Context()
102102

103103
filterArgs := model.PipelinesFilterArgs{

0 commit comments

Comments
 (0)