team

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

README

GitHub Team adapter for Go Sync

This adapter synchronises email addresses with a GitHub team.

Requirements

In order to synchronise with GitHub, you'll need to create a Personal Access Token with the following permissions:

Scopes
admin:org
write:org
read:org

Example

package main

import (
	"context"
	"log"

	"github.com/google/go-github/v47/github"
	"github.com/ovotech/go-sync"
	"github.com/ovotech/go-sync/adapters/github/discovery/saml"
	"github.com/ovotech/go-sync/adapters/github/team"
	"github.com/shurcooL/githubv4"
	"golang.org/x/oauth2"
)

func main() {
	ctx := context.Background()

	// Authenticated client to communicate with GitHub APIs.
	oauthClient := oauth2.NewClient(ctx, oauth2.StaticTokenSource(
		&oauth2.Token{AccessToken: "my-github-token"},
	))

	var (
		gitHubV3Client = github.NewClient(oauthClient)      // GitHub V3 API is used by GH Teams adapter.
		gitHubV4Client = githubv4.NewClient(oauthClient)    // GitHub V4 API is used by SAML discovery.
		samlClient     = saml.New(gitHubV4Client, "my-org") // GitHub Discovery service uses SAML to convert emails into GH users.
	)

	ghTeam := team.New(gitHubV3Client, samlClient, "my-org", "my-team-slug")

	svc := gosync.New(ghTeam)

	// Synchronise a Slack User group with something else.
	anotherServiceAdapter := someAdapter.New()

	err := svc.SyncWith(context.Background(), anotherServiceAdapter)
	if err != nil {
		log.Fatal(err)
	}
}

Documentation

Overview

Package team synchronises emails with GitHub teams.

You must provide a discovery service 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 service, but you may need to write your own.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithLogger

func WithLogger(logger *log.Logger) func(*Team)

WithLogger sets a custom logger.

Types

type GitHubDiscovery

type GitHubDiscovery interface {
	GetUsernameFromEmail(context.Context, []string) ([]string, error)
	GetEmailFromUsername(context.Context, []string) ([]string, error)
}

GitHubDiscovery is required because there are multiple ways to convert a GitHub email into a username. At OVO we use SAML, but other organisations may use public emails or another mechanism.

type Team

type Team struct {
	// contains filtered or unexported fields
}

func New

func New(client *github.Client, discovery GitHubDiscovery, org string, slug string, optsFn ...func(*Team)) *Team

New instantiates a new GitHub Team adapter.

func (*Team) Add

func (t *Team) Add(ctx context.Context, emails []string) error

Add emails to a GitHub Team.

func (*Team) Get

func (t *Team) Get(ctx context.Context) ([]string, error)

Get emails of users in a GitHub team.

func (*Team) Remove

func (t *Team) Remove(ctx context.Context, emails []string) error

Remove emails from a GitHub team.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL