accounts

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2018 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package accounts is a generated protocol buffer package.

It is generated from these files:

github.com/appcelerator/amp/data/accounts/accounts.proto

It has these top-level messages:

User
TeamResource
Team
OrganizationMember
Organization
Account

Index

Constants

View Source
const (
	AmpResourceName = "amprn"
	UserRN          = AmpResourceName + ":user"
	OrganizationRN  = AmpResourceName + ":organization"
	TeamRN          = AmpResourceName + ":team"
	StackRN         = AmpResourceName + ":stack"
	DashboardRN     = AmpResourceName + ":dashboard"
	ObjectStoreRN   = AmpResourceName + ":objectstore"

	CreateAction = "create"
	ReadAction   = "read"
	UpdateAction = "update"
	DeleteAction = "delete"
	LeaveAction  = "leave"
	AdminAction  = "admin"
	AnyAction    = CreateAction + "|" + ReadAction + "|" + UpdateAction + "|" + DeleteAction + "|" + LeaveAction + "|" + AdminAction
)

Resources and actions

View Source
const (
	InvalidName               = Error("username is invalid")
	InvalidEmail              = Error("email is invalid")
	PasswordTooWeak           = Error("password is too weak")
	WrongPassword             = Error("password is wrong")
	InvalidToken              = Error("token is invalid")
	UserAlreadyExists         = Error("user already exists")
	EmailAlreadyUsed          = Error("email is already in use")
	UserNotFound              = Error("user not found")
	UserNotVerified           = Error("user not verified")
	OrganizationAlreadyExists = Error("organization already exists")
	OrganizationNotFound      = Error("organization not found")
	TeamAlreadyExists         = Error("team already exists")
	TeamNotFound              = Error("team not found")
	AtLeastOneOwner           = Error("organization must have at least one owner")
	NotAuthorized             = Error("user not authorized")
	NotPartOfOrganization     = Error("user is not part of the organization")
	InvalidResourceID         = Error("invalid resource ID")
	ResourceNotFound          = Error("resource not found")
	ResourceAlreadyExists     = Error("resource already exists")
	TokenAlreadyUsed          = Error("token has already been used")
)

Errors

View Source
const BCryptCost = 12
View Source
const DefaultOrganization = "default"
View Source
const DefaultOrganizationEmail = "default@organization.amp"
View Source
const SuperOrganization = "so"
View Source
const SuperUser = "su"

Variables

View Source
var OrganizationRole_name = map[int32]string{
	0: "ORGANIZATION_MEMBER",
	1: "ORGANIZATION_OWNER",
}
View Source
var OrganizationRole_value = map[string]int32{
	"ORGANIZATION_MEMBER": 0,
	"ORGANIZATION_OWNER":  1,
}
View Source
var TeamPermissionLevel_name = map[int32]string{
	0: "TEAM_READ",
	1: "TEAM_WRITE",
	2: "TEAM_ADMIN",
}
View Source
var TeamPermissionLevel_value = map[string]int32{
	"TEAM_READ":  0,
	"TEAM_WRITE": 1,
	"TEAM_ADMIN": 2,
}

Functions

func CheckEmailAddress

func CheckEmailAddress(email string) (string, error)

CheckEmailAddress checks email address

func CheckID

func CheckID(ID string) (string, error)

CheckID checks resource id

func CheckName

func CheckName(name string) (string, error)

CheckName checks user name

func CheckPassword

func CheckPassword(password string) (string, error)

CheckPassword checks password

Types

type Account

type Account struct {
	User         string `protobuf:"bytes,1,opt,name=user" json:"user,omitempty"`
	Organization string `protobuf:"bytes,2,opt,name=organization" json:"organization,omitempty"`
}

func GetRequesterAccount

func GetRequesterAccount(ctx context.Context) *Account

GetRequesterAccount gets the requester account from the given context, i.e. the user or organization performing the request

func (*Account) Descriptor

func (*Account) Descriptor() ([]byte, []int)

func (*Account) GetOrganization added in v0.12.0

func (m *Account) GetOrganization() string

func (*Account) GetUser added in v0.12.0

func (m *Account) GetUser() string

func (*Account) ProtoMessage

func (*Account) ProtoMessage()

func (*Account) Reset

