team

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

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

https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token

Examples

See New and Init.

Index

Examples

Constants

View Source
const DiscoveryMechanism gosync.ConfigKey = "discovery_mechanism"

DiscoveryMechanism for converting emails into GitHub users and vice versa. Supported values are:

View Source
const GitHubOrg gosync.ConfigKey = "github_org"

GitHubOrg is the name of your GitHub organisation.

https://docs.github.com/en/organizations/collaborating-with-groups-in-organizations/about-organizations

For example:

https://github.com/ovotech/go-sync

`ovotech` is the name of our organisation.

View Source
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.

View Source
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 Init added in v0.7.0

func Init(ctx context.Context, config map[gosync.ConfigKey]string) (gosync.Adapter, 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)
}

Types

type Team

type Team struct {
	Logger *log.Logger
	// contains filtered or unexported fields
}

func New

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

New GitHub Team gosync.Adapter.

Recommended reading for parameters:

Example
package main

import (
	"context"

	"github.com/google/go-github/v47/github"
	"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()

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

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

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

	gosync.New(adapter)
}

func (*Team) Add

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

Add email addresses to a GitHub Team.

func (*Team) Get

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

Get email addresses in a GitHub Team.

func (*Team) Remove

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

Remove email addresses from a GitHub Team.

Jump to

Keyboard shortcuts

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