Documentation
¶
Overview ¶
Package team synchronises email addresses with GitHub teams.
Discovery ¶
You must provide a discovery adapter in order to use this adapter. This is because converting email addresses to GitHub usernames isn't straightforward. At OVO, we enforce SAML for our GitHub users, and have provided a SAML -> GitHub Username discovery adapter, but you may need to write your own.
Requirements ¶
In order to synchronise with GitHub, you'll need to create a [Personal Access Token] with the following permissions:
- admin:org
- write:org
- read:org
Examples ¶
See [New] and Init.
Index ¶
Examples ¶
Constants ¶
const DiscoveryMechanism gosync.ConfigKey = "discovery_mechanism"
DiscoveryMechanism for converting emails into GitHub users and vice versa. Supported values are:
const GitHubOrg gosync.ConfigKey = "github_org"
GitHubOrg is the name of your GitHub organisation.
For example:
https://github.com/ovotech/go-sync
`ovotech` is the name of our organisation.
const GitHubToken gosync.ConfigKey = "github_token"
GitHubToken is the token used to authenticate with GitHub. See package docs for more information on how to obtain this token.
const SamlMuteUserNotFoundErr gosync.ConfigKey = "saml_mute_user_not_found_err"
SamlMuteUserNotFoundErr mutes the UserNotFoundErr if SAML discovery fails to discover a user from GitHub.
const TeamSlug gosync.ConfigKey = "team_slug"
TeamSlug is the name of your team slug within your organisation.
For example:
https://github.com/orgs/ovotech/teams/foobar
`foobar` is the name of our team slug.
Variables ¶
This section is empty.
Functions ¶
func WithClient ¶ added in v0.14.0
WithClient passes a custom GitHub client to the adapter.
Example ¶
package main
import (
"context"
"log"
"github.com/google/go-github/v47/github"
"golang.org/x/oauth2"
gosync "github.com/ovotech/go-sync"
"github.com/ovotech/go-sync/adapters/github/team"
)
func main() {
ctx := context.Background()
oauthClient := oauth2.NewClient(ctx, oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: "token"},
))
gitHubClient := github.NewClient(oauthClient)
adapter, err := team.Init(ctx, map[gosync.ConfigKey]string{
team.GitHubToken: "my-github-token",
team.GitHubOrg: "my-org",
team.TeamSlug: "my-team-slug",
team.DiscoveryMechanism: "saml",
}, team.WithClient(gitHubClient))
if err != nil {
log.Fatal(err)
}
gosync.New(adapter)
}
func WithDiscoveryService ¶ added in v0.14.0
func WithDiscoveryService(discovery discovery.GitHubDiscovery) gosync.ConfigFn[*Team]
WithDiscoveryService passes a GitHub Discovery Service to the adapter.
Example ¶
package main
import (
"context"
"log"
"github.com/shurcooL/githubv4"
"golang.org/x/oauth2"
gosync "github.com/ovotech/go-sync"
"github.com/ovotech/go-sync/adapters/github/discovery/saml"
"github.com/ovotech/go-sync/adapters/github/team"
)
func main() {
ctx := context.Background()
oauthClient := oauth2.NewClient(ctx, oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: "token"},
))
discoverySvc := saml.New(githubv4.NewClient(oauthClient), "my-org")
adapter, err := team.Init(ctx, map[gosync.ConfigKey]string{
team.GitHubToken: "my-github-token",
team.GitHubOrg: "my-org",
team.TeamSlug: "my-team-slug",
}, team.WithDiscoveryService(discoverySvc))
if err != nil {
log.Fatal(err)
}
gosync.New(adapter)
}
func WithLogger ¶
WithLogger passes a custom logger to the adapter.
Example ¶
package main
import (
"context"
"log"
"os"
gosync "github.com/ovotech/go-sync"
"github.com/ovotech/go-sync/adapters/github/team"
)
func main() {
ctx := context.Background()
logger := log.New(os.Stdout, "", log.LstdFlags)
adapter, err := team.Init(ctx, map[gosync.ConfigKey]string{
team.GitHubToken: "my-github-token",
team.GitHubOrg: "my-org",
team.TeamSlug: "my-team-slug",
team.DiscoveryMechanism: "saml",
}, team.WithLogger(logger))
if err != nil {
log.Fatal(err)
}
gosync.New(adapter)
}
Types ¶
type Team ¶
func Init ¶ added in v0.7.0
func Init( ctx context.Context, config map[gosync.ConfigKey]string, configFns ...gosync.ConfigFn[*Team], ) (*Team, error)
Init a new GitHub Team gosync.Adapter.
Required config:
Example ¶
package main
import (
"context"
"log"
gosync "github.com/ovotech/go-sync"
"github.com/ovotech/go-sync/adapters/github/team"
)
func main() {
ctx := context.Background()
adapter, err := team.Init(ctx, map[gosync.ConfigKey]string{
team.GitHubToken: "my-github-token",
team.GitHubOrg: "my-org",
team.TeamSlug: "my-team-slug",
team.DiscoveryMechanism: "saml",
})
if err != nil {
log.Fatal(err)
}
gosync.New(adapter)
}