auth

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2023 License: MPL-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package auth is responsible for authentication

Index

Constants

View Source
const (
	SiteAdminID       = "user-site-admin"
	SiteAdminUsername = "site-admin"
)

Variables

View Source
var ErrCannotDeleteOnlyOwner = errors.New("cannot remove the last owner")
View Source
var ErrRemovingOwnersTeamNotPermitted = errors.New("the owners team cannot be deleted")
View Source
var (
	SiteAdmin = User{ID: SiteAdminID, Username: SiteAdminUsername}
)

Functions

func NewService

func NewService(opts Options) *service

func NewTeamCommand added in v0.1.9

func NewTeamCommand(httpClient *http.Client) *cobra.Command

func NewUserCommand added in v0.1.9

func NewUserCommand(httpClient *http.Client) *cobra.Command

Types

type AuthService

type AuthService interface {
	TeamService
	UserService
}

type Client

type Client struct {
	internal.JSONAPIClient

	AuthService
}

func (*Client) AddTeamMembership

func (c *Client) AddTeamMembership(ctx context.Context, opts TeamMembershipOptions) error

AddTeamMembership adds users to a team via HTTP.

func (*Client) CreateTeam

func (c *Client) CreateTeam(ctx context.Context, organization string, opts CreateTeamOptions) (*Team, error)

CreateTeam creates a team via HTTP/JSONAPI.

func (*Client) CreateUser

func (c *Client) CreateUser(ctx context.Context, username string, _ ...NewUserOption) (*User, error)

CreateUser creates a user via HTTP/JSONAPI. Options are ignored.

func (*Client) DeleteTeam

func (c *Client) DeleteTeam(ctx context.Context, id string) error

DeleteTeam deletes a team via HTTP/JSONAPI.

func (*Client) DeleteUser

func (c *Client) DeleteUser(ctx context.Context, username string) error

DeleteUser deletes a user via HTTP/JSONAPI.

func (*Client) GetTeam

func (c *Client) GetTeam(ctx context.Context, organization, name string) (*Team, error)

GetTeam retrieves a team via HTTP/JSONAPI.

func (*Client) RemoveTeamMembership

func (c *Client) RemoveTeamMembership(ctx context.Context, opts TeamMembershipOptions) error

RemoveTeamMembership removes users from a team via HTTP.

type CreateTeamOptions

type CreateTeamOptions struct {
	// Name of team to create
	Name *string `schema:"name,required"`

	OrganizationAccessOptions

	// TFE fields that OTF does not support but persists merely to pass the
	// go-tfe integration tests
	SSOTeamID  *string
	Visibility *string
}

type NewUserOption

type NewUserOption func(*User)

func WithTeams

func WithTeams(memberships ...*Team) NewUserOption

type OrganizationAccess

type OrganizationAccess struct {
	ManageWorkspaces bool // admin access on all workspaces
	ManageVCS        bool // manage VCS providers
	ManageModules    bool // manage module registry

	// TFE fields that OTF does not support but persists merely to pass the
	// go-tfe integration tests
	ManageProviders       bool
	ManagePolicies        bool
	ManagePolicyOverrides bool
}

OrganizationAccess defines a team's organization access.

type OrganizationAccessOptions added in v0.0.50

type OrganizationAccessOptions struct {
	ManageWorkspaces *bool `schema:"manage_workspaces"`
	ManageVCS        *bool `schema:"manage_vcs"`
	ManageModules    *bool `schema:"manage_modules"`

	// TFE fields that OTF does not support but persists merely to pass the
	// go-tfe integration tests
	ManageProviders       *bool
	ManagePolicies        *bool
	ManagePolicyOverrides *bool
}

OrganizationAccessOptions defines access to be granted upon team creation or to grant/rescind to/from an existing team.

type OrganizationService

type OrganizationService organization.Service

Aliases to disambiguate service names when embedded together.

type Team

type Team struct {
	ID           string
	CreatedAt    time.Time
	Name         string
	Organization string

	Access OrganizationAccess

	// TFE fields that OTF does not support but persists merely to pass the
	// go-tfe integration tests
	Visibility string
	SSOTeamID  *string
}

Team is a group of users sharing a level of authorization.

func CreateTestTeam

