-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
867 lines (848 loc) · 28.4 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
package main
import (
"encoding/json"
"fmt"
"os"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v2/altsrc"
)
var Version = "development"
type cliFnWrapper func(ctx *cli.Context) error
// Note: All prompt responses will be added to this
var migrationReq = struct {
Auth string `survey:"auth"`
Environment string `survey:"environment"`
Account string `survey:"account"`
SecretScope string `survey:"secretScope"`
SecretManagerScope string `survey:"secretManagerScope"`
ConnectorScope string `survey:"connectorScope"`
WorkflowScope string `survey:"workflowScope"`
PipelineScope string `survey:"pipelineScope"`
TemplateScope string `survey:"templateScope"`
EnvironmentScope string `survey:"environmentScope"`
UserGroupScope string `survey:"userGroupScope"`
OrgIdentifier string `survey:"org"`
ProjectIdentifier string `survey:"project"`
AppId string `survey:"appId"`
AllAppEntities bool `survey:"all"`
WorkflowIds string `survey:"workflowIds"`
PipelineIds string `survey:"pipelineIds"`
TriggerIds string `survey:"triggerIds"`
File string `survey:"load"`
IdentifierCase string `survey:"identifierCase"`
LogLevel string `survey:"logLevel"`
Json bool `survey:"json"`
AllowInsecureReq bool `survey:"insecure"`
ProjectName string `survey:"projectName"`
OrgName string `survey:"orgName"`
UrlNG string `survey:"urlNG"`
UrlCG string `survey:"urlCG"`
DryRun bool `survey:"dryRun"`
FileExtensions string `survey:"fileExtensions"`
CustomExpressionsFile string `survey:"customExpressionsFile"`
CustomStringsFile string `survey:"customStringsFile"`
OverrideFile string `survey:"overrideFile"`
ExportFolderPath string `survey:"export"`
CsvFile string `survey:"csv"`
Names string `survey:"names"`
Identifiers string `survey:"identifiers"`
All bool `survey:"all"`
AsPipelines bool `survey:"asPipelines"`
TargetAccount string `survey:"targetAccount"`
TargetAuthToken string `survey:"targetAuth"`
BaseUrl string `survey:"baseUrl"`
TargetGatewayUrl string `survey:"targetGatewayUrl"`
Force bool `survey:"force"`
Flags string `survey:"flags"`
Platform string `survey:"platform"`
SpinnakerHost string `survey:"spinnaker-host"`
SpinnakerAPIKey string `survey:"spinnaker-api-key"`
SpinnakerAppName string `survey:"app-name"`
PipelineName string `survey:"pipeline-name"`
PipelineJson string `survey:"pipeline-json"`
Cert string `survey:"cert"`
Key string `survey:"key"`
Auth64 string `survey:"auth64"`
}{}
func getReqBody(entityType EntityType, filter Filter) RequestBody {
secretScope := getOrDefault(migrationReq.SecretScope, Project)
inputs := Inputs{
Overrides: LoadOverridesFromFile(migrationReq.OverrideFile),
Replace: LoadCustomeStringsFromFile(migrationReq.CustomStringsFile),
Expressions: LoadYamlFromFile(migrationReq.CustomExpressionsFile),
Settings: LoadSettingsFromFile(migrationReq.OverrideFile),
Defaults: Defaults{
Secret: EntityDefaults{Scope: secretScope},
SecretManager: EntityDefaults{Scope: getOrDefault(migrationReq.SecretManagerScope, secretScope)},
SecretManagerTemplate: EntityDefaults{Scope: getOrDefault(migrationReq.SecretManagerScope, secretScope)},
Connector: EntityDefaults{Scope: getOrDefault(migrationReq.ConnectorScope, Project)},
Template: EntityDefaults{Scope: getOrDefault(migrationReq.TemplateScope, Project)},
Environment: EntityDefaults{Scope: getOrDefault(migrationReq.EnvironmentScope, Project)},
Workflow: EntityDefaults{Scope: getOrDefault(migrationReq.WorkflowScope, Project), WorkflowAsPipeline: migrationReq.AsPipelines},
UserGroup: EntityDefaults{Scope: getOrDefault(migrationReq.UserGroupScope, Account)},
},
}
var flags []string
if len(migrationReq.Flags) > 0 {
flags = Split(migrationReq.Flags, ",")
}
flags = addIfNotExists(flags, "HELM_INFRA_WITH_STAGE_VAR")
destination := DestinationDetails{
ProjectIdentifier: migrationReq.ProjectIdentifier,
OrgIdentifier: migrationReq.OrgIdentifier,
AccountIdentifier: migrationReq.TargetAccount,
AuthToken: migrationReq.TargetAuthToken,
GatewayUrl: migrationReq.TargetGatewayUrl,
}
body := RequestBody{Inputs: inputs, DestinationDetails: destination, EntityType: entityType, Filter: filter, IdentifierCaseFormat: migrationReq.IdentifierCase,
Flags: flags}
b, err := json.Marshal(body)
if err != nil {
log.Debug(err)
}
log.Debugf("Request details: %s", b)
return body
}
func addIfNotExists(arr []string, strToAdd string) []string {
for _, str := range arr {
if str == strToAdd {
return arr
}
}
return append(arr, strToAdd)
}
func logMigrationDetails() {
log.WithFields(log.Fields{
"Account": migrationReq.Account,
"SecretScope": migrationReq.SecretScope,
"ConnectorScope": migrationReq.ConnectorScope,
"TemplateScope": migrationReq.TemplateScope,
"AppID": migrationReq.AppId,
"OrgIdentifier": migrationReq.OrgIdentifier,
"ProjectIdentifier": migrationReq.ProjectIdentifier,
"Flags": migrationReq.Flags,
}).Info("Migration details")
}
func logSpinnakerMigrationDetails(authMethod string) {
determinePipelineOutput := func() string {
if len(migrationReq.PipelineJson) > 0 {
return migrationReq.PipelineJson
}
if len(migrationReq.PipelineName) > 0 {
return migrationReq.PipelineName
}
return "All"
}
// Manually format the log message with line breaks
logMessage := fmt.Sprintf("\nMigration details:\n"+
" Platform: %s\n"+
" Spinnaker Host: %s\n"+
" App name: %s\n"+
" Pipeline(s): %s\n"+
" Authentication method: %s \n"+
" Insecure: %t",
migrationReq.Platform,
migrationReq.SpinnakerHost,
migrationReq.SpinnakerAppName,
determinePipelineOutput(),
authMethod,
migrationReq.AllowInsecureReq,
)
// Log the formatted message
log.Infof(logMessage)
}
func cliWrapper(fn cliFnWrapper, ctx *cli.Context) error {
if len(migrationReq.LogLevel) > 0 {
level, err := log.ParseLevel(migrationReq.LogLevel)
if err != nil {
log.Fatal("Invalid log level")
}
log.SetLevel(level)
}
if migrationReq.Json {
log.SetFormatter(&log.JSONFormatter{})
}
return fn(ctx)
}
func init() {
// Log as JSON instead of the default ASCII formatter.
log.SetFormatter(&log.TextFormatter{
FullTimestamp: true,
})
// Output to stdout instead of the default stderr
// Can be any io.Writer, see below for File example
log.SetOutput(os.Stdout)
// Only log the warning severity or above.
log.SetLevel(log.InfoLevel)
cli.VersionPrinter = func(cCtx *cli.Context) {
fmt.Println(cCtx.App.Version)
}
}
func main() {
CheckGithubForReleases()
globalFlags := []cli.Flag{
altsrc.NewStringFlag(&cli.StringFlag{
Name: "env",
Usage: "possible values - Prod, QA, Dev",
Destination: &migrationReq.Environment,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "base-url",
Usage: "provide the `BASE_URL` for self managed platforms",
Destination: &migrationReq.BaseUrl,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "destination-project",
Usage: "`destination-project` destination project url in next gen",
Destination: &migrationReq.UrlNG,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "source-app",
Usage: "`source-app` source application url in current gen",
Destination: &migrationReq.UrlCG,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "account",
Usage: "`ACCOUNT` that you wish to migrate",
Destination: &migrationReq.Account,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "api-key",
Usage: "`API_KEY` to authenticate & authorise the migration.",
Destination: &migrationReq.Auth,
EnvVars: []string{"HARNESS_MIGRATOR_AUTH"},
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "secret-scope",
Usage: "`SCOPE` to create secrets in. Possible values - account, org, project",
Destination: &migrationReq.SecretScope,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "secret-manager-scope",
Usage: "`SCOPE` to create secret managers in. Possible values - account, org, project",
Destination: &migrationReq.SecretManagerScope,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "connector-scope",
Usage: "`SCOPE` to create connectors in. Possible values - account, org, project",
Destination: &migrationReq.ConnectorScope,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "workflow-scope",
Usage: "`SCOPE` to create workflows in. Possible values - account, org, project",
Destination: &migrationReq.WorkflowScope,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "template-scope",
Usage: "`SCOPE` to create templates in. Possible values - account, org, project",
Destination: &migrationReq.TemplateScope,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "environment-scope",
Usage: "`SCOPE` to create environment in. Possible values - account, org, project",
Destination: &migrationReq.EnvironmentScope,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "user-group-scope",
Usage: "`SCOPE` to create user groups in. Possible values - account, org, project",
Destination: &migrationReq.UserGroupScope,
DefaultText: Account,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "org",
Usage: "organisation `IDENTIFIER` in next gen",
Destination: &migrationReq.OrgIdentifier,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "project",
Usage: "project `IDENTIFIER` in next gen",
Destination: &migrationReq.ProjectIdentifier,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "app",
Usage: "`APP_ID` in current gen",
Destination: &migrationReq.AppId,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "load",
Usage: "`FILE` to load flags from",
Destination: &migrationReq.File,
}),
altsrc.NewBoolFlag(&cli.BoolFlag{
Name: "insecure",
Usage: "allow insecure API requests. This is automatically set to true if environment is Dev",
Destination: &migrationReq.AllowInsecureReq,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "log-level",
Usage: "set the log level. Possible values - trace, debug, info, warn, error, fatal, panic. Default is `info`",
Destination: &migrationReq.LogLevel,
DefaultText: "info",
}),
altsrc.NewBoolFlag(&cli.BoolFlag{
Name: "json",
Usage: "log as JSON instead of standard ASCII formatter",
Destination: &migrationReq.Json,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "identifier-format",
Usage: "`FORMAT` to use for generation of identifiers. Supported values as CAMEL_CASE & LOWER_CASE",
Destination: &migrationReq.IdentifierCase,
Value: "CAMEL_CASE",
DefaultText: "CAMEL_CASE",
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "target-account",
Usage: "destination `ACCOUNT` that you wish to migrate to",
Destination: &migrationReq.TargetAccount,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "target-api-key",
Usage: "`API_KEY` for the target account to authenticate & authorise the migration.",
Destination: &migrationReq.TargetAuthToken,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "target-gateway-url",
Usage: "destination gateway `URL`. For Prod1 & Prod2, use https://app.harness.io/gateway, for Prod3 use https://app3.harness.io/gateway",
Destination: &migrationReq.TargetGatewayUrl,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "custom-expressions",
Usage: "provide a `FILE` to load custom expressions from",
Destination: &migrationReq.CustomExpressionsFile,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "replace",
Usage: "provide a `FILE` to load strings from",
Destination: &migrationReq.CustomStringsFile,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "override",
Usage: "provide a `FILE` to load overrides",
Destination: &migrationReq.OverrideFile,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "flags",
Usage: "provide a list of flags for custom logic",
Destination: &migrationReq.Flags,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "platform",
Usage: "Specifies the platform that serves as the source for migration to the next-generation harness. Supported values: harness-legacy (default), spinnaker.",
Destination: &migrationReq.Platform,
DefaultText: legacy,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "spinnaker-host",
Usage: "Specifies URL to the Spinnaker Gate service. Required when --platform is spinnaker.",
Destination: &migrationReq.SpinnakerHost,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "pipeline-json",
Usage: "Specifies Spinnaker Pipeline JSON file to be migrated.",
Destination: &migrationReq.PipelineJson,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "spinnaker-api-key",
Usage: "Specifies URL to the Spinnaker Gate service. Required when --platform is spinnaker.",
Destination: &migrationReq.SpinnakerAPIKey,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "auth64",
Usage: "Base64 <username>:<password> in case Spinnaker uses basic auth.",
Destination: &migrationReq.Auth64,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "app-name",
Usage: "Specifies Spinnaker Application from which pipelines to be migrated.",
Destination: &migrationReq.SpinnakerAppName,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "cert",
Usage: "x509 cert location for authenticating with spinnaker",
Destination: &migrationReq.Cert,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "key",
Usage: "x509 key location for authenticating with spinnaker",
Destination: &migrationReq.Key,
}),
altsrc.NewBoolFlag(&cli.BoolFlag{
Name: "dryRun",
Usage: "perform a dry run without side effects",
Destination: &migrationReq.DryRun,
}),
}
app := &cli.App{
Name: "harness-upgrade",
Version: Version,
Usage: "Upgrade Harness CD from Current Gen to Next Gen!",
EnableBashCompletion: true,
Suggest: true,
Commands: []*cli.Command{
{
Name: "update",
Aliases: []string{"upgrade"},
Usage: "Check for updates and upgrade the CLI",
Action: func(context *cli.Context) error {
return cliWrapper(Update, context)
},
},
{
Name: "account-summary",
Usage: "Get a summary of an account",
Action: func(context *cli.Context) error {
return cliWrapper(GetAccountSummary, context)
},
},
{
Name: "application-summary",
Usage: "Get a summary of an app",
Action: func(context *cli.Context) error {
return cliWrapper(GetAppSummary, context)
},
},
{
Name: "user-groups",
Usage: "Import user groups from First Gen to Next Gen",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "all",
Usage: "if all user groups need to be migrated",
Destination: &migrationReq.All,
},
&cli.StringFlag{
Name: "ids",
Usage: "`IDs` of the user groups",
Destination: &migrationReq.Identifiers,
},
&cli.StringFlag{
Name: "names",
Usage: "`NAMES` of the user groups",
Destination: &migrationReq.Names,
},
},
Action: func(context *cli.Context) error {
return cliWrapper(migrateUserGroups, context)
},
},
{
Name: "account",
Usage: "Import secrets managers, secrets, connectors. This will not migrate services, environments, triggers, pipelines etc",
Action: func(context *cli.Context) error {
return cliWrapper(migrateAccountLevelEntities, context)
},
},
{
Name: "app",
Usage: "Import an app into an existing project by providing the `appId`",
Action: func(context *cli.Context) error {
return cliWrapper(migrateApp, context)
},
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "all",
Usage: "if set will migrate all workflows & pipelines",
Destination: &migrationReq.AllAppEntities,
},
},
},
{
Name: "service",
Aliases: []string{"services"},
Usage: "Import services into an existing project from an application",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "all",
Usage: "if all services in the app need to be migrated",
Destination: &migrationReq.All,
},
&cli.StringFlag{
Name: "ids",
Usage: "`IDs` of the services",
Destination: &migrationReq.Identifiers,
},
&cli.StringFlag{
Name: "names",
Usage: "`NAMES` of the services",
Destination: &migrationReq.Names,
},
},
Action: func(context *cli.Context) error {
return cliWrapper(migrateServices, context)
},
},
{
Name: "secrets",
Usage: "Import secrets",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "all",
Usage: "if all secrets in the account need to be migrated",
Destination: &migrationReq.All,
},
&cli.StringFlag{
Name: "ids",
Usage: "`IDs` of the secrets",
Destination: &migrationReq.Identifiers,
},
&cli.StringFlag{
Name: "names",
Usage: "`NAMES` of the secrets",
Destination: &migrationReq.Names,
},
},
Action: func(context *cli.Context) error {
return cliWrapper(migrateSecrets, context)
},
},
{
Name: "environments",
Usage: "Import environments into an existing project from an application",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "all",
Usage: "if all environments in the app need to be migrated",
Destination: &migrationReq.All,
},
&cli.StringFlag{
Name: "ids",
Usage: "`IDs` of the environments",
Destination: &migrationReq.Identifiers,
},
&cli.StringFlag{
Name: "names",
Usage: "`NAMES` of the environments",
Destination: &migrationReq.Names,
},
},
Action: func(context *cli.Context) error {
return cliWrapper(migrateEnvironments, context)
},
},
{
Name: "connectors",
Usage: "Import connectors",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "all",
Usage: "if all connectors in the account need to be migrated",
Destination: &migrationReq.All,
},
&cli.StringFlag{
Name: "ids",
Usage: "`IDs` of the connectors",
Destination: &migrationReq.Identifiers,
},
&cli.StringFlag{
Name: "names",
Usage: "`NAMES` of the connectors",
Destination: &migrationReq.Names,
},
},
Action: func(context *cli.Context) error {
return cliWrapper(migrateConnectors, context)
},
},
{
Name: "workflows",
Usage: "Import workflows as stage or pipeline templates by providing the `appId` & `workflowIds`",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "all",
Usage: "if all workflows in the app need to be migrated",
Destination: &migrationReq.All,
},
&cli.BoolFlag{
Name: "as-pipelines",
Usage: "create a pipeline for the workflows, this will create stage templates where possible & reuse the template to create the pipeline",
Destination: &migrationReq.AsPipelines,
},
altsrc.NewStringFlag(&cli.StringFlag{
Name: "workflows",
Usage: "workflows as comma separated values `workflowId1,workflowId2`",
Destination: &migrationReq.WorkflowIds,
}),
},
Action: func(context *cli.Context) error {
return cliWrapper(migrateWorkflows, context)
},
},
{
Name: "pipelines",
Usage: "Import pipelines into an existing project by providing the `appId` & `pipelineIds`",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "dryRun",
Usage: "dry run",
Destination: &migrationReq.DryRun,
},
&cli.BoolFlag{
Name: "all",
Usage: "all pipelines",
Destination: &migrationReq.All,
},
altsrc.NewStringFlag(&cli.StringFlag{
Name: "pipelines",
Usage: "first gen pipeline ids as comma separated values `pipeline1,pipeline2`",
Destination: &migrationReq.PipelineIds,
}),
&cli.StringFlag{
Name: "identifiers",
Usage: "`IDENTIFIERS` of the next gen pipelines",
Destination: &migrationReq.Identifiers,
},
&cli.StringFlag{
Name: "names",
Usage: "`NAMES` of the next gen pipeline",
Destination: &migrationReq.Names,
},
&cli.StringFlag{
Name: "pipeline-name",
Usage: "Specifies Spinnaker Pipeline to be migrated.",
Destination: &migrationReq.PipelineName,
},
&cli.StringFlag{
Name: "cert",
Usage: "Cert file location in case Spinnaker uses x509 auth",
Destination: &migrationReq.Cert,
},
&cli.BoolFlag{
Name: "insecure",
Usage: "Whether to validate the TLS certificate or not",
Destination: &migrationReq.AllowInsecureReq,
},
&cli.StringFlag{
Name: "key",
Usage: "Optional. key file location in case Spinnaker uses x509 auth",
Destination: &migrationReq.Key,
},
},
Subcommands: []*cli.Command{
{
Name: "rm",
Usage: "Remove nextgen pipelines",
Action: func(context *cli.Context) error {
return cliWrapper(BulkRemovePipelines, context)
},
},
{
Name: "import",
Usage: "import first gen pipelines to next gen",
Action: func(context *cli.Context) error {
return cliWrapper(migratePipelines, context)
},
},
},
},
{
Name: "triggers",
Usage: "Import triggers by providing the `appId` & `triggerIds`",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "all",
Usage: "if all triggers in the app need to be migrated",
Destination: &migrationReq.All,
},
altsrc.NewStringFlag(&cli.StringFlag{
Name: "triggers",
Usage: "triggers as comma separated values `triggerId1,triggerId2`",
Destination: &migrationReq.TriggerIds,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "names",
Usage: "First Gen `NAMES` of the triggers",
Destination: &migrationReq.Names,
}),
},
Action: func(context *cli.Context) error {
return cliWrapper(migrateTriggers, context)
},
},
{
Name: "expressions",
Usage: "looks for harness CG expressions in current directory & sub directories from current folder & replaces them with equivalent NG expressions",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "dry-run",
Usage: "if set will only list found expressions without actually replacing anything",
Destination: &migrationReq.DryRun,
},
&cli.StringFlag{
Name: "extensions",
Usage: "provide comma separated file extensions to look for expressions in. defaults to json, yaml & yml extensions",
Value: "json,yaml,yml",
DefaultText: "json,yaml,yml",
Destination: &migrationReq.FileExtensions,
},
},
Action: func(context *cli.Context) error {
return cliWrapper(ReplaceCurrentGenExpressionsWithNextGen, context)
},
},
{
Name: "project",
Usage: "Project specific commands like create, delete, list etc.",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "name",
Usage: "`NAME` for the project",
Destination: &migrationReq.ProjectName,
},
&cli.StringFlag{
Name: "identifier",
Usage: "`IDENTIFIER` for the project",
Destination: &migrationReq.ProjectIdentifier,
},
&cli.StringFlag{
Name: "export",
Usage: "`FOLDER_PATH` of where the files need to be exported to",
Value: ".",
DefaultText: ".",
Destination: &migrationReq.ExportFolderPath,
},
&cli.StringFlag{
Name: "csv",
Usage: "`CSV_FILE` path to the csv file",
Destination: &migrationReq.CsvFile,
},
&cli.StringFlag{
Name: "identifiers",
Usage: "`IDENTIFIERS` of the projects",
Destination: &migrationReq.Identifiers,
},
&cli.StringFlag{
Name: "names",
Usage: "`NAMES` of the projects",
Destination: &migrationReq.Names,
},
},
Subcommands: []*cli.Command{
{
Name: "csv-template",
Usage: "Get a CSV with application name, project name, project identifier template for an account",
Action: func(context *cli.Context) error {
return cliWrapper(GetProjectCSVTemplate, context)
},
},
{
Name: "create",
Usage: "Create a project",
Action: func(context *cli.Context) error {
return cliWrapper(createProject, context)
},
},
{
Name: "create-bulk",
Usage: "Creates apps as projects",
Action: func(context *cli.Context) error {
return cliWrapper(bulkCreateProject, context)
},
},
{
Name: "rm",
Usage: "Remove projects",
Action: func(context *cli.Context) error {
return cliWrapper(bulkRemoveProject, context)
},
},
},
},
{
Name: "org",
Usage: "Org specific commands.",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "name",
Usage: "`NAME` for the org",
Destination: &migrationReq.OrgName,
},
&cli.StringFlag{
Name: "identifier",
Usage: "`IDENTIFIER` for the org",
Destination: &migrationReq.OrgIdentifier,
},
&cli.StringFlag{
Name: "identifiers",
Usage: "`IDENTIFIERS` of the org",
Destination: &migrationReq.Identifiers,
},
&cli.StringFlag{
Name: "names",
Usage: "`NAMES` of the org",
Destination: &migrationReq.Names,
},
},
Subcommands: []*cli.Command{
{
Name: "create",
Usage: "Create an org",
Action: func(context *cli.Context) error {
return cliWrapper(createOrg, context)
},
},
{
Name: "rm",
Usage: "Remove org",
Action: func(context *cli.Context) error {
return cliWrapper(bulkRemoveOrg, context)
},
},
},
},
{
Name: "templates",
Usage: "Template specific commands.",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "identifiers",
Usage: "`IDENTIFIERS` of the next gen templates",
Destination: &migrationReq.Identifiers,
},
&cli.StringFlag{
Name: "ids",
Usage: "`IDS` of the first gen templates",
Destination: &migrationReq.Identifiers,
},
&cli.StringFlag{
Name: "names",
Usage: "`NAMES` of the template",
Destination: &migrationReq.Names,
},
&cli.BoolFlag{
Name: "force",
Usage: "to force delete template",
Destination: &migrationReq.Force,
},
&cli.BoolFlag{
Name: "all",
Usage: "if set will delete all templates",
Destination: &migrationReq.All,
},
},
Subcommands: []*cli.Command{
{
Name: "rm",
Usage: "Remove templates",
Action: func(context *cli.Context) error {
return cliWrapper(BulkRemoveTemplates, context)
},
},
{
Name: "import",
Usage: "import templates. pass the --app flag if you want to migrate app level templates else do not pass",
Action: func(context *cli.Context) error {
return cliWrapper(MigrateTemplates, context)
},
},
},
},
},
Before: altsrc.InitInputSourceWithContext(globalFlags, altsrc.NewYamlSourceFromFlagFunc("load")),
Flags: globalFlags,
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}