func (m *Account) Reset()

func (*Account) String

func (m *Account) String() string

type Error

type Error string

Error type

func (Error) Error

func (e Error) Error() string

type Interface

type Interface interface {
	// CreateUser creates a new user with given password
	CreateUser(ctx context.Context, name string, email string, password string) (user *User, err error)

	// CheckUserPassword checks the given user password
	CheckUserPassword(ctx context.Context, name string, password string) (err error)

	// SetUserPassword sets the given user password
	SetUserPassword(ctx context.Context, name string, password string) (err error)

	// GetUser fetches a user by name
	GetUser(ctx context.Context, name string) (user *User, err error)

	// GetUserByEmail fetches a user by email
	GetUserByEmail(ctx context.Context, email string) (user *User, err error)

	//GetUserEmail fetches a users email
	GetUserEmail(ctx context.Context, user *User) (string, error)

	// GetUserOrganizations gets the organizations the given user is member of
	GetUserOrganizations(ctx context.Context, name string) (organizations []*Organization, err error)

	// ListUsers lists users
	ListUsers(ctx context.Context) (users []*User, err error)

	// VerifyUser verifies a user account
	VerifyUser(ctx context.Context, name string) (err error)

	// DeleteNotVerifedUser deletes a not verified user by-passing the authorization check
	DeleteNotVerifiedUser(ctx context.Context, name string) (err error)

	// DeleteUser deletes a user by name
	DeleteUser(ctx context.Context, name string) (*User, error)

	// CreateOrganization creates a new organization
	CreateOrganization(ctx context.Context, name string, email string) (err error)

	// GetOrganization fetches a organization by name
	GetOrganization(ctx context.Context, name string) (organization *Organization, err error)

	// AddUserToOrganization adds a user to the given organization
	AddUserToOrganization(ctx context.Context, organizationName string, userName string) (err error)

	// RemoveUserFromOrganization removes a user from the given organization
	RemoveUserFromOrganization(ctx context.Context, organizationName string, userName string) (err error)

	// ChangeOrganizationMemberRole changes the role of given user in the given organization
	ChangeOrganizationMemberRole(ctx context.Context, organizationName string, userName string, role OrganizationRole) (err error)

	// ListOrganizations lists organizations
	ListOrganizations(ctx context.Context) (organizations []*Organization, err error)

	// DeleteOrganization deletes a organization by name
	DeleteOrganization(ctx context.Context, name string) (err error)

	// CreateTeam creates a new team
	CreateTeam(ctx context.Context, organizationName string, teamName string) (err error)

	// GetTeam fetches a team by name
	GetTeam(ctx context.Context, organizationName string, teamName string) (team *Team, err error)

	// ListTeams lists teams
	ListTeams(ctx context.Context, organizationName string) (teams []*Team, err error)

	// AddUserToTeam adds a user to the given team
	AddUserToTeam(ctx context.Context, organizationName string, teamName string, userName string) (err error)

	// RemoveUserFromTeam removes a user from the given team
	RemoveUserFromTeam(ctx context.Context, organizationName string, teamName string, userName string) (err error)

	// AddResourceToTeam adds a resource to the given team
	AddResourceToTeam(ctx context.Context, organizationName string, teamName string, resourceID string) (err error)

	// RemoveResourceFromTeam removes a resource from the given team
	RemoveResourceFromTeam(ctx context.Context, organizationName string, teamName string, resourceID string) (err error)

	// ChangeTeamResourcePermissionLevel changes the permission level over the given resource in the given team
	ChangeTeamResourcePermissionLevel(ctx context.Context, organizationName string, teamName string, resource string, permissionLevel TeamPermissionLevel) (err error)

	// ChangeTeamName changes the name of given team
	ChangeTeamName(ctx context.Context, organizationName string, teamName, newName string) (err error)

	// DeleteTeam deletes a team by name
	DeleteTeam(ctx context.Context, organizationName string, teamName string) (err error)

	// IsAuthorized returns whether the requesting user is authorized to perform the given action on given resource
	IsAuthorized(ctx context.Context, owner *Account, action string, resource string, resourceId string) bool

	// Reset resets the user storage
	Reset(ctx context.Context)
}

Interface defines the user data access layer

type Organization

