@@ -21,6 +21,15 @@ import (
21
21
"strings"
22
22
"time"
23
23
24
+ "github.com/codefresh-io/cli-v2/pkg/log"
25
+ "github.com/codefresh-io/cli-v2/pkg/runtime"
26
+ "github.com/codefresh-io/cli-v2/pkg/store"
27
+ "github.com/codefresh-io/cli-v2/pkg/util"
28
+ apu "github.com/codefresh-io/cli-v2/pkg/util/aputil"
29
+ eventsutil "github.com/codefresh-io/cli-v2/pkg/util/events"
30
+ ingressutil "github.com/codefresh-io/cli-v2/pkg/util/ingress"
31
+ wfutil "github.com/codefresh-io/cli-v2/pkg/util/workflow"
32
+
24
33
"github.com/Masterminds/semver/v3"
25
34
apcmd "github.com/argoproj-labs/argocd-autopilot/cmd/commands"
26
35
"github.com/argoproj-labs/argocd-autopilot/pkg/application"
@@ -35,14 +44,6 @@ import (
35
44
sensorsv1alpha1 "github.com/argoproj/argo-events/pkg/apis/sensor/v1alpha1"
36
45
wf "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow"
37
46
wfv1alpha1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
38
- "github.com/codefresh-io/cli-v2/pkg/log"
39
- "github.com/codefresh-io/cli-v2/pkg/runtime"
40
- "github.com/codefresh-io/cli-v2/pkg/store"
41
- "github.com/codefresh-io/cli-v2/pkg/util"
42
- apu "github.com/codefresh-io/cli-v2/pkg/util/aputil"
43
- eventsutil "github.com/codefresh-io/cli-v2/pkg/util/events"
44
- ingressutil "github.com/codefresh-io/cli-v2/pkg/util/ingress"
45
- wfutil "github.com/codefresh-io/cli-v2/pkg/util/workflow"
46
47
appProxyModel "github.com/codefresh-io/go-sdk/pkg/codefresh/model/app-proxy"
47
48
billyUtils "github.com/go-git/go-billy/v5/util"
48
49
"github.com/juju/ansiterm"
81
82
GsName string
82
83
InsCloneOpts * git.CloneOptions
83
84
GsCloneOpts * git.CloneOptions
84
- Include string
85
- Exclude string
85
+ Include * string
86
+ Exclude * string
86
87
}
87
88
88
89
gitSourceCronExampleOptions struct {
@@ -108,7 +109,7 @@ type (
108
109
}
109
110
)
110
111
111
- var versionOfGitSourceByAppProxyRefactor = semver .MustParse ("0.0.325 " )
112
+ var versionOfGitSourceByAppProxyRefactor = semver .MustParse ("0.0.326 " )
112
113
113
114
func NewGitSourceCommand () * cobra.Command {
114
115
cmd := & cobra.Command {
@@ -232,36 +233,35 @@ func RunGitSourceCreate(ctx context.Context, opts *GitSourceCreateOptions) error
232
233
}
233
234
234
235
if version .LessThan (versionOfGitSourceByAppProxyRefactor ) {
235
- log .G (ctx ).Infof ("runtime \" %s\" is using a depracated git-source api. Versions %s and up use the app-proxy for this command" , opts .RuntimeName , minAddClusterSupportedVersion )
236
+ log .G (ctx ).Warnf ("runtime \" %s\" is using a depracated git-source api. Versions %s and up use the app-proxy for this command" , opts .RuntimeName , minAddClusterSupportedVersion )
236
237
return legacyGitSourceCreate (ctx , opts )
237
- } else {
238
- appProxy , err := cfConfig .NewClient ().AppProxy (ctx , opts .RuntimeName , store .Get ().InsecureIngressHost )
239
- if err != nil {
240
- return err
241
- }
238
+ }
242
239
243
- appSpecifier := opts .GsCloneOpts .Repo
244
- isInternal := util .StringIndexOf (store .Get ().CFInternalGitSources , opts .GsName ) > - 1
245
-
246
- err = appProxy .AppProxyGitSources ().Create (ctx , & appProxyModel.CreateGitSourceInput {
247
- AppName : opts .GsName ,
248
- AppSpecifier : appSpecifier ,
249
- DestServer : store .Get ().InCluster ,
250
- DestNamespace : opts .RuntimeName ,
251
- IsInternal : & isInternal ,
252
- Include : & opts .Include ,
253
- Exclude : & opts .Exclude ,
254
- })
240
+ appProxy , err := cfConfig .NewClient ().AppProxy (ctx , opts .RuntimeName , store .Get ().InsecureIngressHost )
241
+ if err != nil {
242
+ return err
243
+ }
255
244
256
- if err != nil {
257
- log .G (ctx ).Errorf ("failed to create git-source: %w" , err )
258
- log .G (ctx ).Info ("attempting creation of git-source without using app-proxy" )
259
- return legacyGitSourceCreate (ctx , opts )
260
- }
245
+ appSpecifier := opts .GsCloneOpts .Repo
246
+ isInternal := util .StringIndexOf (store .Get ().CFInternalGitSources , opts .GsName ) > - 1
261
247
262
- log .G (ctx ).Infof ("Successfully created git-source: \" %s\" " , opts .GsName )
248
+ err = appProxy .AppProxyGitSources ().Create (ctx , & appProxyModel.CreateGitSourceInput {
249
+ AppName : opts .GsName ,
250
+ AppSpecifier : appSpecifier ,
251
+ DestServer : store .Get ().InCluster ,
252
+ DestNamespace : opts .RuntimeName ,
253
+ IsInternal : & isInternal ,
254
+ Include : & opts .Include ,
255
+ Exclude : & opts .Exclude ,
256
+ })
257
+
258
+ if err != nil {
259
+ log .G (ctx ).Errorf ("failed to create git-source: %w" , err )
260
+ log .G (ctx ).Info ("attempting creation of git-source without using app-proxy" )
261
+ return legacyGitSourceCreate (ctx , opts )
263
262
}
264
263
264
+ log .G (ctx ).Infof ("Successfully created git-source: \" %s\" " , opts .GsName )
265
265
return nil
266
266
}
267
267
@@ -612,7 +612,19 @@ func RunGitSourceDelete(ctx context.Context, opts *GitSourceDeleteOptions) error
612
612
}
613
613
614
614
if version .LessThan (versionOfGitSourceByAppProxyRefactor ) {
615
- log .G (ctx ).Infof ("runtime \" %s\" is using a depracated git-source api. Versions %s and up use the app-proxy for this command" , opts .RuntimeName , minAddClusterSupportedVersion )
615
+ log .G (ctx ).Warnf ("runtime \" %s\" is using a depracated git-source api. Versions %s and up use the app-proxy for this command" , opts .RuntimeName , minAddClusterSupportedVersion )
616
+ return legacyGitSourceDelete (ctx , opts )
617
+ }
618
+
619
+ appProxy , err := cfConfig .NewClient ().AppProxy (ctx , opts .RuntimeName , store .Get ().InsecureIngressHost )
620
+ if err != nil {
621
+ return err
622
+ }
623
+
624
+ err = appProxy .AppProxyGitSources ().Delete (ctx , opts .GsName )
625
+ if err != nil {
626
+ log .G (ctx ).Errorf ("failed to delete git-source: %w" , err )
627
+ log .G (ctx ).Info ("attempting deletion of git-source without using app-proxy" )
616
628
err = apcmd .RunAppDelete (ctx , & apcmd.AppDeleteOptions {
617
629
CloneOpts : opts .InsCloneOpts ,
618
630
ProjectName : opts .RuntimeName ,
@@ -623,27 +635,6 @@ func RunGitSourceDelete(ctx context.Context, opts *GitSourceDeleteOptions) error
623
635
if err != nil {
624
636
return fmt .Errorf ("failed to delete the git-source %s. Err: %w" , opts .GsName , err )
625
637
}
626
- } else {
627
- appProxy , err := cfConfig .NewClient ().AppProxy (ctx , opts .RuntimeName , store .Get ().InsecureIngressHost )
628
- if err != nil {
629
- return err
630
- }
631
-
632
- err = appProxy .AppProxyGitSources ().Delete (ctx , opts .GsName )
633
- if err != nil {
634
- log .G (ctx ).Errorf ("failed to delete git-source: %w" , err )
635
- log .G (ctx ).Info ("attempting deletion of git-source without using app-proxy" )
636
- err = apcmd .RunAppDelete (ctx , & apcmd.AppDeleteOptions {
637
- CloneOpts : opts .InsCloneOpts ,
638
- ProjectName : opts .RuntimeName ,
639
- AppName : opts .GsName ,
640
- Global : false ,
641
- })
642
-
643
- if err != nil {
644
- return fmt .Errorf ("failed to delete the git-source %s. Err: %w" , opts .GsName , err )
645
- }
646
- }
647
638
}
648
639
649
640
log .G (ctx ).Infof ("Successfully deleted the git-source: %s" , opts .GsName )
@@ -692,20 +683,26 @@ func NewGitSourceEditCommand() *cobra.Command {
692
683
RunE : func (cmd * cobra.Command , args []string ) error {
693
684
ctx := cmd .Context ()
694
685
695
- return RunGitSourceEdit ( ctx , & GitSourceEditOptions {
686
+ opts := & GitSourceEditOptions {
696
687
RuntimeName : args [0 ],
697
688
GsName : args [1 ],
698
689
InsCloneOpts : insCloneOpts ,
699
690
GsCloneOpts : gsCloneOpts ,
700
- Include : include ,
701
- Exclude : exclude ,
702
- })
691
+ }
692
+ if cmd .Flags ().Changed ("include" ) {
693
+ opts .Include = & include
694
+ }
695
+
696
+ if cmd .Flags ().Changed ("exclude" ) {
697
+ opts .Exclude = & exclude
698
+ }
699
+
700
+ return RunGitSourceEdit (ctx , opts )
703
701
},
704
702
}
705
703
706
- // defaults to "nil" string in order to allows an empty value
707
- cmd .Flags ().StringVar (& include , "include" , "nil" , "files to include. can be either filenames or a glob" )
708
- cmd .Flags ().StringVar (& exclude , "exclude" , "nil" , "files to exclude. can be either filenames or a glob" )
704
+ cmd .Flags ().StringVar (& include , "include" , "" , "files to include. can be either filenames or a glob" )
705
+ cmd .Flags ().StringVar (& exclude , "exclude" , "" , "files to exclude. can be either filenames or a glob" )
709
706
710
707
insCloneOpts = apu .AddCloneFlags (cmd , & apu.CloneFlagsOptions {
711
708
CreateIfNotExist : true ,
@@ -722,41 +719,35 @@ func NewGitSourceEditCommand() *cobra.Command {
722
719
}
723
720
724
721
func RunGitSourceEdit (ctx context.Context , opts * GitSourceEditOptions ) error {
725
- repo , fs , err := opts .InsCloneOpts .GetRepo (ctx )
726
- if err != nil {
727
- return err
728
- }
729
-
730
722
version , err := getRuntimeVersion (ctx , opts .RuntimeName )
731
723
if err != nil {
732
724
return err
733
725
}
734
726
735
727
if version .LessThan (versionOfGitSourceByAppProxyRefactor ) {
736
- return legacyGitSourceEdit (ctx , opts , repo , fs , err )
737
- } else {
738
- appProxy , err := cfConfig .NewClient ().AppProxy (ctx , opts .RuntimeName , store .Get ().InsecureIngressHost )
739
- if err != nil {
740
- return err
741
- }
742
-
743
- err = appProxy .AppProxyGitSources ().Edit (ctx , & appProxyModel.EditGitSourceInput {
744
- AppName : opts .GsName ,
745
- AppSpecifier : opts .GsCloneOpts .Repo ,
746
- Include : & opts .Include ,
747
- Exclude : & opts .Exclude ,
748
- })
728
+ log .G (ctx ).Warnf ("runtime \" %s\" is using a depracated git-source api. Versions %s and up use the app-proxy for this command" , opts .RuntimeName , minAddClusterSupportedVersion )
729
+ return legacyGitSourceEdit (ctx , opts )
730
+ }
749
731
750
- if err != nil {
751
- log . G ( ctx ). Errorf ( "failed to edit git-source: %w" , err )
752
- log . G ( ctx ). Info ( "attempting edit of git-source without using app-proxy" )
753
- return legacyGitSourceEdit ( ctx , opts , repo , fs , err )
732
+ appProxy , err := cfConfig . NewClient (). AppProxy ( ctx , opts . RuntimeName , store . Get (). InsecureIngressHost )
733
+ if err != nil {
734
+ return err
735
+ }
754
736
755
- }
737
+ err = appProxy .AppProxyGitSources ().Edit (ctx , & appProxyModel.EditGitSourceInput {
738
+ AppName : opts .GsName ,
739
+ AppSpecifier : opts .GsCloneOpts .Repo ,
740
+ Include : opts .Include ,
741
+ Exclude : opts .Exclude ,
742
+ })
756
743
757
- log .G (ctx ).Infof ("Successfully edited git-source: \" %s\" " , opts .GsName )
744
+ if err != nil {
745
+ log .G (ctx ).Errorf ("failed to edit git-source: %w" , err )
746
+ log .G (ctx ).Info ("attempting edit of git-source without using app-proxy" )
747
+ return legacyGitSourceEdit (ctx , opts )
758
748
}
759
749
750
+ log .G (ctx ).Infof ("Successfully edited git-source: \" %s\" " , opts .GsName )
760
751
return nil
761
752
}
762
753
@@ -1273,12 +1264,12 @@ func legacyGitSourceCreate(ctx context.Context, opts *GitSourceCreateOptions) er
1273
1264
return nil
1274
1265
}
1275
1266
1276
- func legacyGitSourceEdit (ctx context.Context , opts * GitSourceEditOptions , repo git.Repository , fs fs.FS , err error ) error {
1277
- log .G (ctx ).Infof ("runtime \" %s\" is using a depracated git-source api. Versions %s and up use the app-proxy for this command" , opts .RuntimeName , minAddClusterSupportedVersion )
1278
-
1267
+ func legacyGitSourceEdit (ctx context.Context , opts * GitSourceEditOptions ) error {
1268
+ repo , fs , err := opts .InsCloneOpts .GetRepo (ctx )
1279
1269
if err != nil {
1280
1270
return fmt .Errorf ("failed to clone the installation repo, attempting to edit git-source %s. Err: %w" , opts .GsName , err )
1281
1271
}
1272
+
1282
1273
c := & dirConfig {}
1283
1274
fileName := fs .Join (apstore .Default .AppsDir , opts .GsName , opts .RuntimeName , "config_dir.json" )
1284
1275
err = fs .ReadJson (fileName , c )
@@ -1290,12 +1281,12 @@ func legacyGitSourceEdit(ctx context.Context, opts *GitSourceEditOptions, repo g
1290
1281
c .Config .SrcRepoURL = opts .GsCloneOpts .URL ()
1291
1282
c .Config .SrcTargetRevision = opts .GsCloneOpts .Revision ()
1292
1283
1293
- if opts .Include != " nil" {
1294
- c .Include = opts .Include
1284
+ if opts .Include != nil {
1285
+ c .Include = * opts .Include
1295
1286
}
1296
1287
1297
- if opts .Exclude != " nil" {
1298
- c .Exclude = opts .Include
1288
+ if opts .Exclude != nil {
1289
+ c .Exclude = * opts .Exclude
1299
1290
}
1300
1291
1301
1292
err = fs .WriteJson (fileName , c )
@@ -1308,6 +1299,22 @@ func legacyGitSourceEdit(ctx context.Context, opts *GitSourceEditOptions, repo g
1308
1299
return fmt .Errorf ("failed to persist the updated git-source: %s. Err: %w" , opts .GsName , err )
1309
1300
}
1310
1301
1311
- log .G (ctx ).Infof ("Successfully created git-source: \" %s\" " , opts .GsName )
1302
+ log .G (ctx ).Infof ("Successfully edited git-source: \" %s\" " , opts .GsName )
1312
1303
return nil
1313
1304
}
1305
+
1306
+ func legacyGitSourceDelete (ctx context.Context , opts * GitSourceDeleteOptions ) error {
1307
+ err := apcmd .RunAppDelete (ctx , & apcmd.AppDeleteOptions {
1308
+ CloneOpts : opts .InsCloneOpts ,
1309
+ ProjectName : opts .RuntimeName ,
1310
+ AppName : opts .GsName ,
1311
+ Global : false ,
1312
+ })
1313
+
1314
+ if err != nil {
1315
+ return fmt .Errorf ("failed to delete the git-source %s. Err: %w" , opts .GsName , err )
1316
+ }
1317
+
1318
+ log .G (ctx ).Infof ("Successfully deleted the git-source: %s" , opts .GsName )
1319
+ return nil
1320
+ }
0 commit comments