team

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2023 License: Apache-2.0 Imports: 11 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 SamlMuteUserNotFoundErr gosync.ConfigKey = "saml_mute_user_not_found_err"

SamlMuteUserNotFoundErr mutes the UserNotFoundErr if SAML discovery fails to discover a user from GitHub.

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 WithClient added in v0.14.0

func WithClient(client *github.Client) gosync.ConfigFn[*Team]

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

func WithLogger(logger *log.Logger) gosync.ConfigFn[*Team]

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

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

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)
}

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