Skip to content
This repository was archived by the owner on Aug 24, 2024. It is now read-only.

Commit 23c3138

Browse files
committed
fix migration2 after an excessive refactor
1 parent 44ebefc commit 23c3138

File tree

7 files changed

+44
-56
lines changed

7 files changed

+44
-56
lines changed

go.mod

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@ require (
88
github.com/dustin/go-humanize v1.0.0
99
github.com/fatih/color v1.9.0
1010
github.com/go-git/go-git/v5 v5.1.0
11+
github.com/mattn/go-isatty v0.0.12 // indirect
1112
github.com/pkg/errors v0.9.1
12-
github.com/shurcooL/githubv4 v0.0.0-20200915023059-bc5e4feb2971
13-
github.com/shurcooL/graphql v0.0.0-20181231061246-d48a9a75455f // indirect
1413
github.com/spf13/cobra v1.0.0
1514
github.com/stretchr/testify v1.6.1
16-
github.com/xanzy/go-gitlab v0.37.0
17-
golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288
18-
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4
1915
golang.org/x/text v0.3.3
2016
)
2117

go.sum

Lines changed: 16 additions & 27 deletions
Large diffs are not rendered by default.

migration2/after/bridge/core/auth/credential.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import (
1616
const (
1717
keyringKeyPrefix = "auth-"
1818
keyringKeyKind = "kind"
19-
keyringKeyTarget = "TargetT"
19+
keyringKeyTarget = "target"
2020
keyringKeyCreateTime = "createtime"
21-
keyringKeySalt = "SaltT"
22-
keyringKeyPrefixMeta = "MetaT."
21+
keyringKeySalt = "salt"
22+
keyringKeyPrefixMeta = "meta."
2323

2424
MetaKeyLogin = "login"
2525
MetaKeyBaseURL = "base-url"

migration2/after/bridge/core/auth/credential_base.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import (
1111
)
1212

1313
type CredentialBase struct {
14-
TargetT string
15-
CreateTimeT time.Time
16-
SaltT []byte
17-
MetaT map[string]string
14+
TargetT string `json:"target"`
15+
CreateTimeT time.Time `json:"create_time"`
16+
SaltT []byte `json:"salt"`
17+
MetaT map[string]string `json:"meta"`
1818
}
1919

2020
func NewCredentialBase(target string, createTime time.Time, salt []byte, meta map[string]string) *CredentialBase {
@@ -99,7 +99,7 @@ func (cb *CredentialBase) Salt() []byte {
9999

100100
func (cb *CredentialBase) validate() error {
101101
if cb.TargetT == "" {
102-
return fmt.Errorf("missing TargetT")
102+
return fmt.Errorf("missing target")
103103
}
104104
if cb.CreateTimeT.IsZero() || cb.CreateTimeT.Equal(time.Time{}) {
105105
return fmt.Errorf("missing creation time")

migration2/before/bridge/core/auth/credential.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import (
1616
const (
1717
configKeyPrefix = "git-bug.auth"
1818
configKeyKind = "kind"
19-
configKeyTarget = "TargetT"
19+
configKeyTarget = "target"
2020
configKeyCreateTime = "createtime"
21-
configKeySalt = "SaltT"
22-
configKeyPrefixMeta = "MetaT."
21+
configKeySalt = "salt"
22+
configKeyPrefixMeta = "meta."
2323

2424
MetaKeyLogin = "login"
2525
MetaKeyBaseURL = "base-url"
@@ -159,7 +159,7 @@ func makeSalt() []byte {
159159
func saltFromConfig(configs map[string]string) ([]byte, error) {
160160
val, ok := configs[configKeySalt]
161161
if !ok {
162-
return nil, fmt.Errorf("no credential SaltT found")
162+
return nil, fmt.Errorf("no credential salt found")
163163
}
164164
return base64.StdEncoding.DecodeString(val)
165165
}

migration2/before/bridge/core/auth/credential_base.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import (
88
)
99

1010
type CredentialBase struct {
11-
TargetT string
12-
CreateTimeT time.Time
13-
SaltT []byte
14-
MetaT map[string]string
11+
TargetT string `json:"target"`
12+
CreateTimeT time.Time `json:"create_time"`
13+
SaltT []byte `json:"salt"`
14+
MetaT map[string]string `json:"meta"`
1515
}
1616

1717
func newCredentialBase(target string) *CredentialBase {
@@ -61,7 +61,7 @@ func (cb *CredentialBase) Salt() []byte {
6161

6262
func (cb *CredentialBase) validate() error {
6363
if cb.TargetT == "" {
64-
return fmt.Errorf("missing TargetT")
64+
return fmt.Errorf("missing target")
6565
}
6666
if cb.CreateTimeT.IsZero() || cb.CreateTimeT.Equal(time.Time{}) {
6767
return fmt.Errorf("missing creation time")

migration2/migration2_test.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ func TestMigrate12(t *testing.T) {
2828
err = beforeauth.Store(repo1, token)
2929
require.NoError(t, err)
3030

31+
repo2 := afterrepo.NewMockRepoForTest()
32+
require.NoError(t, err)
33+
34+
m := Migration2{}
35+
err = m.migrate(repo1, repo2)
36+
require.NoError(t, err, "got error when migrating repository with version 2")
37+
38+
// to avoid the types problem, we compare the json output of those credentials
39+
// which also mean we need to ensure a deterministic ordering:
40+
3141
oldCredentials, err := beforeauth.List(repo1)
3242
require.NoError(t, err)
3343
sort.Slice(oldCredentials, func(i, j int) bool {
@@ -39,13 +49,6 @@ func TestMigrate12(t *testing.T) {
3949
oldJSON, err := json.Marshal(oldCredentials)
4050
require.NoError(t, err)
4151

42-
repo2 := afterrepo.NewMockRepoForTest()
43-
require.NoError(t, err)
44-
45-
m := Migration2{}
46-
err = m.migrate(repo1, repo2)
47-
require.NoError(t, err, "got error when migrating repository with version 2")
48-
4952
newCredentials, err := afterauth.List(repo2)
5053
require.NoError(t, err)
5154
sort.Slice(newCredentials, func(i, j int) bool {

0 commit comments

Comments
 (0)