-
Notifications
You must be signed in to change notification settings - Fork 7
/
app.go
100 lines (87 loc) · 2.72 KB
/
app.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
package main
import (
log "github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
func migrateApp(*cli.Context) error {
promptConfirm := PromptDefaultInputs()
if migrationReq.Platform == spinnaker {
return migrateSpinnakerApplication()
}
if len(migrationReq.AppId) == 0 {
promptConfirm = true
migrationReq.AppId = TextInput("Please provide the application ID of the app that you wish to import -")
}
if len(migrationReq.WorkflowScope) == 0 {
promptConfirm = true
migrationReq.WorkflowScope = SelectInput("Scope for workflows:", scopes, Project)
}
promptConfirm = PromptOrgAndProject([]string{Project}) || promptConfirm
logMigrationDetails()
if promptConfirm {
confirm := ConfirmInput("Do you want to proceed with app migration?")
if !confirm {
log.Fatal("Aborting...")
}
}
// Migrating the app
log.Info("Importing the application....")
log.Info("Importing the services, environments, infra, manifests...")
CreateEntities(getReqBody(Application, Filter{
AppId: migrationReq.AppId,
}))
if migrationReq.AllAppEntities {
log.Info("Importing all the workflows...")
CreateEntities(getReqBody(Workflow, Filter{
AppId: migrationReq.AppId,
}))
log.Info("Importing all the pipelines...")
CreateEntities(getReqBody(Pipeline, Filter{
AppId: migrationReq.AppId,
}))
}
log.Info("Imported the application.")
return nil
}
func migrateSpinnakerApplication() error {
log.Info("Starting the migration of Spinnaker application")
authMethod := authBasic
if len(migrationReq.Cert) > 0 {
authMethod = authx509
}
log.Info("Importing the application....")
if len(migrationReq.SpinnakerHost) == 0 {
migrationReq.SpinnakerHost = TextInput("Please provide spinnaker host : ")
}
if len(migrationReq.SpinnakerAppName) == 0 {
migrationReq.SpinnakerAppName = TextInput("Please provide the Spinnaker application name : ")
}
logSpinnakerMigrationDetails(authMethod)
confirm := ConfirmInput("Do you want to proceed?")
if !confirm {
log.Fatal("Aborting...")
}
if len(migrationReq.ProjectIdentifier) == 0 {
migrationReq.ProjectIdentifier = TextInput("Name of the Project : ")
}
jsonBody, err := getAllPipelines(authMethod, migrationReq.SpinnakerAppName)
if err != nil {
return err
}
pipelines, err := normalizeJsonArray(jsonBody)
if err != nil {
return err
}
//first check if there are any pipeline to be migrated or not if not then don't create the project
if len(pipelines) == 0 {
log.Info("No pipelines found to be migrated")
return nil
}
dryRun := migrationReq.DryRun
payload := map[string]interface{}{
"pipelines": pipelines, // Expecting pipelines as []map[string]interface{}
"dryRun": dryRun, // dryRun as a bool
}
_, err = createSpinnakerPipelines(payload, dryRun)
return err
}