-
Notifications
You must be signed in to change notification settings - Fork 493
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix azure devops migration from 0.17 to 0.18 (#5999)
Cherry-pick of #5957 * fix: Fix AzDO connection migration 0.17 -> 0.18 In 0.17, all connection fields are encrypted. In 0.18 only `token` is, so we need a migration of AzDo connection to decrypt all fields but `token`. * fix: Allow setting entities=None to ScopeConfig Allow setting `entities` field to `None` in `ScopeConfig` and fallback to default value. * feat: Add RenameColumn migration op * fix: Add missing AzDO migrations from 0.17 to 0.18 Now that migrations have been made manual, we need to add all the migrations for all that changed from 0.17 to 0.18 that were automatic before... Those are all required migrations collected with `git diff v0.17.0 v0.18.0-beta7 -- backend/python/plugins/azuredevops/azuredevops/models.py`: * Rename GitRepository.transformation_rule_id -> scope_config_id * Add GitRepository.provider * Rename Job.startTime -> start_time * Rename Job.finishTime -> start_time --------- Co-authored-by: Camille Teruel <camille.teruel@meri.co>
- Loading branch information
1 parent
03ee5cf
commit c93dc82
Showing
5 changed files
with
135 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
...es/remote/models/migrationscripts/azuredevops/azuredevops_20230714_decrypt_azdo_fields.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
Licensed to the Apache Software Foundation (ASF) under one or more | ||
contributor license agreements. See the NOTICE file distributed with | ||
this work for additional information regarding copyright ownership. | ||
The ASF licenses this file to You under the Apache License, Version 2.0 | ||
(the "License"); you may not use this file except in compliance with | ||
the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package azuredevops | ||
|
||
import ( | ||
"github.com/apache/incubator-devlake/core/context" | ||
"github.com/apache/incubator-devlake/core/errors" | ||
"github.com/apache/incubator-devlake/core/models/migrationscripts/archived" | ||
"github.com/apache/incubator-devlake/core/plugin" | ||
"github.com/apache/incubator-devlake/helpers/migrationhelper" | ||
) | ||
|
||
var _ plugin.MigrationScript = (*DecryptConnectionFields)(nil) | ||
|
||
type azureDevopsConnection20230825 struct { | ||
archived.Model | ||
Name string | ||
Token string | ||
Proxy *string | ||
Organization *string | ||
} | ||
|
||
type DecryptConnectionFields struct{} | ||
|
||
func (script *DecryptConnectionFields) Up(basicRes context.BasicRes) errors.Error { | ||
encryptionSecret := basicRes.GetConfig(plugin.EncodeKeyEnvStr) | ||
if encryptionSecret == "" { | ||
return errors.BadInput.New("invalid encryptionSecret") | ||
} | ||
|
||
err := migrationhelper.TransformColumns( | ||
basicRes, | ||
script, | ||
"_tool_azuredevops_azuredevopsconnections", | ||
[]string{"name", "proxy", "organization"}, | ||
func(src *azureDevopsConnection20230825) (*azureDevopsConnection20230825, errors.Error) { | ||
encName := src.Name | ||
name, err := plugin.Decrypt(encryptionSecret, encName) | ||
if err != nil { | ||
return src, nil | ||
} | ||
src.Name = name | ||
|
||
if src.Proxy != nil { | ||
encProxy := *src.Proxy | ||
decProxy, err := plugin.Decrypt(encryptionSecret, encProxy) | ||
if err != nil { | ||
return src, nil | ||
} | ||
if decProxy == "" { | ||
src.Proxy = nil | ||
} else { | ||
src.Proxy = &decProxy | ||
} | ||
} | ||
|
||
if src.Organization != nil { | ||
encOrg := *src.Organization | ||
decOrg, err := plugin.Decrypt(encryptionSecret, encOrg) | ||
if err != nil { | ||
return src, nil | ||
} | ||
if decOrg == "" { | ||
src.Organization = nil | ||
} else { | ||
src.Organization = &decOrg | ||
} | ||
} | ||
return src, nil | ||
}, | ||
) | ||
return err | ||
} | ||
|
||
func (*DecryptConnectionFields) Version() uint64 { | ||
return 20230825090504 | ||
} | ||
|
||
func (script *DecryptConnectionFields) Name() string { | ||
return "Decrypt Azure DevOps connection fields" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters