auth

package
v1.0.6-1 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2020 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendToACL

func AppendToACL(projectUUID string, resourceType string, resourceName string, acl []string, store stores.Store) error

AppendToACL is used to append unique users to a topic's or sub's ACL

func AppendToUserProjects

func AppendToUserProjects(userUUID string, projectUUID string, store stores.Store, pRoles ...string) error

AppendToUserProjects appends a unique project to the user's project list

func AreValidUsers

func AreValidUsers(projectUUID string, users []string, store stores.Store) (bool, error)

AreValidUsers accepts a user array of usernames and checks if users exist in the store

func Authenticate

func Authenticate(projectUUID string, token string, store stores.Store) ([]string, string)

Authenticate based on token

func Authorize

func Authorize(resource string, roles []string, store stores.Store) bool

Authorize based on resource and role information

func ExistsWithName

func ExistsWithName(name string, store stores.Store) bool

ExistsWithName returns true if a user with name exists

func ExistsWithUUID

func ExistsWithUUID(uuid string, store stores.Store) bool

ExistsWithUUID return true if a user with uuid exists

func GenToken

func GenToken() (string, error)

GenToken generates a new token

func GetNameByUUID

func GetNameByUUID(uuid string, store stores.Store) string

GetNameByUUID queries user by UUID and returns the user's name. If not found, returns an empty string

func GetUUIDByName

func GetUUIDByName(name string, store stores.Store) string

GetUUIDByName queries user by name and returns the corresponding UUID

func IsConsumer

func IsConsumer(roles []string) bool

IsConsumer Checks if a user is consumer

func IsProjectAdmin

func IsProjectAdmin(roles []string) bool

IsProjectAdmin checks if the user is a project admin

func IsPublisher

func IsPublisher(roles []string) bool

IsPublisher Checks if a user is publisher

func IsPushWorker

func IsPushWorker(roles []string) bool

IsPushWorker Checks if a user is a push worker

func IsRoleValid

func IsRoleValid(role string, validRoles []string) bool

IsRoleValid checks if a role is a valid against a list of valid roles

func IsServiceAdmin

func IsServiceAdmin(roles []string) bool

IsServiceAdmin checks if the user is a service admin

func ModACL

func ModACL(projectUUID string, resourceType string, resourceName string, acl []string, store stores.Store) error

ModACL is called to modify an acl

func PerResource

func PerResource(project string, resType string, resName string, userUUID string, store stores.Store) bool

PerResource (for topics and subscriptions)

func RemoveFromACL

func RemoveFromACL(projectUUID string, resourceType string, resourceName string, acl []string, store stores.Store) error

AppendToACL is used to remove users from a topic's or sub's acl

func RemoveUser

func RemoveUser(uuid string, store stores.Store) error

RemoveUser removes an existing user

Types

type ACL

type ACL struct {
	AuthUsers []string `json:"authorized_users"`
}

ACL holds the authorized users for a resource (topic/subscription)

func GetACL

func GetACL(projectUUID string, resourceType string, resourceName string, store stores.Store) (ACL, error)

GetACL returns an authorized list of user for the resource (topic or subscription)

func GetACLFromJSON

func GetACLFromJSON(input []byte) (ACL, error)

GetACLFromJSON retrieves ACL info from JSON

func (*ACL) ExportJSON

func (acl *ACL) ExportJSON() (string, error)

ExportJSON export topic acl body to json for use in http response

type PaginatedUsers

type PaginatedUsers struct {
	Users         []User `json:"users"`
	NextPageToken string `json:"nextPageToken"`
	TotalSize     int32  `json:"totalSize"`
}

PaginatedUsers holds information about a users' page and how to access the next page

func PaginatedFindUsers

func PaginatedFindUsers(pageToken string, pageSize int32, projectUUID string, priviledged bool, store stores.Store) (PaginatedUsers, error)

PaginatedFindUsers returns a page of users

func (*PaginatedUsers) ExportJSON

func (pus *PaginatedUsers) ExportJSON() (string, error)

ExportJSON exports Paginated users list to json format

type ProjectRoles

type ProjectRoles struct {
	Project string   `json:"project"`
	Roles   []string `json:"roles"`
	Topics  []string `json:"topics"`
	Subs    []string `json:"subscriptions"`
}

ProjectRoles is the struct that hold project and role information of the user

type User

type User struct {
	UUID         string         `json:"uuid"`
	Projects     []ProjectRoles `json:"projects"`
	Name         string         `json:"name"`
	Token        string         `json:"token,omitempty"`
	Email        string         `json:"email"`
	ServiceRoles []string       `json:"service_roles"`
	CreatedOn    string         `json:"created_on,omitempty"`
	ModifiedOn   string         `json:"modified_on,omitempty"`
	CreatedBy    string         `json:"created_by,omitempty"`
}

User is the struct that holds user information

func CreateUser

func CreateUser(uuid string, name string, projectList []ProjectRoles, token string, email string, serviceRoles []string, createdOn time.Time, createdBy string, store stores.Store) (User, error)

CreateUser creates a new user

func GetPushWorker

func GetPushWorker(pwToken string, store stores.Store) (User, error)

GetPushWorker returns a push worker user by token

func GetUserByToken

func GetUserByToken(token string, store stores.Store) (User, error)

GetUserByToken returns a specific user by his token

func GetUserByUUID

func GetUserByUUID(uuid string, store stores.Store) (User, error)

GetUserByUUID returns user information by UUID

func GetUserFromJSON

func GetUserFromJSON(input []byte) (User, error)

GetUserFromJSON retrieves User info From JSON string

func NewUser

func NewUser(uuid string, projects []ProjectRoles, name string, token string, email string, serviceRoles []string, createdOn time.Time, modifiedOn time.Time, createdBy string) User

NewUser accepts parameters and creates a new user

func UpdateUser

func UpdateUser(uuid string, name string, projectList []ProjectRoles, email string, serviceRoles []string, modifiedOn time.Time, store stores.Store) (User, error)

UpdateUser updates an existing user's information

func UpdateUserToken

func UpdateUserToken(uuid string, token string, store stores.Store) (User, error)

UpdateUserToken updates an existing user's token

func (*User) ExportJSON

func (u *User) ExportJSON() (string, error)

ExportJSON exports User to json format

type Users

type Users struct {
	List []User `json:"users,omitempty"`
}

Users holds a list of available users

func FindUsers

func FindUsers(projectUUID string, uuid string, name string, priviledged bool, store stores.Store) (Users, error)

FindUsers returns a specific user or a list of all available users belonging to a project in the datastore.

func (*Users) Empty

func (us *Users) Empty() bool

Empty returns true if users list is empty

func (*Users) ExportJSON

func (us *Users) ExportJSON() (string, error)

ExportJSON exports Users list to json format

func (*Users) One

func (us *Users) One() User

One returns the first user if a user list is not empty

Jump to

Keyboard shortcuts

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