user

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2023 License: MPL-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package user manages user accounts and their team membership.

Index

Constants

View Source
const (
	SiteAdminID       = "user-site-admin"
	SiteAdminUsername = "site-admin"
)
View Source
const UserTokenKind tokens.Kind = "user_token"

Variables

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

Functions

func NewTeamMembershipCommand

func NewTeamMembershipCommand(apiclient *otfapi.Client) *cobra.Command

func NewUserCommand

func NewUserCommand(apiClient *otfapi.Client) *cobra.Command

Types

type CreateUserOptions

type CreateUserOptions struct {
	Username string `json:"username"`
}

type CreateUserTokenOptions

type CreateUserTokenOptions struct {
	Description string
}

CreateUserTokenOptions are options for creating a user token via the service endpoint

type NewUserOption

type NewUserOption func(*User)

func WithTeams

func WithTeams(memberships ...*team.Team) NewUserOption

type Options

type Options struct {
	SiteToken     string
	TokensService *tokens.Service
	TeamService   *team.Service

	*sql.DB
	*tfeapi.Responder
	html.Renderer
	logr.Logger
}

type Service added in v0.2.2

type Service struct {
	logr.Logger
	// contains filtered or unexported fields
}

func NewService

func NewService(opts Options) *Service

func (*Service) AddHandlers added in v0.2.2

func (a *Service) AddHandlers(r *mux.Router)

func (*Service) AddTeamMembership added in v0.2.2

func (a *Service) AddTeamMembership(ctx context.Context, teamID string, usernames []string) error

AddTeamMembership adds users to a team. If a user does not exist then the user is created first.

func (*Service) Create added in v0.2.2

func (a *Service) Create(ctx context.Context, username string, opts ...NewUserOption) (*User, error)

func (*Service) CreateToken added in v0.2.2

func (a *Service) CreateToken(ctx context.Context, opts CreateUserTokenOptions) (*UserToken, []byte, error)

CreateToken creates a user token. Only users can create a user token, and they can only create a token for themselves.

func (*Service) Delete added in v0.2.2

func (a *Service) Delete(ctx context.Context, username string) error

func (*Service) DeleteToken added in v0.2.2

func (a *Service) DeleteToken(ctx context.Context, tokenID string) error

func (*Service) GetUser added in v0.2.2

func (a *Service) GetUser(ctx context.Context, spec UserSpec) (*User, error)

func (*Service) List added in v0.2.2

func (a *Service) List(ctx context.Context) ([]*User, error)

List lists all users.

func (*Service) ListOrganizationUsers added in v0.2.2

func (a *Service) ListOrganizationUsers(ctx context.Context, organization string) ([]*User, error)

ListOrganizationUsers lists an organization's users

func (*Service) ListTeamUsers added in v0.2.2

func (a *Service) ListTeamUsers(ctx context.Context, teamID string) ([]*User, error)

ListTeamUsers lists users that are members of the given team. The caller needs either organization-wide authority to call this endpoint, or they need to be a member of the team.

func (*Service) ListTokens added in v0.2.2

func (a *Service) ListTokens(ctx context.Context) ([]*UserToken, error)

func (Service) NewUserToken added in v0.2.2

func (f Service) NewUserToken(username string, opts CreateUserTokenOptions) (*UserToken, []byte, error)

func (*Service) RemoveTeamMembership added in v0.2.2

func (a *Service) RemoveTeamMembership(ctx context.Context, teamID string, usernames []string) error

RemoveTeamMembership removes users from a team.

func (*Service) SetSiteAdmins added in v0.2.2

func (a *Service) SetSiteAdmins(ctx context.Context, usernames ...string) error

SetSiteAdmins authoritatively promotes users with the given usernames to site admins. If no such users exist then they are created. Any unspecified users that are currently site admins are demoted.

type User

type User struct {
	ID        string    `jsonapi:"primary,users"`
	CreatedAt time.Time `jsonapi:"attribute" json:"created-at"`
	UpdatedAt time.Time `jsonapi:"attribute" json:"updated-at"`
	SiteAdmin bool      `jsonapi:"attribute" json:"site-admin"`

	// username is globally unique
	Username string `jsonapi:"attribute" json:"username"`

	// user belongs to many teams
	Teams []*team.Team
}

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

func (u *User) CanAccessTeam(action rbac.Action, teamID string) 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 UserListOptions

type UserListOptions struct {
	Organization *string
	TeamName     *string
}

UserListOptions are options for the ListUsers endpoint.

type UserSpec

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

func (UserSpec) LogValue

func (s UserSpec) LogValue() slog.Value

type UserToken

type UserToken struct {
	ID          string
	CreatedAt   time.Time
	Description string
	Username    string // Token belongs to a user
}

UserToken provides information about an API token for a user.

Jump to

Keyboard shortcuts

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