type Organization struct {
	Name     string                `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
	Email    string                `protobuf:"bytes,2,opt,name=email" json:"email,omitempty"`
	CreateDt int64                 `protobuf:"varint,3,opt,name=create_dt,json=createDt" json:"create_dt,omitempty"`
	Members  []*OrganizationMember `protobuf:"bytes,4,rep,name=members" json:"members,omitempty"`
	Teams    []*Team               `protobuf:"bytes,5,rep,name=teams" json:"teams,omitempty"`
}

func (*Organization) Descriptor

func (*Organization) Descriptor() ([]byte, []int)

func (*Organization) GetCreateDt

func (m *Organization) GetCreateDt() int64

func (*Organization) GetEmail

func (m *Organization) GetEmail() string

func (*Organization) GetMembers

func (m *Organization) GetMembers() []*OrganizationMember

func (*Organization) GetName

func (m *Organization) GetName() string

func (*Organization) GetTeams

func (m *Organization) GetTeams() []*Team

func (*Organization) HasMember

func (o *Organization) HasMember(memberName string) bool

HasMember returns whether the given user is an organization member

func (*Organization) ProtoMessage

func (*Organization) ProtoMessage()

func (*Organization) Reset

func (m *Organization) Reset()

func (*Organization) String

func (m *Organization) String() string

func (*Organization) Validate

func (o *Organization) Validate() (err error)

Validate validates Organization

type OrganizationMember

type OrganizationMember struct {
	Name string           `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
	Role OrganizationRole `protobuf:"varint,2,opt,name=role,enum=accounts.OrganizationRole" json:"role,omitempty"`
}

func (*OrganizationMember) Descriptor

func (*OrganizationMember) Descriptor() ([]byte, []int)

func (*OrganizationMember) GetName

func (m *OrganizationMember) GetName() string

func (*OrganizationMember) GetRole

func (m *OrganizationMember) GetRole() OrganizationRole

func (*OrganizationMember) ProtoMessage

func (*OrganizationMember) ProtoMessage()

func (*OrganizationMember) Reset

func (m *OrganizationMember) Reset()

func (*OrganizationMember) String

func (m *OrganizationMember) String() string

type OrganizationRole

type OrganizationRole int32
const (
	OrganizationRole_ORGANIZATION_MEMBER OrganizationRole = 0
	OrganizationRole_ORGANIZATION_OWNER  OrganizationRole = 1
)

func (OrganizationRole) EnumDescriptor

func (OrganizationRole) EnumDescriptor() ([]byte, []int)

func (OrganizationRole) String

func (x OrganizationRole) String() string

type OwnerCondition added in v0.12.0

type OwnerCondition struct {
	ExpectedRoles            []OrganizationRole
	ExpectedPermissionLevels []TeamPermissionLevel
}

OwnerCondition is a condition which is fulfilled if the request's subject has ownership over the resource

func (*OwnerCondition) Fulfills added in v0.12.0

func (c *OwnerCondition) Fulfills(value interface{}, r *ladon.Request) bool

Fulfills returns true if subject is granted resource access

func (*OwnerCondition) GetName added in v0.12.0

func (c *OwnerCondition) GetName() string

GetName returns the condition's name.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store implements user data.Interface

func NewStore

func NewStore(s storage.Interface, registration string, SUPassword string) (*Store, error)

NewStore returns a new accounts storage

func (*Store) AddResourceToTeam

func (s *Store) AddResourceToTeam(ctx context.Context, organizationName string, teamName string, resourceID string) error

AddResourceToTeam adds a resource to the given team

func (*Store) AddUserToOrganization

func (s *Store) AddUserToOrganization(ctx context.Context, organizationName string, userName string) (err error)

AddUserToOrganization adds a user to the given organization

func (*Store) AddUserToTeam

func (s *Store) AddUserToTeam(ctx context.Context, organizationName string, teamName string, userName string) error

AddUserToTeam adds a user to the given team

func (*Store) ChangeOrganizationMemberRole

func (s *Store) ChangeOrganizationMemberRole(ctx context.Context, organizationName string, userName string, role OrganizationRole) (err error)

ChangeOrganizationMemberRole changes the role of given user in the given organization

func (*Store) ChangeTeamName added in v0.12.0

