authorizer

package
v0.9.1-rc.6 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2022 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package authorizer is a hard coded package that contains the roles, actions, permissions and function related to ShellHub's API.

Index

Constants

View Source
const (
	MemberRoleObserver      = "observer"
	MemberRoleOperator      = "operator"
	MemberRoleAdministrator = "administrator"
	MemberRoleOwner         = "owner"
)
View Source
const (
	DeviceAccept = iota
	DeviceReject
	DeviceRemove
	DeviceConnect
	DeviceRename
	DeviceDetails

	DeviceCreateTag
	DeviceUpdateTag
	DeviceRemoveTag
	DeviceRenameTag
	DeviceDeleteTag

	SessionPlay
	SessionClose
	SessionRemove
	SessionDetails

	FirewallCreate
	FirewallEdit
	FirewallRemove

	FirewallAddTag
	FirewallRemoveTag
	FirewallUpdateTag

	PublicKeyCreate
	PublicKeyEdit
	PublicKeyRemove

	PublicKeyAddTag
	PublicKeyRemoveTag
	PublicKeyUpdateTag

	NamespaceRename
	NamespaceAddMember
	NamespaceRemoveMember
	NamespaceEditMember
	NamespaceEnableSessionRecord
	NamespaceDelete

	BillingChooseDevices
	BillingAddPaymentMethod
	BillingUpdatePaymentMethod
	BillingRemovePaymentMethod
	BillingCancelSubscription
	BillingCreateSubscription
	BillingGetPaymentMethod
	BillingGetSubscription
)

Variables

View Source
var Actions = actions{
	Device: deviceActions{
		Accept:    DeviceAccept,
		Reject:    DeviceReject,
		Remove:    DeviceRemove,
		Connect:   DeviceConnect,
		Rename:    DeviceRename,
		CreateTag: DeviceCreateTag,
		UpdateTag: DeviceUpdateTag,
		RemoveTag: DeviceRemoveTag,
		RenameTag: DeviceRenameTag,
		DeleteTag: DeviceDeleteTag,
	},
	Session: sessionActions{
		Play:    SessionPlay,
		Close:   SessionClose,
		Remove:  SessionRemove,
		Details: SessionDetails,
	},
	Firewall: firewallActions{
		Create: FirewallCreate,
		Edit:   FirewallEdit,
		Remove: FirewallRemove,
	},
	PublicKey: publicKeyActions{
		Create:    PublicKeyCreate,
		Edit:      PublicKeyEdit,
		Remove:    PublicKeyRemove,
		AddTag:    PublicKeyAddTag,
		RemoveTag: PublicKeyRemoveTag,
		UpdateTag: PublicKeyUpdateTag,
	},
	Namespace: namespaceActions{
		Rename:              NamespaceRename,
		AddMember:           NamespaceAddMember,
		RemoveMember:        NamespaceRemoveMember,
		EditMember:          NamespaceEditMember,
		EnableSessionRecord: NamespaceEnableSessionRecord,
		Delete:              NamespaceDelete,
	},
	Billing: billingActions{
		ChooseDevices:       BillingChooseDevices,
		AddPaymentMethod:    BillingAddPaymentMethod,
		UpdatePaymentMethod: BillingUpdatePaymentMethod,
		RemovePaymentMethod: BillingRemovePaymentMethod,
		CancelSubscription:  BillingCancelSubscription,
		CreateSubscription:  BillingCreateSubscription,
		GetSubscription:     BillingGetSubscription,
	},
}

Actions has all available and allowed actions. You should use it to get the code's action.

Functions

func CheckPermission

func CheckPermission(userRole string, action int) bool

CheckPermission checks if the user's role has the permission to execute an action.

func CheckRole

func CheckRole(firstRole, secondRole string) bool

CheckRole checks if the first role has a great value than second.

func GetRoleCode

func GetRoleCode(role string) int

GetRoleCode converts a member's role to an int.

Types

type Action

type Action int

type Permissions

type Permissions []int

Jump to

Keyboard shortcuts

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