From 725738f05a43a6f6aed63afc983aa6e018fc122a Mon Sep 17 00:00:00 2001 From: Tit Petric Date: Sun, 1 Jul 2018 00:10:26 +0200 Subject: [PATCH] small refactor rbac interfaces --- rbac/interfaces.go | 106 +++++++++++++++++++++++---------------------- rbac/interfaces.sh | 2 - 2 files changed, 54 insertions(+), 54 deletions(-) delete mode 100755 rbac/interfaces.sh diff --git a/rbac/interfaces.go b/rbac/interfaces.go index 51db4e181..720e46e73 100644 --- a/rbac/interfaces.go +++ b/rbac/interfaces.go @@ -1,66 +1,68 @@ package rbac -// Permissions is a stateful object -type Permissions interface /* for Session, User, Roles, Resource */ { - // Scoped for [Resource] - Grant(permission string) error - Revoke(permission string) error - List() ([]string, error) +type ( + // Permissions is a stateful object + Permissions interface /* for Session, User, Roles, Resource */ { + // Scoped for [Resource] + Grant(permission string) error + Revoke(permission string) error + List() ([]string, error) - // Check permission of stateful object (Session, User, Roles) - CheckAccess(permission string) (bool, error) -} + // Check permission of stateful object (Session, User, Roles) + CheckAccess(permission string) (bool, error) + } -// Roles is a stateful object -type Roles interface /* for Session, User */ { - // Scoped to User - Add(role string) error - Delete(role string) error + // Roles is a stateful object + Roles interface /* for Session, User */ { + // Scoped to User + Add(role string) error + Delete(role string) error - // Scoped to Session, User - List() ([]string, error) - ListAuthorized() ([]string, error) + // Scoped to Session, User + List() ([]string, error) + ListAuthorized() ([]string, error) - // Scoped to Session - GrantRole(role string) error - RevokeRole(role string) error + // Scoped to Session + GrantRole(role string) error + RevokeRole(role string) error - // Permissions are scoped to [Session, User] - Permissions(role string) Permissions -} + // Permissions are scoped to [Session, User] + Permissions(role string) Permissions + } -// Session object holds session state (Create, Load) -type Session interface { - // Unscoped functions - Create(userID string, roles ...string) error - Load(sessionID string) error - Delete() error + // Session object holds session state (Create, Load) + Session interface { + // Unscoped functions + Create(userID string, roles ...string) error + Load(sessionID string) error + Delete() error - // User returns User scoped object with global roles/permissions - User() (User, error) + // User returns User scoped object with global roles/permissions + User() (User, error) - // Roles and Permissions return session scoped objects - Roles() Roles - Permissions() Permissions -} + // Roles and Permissions return session scoped objects + Roles() Roles + Permissions() Permissions + } -// Resource is a static object -type Resource interface { - Load(resource string) error - Create(resource string) error - Delete(resource string) error + // Resource is a static object + Resource interface { + Load(resource string) error + Create(resource string) error + Delete(resource string) error - RolePermissions(resource string, role string) Permissions - UserPermissions(resource string, user string) Permissions -} + RolePermissions(resource string, role string) Permissions + UserPermissions(resource string, user string) Permissions + } -// Users is a static object -type User interface { - Load(user string) error - Create(user string) error - Delete(user string) error + // Users is a static object + User interface { + Load(user string) error + Create(user string) error + Delete(user string) error - // Roles and Permissions return User scoped objects - Roles(user string) Roles - Permissions(user string) Permissions -} + // Roles and Permissions return User scoped objects + Roles(user string) Roles + Permissions(user string) Permissions + } +) diff --git a/rbac/interfaces.sh b/rbac/interfaces.sh deleted file mode 100755 index 5c5c95263..000000000 --- a/rbac/interfaces.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -echo $(echo $(sed -n 's/^\(type \|\s*\)\([A-Z][^[:space:]]*\) interface .*/\2/p' "interfaces.go") | tr ' ' ',')