/
config.go
53 lines (47 loc) · 1.05 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package githubprovider
import (
"golang.org/x/oauth2"
"github.com/google/go-github/github"
)
type Config struct {
UserKey string
OrganizationKey string
}
// Clients are created for auth. client
// OrgClient creates a new github client with authenticated owner of organization
// UserClient refers user's client.
//
// In example: while adding a new member to organization.
// OrgClient refers organization (owner of organization)
// UserClient refers member
type Clients struct {
OrgClient *github.Client
UserClient *github.Client
}
// Client returns clients for accessing github.
func (c *Config) Clients() (*Clients, error) {
orgClient := github.NewClient(
oauth2.NewClient(
oauth2.NoContext,
oauth2.StaticTokenSource(
&oauth2.Token{
AccessToken: c.OrganizationKey,
},
),
),
)
userClient := github.NewClient(
oauth2.NewClient(
oauth2.NoContext,
oauth2.StaticTokenSource(
&oauth2.Token{
AccessToken: c.UserKey,
},
),
),
)
return &Clients{
OrgClient: orgClient,
UserClient: userClient,
}, nil
}