aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/github/export.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-02-23 14:05:03 +0100
committerMichael Muré <batolettre@gmail.com>2020-02-23 14:20:54 +0100
commit0cebe1e57e7e4b03aef77cd11bd4fc683c32afc6 (patch)
tree6c488eef7d39ffcf9226cb1952460b44920ed39e /bridge/github/export.go
parentb3318335986618388637a9d35d68b39633e4548a (diff)
downloadgit-bug-0cebe1e57e7e4b03aef77cd11bd4fc683c32afc6.tar.gz
bridge: record the login used during the configure and use it as default credential
fix #338
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
}