func CreateTestTeam(t *testing.T, db *sql.DB, organization *organization.Organization) *Team

func NewTestTeam

func NewTestTeam(t *testing.T, organization string) *Team

func (*Team) IsOwners

func (t *Team) IsOwners() bool

func (*Team) OrganizationAccess

func (t *Team) OrganizationAccess() OrganizationAccess

func (*Team) String

func (t *Team) String() string

func (*Team) Update

func (t *Team) Update(opts UpdateTeamOptions) error

type TeamCLI added in v0.1.9

type TeamCLI struct {
	AuthService
}

type TeamMembershipOptions

type TeamMembershipOptions struct {
	Usernames []string
	TeamID    string
}

type TeamService

type TeamService interface {
	CreateTeam(ctx context.Context, organization string, opts CreateTeamOptions) (*Team, error)
	GetTeam(ctx context.Context, organization, team string) (*Team, error)
	GetTeamByID(ctx context.Context, teamID string) (*Team, error)
	ListTeams(ctx context.Context, organization string) ([]*Team, error)
	ListTeamMembers(ctx context.Context, teamID string) ([]*User, error)
	UpdateTeam(ctx context.Context, teamID string, opts UpdateTeamOptions) (*Team, error)
	DeleteTeam(ctx context.Context, teamID string) error
}

type UpdateTeamOptions

type UpdateTeamOptions struct {
	Name *string

	OrganizationAccessOptions

	// TFE fields that OTF does not support but persists merely to pass the
	// go-tfe integration tests
	SSOTeamID  *string
	Visibility *string
}

type User

type User struct {
	ID        string // ID uniquely identifies users
	CreatedAt time.Time
	UpdatedAt time.Time
	Username  string  // username is globally unique
	SiteAdmin bool    // Indicates whether user is a site admin
	Teams     []*Team // user belongs to many teams
}

User represents an otf user account.

func NewUser

func NewUser(username string, opts ...NewUserOption) *User

func UserFromContext

func UserFromContext(ctx context.Context) (*User, error)

UserFromContext retrieves a user from a context

func (*User) CanAccessOrganization

func (u *User) CanAccessOrganization(action rbac.Action, org string) bool

func (*User) CanAccessSite

func (u *User) CanAccessSite(action rbac.Action) bool

func (*User) CanAccessWorkspace

func (u *User) CanAccessWorkspace(action rbac.Action, policy internal.WorkspacePolicy) bool

func (*User) IsOwner

func (u *User) IsOwner(organization string) bool

IsOwner determines if user is an owner of an organization

func (*User) IsSiteAdmin

func (u *User) IsSiteAdmin() bool

IsSiteAdmin determines whether user is a site admin. A user is a site admin in either of two cases: (1) their account has been promoted to site admin (think sudo) (2) the account is *the* site admin (think root)

func (*User) IsTeamMember

func (u *User) IsTeamMember(teamID string) bool

IsTeamMember determines whether user is a member of the given team.

func (*User) Organizations

func (u *User) Organizations() []string

Organizations returns the user's membership of organizations (indirectly via their membership of teams).

NOTE: always returns a non-nil slice

func (*User) String

func (u *User) String() string

type UserCLI added in v0.1.9

type UserCLI struct {
	UserService
}

type UserListOptions

type UserListOptions struct {
	Organization *string
	TeamName     *string
}

UserListOptions are options for the ListUsers endpoint.

type UserService

type UserService interface {
	CreateUser(ctx context.Context, username string, opts ...NewUserOption) (*User, error)
	GetUser(ctx context.Context, spec UserSpec) (*User, error)
	ListUsers(ctx context.Context) ([]*User, error)
	ListOrganizationUsers(ctx context.Context, organization string) ([]*User, error)
	DeleteUser(ctx context.Context, username string) error
	AddTeamMembership(ctx context.Context, opts TeamMembershipOptions) error
	RemoveTeamMembership(ctx context.Context, opts TeamMembershipOptions) error
	SetSiteAdmins(ctx context.Context, usernames ...string) error
}

type UserSpec

type UserSpec struct {
	UserID                *string
	Username              *string
	AuthenticationTokenID *string
}

func (UserSpec) LogValue

func (s UserSpec) LogValue() slog.Value

Jump to

Keyboard shortcuts

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