func (s *Store) ChangeTeamName(ctx context.Context, organizationName string, teamName, newName string) (err error)

ChangeTeamName changes the name of given team

func (*Store) ChangeTeamResourcePermissionLevel

func (s *Store) ChangeTeamResourcePermissionLevel(ctx context.Context, organizationName string, teamName string, resourceID string, permissionLevel TeamPermissionLevel) (err error)

ChangeTeamResourcePermissionLevel changes the permission level over the given resource in the given team

func (*Store) CheckUserPassword

func (s *Store) CheckUserPassword(ctx context.Context, name string, password string) error

CheckUserPassword checks the given user password

func (*Store) CreateOrganization

func (s *Store) CreateOrganization(ctx context.Context, name string, email string) error

CreateOrganization creates a new organization

func (*Store) CreateTeam

func (s *Store) CreateTeam(ctx context.Context, organizationName, teamName string) error

CreateTeam creates a new team

func (*Store) CreateUser

func (s *Store) CreateUser(ctx context.Context, name string, email string, password string) (user *User, err error)

CreateUser creates a new user

func (*Store) DeleteNotVerifiedUser added in v0.12.0

func (s *Store) DeleteNotVerifiedUser(ctx context.Context, name string) error

DeleteNotVerifiedUser deletes the user by name only if it's not verified

func (*Store) DeleteOrganization

func (s *Store) DeleteOrganization(ctx context.Context, name string) error

DeleteOrganization deletes a organization by name

func (*Store) DeleteTeam

func (s *Store) DeleteTeam(ctx context.Context, organizationName string, teamName string) error

DeleteTeam deletes a team by name

func (*Store) DeleteUser

func (s *Store) DeleteUser(ctx context.Context, name string) (*User, error)

DeleteUser deletes a user by name

func (*Store) GetOrganization

func (s *Store) GetOrganization(ctx context.Context, name string) (organization *Organization, err error)

GetOrganization fetches a organization by name

func (*Store) GetTeam

func (s *Store) GetTeam(ctx context.Context, organizationName string, teamName string) (*Team, error)

GetTeam fetches a team by name

func (*Store) GetUser

func (s *Store) GetUser(ctx context.Context, name string) (user *User, err error)

GetUser fetches a user by name

func (*Store) GetUserByEmail

func (s *Store) GetUserByEmail(ctx context.Context, email string) (*User, error)

GetUserByEmail fetches a user by email

func (*Store) GetUserEmail added in v0.15.0

func (s *Store) GetUserEmail(ctx context.Context, user *User) (string, error)

GetUserEmail fetches a users email

func (*Store) GetUserOrganizations added in v0.9.1

func (s *Store) GetUserOrganizations(ctx context.Context, name string) ([]*Organization, error)

GetUserOrganizations gets the organizations the given user is member of

func (*Store) IsAuthorized

func (s *Store) IsAuthorized(ctx context.Context, owner *Account, action string, resource string, resourceID string) bool

IsAuthorized returns whether the requesting user is authorized to perform the given action on given resource

func (*Store) ListOrganizations

func (s *Store) ListOrganizations(ctx context.Context) ([]*Organization, error)

ListOrganizations lists organizations

func (*Store) ListTeams

func (s *Store) ListTeams(ctx context.Context, organizationName string) ([]*Team, error)

ListTeams lists teams

func (*Store) ListUsers

func (s *Store) ListUsers(ctx context.Context) ([]*User, error)

ListUsers lists users

func (*Store) RemoveResourceFromTeam

func (s *Store) RemoveResourceFromTeam(ctx context.Context, organizationName string, teamName string, resourceID string) error

RemoveResourceFromTeam removes a resource from the given team

func (*Store) RemoveUserFromOrganization

func (s *Store) RemoveUserFromOrganization(ctx context.Context, organizationName string, userName string) (err error)

RemoveUserFromOrganization removes a user from the given organization

func (*Store) RemoveUserFromTeam

func (s *Store) RemoveUserFromTeam(ctx context.Context, organizationName string, teamName string, userName string) error

RemoveUserFromTeam removes a user from the given team

func (*Store) Reset

func (s *Store) Reset(ctx context.Context)

Reset resets the account storage

func (*Store) SetUserPassword

