Documentation
¶
Overview ¶
Package user manages user accounts and their team membership.
Index ¶
- Constants
- Variables
- func NewService(opts Options) *service
- func NewTeamMembershipCommand(apiclient *otfapi.Client) *cobra.Command
- func NewUserCommand(api *otfapi.Client) *cobra.Command
- type CreateUserOptions
- type CreateUserTokenOptions
- type NewUserOption
- type Options
- type User
- func (u *User) CanAccessOrganization(action rbac.Action, org string) bool
- func (u *User) CanAccessSite(action rbac.Action) bool
- func (u *User) CanAccessTeam(action rbac.Action, teamID string) bool
- func (u *User) CanAccessWorkspace(action rbac.Action, policy internal.WorkspacePolicy) bool
- func (u *User) IsOwner(organization string) bool
- func (u *User) IsSiteAdmin() bool
- func (u *User) IsTeamMember(teamID string) bool
- func (u *User) Organizations() []string
- func (u *User) String() string
- type UserListOptions
- type UserService
- type UserSpec
- type UserToken
Constants ¶
const ( SiteAdminID = "user-site-admin" SiteAdminUsername = "site-admin" )
const UserTokenKind tokens.Kind = "user_token"
Variables ¶
var ErrCannotDeleteOnlyOwner = errors.New("cannot remove the last owner")
var (
SiteAdmin = User{ID: SiteAdminID, Username: SiteAdminUsername}
)
Functions ¶
func NewService ¶
func NewService(opts Options) *service
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 *sql.DB *tfeapi.Responder html.Renderer internal.HostnameService tokens.TokensService logr.Logger team.TeamService }
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 ¶
UserFromContext retrieves a user from a context
func (*User) CanAccessOrganization ¶
func (*User) CanAccessWorkspace ¶
func (*User) IsSiteAdmin ¶
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 ¶
IsTeamMember determines whether user is a member of the given team.
func (*User) Organizations ¶
Organizations returns the user's membership of organizations (indirectly via their membership of teams).
NOTE: always returns a non-nil slice
type UserListOptions ¶
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) ListTeamUsers(ctx context.Context, teamID string) ([]*User, error) DeleteUser(ctx context.Context, username string) error AddTeamMembership(ctx context.Context, teamID string, usernames []string) error RemoveTeamMembership(ctx context.Context, teamID string, usernames []string) error SetSiteAdmins(ctx context.Context, usernames ...string) error // contains filtered or unexported methods }