automaticConfigUpgrade takes the config path of the current 2.x config and attempts to perform the update steps to update it to a 3.x config Returns the new startup config, a bool of whether to fallback to legacy config, map of users per database, map of roles per database, and an error
(ctx context.Context, configPath string)
| 194 | // update it to a 3.x config |
| 195 | // Returns the new startup config, a bool of whether to fallback to legacy config, map of users per database, map of roles per database, and an error |
| 196 | func automaticConfigUpgrade(ctx context.Context, configPath string) (sc *StartupConfig, disablePersistentConfig bool, users map[string]map[string]*auth.PrincipalConfig, roles map[string]map[string]*auth.PrincipalConfig, err error) { |
| 197 | legacyServerConfig, err := LoadLegacyServerConfig(ctx, configPath) |
| 198 | if err != nil { |
| 199 | return nil, false, nil, nil, err |
| 200 | } |
| 201 | |
| 202 | if legacyServerConfig.DisablePersistentConfig != nil && *legacyServerConfig.DisablePersistentConfig { |
| 203 | return nil, true, users, roles, nil |
| 204 | } |
| 205 | |
| 206 | base.InfofCtx(ctx, base.KeyAll, "Config is a legacy config, and disable_persistent_config was not requested. Attempting automatic config upgrade.") |
| 207 | |
| 208 | startupConfig, dbConfigs, err := legacyServerConfig.ToStartupConfig(ctx) |
| 209 | if err != nil { |
| 210 | return nil, false, nil, nil, err |
| 211 | } |
| 212 | |
| 213 | dbConfigs, err = sanitizeDbConfigs(dbConfigs) |
| 214 | if err != nil { |
| 215 | return nil, false, nil, nil, err |
| 216 | } |
| 217 | |
| 218 | // Attempt to establish connection to server |
| 219 | cluster, err := CreateBootstrapConnectionFromStartupConfig(ctx, startupConfig, base.PerUseClusterConnections) |
| 220 | if err != nil { |
| 221 | return nil, false, nil, nil, err |
| 222 | } |
| 223 | |
| 224 | bootstrap := bootstrapContext{ |
| 225 | Connection: cluster, |
| 226 | } |
| 227 | // Write database configs to CBS with groupID "default" |
| 228 | for _, dbConfig := range dbConfigs { |
| 229 | dbc := dbConfig.ToDatabaseConfig() |
| 230 | |
| 231 | dbc.Version, err = GenerateDatabaseConfigVersionID(ctx, "", &dbc.DbConfig) |
| 232 | if err != nil { |
| 233 | return nil, false, nil, nil, err |
| 234 | } |
| 235 | |
| 236 | dbc.SGVersion = base.ProductVersion.String() |
| 237 | |
| 238 | // Return users and roles separate from config |
| 239 | users = make(map[string]map[string]*auth.PrincipalConfig) |
| 240 | roles = make(map[string]map[string]*auth.PrincipalConfig) |
| 241 | users[dbc.Name] = dbc.Users |
| 242 | roles[dbc.Name] = dbc.Roles |
| 243 | dbc.Roles = nil |
| 244 | dbc.Users = nil |
| 245 | |
| 246 | configGroupID := PersistentConfigDefaultGroupID |
| 247 | if startupConfig.Bootstrap.ConfigGroupID != "" { |
| 248 | configGroupID = startupConfig.Bootstrap.ConfigGroupID |
| 249 | } |
| 250 | |
| 251 | _, err = bootstrap.InsertConfig(ctx, *dbc.Bucket, configGroupID, dbc) |
| 252 | if err != nil { |
| 253 | // If key already exists just continue |