func (s *Store) SetUserPassword(ctx context.Context, name string, password string) error

SetUserPassword sets the given user password

func (*Store) VerifyUser

func (s *Store) VerifyUser(ctx context.Context, userName string) error

VerifyUser verifies a user account

type Team

type Team struct {
	Name      string          `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
	CreateDt  int64           `protobuf:"varint,2,opt,name=create_dt,json=createDt" json:"create_dt,omitempty"`
	Owner     *Account        `protobuf:"bytes,3,opt,name=owner" json:"owner,omitempty"`
	Members   []string        `protobuf:"bytes,4,rep,name=members" json:"members,omitempty"`
	Resources []*TeamResource `protobuf:"bytes,5,rep,name=resources" json:"resources,omitempty"`
}

func (*Team) Descriptor

func (*Team) Descriptor() ([]byte, []int)

func (*Team) GetCreateDt

func (m *Team) GetCreateDt() int64

func (*Team) GetMembers

func (m *Team) GetMembers() []string

func (*Team) GetName

func (m *Team) GetName() string

func (*Team) GetOwner added in v0.12.0

func (m *Team) GetOwner() *Account

func (*Team) GetResources

func (m *Team) GetResources() []*TeamResource

func (*Team) ProtoMessage

func (*Team) ProtoMessage()

func (*Team) Reset

func (m *Team) Reset()

func (*Team) String

func (m *Team) String() string

func (*Team) Validate

func (t *Team) Validate() (err error)

Validate validates Team

type TeamPermissionLevel

type TeamPermissionLevel int32
const (
	TeamPermissionLevel_TEAM_READ  TeamPermissionLevel = 0
	TeamPermissionLevel_TEAM_WRITE TeamPermissionLevel = 1
	TeamPermissionLevel_TEAM_ADMIN TeamPermissionLevel = 2
)

func (TeamPermissionLevel) EnumDescriptor

func (TeamPermissionLevel) EnumDescriptor() ([]byte, []int)

func (TeamPermissionLevel) String

func (x TeamPermissionLevel) String() string

type TeamResource

type TeamResource struct {
	Id              string              `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
	PermissionLevel TeamPermissionLevel `` /* 134-byte string literal not displayed */
}

func (*TeamResource) Descriptor

func (*TeamResource) Descriptor() ([]byte, []int)

func (*TeamResource) GetId

func (m *TeamResource) GetId() string

func (*TeamResource) GetPermissionLevel

func (m *TeamResource) GetPermissionLevel() TeamPermissionLevel

func (*TeamResource) ProtoMessage

func (*TeamResource) ProtoMessage()

func (*TeamResource) Reset

func (m *TeamResource) Reset()

func (*TeamResource) String

func (m *TeamResource) String() string

type User

type User struct {
	Name         string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
	Email        string `protobuf:"bytes,2,opt,name=email" json:"email,omitempty"`
	PasswordHash []byte `protobuf:"bytes,3,opt,name=password_hash,json=passwordHash,proto3" json:"password_hash,omitempty"`
	IsVerified   bool   `protobuf:"varint,4,opt,name=is_verified,json=isVerified" json:"is_verified,omitempty"`
	CreateDt     int64  `protobuf:"varint,5,opt,name=create_dt,json=createDt" json:"create_dt,omitempty"`
	TokenUsed    bool   `protobuf:"varint,6,opt,name=token_used,json=tokenUsed" json:"token_used,omitempty"`
}

func (*User) Descriptor

func (*User) Descriptor() ([]byte, []int)

func (*User) GetCreateDt

func (m *User) GetCreateDt() int64

func (*User) GetEmail

func (m *User) GetEmail() string

func (*User) GetIsVerified

func (m *User) GetIsVerified() bool

func (*User) GetName

func (m *User) GetName() string

func (*User) GetPasswordHash

func (m *User) GetPasswordHash() []byte

func (*User) GetTokenUsed added in v0.9.1

func (m *User) GetTokenUsed() bool

func (*User) ProtoMessage

func (*User) ProtoMessage()

func (*User) Reset

func (m *User) Reset()

func (*User) String

func (m *User) String() string

func (*User) Validate

func (u *User) Validate() (err error)

Validate validates User

Jump to

Keyboard shortcuts

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