aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/github/export.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-02-23 19:20:45 +0100
committerGitHub <noreply@github.com>2020-02-23 19:20:45 +0100
commit8ef6438fb476e9d510a39ead321cbeee6288e2d2 (patch)
tree2bcd2a5420bbdbed13b3de82992c30b7d17893e2 /bridge/github/export.go
parent0e68c10ffc3f9e72e32b8cdfcd917b3fe1ab240c (diff)
parent0cebe1e57e7e4b03aef77cd11bd4fc683c32afc6 (diff)
downloadgit-bug-8ef6438fb476e9d510a39ead321cbeee6288e2d2.tar.gz
Merge pull request #341 from MichaelMure/bridges-default-login
bridge: record the login used during the configure and use it as default credential
Diffstat (limited to 'bridge/github/export.go')
-rw-r--r--bridge/github/export.go47
1 files changed, 20 insertions, 27 deletions
diff --git a/bridge/github/export.go b/bridge/github/export.go
index 12b62fa6..b939d878 100644
--- a/bridge/github/export.go
+++ b/bridge/github/export.go
@@ -35,10 +35,13 @@ type githubExporter struct {
identityClient map[entity.Id]*githubv4.Client
// the client to use for non user-specific queries
- // should be the client of the default user
+ // it's the client associated to the "default-login" config
+ // used for the github V4 API (graphql)
defaultClient *githubv4.Client
// the token of the default user
+ // it's the token associated to the "default-login" config
+ // used for the github V3 API (REST)
defaultToken *auth.Token
// github repository ID
@@ -59,34 +62,12 @@ func (ge *githubExporter) Init(_ context.Context, repo *cache.RepoCache, conf co
ge.cachedOperationIDs = make(map[entity.Id]string)
ge.cachedLabels = make(map[string]string)
- user, err := repo.GetUserIdentity()
- if err != nil {
- return err
- }
-
// preload all clients
- err = ge.cacheAllClient(repo)
+ err := ge.cacheAllClient(repo)
if err != nil {
return err
}
- ge.defaultClient, err = ge.getClientForIdentity(user.Id())
- if err != nil {
- return err
- }
-
- login := user.ImmutableMetadata()[metaKeyGithubLogin]
- creds, err := auth.List(repo, auth.WithMeta(auth.MetaKeyLogin, login), auth.WithTarget(target), auth.WithKind(auth.KindToken))
- if err != nil {
- return err
- }
-
- if len(creds) == 0 {
- return ErrMissingIdentityToken
- }
-
- ge.defaultToken = creds[0].(*auth.Token)
-
return nil
}
@@ -111,12 +92,24 @@ func (ge *githubExporter) cacheAllClient(repo *cache.RepoCache) error {
return nil
}
- if _, ok := ge.identityClient[user.Id()]; !ok {
- client := buildClient(creds[0].(*auth.Token))
- ge.identityClient[user.Id()] = client
+ if _, ok := ge.identityClient[user.Id()]; ok {
+ continue
+ }
+
+ client := buildClient(creds[0].(*auth.Token))
+ ge.identityClient[user.Id()] = client
+
+ // assign the default client and token as well
+ if ge.defaultClient == nil && login == ge.conf[confKeyDefaultLogin] {
+ ge.defaultClient = client
+ ge.defaultToken = creds[0].(*auth.Token)
}
}
+ if ge.defaultClient == nil {
+ return fmt.Errorf("no token found for the default login \"%s\"", ge.conf[confKeyDefaultLogin])
+ }
+
return nil
}