reconciler

package
v0.0.0-...-110cbc6 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package reconciler reconciles the events

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBadParameter is returned when bad parameters are passed to a request
	ErrBadParameter = errors.New("bad parameters in request")

	// ErrRequestNonSuccess is returned when a call to the slack API returns a non-success status
	ErrRequestNonSuccess = errors.New("got a non-success response from slack")

	// ErrAppNameEmpty is returned when the governor application name is empty
	ErrAppNameEmpty = errors.New("governor application name is empty")

	// ErrGovernorUserPendingStatus is returned when an event it received for a user with pending status
	ErrGovernorUserPendingStatus = errors.New("governor user has pending status")

	// ErrGroupMembershipNotFound is returned when a group membership action
	// is requested and the user is not found in the group
	ErrGroupMembershipNotFound = errors.New("user not found in group")

	// ErrGroupMembershipFound is returned when a group membership delete request finds the
	// user in the governor group
	ErrGroupMembershipFound = errors.New("delete request user found in group")

	// ErrSlackUserGroupNotFound is returned when the slack user group is not found
	ErrSlackUserGroupNotFound = errors.New("slack user group not found")

	// ErrSlackWorkspaceNotFound is returned when the slack workspace (team) is not found
	ErrSlackWorkspaceNotFound = errors.New("slack workspace not found")
)

Functions

This section is empty.

Types

type Option

type Option func(r *Reconciler)

Option is a functional configuration option

func WithApplicationType

func WithApplicationType(t string) Option

WithApplicationType sets the application type slug

func WithAuditEventWriter

func WithAuditEventWriter(a *auditevent.EventWriter) Option

WithAuditEventWriter sets auditEventWriter

func WithClient

func WithClient(c *slack.Client) Option

WithClient sets slack client

func WithDryRun

func WithDryRun(d bool) Option

WithDryRun sets dryrun

func WithGovernorClient

func WithGovernorClient(c *governor.Client) Option

WithGovernorClient sets governor api client

func WithInterval

func WithInterval(i time.Duration) Option

WithInterval sets the reconciler interval

func WithLocker

func WithLocker(l *natslock.Locker) Option

WithLocker sets the lead election locker

func WithLogger

func WithLogger(l *zap.Logger) Option

WithLogger sets logger

func WithQueue

func WithQueue(q string) Option

WithQueue sets nats queue for events

func WithUserGroupPrefix

func WithUserGroupPrefix(p string) Option

WithUserGroupPrefix sets a prefix for user group names

type Reconciler

type Reconciler struct {
	Client         *slack.Client
	GovernorClient govClientIface
	ID             uuid.UUID
	Locker         *natslock.Locker
	Logger         *zap.Logger
	// contains filtered or unexported fields
}

Reconciler reconciles with downstream system

func New

func New(opts ...Option) *Reconciler

New returns a new reconciler

func (*Reconciler) AddUserGroupMember

func (r *Reconciler) AddUserGroupMember(ctx context.Context, groupID, userID string) error

AddUserGroupMember adds a user to a user group if they are not already a member

func (*Reconciler) CreateUserGroup

func (r *Reconciler) CreateUserGroup(ctx context.Context, groupID, appID string) error

CreateUserGroup creates a slack user group for the given governor group if it's linked to a slack application

func (*Reconciler) DeleteUserGroup

func (r *Reconciler) DeleteUserGroup(ctx context.Context, groupID, appID string) error

DeleteUserGroup deletes a corresponding slack user group for the given governor group if it's linked to a slack application. Since Slack doesn't support deleting user groups we simulate deletion by disabling and renaming the user group to a timestamped name.

func (*Reconciler) RemoveUserGroupMember

func (r *Reconciler) RemoveUserGroupMember(ctx context.Context, groupID, userID string) error

RemoveUserGroupMember removes a user from a user group. Slack doesn't allow removing the last user in a group, so in that case we'll return an error.

func (*Reconciler) Run

func (r *Reconciler) Run(ctx context.Context)

Run starts the reconciler loop

func (*Reconciler) Stop

func (r *Reconciler) Stop()

Stop stops the reconciler loop and does any necessary cleanup

func (*Reconciler) UpdateUserGroupMembers

func (r *Reconciler) UpdateUserGroupMembers(ctx context.Context, groupID, appID string) error

UpdateUserGroupMembers updates the members of a slack user group to match the members of the governor group

type UserGroup

type UserGroup struct {
	ID          string
	Name        string
	Handle      string
	Description string
	Users       []string
}

UserGroup has the basic details of a slack user group

Jump to

Keyboard shortcuts

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