Retire multi-account migration (#14430) · cli/cli@ba51bb4 · GitHub
Skip to content

Commit ba51bb4

Browse files
Retire multi-account migration (#14430)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 8fcd6a6 commit ba51bb4

5 files changed

Lines changed: 39 additions & 34 deletions

File tree

‎docs/multiple-accounts.md‎

Lines changed: 5 additions & 0 deletions

‎internal/config/auth_config_test.go‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ func TestUserWorksRightAfterMigration(t *testing.T) {
693693
require.NoError(t, err)
694694

695695
// When we migrate
696-
var m migration.MultiAccount
696+
var m migration.MultiAccountDeprecated
697697
c := cfg{authCfg.cfg}
698698
require.NoError(t, c.Migrate(m))
699699

@@ -710,7 +710,7 @@ func TestGitProtocolWorksRightAfterMigration(t *testing.T) {
710710
require.NoError(t, err)
711711

712712
// When we migrate
713-
var m migration.MultiAccount
713+
var m migration.MultiAccountDeprecated
714714
c := cfg{authCfg.cfg}
715715
require.NoError(t, c.Migrate(m))
716716

@@ -727,7 +727,7 @@ func TestHostsWorksRightAfterMigration(t *testing.T) {
727727
require.NoError(t, err)
728728

729729
// When we migrate
730-
var m migration.MultiAccount
730+
var m migration.MultiAccountDeprecated
731731
c := cfg{authCfg.cfg}
732732
require.NoError(t, c.Migrate(m))
733733

@@ -743,7 +743,7 @@ func TestDefaultHostWorksRightAfterMigration(t *testing.T) {
743743
require.NoError(t, err)
744744

745745
// When we migrate
746-
var m migration.MultiAccount
746+
var m migration.MultiAccountDeprecated
747747
c := cfg{authCfg.cfg}
748748
require.NoError(t, c.Migrate(m))
749749

@@ -760,7 +760,7 @@ func TestTokenWorksRightAfterMigration(t *testing.T) {
760760
require.NoError(t, err)
761761

762762
// When we migrate
763-
var m migration.MultiAccount
763+
var m migration.MultiAccountDeprecated
764764
c := cfg{authCfg.cfg}
765765
require.NoError(t, c.Migrate(m))
766766

@@ -837,7 +837,7 @@ func TestLogoutRightAfterMigrationRemovesHost(t *testing.T) {
837837
require.NoError(t, err)
838838

839839
// When we migrate and logout
840-
var m migration.MultiAccount
840+
var m migration.MultiAccountDeprecated
841841
c := cfg{authCfg.cfg}
842842
require.NoError(t, c.Migrate(m))
843843

@@ -852,7 +852,7 @@ func TestLoginInsecurePostMigrationUsesConfigForToken(t *testing.T) {
852852
authCfg := newTestAuthConfig(t)
853853

854854
// When we migrate and login with insecure storage
855-
var m migration.MultiAccount
855+
var m migration.MultiAccountDeprecated
856856
c := cfg{authCfg.cfg}
857857
require.NoError(t, c.Migrate(m))
858858

@@ -871,7 +871,7 @@ func TestLoginPostMigrationSetsGitProtocol(t *testing.T) {
871871
// Given we have logged in after migration
872872
authCfg := newTestAuthConfig(t)
873873

874-
var m migration.MultiAccount
874+
var m migration.MultiAccountDeprecated
875875
c := cfg{authCfg.cfg}
876876
require.NoError(t, c.Migrate(m))
877877

@@ -890,7 +890,7 @@ func TestLoginPostMigrationSetsUser(t *testing.T) {
890890
// Given we have logged in after migration
891891
authCfg := newTestAuthConfig(t)
892892

893-
var m migration.MultiAccount
893+
var m migration.MultiAccountDeprecated
894894
c := cfg{authCfg.cfg}
895895
require.NoError(t, c.Migrate(m))
896896

@@ -912,7 +912,7 @@ func TestLoginSecurePostMigrationRemovesTokenFromConfig(t *testing.T) {
912912
require.NoError(t, err)
913913

914914
// When we migrate and login again with secure storage
915-
var m migration.MultiAccount
915+
var m migration.MultiAccountDeprecated
916916
c := cfg{authCfg.cfg}
917917
require.NoError(t, c.Migrate(m))
918918

‎internal/config/migration/multi_account.go‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,31 @@ type tokenSource struct {
6868
// breaking existing users of go-gh which looks at a specific location
6969
// in the config for oauth tokens that are stored insecurely.
7070

71-
type MultiAccount struct {
71+
// MultiAccountDeprecated migrates the pre-v2.40 one-account-per-host
72+
// configuration into the multi-account schema.
73+
//
74+
// This migration no longer runs automatically. Its compatibility window
75+
// covered upgrades from versions that predated the multi-account schema.
76+
// Supported configurations now already use that schema, so running it before
77+
// every command no longer provides value. The implementation remains as
78+
// executable documentation of the original migration and its compatibility
79+
// constraints.
80+
type MultiAccountDeprecated struct {
7281
// Allow injecting a transport layer in tests.
7382
Transport http.RoundTripper
7483
}
7584

76-
func (m MultiAccount) PreVersion() string {
85+
func (m MultiAccountDeprecated) PreVersion() string {
7786
// It is expected that there is no version key since this migration
7887
// introduces it.
7988
return ""
8089
}
8190

82-
func (m MultiAccount) PostVersion() string {
91+
func (m MultiAccountDeprecated) PostVersion() string {
8392
return "1"
8493
}
8594

86-
func (m MultiAccount) Do(c *config.Config) error {
95+
func (m MultiAccountDeprecated) Do(c *config.Config) error {
8796
hostnames, err := c.Keys(hostsKey)
8897
// [github.com, github.localhost]
8998
// We wouldn't expect to have a hosts key when this is the first time anyone

‎internal/config/migration/multi_account_test.go‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/stretchr/testify/require"
1313
)
1414

15-
func TestMigration(t *testing.T) {
15+
func TestMultiAccountDeprecatedMigration(t *testing.T) {
1616
cfg := config.ReadFromString(`
1717
hosts:
1818
github.com:
@@ -25,7 +25,7 @@ hosts:
2525
git_protocol: https
2626
`)
2727

28-
var m migration.MultiAccount
28+
var m migration.MultiAccountDeprecated
2929
require.NoError(t, m.Do(cfg))
3030

3131
// First we'll check that the oauth tokens have been moved to their new locations
@@ -60,7 +60,7 @@ hosts:
6060
require.NoError(t, keyring.Set("gh:github.com", "", userOneToken))
6161
require.NoError(t, keyring.Set("gh:enterprise.com", "", userTwoToken))
6262

63-
var m migration.MultiAccount
63+
var m migration.MultiAccountDeprecated
6464
require.NoError(t, m.Do(cfg))
6565

6666
// Verify token gets stored with host and username
@@ -96,19 +96,19 @@ hosts:
9696
}
9797

9898
func TestPreVersionIsEmptyString(t *testing.T) {
99-
var m migration.MultiAccount
99+
var m migration.MultiAccountDeprecated
100100
require.Equal(t, "", m.PreVersion())
101101
}
102102

103103
func TestPostVersion(t *testing.T) {
104-
var m migration.MultiAccount
104+
var m migration.MultiAccountDeprecated
105105
require.Equal(t, "1", m.PostVersion())
106106
}
107107

108108
func TestMigrationReturnsSuccessfullyWhenNoHostsEntry(t *testing.T) {
109109
cfg := config.ReadFromString(``)
110110

111-
var m migration.MultiAccount
111+
var m migration.MultiAccountDeprecated
112112
require.NoError(t, m.Do(cfg))
113113
}
114114

@@ -117,7 +117,7 @@ func TestMigrationReturnsSuccessfullyWhenEmptyHosts(t *testing.T) {
117117
hosts:
118118
`)
119119

120-
var m migration.MultiAccount
120+
var m migration.MultiAccountDeprecated
121121
require.NoError(t, m.Do(cfg))
122122
}
123123

@@ -142,7 +142,7 @@ hosts:
142142
httpmock.StringResponse(`{"data":{"viewer":{"login":"monalisa"}}}`),
143143
)
144144

145-
m := migration.MultiAccount{Transport: reg}
145+
m := migration.MultiAccountDeprecated{Transport: reg}
146146
require.NoError(t, m.Do(cfg))
147147

148148
require.Equal(t, fmt.Sprintf("token %s", token), reg.Requests[0].Header.Get("Authorization"))
@@ -182,7 +182,7 @@ hosts:
182182
httpmock.StringResponse(`{"data":{"viewer":{"login":"monalisa"}}}`),
183183
)
184184

185-
m := migration.MultiAccount{Transport: reg}
185+
m := migration.MultiAccountDeprecated{Transport: reg}
186186
require.NoError(t, m.Do(cfg))
187187

188188
require.Equal(t, "token test-token", reg.Requests[0].Header.Get("Authorization"))
@@ -201,7 +201,7 @@ hosts:
201201
git_protocol: ssh
202202
`)
203203

204-
m := migration.MultiAccount{}
204+
m := migration.MultiAccountDeprecated{}
205205
require.NoError(t, m.Do(cfg))
206206

207207
requireNoKey(t, cfg, []string{"hosts", "github.com"})
@@ -218,7 +218,7 @@ hosts:
218218
git_protocol: ssh
219219
`)
220220

221-
m := migration.MultiAccount{}
221+
m := migration.MultiAccountDeprecated{}
222222
err := m.Do(cfg)
223223

224224
require.ErrorContains(t, err, `couldn't find oauth token for "github.com": keyring test error`)

‎internal/ghcmd/cmd.go‎

Lines changed: 0 additions & 9 deletions

0 commit comments

Comments
 (0)