This repository has been archived by the owner on May 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
migrate.go
201 lines (183 loc) · 6.08 KB
/
migrate.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
package commands
//
// Deprecated, repurpose this command if we have to run another migration later
//
// var MigrateCommand = cli.Command{
// Name: "migrate",
// Description: "Migrate from config version 1 to config version 2",
// Usage: "Migrate from config version 1 to config version 2",
// Action: func(c *cli.Context) error {
// ctx := c.Context
// file := c.String("file")
// cfgv1, err := LoadConfigV1(file)
// if err != nil {
// return err
// }
// if cfgv1.Version != 1 {
// return fmt.Errorf("expected config to be version 1, found %d", cfgv1.Version)
// }
// clio.Info("detected config version 1")
// clio.Info("this command will update your config to match the new format")
// conf := survey.Confirm{Message: "Please confirm you want to migrate your config version from 1 -> 2"}
// var migrate bool
// err = survey.AskOne(&conf, &migrate)
// if err != nil {
// return err
// }
// if !migrate {
// clio.Info("cancelled migration")
// return nil
// }
// cfgv2 := deploy.Config{
// Version: 2,
// Deployment: cfgv1.Deployment,
// }
// // identity provider type
// cfgv2.Deployment.Parameters.IdentityProviderType = strings.ToLower(cfgv1.Deployment.Parameters.IdentityProviderType)
// // providers
// for k, v := range cfgv1.Providers {
// newWith := make(map[string]string)
// for k2, w := range v.With {
// // add a version to the provider ssm params
// if strings.HasPrefix(w, "awsssm://") {
// cfg, err := cfaws.ConfigFromContextOrDefault(ctx)
// if err != nil {
// return err
// }
// client := ssm.NewFromConfig(cfg)
// // get the lastest param version from ssm
// o, err := client.GetParameterHistory(ctx, &ssm.GetParameterHistoryInput{Name: aws.String(strings.TrimPrefix(w, "awsssm://"))})
// if err != nil {
// return err
// }
// version := int64(1)
// for _, p := range o.Parameters {
// if p.Version > int64(version) {
// version = p.Version
// }
// }
// // fix some bad casing from v1 config
// w += fmt.Sprintf(":%d", version)
// }
// newWith[strings.ReplaceAll(k2, "ID", "Id")] = w
// }
// err := cfgv2.Deployment.Parameters.ProviderConfiguration.Add(k, deploy.Provider{Uses: v.Uses, With: newWith})
// if err != nil {
// return err
// }
// }
// // Identity
// if cfgv1.Identity != nil {
// if cfgv1.Identity.Azure != nil {
// b, err := json.Marshal(cfgv1.Identity.Azure)
// if err != nil {
// return err
// }
// var newWith map[string]string
// err = json.Unmarshal(b, &newWith)
// if err != nil {
// return err
// }
// cfgv2.Deployment.Parameters.IdentityConfiguration.Upsert(identitysync.IDPTypeAzureAD, newWith)
// }
// if cfgv1.Identity.Google != nil {
// b, err := json.Marshal(cfgv1.Identity.Google)
// if err != nil {
// return err
// }
// var newWith map[string]string
// err = json.Unmarshal(b, &newWith)
// if err != nil {
// return err
// }
// cfgv2.Deployment.Parameters.IdentityConfiguration.Upsert(identitysync.IDPTypeGoogle, newWith)
// }
// if cfgv1.Identity.Okta != nil {
// b, err := json.Marshal(cfgv1.Identity.Okta)
// if err != nil {
// return err
// }
// var newWith map[string]string
// err = json.Unmarshal(b, &newWith)
// if err != nil {
// return err
// }
// cfgv2.Deployment.Parameters.IdentityConfiguration.Upsert(identitysync.IDPTypeOkta, newWith)
// }
// }
// // Identity
// if cfgv1.Notifications != nil {
// if cfgv1.Notifications.Slack != nil {
// b, err := json.Marshal(cfgv1.Notifications.Slack)
// if err != nil {
// return err
// }
// var newWith map[string]string
// err = json.Unmarshal(b, &newWith)
// if err != nil {
// return err
// }
// cfgv2.Deployment.Parameters.NotificationsConfiguration.Upsert(slacknotifier.NotificationsTypeSlack, newWith)
// }
// }
// err = cfgv2.Save(file)
// if err != nil {
// return err
// }
// clio.Success("Successfully migrated from config version 1 -> 2")
// return nil
// },
// }
// func LoadConfigV1(f string) (ConfigV1, error) {
// if _, err := os.Stat(f); errors.Is(err, os.ErrNotExist) {
// return ConfigV1{}, errors.New("config file does not exist")
// }
// fileRead, err := os.OpenFile(f, os.O_RDWR|os.O_CREATE, 0600)
// if err != nil {
// return ConfigV1{}, err
// }
// defer fileRead.Close()
// var dc ConfigV1
// err = yaml.NewDecoder(fileRead).Decode(&dc)
// if err != nil {
// return ConfigV1{}, err
// }
// return dc, nil
// }
// type ConfigV1 struct {
// Version int `yaml:"version"`
// Deployment deploy.Deployment `yaml:"deployment"`
// Providers map[string]Provider `yaml:"providers,omitempty"`
// Notifications *NotificationsConfig `yaml:"notifications,omitempty"`
// Identity *IdentityConfig `yaml:"identity,omitempty"`
// }
// type Provider struct {
// Uses string `yaml:"uses" json:"uses"`
// With map[string]string `yaml:"with" json:"with"`
// }
// type IdentityConfig struct {
// Google *Google `yaml:"google,omitempty" json:"google,omitempty"`
// Okta *Okta `yaml:"okta,omitempty" json:"okta,omitempty"`
// Azure *Azure `yaml:"azure,omitempty" json:"azure,omitempty"`
// }
// type Google struct {
// APIToken string `yaml:"apiToken" json:"apiToken"`
// Domain string `yaml:"domain" json:"domain"`
// AdminEmail string `yaml:"adminEmail" json:"adminEmail"`
// }
// type Okta struct {
// APIToken string `yaml:"apiToken" json:"apiToken"`
// OrgURL string `yaml:"orgUrl" json:"orgUrl"`
// }
// type Azure struct {
// // V1 config had a casing issue with yaml
// TenantID string `yaml:"tenantID" json:"tenantId"`
// ClientID string `yaml:"clientID" json:"clientId"`
// ClientSecret string `yaml:"clientSecret" json:"clientSecret"`
// }
// type NotificationsConfig struct {
// Slack *SlackConfig `yaml:"slack,omitempty" json:"slack,omitempty"`
// }
// type SlackConfig struct {
// APIToken string `yaml:"apiToken" json:"apiToken"`
// }