auth

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2025 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const (
	AcceptedRegistrationStatus = "accepted"
	PendingRegistrationStatus  = "pending"
	DeclinedRegistrationStatus = "declined"
)

Variables

This section is empty.

Functions

func AppendToACL

func AppendToACL(ctx context.Context, 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(ctx context.Context, 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(ctx context.Context, 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(ctx context.Context, projectUUID string, token string, store stores.Store) ([]string, string)

Authenticate based on token

func Authorize

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

Authorize based on resource and role information

func DeleteUserRegistration

func DeleteUserRegistration(ctx context.Context, regUUID string, str stores.Store) error

DeleteUserRegistration removes the respective registration from the store based on the given uuid

func ExistsWithName

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

ExistsWithName returns true if a user with name exists

func ExistsWithUUID

func ExistsWithUUID(ctx context.Context, 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(ctx context.Context, 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(ctx context.Context, name string, store stores.Store) string

GetUUIDByName queries user by name and returns the corresponding UUID

func IsAdminViewer

func IsAdminViewer(roles []string) bool

IsAdminViewer checks if the user is an admon viewer

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(ctx context.Context, projectUUID string, resourceType string, resourceName string, acl []string, store stores.Store) error

ModACL is called to modify an acl

func PerResource

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

PerResource (for topics and subscriptions)

func RemoveFromACL

func RemoveFromACL(ctx context.Context, 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(ctx context.Context, uuid string, store stores.Store) error

RemoveUser removes an existing user

func UpdateUserRegistration

func UpdateUserRegistration(ctx context.Context, regUUID, status, declineComment, modifiedBy string, modifiedAt time.Time, refStr stores.Store) error

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(ctx context.Context, 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     int64  `json:"totalSize"`
}

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

func PaginatedFindUsers

func PaginatedFindUsers(ctx context.Context, pageToken string, pageSize int64, projectUUID string, privileged, detailedView 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,omitempty"`
	Name         string         `json:"name"`
	FirstName    string         `json:"first_name,omitempty"`
	LastName     string         `json:"last_name,omitempty"`
	Organization string         `json:"organization,omitempty"`
	Description  string         `json:"description,omitempty"`
	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(ctx context.Context, uuid string, name string, fname string, lname string, org string, desc 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(ctx context.Context, pwToken string, store stores.Store) (User, error)

GetPushWorker returns a push worker user by token

func GetUserByToken

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

GetUserByToken returns a specific user by his token

func GetUserByUUID

func GetUserByUUID(ctx context.Context, 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, fname string, lname string, org string, desc 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(ctx context.Context, uuid, firstName, lastName, organization, description string, name string, projectList []ProjectRoles, email string, serviceRoles []string, modifiedOn time.Time, reflectObj bool, store stores.Store) (User, error)

UpdateUser updates an existing user's information IF the function caller needs to have a view on the updated user object it can set the reflectObj to true

func UpdateUserToken

func UpdateUserToken(ctx context.Context, 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 UserRegistration

type UserRegistration struct {
	UUID            string `json:"uuid"`
	Name            string `json:"name"`
	FirstName       string `json:"first_name"`
	LastName        string `json:"last_name"`
	Organization    string `json:"organization"`
	Description     string `json:"description"`
	Email           string `json:"email"`
	Status          string `json:"status"`
	DeclineComment  string `json:"decline_comment,omitempty"`
	ActivationToken string `json:"activation_token,omitempty"`
	RegisteredAt    string `json:"registered_at"`
	ModifiedBy      string `json:"modified_by,omitempty"`
	ModifiedAt      string `json:"modified_at,omitempty"`
}

UserRegistration holds information about a new user registration

func FindUserRegistration

func FindUserRegistration(ctx context.Context, regUUID, status string, str stores.Store) (UserRegistration, error)

func RegisterUser

func RegisterUser(ctx context.Context, uuid, name, fname, lname, email, org, desc, registeredAt, atkn, status string, str stores.Store) (UserRegistration, error)

RegisterUser registers a new user to the store

type UserRegistrationsList

type UserRegistrationsList struct {
	UserRegistrations []UserRegistration `json:"user_registrations"`
}

UserRegistrationsList holds a list with all the user registrations in the service

func FindUserRegistrations

func FindUserRegistrations(ctx context.Context, status, activationToken, name, email, org string, str stores.Store) (UserRegistrationsList, error)

type Users

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

Users holds a list of available users

func FindUsers

func FindUsers(ctx context.Context, 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