accounts

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2017 License: Apache-2.0 Imports: 16 Imported by: 28

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"
	OrganizationRN  = AmpResourceName + ":organization"
	TeamRN          = AmpResourceName + ":team"
	FunctionRN      = AmpResourceName + ":function"
	StackRN         = AmpResourceName + ":stack"

	CreateAction = "create"
	ReadAction   = "read"
	UpdateAction = "update"
	DeleteAction = "delete"
	AdminAction  = CreateAction + "|" + ReadAction + "|" + UpdateAction + "|" + DeleteAction
)

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

Errors

Variables

View Source
var AccountType_name = map[int32]string{
	0: "USER",
	1: "ORGANIZATION",
}
View Source
var AccountType_value = map[string]int32{
	"USER":         0,
	"ORGANIZATION": 1,
}
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 {
	Type AccountType `protobuf:"varint,1,opt,name=type,enum=accounts.AccountType" json:"type,omitempty"`
	Name string      `protobuf:"bytes,2,opt,name=name" json:"name,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) GetName

func (m *Account) GetName() string

func (*Account) GetType

func (m *Account) GetType() AccountType

func (*Account) ProtoMessage

func (*Account) ProtoMessage()

func (*Account) Reset

func (m *Account) Reset()

func (*Account) String

func (m *Account) String() string

type AccountType

type AccountType int32
const (
	AccountType_USER         AccountType = 0
	AccountType_ORGANIZATION AccountType = 1
)

func (AccountType) EnumDescriptor

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

func (AccountType) String

func (x AccountType) 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)

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

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

	// DeleteUser deletes a user by name
	DeleteUser(ctx context.Context, name string) (err 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, resourceName string) (err error)

	// RemoveResourceFromTeam removes a resource from the given team
	RemoveResourceFromTeam(ctx context.Context, organizationName string, teamName string, resourceName 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)

	// 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 store
	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 OrganizationAccessCondition

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

OrganizationAccessCondition is a condition which is fulfilled if the request's subject has the expected access in the organization (either by organization role or team access)

func (*OrganizationAccessCondition) Fulfills

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

Fulfills returns true if subject is granted resource access

func (*OrganizationAccessCondition) GetName

func (c *OrganizationAccessCondition) GetName() string

GetName returns the condition's name.

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 Store

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

Store implements user data.Interface

func NewStore

func NewStore(store storage.Interface) *Store

NewStore returns an etcd implementation of user.Interface

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

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, token string) (*User, 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"`
	Members   []string        `protobuf:"bytes,3,rep,name=members" json:"members,omitempty"`
	Resources []*TeamResource `protobuf:"bytes,4,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) 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 string `protobuf:"bytes,3,opt,name=password_hash,json=passwordHash" 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"`
}

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() string

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